ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
WindFarm Class Reference

Manage a collection of wind turbine models. More...

#include <ERF_WindFarm.H>

Inheritance diagram for WindFarm:
Collaboration diagram for WindFarm:

Public Member Functions

 WindFarm ()
 
virtual ~WindFarm ()=default
 
 WindFarm (int nlev, const WindFarmType &a_windfarm_type)
 
void read_tables (std::string windfarm_loc_table, std::string windfarm_spec_table, bool x_y, bool lat_lon, const amrex::Real windfarm_x_shift=zero, const amrex::Real windfarm_y_shift=zero)
 Read turbine location and specification tables. More...
 
void init_windfarm_lat_lon (const std::string windfarm_loc_table, const amrex::Real windfarm_x_shift, const amrex::Real windfarm_y_shift)
 Initialize wind farm using latitude and longitude coordinates. More...
 
void init_windfarm_x_y (const std::string windfarm_loc_table)
 Initialize wind farm using Cartesian coordinates. More...
 
void read_windfarm_locations_table (const std::string windfarm_loc_table, bool x_y, bool lat_lon, const amrex::Real windfarm_x_shift=zero, const amrex::Real windfarm_y_shift=zero)
 Read the turbine location table. More...
 
void read_windfarm_spec_table (const std::string windfarm_spec_table)
 Read the turbine specification table. More...
 
void read_windfarm_blade_table (const std::string windfarm_blade_table)
 Read the turbine blade table. More...
 
void read_windfarm_airfoil_tables (const std::string windfarm_airfoil_tables, const std::string windfarm_blade_table)
 Read the airfoil tables. More...
 
void read_windfarm_spec_table_extra (const std::string windfarm_spec_table_extra)
 Read extra turbine specifications. More...
 
void fill_Nturb_multifab (const amrex::Geometry &geom, amrex::MultiFab &mf_Nturb, std::unique_ptr< amrex::MultiFab > &z_phys_nd, bool set_zloc)
 Fill the turbine count MultiFab. More...
 
void fill_SMark_multifab (const amrex::Geometry &geom, amrex::MultiFab &mf_SMark, const amrex::Real &sampling_distance_by_D, const amrex::Real &turb_disk_angle, std::unique_ptr< amrex::MultiFab > &z_phys_cc)
 Fill the SMark MultiFab. More...
 
void fill_SMark_multifab_mesoscale_models (const amrex::Geometry &geom, amrex::MultiFab &mf_SMark, const amrex::MultiFab &mf_Nturb, std::unique_ptr< amrex::MultiFab > &z_phys_cc, const std::unique_ptr< amrex::MultiFab > &z_sfc_nd)
 Fill the SMark MultiFab for mesoscale models. More...
 
void write_turbine_locations_vtk ()
 Write turbine locations to a VTK file. More...
 
void write_actuator_disks_vtk (const amrex::Geometry &geom, const amrex::Real &sampling_distance_by_D)
 Write actuator disks to a VTK file. More...
 
void advance (const amrex::Geometry &a_geom, const double &dt_advance, amrex::MultiFab &cons_in, amrex::MultiFab &mf_vars_windfarm, amrex::MultiFab &U_old, amrex::MultiFab &V_old, amrex::MultiFab &W_old, const amrex::MultiFab &mf_Nturb, const amrex::MultiFab &mf_SMark, const amrex::MultiFab *z_phys_nd, const amrex::MultiFab *z_phys_cc, const double &time) override
 Advance the wind farm model in time. More...
 
void set_turb_spec (const amrex::Real &a_rotor_rad, const amrex::Real &a_hub_height, const amrex::Real &a_thrust_coeff_standing, const amrex::Vector< amrex::Real > &a_wind_speed, const amrex::Vector< amrex::Real > &a_thrust_coeff, const amrex::Vector< amrex::Real > &a_power) override
 Set general turbine specifications. More...
 
void set_turb_loc (const amrex::Vector< amrex::Real > &a_xloc, const amrex::Vector< amrex::Real > &a_yloc) override
 Set turbine locations. More...
 
void set_turb_zloc (const amrex::Vector< amrex::Real > &a_zloc) override
 Set the ground elevation under each turbine. More...
 
void set_turb_disk_angle (const amrex::Real &a_turb_disk_angle) override
 Set the turbine disk angle. More...
 
void set_blade_spec (const amrex::Vector< amrex::Real > &a_bld_rad_loc, const amrex::Vector< amrex::Real > &a_bld_twist, const amrex::Vector< amrex::Real > &a_bld_chord) override
 Set blade specifications. More...
 
void set_blade_airfoil_spec (const amrex::Vector< amrex::Vector< amrex::Real >> &a_bld_airfoil_aoa, const amrex::Vector< amrex::Vector< amrex::Real >> &a_bld_airfoil_Cl, const amrex::Vector< amrex::Vector< amrex::Real >> &a_bld_airfoil_Cd) override
 Set blade airfoil specifications. More...
 
void set_turb_spec_extra (const amrex::Vector< amrex::Real > &a_velocity, const amrex::Vector< amrex::Real > &a_C_P, const amrex::Vector< amrex::Real > &a_C_T, const amrex::Vector< amrex::Real > &a_rotor_RPM, const amrex::Vector< amrex::Real > &a_blade_pitch) override
 Set extra turbine specifications. More...
 
- Public Member Functions inherited from NullWindFarm
 NullWindFarm ()
 
virtual ~NullWindFarm ()=default
 
void get_turb_spec (amrex::Real &rotor_rad, amrex::Real &hub_height, amrex::Real &thrust_coeff_standing, amrex::Vector< amrex::Real > &wind_speed, amrex::Vector< amrex::Real > &thrust_coeff, amrex::Vector< amrex::Real > &power)
 
void get_turb_loc (amrex::Vector< amrex::Real > &xloc, amrex::Vector< amrex::Real > &yloc)
 
void get_turb_disk_angle (amrex::Real &turb_disk_angle)
 
void get_blade_spec (amrex::Vector< amrex::Real > &bld_rad_loc, amrex::Vector< amrex::Real > &bld_twist, amrex::Vector< amrex::Real > &bld_chord)
 
void get_blade_airfoil_spec (amrex::Vector< amrex::Vector< amrex::Real >> &bld_airfoil_aoa, amrex::Vector< amrex::Vector< amrex::Real >> &bld_airfoil_Cl, amrex::Vector< amrex::Vector< amrex::Real >> &bld_airfoil_Cd)
 
void get_turb_spec_extra (amrex::Vector< amrex::Real > &velocity, amrex::Vector< amrex::Real > &C_P, amrex::Vector< amrex::Real > &C_T, amrex::Vector< amrex::Real > &rotor_RPM, amrex::Vector< amrex::Real > &blade_pitch)
 

Protected Member Functions

template<class NewWindFarmModel >
void SetModel ()
 Create and set the specified windfarm model. More...
 

Protected Attributes

amrex::Vector< amrex::Real > xloc
 
amrex::Vector< amrex::Real > yloc
 
amrex::Vector< amrex::Real > zloc
 
amrex::Real my_turb_disk_angle
 
amrex::Real hub_height
 
amrex::Real rotor_rad
 
amrex::Real thrust_coeff_standing
 
amrex::Real nominal_power
 
amrex::Vector< amrex::Real > wind_speed
 
amrex::Vector< amrex::Real > thrust_coeff
 
amrex::Vector< amrex::Real > power
 
amrex::Vector< amrex::Real > bld_rad_loc
 
amrex::Vector< amrex::Real > bld_twist
 
amrex::Vector< amrex::Real > bld_chord
 
amrex::Vector< amrex::Vector< amrex::Real > > bld_airfoil_aoa
 
amrex::Vector< amrex::Vector< amrex::Real > > bld_airfoil_Cl
 
amrex::Vector< amrex::Vector< amrex::Real > > bld_airfoil_Cd
 
int n_bld_sections
 
amrex::Vector< amrex::Real > velocity
 
amrex::Vector< amrex::Real > C_P
 
amrex::Vector< amrex::Real > C_T
 
amrex::Vector< amrex::Real > rotor_RPM
 
amrex::Vector< amrex::Real > blade_pitch
 
- Protected Attributes inherited from NullWindFarm
amrex::Vector< amrex::Real > m_xloc
 
amrex::Vector< amrex::Real > m_yloc
 
amrex::Vector< amrex::Real > m_zloc
 
amrex::Real m_turb_disk_angle
 
amrex::Real m_hub_height
 
amrex::Real m_rotor_rad
 
amrex::Real m_thrust_coeff_standing
 
amrex::Real m_nominal_power
 
amrex::Vector< amrex::Real > m_wind_speed
 
amrex::Vector< amrex::Real > m_thrust_coeff
 
amrex::Vector< amrex::Real > m_power
 
amrex::Vector< amrex::Real > m_bld_rad_loc
 
amrex::Vector< amrex::Real > m_bld_twist
 
amrex::Vector< amrex::Real > m_bld_chord
 
amrex::Vector< amrex::Vector< amrex::Real > > m_bld_airfoil_aoa
 
amrex::Vector< amrex::Vector< amrex::Real > > m_bld_airfoil_Cl
 
amrex::Vector< amrex::Vector< amrex::Real > > m_bld_airfoil_Cd
 
amrex::Vector< amrex::Real > m_velocity
 
amrex::Vector< amrex::Real > m_C_P
 
amrex::Vector< amrex::Real > m_C_T
 
amrex::Vector< amrex::Real > m_rotor_RPM
 
amrex::Vector< amrex::Real > m_blade_pitch
 

Private Attributes

amrex::Vector< std::unique_ptr< NullWindFarm > > m_windfarm_model
 

Additional Inherited Members

- Static Public Member Functions inherited from NullWindFarm
static AMREX_GPU_DEVICE bool find_if_marked (amrex::Real x1, amrex::Real x2, amrex::Real y1, amrex::Real y2, amrex::Real x0, amrex::Real y0, amrex::Real nx, amrex::Real ny, amrex::Real d_hub_height, amrex::Real d_rotor_rad, amrex::Real z)
 

Detailed Description

Manage a collection of wind turbine models.

Constructor & Destructor Documentation

◆ WindFarm() [1/2]

WindFarm::WindFarm ( )
inline
21 {}

◆ ~WindFarm()

virtual WindFarm::~WindFarm ( )
virtualdefault

◆ WindFarm() [2/2]

WindFarm::WindFarm ( int  nlev,
const WindFarmType &  a_windfarm_type 
)
inline
27  {
28  m_windfarm_model.resize(nlev);
29  if (a_windfarm_type == WindFarmType::Fitch) {
30  SetModel<Fitch>();
31  amrex::Print() << "Fitch windfarm model!\n";
32  }
33  else if (a_windfarm_type == WindFarmType::EWP) {
34  SetModel<EWP>();
35  amrex::Print() << "EWP windfarm model!\n";
36  }
37  else if (a_windfarm_type == WindFarmType::SimpleAD) {
38  SetModel<SimpleAD>();
39  amrex::Print() << "Simplified actuator disk windfarm model!\n";
40  }
41  else if (a_windfarm_type == WindFarmType::GeneralAD) {
42  SetModel<GeneralAD>();
43  amrex::Print() << "Generalized actuator disk windfarm model!\n";
44  }
45  else {
46  amrex::Abort("WindFarm: Dont know this windfarm_type!") ;
47  }
48  }
amrex::Vector< std::unique_ptr< NullWindFarm > > m_windfarm_model
Definition: ERF_WindFarm.H:319

Member Function Documentation

◆ advance()

void WindFarm::advance ( const amrex::Geometry &  a_geom,
const double &  dt_advance,
amrex::MultiFab &  cons_in,
amrex::MultiFab &  mf_vars_windfarm,
amrex::MultiFab &  U_old,
amrex::MultiFab &  V_old,
amrex::MultiFab &  W_old,
const amrex::MultiFab &  mf_Nturb,
const amrex::MultiFab &  mf_SMark,
const amrex::MultiFab *  z_phys_nd,
const amrex::MultiFab *  z_phys_cc,
const double &  time 
)
inlineoverridevirtual

Advance the wind farm model in time.

Parameters
[in]a_geomGeometry
[in]dt_advanceTimestep.
[in,out]cons_inConservative variables.
[in,out]mf_vars_windfarmWind farm variables MultiFab.
[in,out]U_oldOld x-velocity MultiFab.
[in,out]V_oldOld y-velocity MultiFab.
[in,out]W_oldOld z-velocity MultiFab.
[in]mf_NturbTurbine count MultiFab.
[in]mf_SMarkSMark MultiFab.
[in]z_phys_ndPhysical heights of the nodes (may be null).
[in]z_phys_ccPhysical heights of the cell centers (may be null).
[in]timeCurrent simulation time.

Implements NullWindFarm.

202  {
203  m_windfarm_model[0]->advance(a_geom, dt_advance, cons_in, mf_vars_windfarm,
204  U_old, V_old, W_old, mf_Nturb, mf_SMark,
205  z_phys_nd, z_phys_cc, time);
206  }

◆ fill_Nturb_multifab()

void WindFarm::fill_Nturb_multifab ( const amrex::Geometry &  geom,
amrex::MultiFab &  mf_Nturb,
std::unique_ptr< amrex::MultiFab > &  z_phys_nd,
bool  set_zloc 
)

Fill the turbine count MultiFab.

Parameters
[in]geomGeometry
[out]mf_NturbMultiFab to fill with turbine counts.
[in,out]z_phys_ndPhysical height MultiFab.
[in]set_zlocAlso set the ground elevation under each turbine (zloc) and check that every turbine in the domain is counted once: true on level 0 only, which covers the domain; the ground under a turbine does not depend on the level.

Fill a MultiFab with the number of turbines per cell and determine base heights.

Parameters
[in]geomGeometry defining the domain.
[in,out]mf_NturbMultiFab to be filled with turbine counts per cell.
[in]z_phys_ndNode-centered physical height FAB.
465 {
466  // zloc is set from level 0 only. assign, not resize: resize keeps the previous values,
467  // which the sums below would then add to.
468  if (set_zloc) { zloc.assign(xloc.size(), zero); }
469  Vector<int> is_counted;
470  is_counted.resize(xloc.size(),0);
471 
472  amrex::Gpu::DeviceVector<Real> d_xloc(xloc.size());
473  amrex::Gpu::DeviceVector<Real> d_yloc(yloc.size());
474  amrex::Gpu::DeviceVector<Real> d_zloc(xloc.size());
475  amrex::Gpu::DeviceVector<int> d_is_counted(xloc.size());
476  amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, xloc.begin(), xloc.end(), d_xloc.begin());
477  amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, yloc.begin(), yloc.end(), d_yloc.begin());
478  amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, zloc.begin(), zloc.end(), d_zloc.begin());
479  amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, is_counted.begin(), is_counted.end(), d_is_counted.begin());
480 
481  Real* d_xloc_ptr = d_xloc.data();
482  Real* d_yloc_ptr = d_yloc.data();
483  Real* d_zloc_ptr = d_zloc.data();
484  int* d_is_counted_ptr = d_is_counted.data();
485 
486  mf_Nturb.setVal(0);
487 
488  int i_lo = geom.Domain().smallEnd(0); int i_hi = geom.Domain().bigEnd(0);
489  int j_lo = geom.Domain().smallEnd(1); int j_hi = geom.Domain().bigEnd(1);
490  auto dx = geom.CellSizeArray();
491  if(dx[0]<= 1e-3 or dx[1]<=1e-3 or dx[2]<= 1e-3) {
492  Abort("The value of grid spacing for wind farm parametrization cannot be less than 1e-3 m. "
493  "It should be usually of order 1 m");
494  }
495  auto ProbLoArr = geom.ProbLoArray();
496  auto ProbHiArr = geom.ProbHiArray();
497  int num_turb = xloc.size();
498 
499  bool is_terrain = z_phys_nd ? true: false;
500  const bool find_zloc = is_terrain && set_zloc;
501 
502  // The ground is at the bottom of the domain, not at the bottom of each box --
503  // these differ for every box that doesn't touch the ground, which happens
504  // whenever the grids are decomposed in the vertical direction
505  const int k0 = geom.Domain().smallEnd(2);
506 
507  // Initialize wind farm
508  for ( MFIter mfi(mf_Nturb,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
509  const Box& bx = mfi.tilebox();
510  auto Nturb_array = mf_Nturb.array(mfi);
511  // Read only when is_terrain, so leave it empty when there is no z_phys_nd
512  const Array4<const Real> z_nd_arr = (is_terrain) ? z_phys_nd->const_array(mfi) : Array4<const Real>{};
513  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
514  int li = amrex::min(amrex::max(i, i_lo), i_hi);
515  int lj = amrex::min(amrex::max(j, j_lo), j_hi);
516 
517  Real x1 = ProbLoArr[0] + li*dx[0];
518  Real x2 = ProbLoArr[0] + (li+1)*dx[0];
519  Real y1 = ProbLoArr[1] + lj*dx[1];
520  Real y2 = ProbLoArr[1] + (lj+1)*dx[1];
521 
522  for(int it=0; it<num_turb; it++){
523  if( d_xloc_ptr[it]+1e-3 > x1 and d_xloc_ptr[it]+1e-3 < x2 and
524  d_yloc_ptr[it]+1e-3 > y1 and d_yloc_ptr[it]+1e-3 < y2){
525  Nturb_array(i,j,k,0) = Nturb_array(i,j,k,0) + 1;
526  //
527  // Only the cell at the bottom of the domain counts this turbine and
528  // stores its surface elevation. d_is_counted is a per-rank array
529  // which is summed over all ranks below, so if we counted at every k
530  // then a column spread over more than one rank (which happens when
531  // the grids are decomposed in z) would be counted more than once.
532  //
533  if (find_zloc and k == k0) {
534  int expected = 0;
535  int desired = 1;
536  // Atomic Compare-And-Swap: Increment only if d_is_counted_ptr[it] was 0
537  if (Gpu::Atomic::CAS(&d_is_counted_ptr[it], expected, desired) == expected) {
538  // The current thread successfully set d_is_counted_ptr[it] from 0 to 1
539  Gpu::Atomic::Add(&d_zloc_ptr[it], z_nd_arr(i, j, k0));
540  }
541  }
542  }
543  }
544  });
545  }
546 
547  mf_Nturb.FillBoundary(geom.periodicity());
548 
549  if (!set_zloc) { return; }
550 
551  Gpu::copy(Gpu::deviceToHost, d_zloc.begin(), d_zloc.end(), zloc.begin());
552  Gpu::copy(Gpu::deviceToHost, d_is_counted.begin(), d_is_counted.end(), is_counted.begin());
553 
554  amrex::ParallelAllReduce::Sum(zloc.data(),
555  zloc.size(),
556  amrex::ParallelContext::CommunicatorAll());
557 
558  amrex::ParallelAllReduce::Sum(is_counted.data(),
559  is_counted.size(),
560  amrex::ParallelContext::CommunicatorAll());
561 
563 
564  for(int it=0;it<num_turb;it++) {
565  if(is_terrain and
566  xloc[it] > ProbLoArr[0] and
567  xloc[it] < ProbHiArr[0] and
568  yloc[it] > ProbLoArr[1] and
569  yloc[it] < ProbHiArr[1] ) {
570  if(is_counted[it] != 1) {
571  Abort("Wind turbine " + std::to_string(it) + "has been counted " + std::to_string(is_counted[it]) + " times" +
572  " It should have been counted only once. Aborting....");
573  }
574  }
575  }
576 
577  // Debugging
578  /*int my_rank = amrex::ParallelDescriptor::MyProc();
579 
580  for(int it=0;it<num_turb;it++) {
581  std::cout << "The value of zloc is " << my_rank << " " << zloc[it] << " " << is_counted[it] << "\n";
582  }*/
583 }
GpuArray< Real, AMREX_SPACEDIM > dx
Definition: ERF_ActuatorSpreading.cpp:131
ParallelFor(fab_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) { qrcuten_arr(i, j, k)=Real(0);qscuten_arr(i, j, k)=Real(0);qicuten_arr(i, j, k)=Real(0);})
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
amrex::Vector< amrex::Real > yloc
Definition: ERF_WindFarm.H:300
amrex::Vector< amrex::Real > zloc
Definition: ERF_WindFarm.H:300
void set_turb_zloc(const amrex::Vector< amrex::Real > &a_zloc) override
Set the ground elevation under each turbine.
Definition: ERF_WindFarm.H:241
amrex::Vector< amrex::Real > xloc
Definition: ERF_WindFarm.H:300
Here is the call graph for this function:

◆ fill_SMark_multifab()

void WindFarm::fill_SMark_multifab ( const amrex::Geometry &  geom,
amrex::MultiFab &  mf_SMark,
const amrex::Real &  sampling_distance_by_D,
const amrex::Real &  turb_disk_angle,
std::unique_ptr< amrex::MultiFab > &  z_phys_cc 
)

Fill the SMark MultiFab.

Parameters
[in]geomGeometry
[out]mf_SMarkMultiFab to fill with SMark values.
[in]sampling_distance_by_DSampling distance normalized by rotor diameter.
[in]turb_disk_angleTurbine disk angle.
[in,out]z_phys_ccPhysical height MultiFab.

Fill the SMark MultiFab identifying turbine disks and sampling points.

Parameters
[in]geomGeometry defining the domain.
[in,out]mf_SMarkMultiFab to be filled with turbine markers.
[in]sampling_distance_by_DNormalized sampling distance.
[in]turb_disk_angleAngle of the turbine disk in degrees.
[in]z_phys_ccCell-centered physical height FAB.
666 {
667  // Copy turbine locations to device
668  Gpu::DeviceVector<Real> d_xloc(xloc.size());
669  Gpu::DeviceVector<Real> d_yloc(yloc.size());
670  Gpu::DeviceVector<Real> d_zloc(zloc.size());
671 
672  Gpu::copy(Gpu::hostToDevice, xloc.begin(), xloc.end(), d_xloc.begin());
673 
674  Gpu::copy(Gpu::hostToDevice, yloc.begin(), yloc.end(), d_yloc.begin());
675 
676  Gpu::copy(Gpu::hostToDevice, zloc.begin(), zloc.end(), d_zloc.begin());
677 
678  Real d_rotor_rad = rotor_rad;
679  Real d_hub_height = hub_height;
680  Real d_sampling_distance = sampling_distance_by_D * two * rotor_rad;
681 
682  Real* d_xloc_ptr = d_xloc.data();
683  Real* d_yloc_ptr = d_yloc.data();
684  Real* d_zloc_ptr = d_zloc.data();
685 
686  mf_SMark.setVal(-1.0);
687 
688  const int i_lo = geom.Domain().smallEnd(0);
689  const int i_hi = geom.Domain().bigEnd(0);
690  const int j_lo = geom.Domain().smallEnd(1);
691  const int j_hi = geom.Domain().bigEnd(1);
692  const int k_lo = geom.Domain().smallEnd(2);
693  const int k_hi = geom.Domain().bigEnd(2);
694 
695  auto dx = geom.CellSizeArray();
696  auto ProbLoArr = geom.ProbLoArray();
697 
698  const int num_turb = static_cast<int>(xloc.size());
699 
700  Real theta = turb_disk_angle * M_PI / Real(180.0) - myhalf * M_PI;
701 
704 
705  Real nx = -std::cos(theta);
706  Real ny = -std::sin(theta);
707 
708  // ------------------------------------------------------------
709  // Device-side overlap information
710  //
711  // overlap_info[0] = overlap flag
712  // overlap_info[1] = first turbine index
713  // overlap_info[2] = second turbine index
714  // ------------------------------------------------------------
715 
716  int h_overlap_info[3] = {0, -1, -1};
717 
718  Gpu::DeviceVector<int> d_overlap_info(3);
719 
720  Gpu::copy(Gpu::hostToDevice, h_overlap_info, h_overlap_info + 3, d_overlap_info.begin());
721 
722  int* d_overlap_info_ptr = d_overlap_info.data();
723 
724  // ------------------------------------------------------------
725  // Initialize wind farm
726  // ------------------------------------------------------------
727 
728  for (MFIter mfi(mf_SMark, TilingIfNotGPU()); mfi.isValid(); ++mfi)
729  {
730  const Box& gbx = mfi.growntilebox(1);
731 
732  auto SMark_array = mf_SMark.array(mfi);
733 
734  const Array4<const Real>& z_cc_arr = z_phys_cc->const_array(mfi);
735 
736  ParallelFor(
737  gbx,
738  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
739  {
740  int ii = amrex::min(amrex::max(i, i_lo), i_hi);
741  int jj = amrex::min(amrex::max(j, j_lo), j_hi);
742  int kk = amrex::min(amrex::max(k, k_lo), k_hi);
743 
744  // ------------------------------------------------
745  // Mesh-cell x/y extents
746  // ------------------------------------------------
747 
748  Real x1 = ProbLoArr[0] + ii * dx[0];
749  Real x2 = ProbLoArr[0] + (ii + 1) * dx[0];
750 
751  Real y1 = ProbLoArr[1] + jj * dx[1];
752  Real y2 = ProbLoArr[1] + (jj + 1) * dx[1];
753 
754  // ------------------------------------------------
755  // Cell-centered physical z
756  // ------------------------------------------------
757 
758  Real z = z_cc_arr(ii, jj, kk);
759 
760  int check_int = 0;
761  int first_turb = -1;
762 
763  for (int it = 0; it < num_turb; ++it)
764  {
765  Real z0 = d_zloc_ptr[it];
766 
767  // ------------------------------------------------
768  // Sampling point upstream/downstream of turbine
769  // ------------------------------------------------
770 
771  Real x0 = d_xloc_ptr[it] + d_sampling_distance * nx;
772 
773  Real y0 = d_yloc_ptr[it] + d_sampling_distance * ny;
774 
775  bool is_cell_marked =
777  x1, x2, y1, y2,
778  x0, y0,
779  nx, ny,
780  d_hub_height + z0,
781  d_rotor_rad,
782  z);
783 
784  if (is_cell_marked)
785  {
786  SMark_array(i, j, k, 0) = it;
787  }
788 
789  // ------------------------------------------------
790  // Actual turbine disk
791  // ------------------------------------------------
792 
793  x0 = d_xloc_ptr[it];
794  y0 = d_yloc_ptr[it];
795 
796  is_cell_marked =
798  x1, x2, y1, y2,
799  x0, y0,
800  nx, ny,
801  d_hub_height + z0,
802  d_rotor_rad,
803  z);
804 
805  if (is_cell_marked)
806  {
807  SMark_array(i, j, k, 1) = it;
808 
809  if (check_int == 0)
810  {
811  first_turb = it;
812  }
813 
814  ++check_int;
815 
816  // ------------------------------------------------
817  // More than one turbine disk marks this cell
818  // ------------------------------------------------
819 
820  if (check_int > 1)
821  {
822  // Set overlap flag.
823  amrex::Gpu::Atomic::Exch(&d_overlap_info_ptr[0], 1);
824 
825  // Save the turbine indices. Multiple threads
826  // may write these, so use atomics.
827  amrex::Gpu::Atomic::Exch(&d_overlap_info_ptr[1], first_turb);
828 
829  amrex::Gpu::Atomic::Exch(&d_overlap_info_ptr[2], it);
830  }
831  }
832  }
833  });
834  }
835 
836  // ------------------------------------------------------------
837  // Copy overlap information back to host.
838  // This also synchronizes the GPU work.
839  // ------------------------------------------------------------
840 
841  Gpu::copy(Gpu::deviceToHost, d_overlap_info.begin(), d_overlap_info.end(), h_overlap_info);
842 
843  // ------------------------------------------------------------
844  // Handle overlap on the HOST, not inside the GPU kernel.
845  // ------------------------------------------------------------
846 
847  if (h_overlap_info[0] != 0)
848  {
849  amrex::Error(
850  "Actuator disks with indices " + std::to_string(h_overlap_info[1]) +
851  " and " + std::to_string(h_overlap_info[2]) + " are overlapping. "
852  "Visualize actuator_disks.vtk and check the "
853  "windturbine locations input file. Exiting..");
854  }
855 }
#define M_PI
Definition: ERF_HurricaneDiagnostics.cpp:30
const int nx
Definition: ERF_InitCustomPertVels_CloudChamber.H:14
const int ny
Definition: ERF_InitCustomPertVels_CloudChamber.H:15
Real z0
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:12
constexpr amrex::Real two
Definition: ERF_NumericalConstants.H:38
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
static AMREX_GPU_DEVICE bool find_if_marked(amrex::Real x1, amrex::Real x2, amrex::Real y1, amrex::Real y2, amrex::Real x0, amrex::Real y0, amrex::Real nx, amrex::Real ny, amrex::Real d_hub_height, amrex::Real d_rotor_rad, amrex::Real z)
Definition: ERF_NullWindFarm.H:167
amrex::Real my_turb_disk_angle
Definition: ERF_WindFarm.H:301
amrex::Real hub_height
Definition: ERF_WindFarm.H:302
amrex::Real rotor_rad
Definition: ERF_WindFarm.H:302
void set_turb_disk_angle(const amrex::Real &a_turb_disk_angle) override
Set the turbine disk angle.
Definition: ERF_WindFarm.H:250
@ theta
Definition: ERF_Kessler.H:26
Here is the call graph for this function:

◆ fill_SMark_multifab_mesoscale_models()

void WindFarm::fill_SMark_multifab_mesoscale_models ( const amrex::Geometry &  geom,
amrex::MultiFab &  mf_SMark,
const amrex::MultiFab &  mf_Nturb,
std::unique_ptr< amrex::MultiFab > &  z_phys_cc,
const std::unique_ptr< amrex::MultiFab > &  z_sfc_nd 
)

Fill the SMark MultiFab for mesoscale models.

Parameters
[in]geomGeometry
[out]mf_SMarkMultiFab to fill with SMark values.
[in]mf_NturbMultiFab containing turbine counts.
[in,out]z_phys_ccPhysical height MultiFab.
[in]z_sfc_ndHeights of the ground at the nodes.

Fill the SMark MultiFab for mesoscale model parametrization.

Parameters
[in]geomGeometry defining the domain.
[in,out]mf_SMarkMultiFab to be filled with turbine markers.
[in]mf_NturbMultiFab containing turbine counts per cell.
[in]z_phys_ndNode-centered physical height FAB.
[in]z_sfc_ndHeights of the ground at the nodes.
600 {
601  mf_SMark.setVal(-1.0);
602 
603  Real d_hub_height = hub_height;
604 
605  amrex::Gpu::DeviceVector<Real> d_xloc(xloc.size());
606  amrex::Gpu::DeviceVector<Real> d_yloc(yloc.size());
607  amrex::Gpu::DeviceVector<Real> d_zloc(xloc.size());
608  amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, xloc.begin(), xloc.end(), d_xloc.begin());
609  amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, yloc.begin(), yloc.end(), d_yloc.begin());
610  amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, zloc.begin(), zloc.end(), d_zloc.begin());
611 
612  int i_lo = geom.Domain().smallEnd(0); int i_hi = geom.Domain().bigEnd(0);
613  int j_lo = geom.Domain().smallEnd(1); int j_hi = geom.Domain().bigEnd(1);
614  int k_lo = geom.Domain().smallEnd(2); int k_hi = geom.Domain().bigEnd(2);
615 
616  // Node heights come from z_phys_nd, or from the flat mesh if there is none
617  const bool is_terrain = (z_phys_nd != nullptr);
618  auto dx = geom.CellSizeArray();
619  auto ProbLoArr = geom.ProbLoArray();
620 
621  // Initialize wind farm
622  for ( MFIter mfi(mf_SMark,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
623 
624  const Box& gbx = mfi.growntilebox(1);
625  auto SMark_array = mf_SMark.array(mfi);
626  auto Nturb_array = mf_Nturb.array(mfi);
627  const Array4<const Real> z_nd_arr = (is_terrain) ? z_phys_nd->const_array(mfi) : Array4<const Real>{};
628  // The hub height is above the ground, not above the bottom of this box -- these
629  // differ for every box that doesn't touch the ground
630  const Array4<const Real> z_sfc_arr = (is_terrain) ? z_sfc_nd->const_array(mfi) : Array4<const Real>{};
631 
632  ParallelFor(gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
633  if(Nturb_array(i,j,k,0) > 0) {
634  int li = amrex::min(amrex::max(i, i_lo), i_hi);
635  int lj = amrex::min(amrex::max(j, j_lo), j_hi);
636  int lk = amrex::min(amrex::max(k, k_lo), k_hi);
637 
638  Real z1 = (is_terrain) ? z_nd_arr(li,lj,lk ) : ProbLoArr[2] + lk *dx[2];
639  Real z2 = (is_terrain) ? z_nd_arr(li,lj,lk+1) : ProbLoArr[2] + (lk+1)*dx[2];
640 
641  Real zturb = ((is_terrain) ? z_sfc_arr(li,lj,0) : ProbLoArr[2] + k_lo*dx[2]) + d_hub_height;
642  if (zturb+1e-3 > z1 and zturb+1e-3 < z2) {
643  SMark_array(i,j,k,0) = one;
644  }
645  }
646  });
647  }
648 }
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
Here is the call graph for this function:

◆ init_windfarm_lat_lon()

void WindFarm::init_windfarm_lat_lon ( const std::string  windfarm_loc_table,
const amrex::Real  windfarm_x_shift,
const amrex::Real  windfarm_y_shift 
)

Initialize wind farm using latitude and longitude coordinates.

Parameters
[in]windfarm_loc_tablePath to the location table.
[in]windfarm_x_shiftX-coordinate shift.
[in]windfarm_y_shiftY-coordinate shift.

Initialize turbine locations from latitude and longitude coordinates.

Parameters
[in]windfarm_loc_tablePath to the turbine locations table.
[in]windfarm_x_shiftShift applied to the resulting x coordinates.
[in]windfarm_y_shiftShift applied to the resulting y coordinates.
74 {
75  // Re-reading the file must not append to a previous level's list.
76  xloc.clear();
77  yloc.clear();
78 
79  // Read turbine locations from windturbines.txt
80  std::ifstream file(windfarm_loc_table);
81  if (!file.is_open()) {
82  amrex::Error("Wind turbines location table not found. Either the inputs is missing the"
83  " erf.windfarm_loc_table entry or the file specified in the entry " + windfarm_loc_table + " is missing.");
84  }
85  // Vector of vectors to store the matrix
86  Vector<Real> lat, lon;
87  Real value1, value2, value3;
88 
89  while (file >> value1 >> value2 >> value3) {
90 
91  if(std::fabs(value1) > Real(90.0)) {
92  amrex::Error("The value of latitude for entry " + std::to_string(lat.size() + 1) +
93  " in " + windfarm_loc_table + " should be within -90 and 90");
94  }
95 
96  if(std::fabs(value2) > Real(180.0)) {
97  amrex::Error("The value of longitude for entry " + std::to_string(lat.size() + 1) +
98  " in " + windfarm_loc_table + " should be within -180 and 180");
99  }
100  lat.push_back(value1);
101  lon.push_back(value2);
102  }
103  file.close();
104 
105  Real rad_earth = Real(6371.0e3); // Radius of the earth
106  Real m_per_deg_lat = rad_earth*two*M_PI/(two*Real(180.0));
107 
108  // Find the coordinates of average of min and max of the farm
109  // Rotate about that point
110  ParmParse pp("erf");
111  std::string fname_usgs;
112  auto valid_fname_USGS = pp.queryAdd("terrain_file_name_USGS",fname_usgs);
113  Real lon_ref, lat_ref;
114 
115  if (valid_fname_USGS) {
116  std::ifstream file_usgs(fname_usgs);
117  if (!file_usgs.is_open()) {
118  amrex::Error("Could not open the file " + fname_usgs + " specified by the inputs file entry"
119  " erf.terrain_file_name_USGS. Either correct the entry or remove it, in which"
120  " case the reference point is taken from the turbine locations.");
121  }
122  file_usgs >> lon_ref >> lat_ref;
123  if (file_usgs.fail()) {
124  amrex::Error("Could not read the reference longitude and latitude from the first line of "
125  + fname_usgs + ", specified by the inputs file entry erf.terrain_file_name_USGS.");
126  }
127  file_usgs.close();
128  lon_ref = lon_ref*M_PI/Real(180.0);
129  lat_ref = lat_ref*M_PI/Real(180.0);
130  } else {
131  Real lat_min = *std::min_element(lat.begin(), lat.end());
132  Real lon_min = *std::min_element(lon.begin(), lon.end());
133 
134  lon_ref = lon_min*M_PI/Real(180.0);
135  lat_ref = lat_min*M_PI/Real(180.0);
136  }
137 
138 
139  for(int it=0;it<lat.size();it++){
140  lat[it] = lat[it]*M_PI/Real(180.0);
141  lon[it] = lon[it]*M_PI/Real(180.0);
142  Real delta_lat = (lat[it] - lat_ref);
143  Real delta_lon = (lon[it] - lon_ref);
144 
145  Real term1 = amrex::Math::powi<2>(sin(delta_lat/two));
146  Real term2 = cos(lat[it])*cos(lat_ref)*amrex::Math::powi<2>(sin(delta_lon/two));
147  Real dist = two*rad_earth*std::asin(std::sqrt(term1 + term2));
148  Real dy_turb = delta_lat * m_per_deg_lat * Real(180.0)/M_PI ;
149 
150  if(dist<dy_turb){
151  if(std::fabs(dist-dy_turb)<1e-8){
152  dist=dy_turb;
153  }
154  else{
155  Abort("The value of dist is less than dy_turb "+ std::to_string(dist) + " " + std::to_string(dy_turb));
156  }
157  }
158  Real tmp = amrex::Math::powi<2>(dist) - amrex::Math::powi<2>(dy_turb);
159 
160  if(std::fabs(tmp)<1e-8){
161  tmp = zero;
162  }
163  Real dx_turb = std::sqrt(tmp);
164 
165 
166  if(delta_lon >= zero) {
167  xloc.push_back(dx_turb);
168  }
169  else {
170  xloc.push_back(-dx_turb);
171  }
172  yloc.push_back(dy_turb);
173  }
174 
175  for(int it = 0;it<xloc.size(); it++){
176  xloc[it] = xloc[it] + windfarm_x_shift;
177  yloc[it] = yloc[it] + windfarm_y_shift;
178  }
179 }
ParmParse pp("prob")
@ tmp
Definition: ERF_AdvanceWSM6.cpp:116
Here is the call graph for this function:

◆ init_windfarm_x_y()

void WindFarm::init_windfarm_x_y ( const std::string  windfarm_loc_table)

Initialize wind farm using Cartesian coordinates.

Parameters
[in]windfarm_loc_tablePath to the location table.

Initialize turbine locations from Cartesian x and y coordinates.

Parameters
[in]windfarm_loc_tablePath to the turbine locations table.
188 {
189  // Read turbine locations from windturbines.txt
190  std::ifstream file(windfarm_loc_table);
191  if (!file.is_open()) {
192  amrex::Error("Wind turbines location table not found. Either the inputs is missing the"
193  " erf.windfarm_loc_table entry or the file specified in the entry " + windfarm_loc_table + " is missing.");
194  }
195  // Vector of vectors to store the matrix
196  Real value1, value2;
197 
198  // Re-reading the file must not append to a previous level's list.
199  xloc.clear();
200  yloc.clear();
201 
202  while (file >> value1 >> value2) {
203  value1 = value1 + 1e-3;
204  value2 = value2 + 1e-3;
205  xloc.push_back(value1);
206  yloc.push_back(value2);
207  }
208  file.close();
209 }

◆ read_tables()

void WindFarm::read_tables ( std::string  windfarm_loc_table,
std::string  windfarm_spec_table,
bool  x_y,
bool  lat_lon,
const amrex::Real  windfarm_x_shift = zero,
const amrex::Real  windfarm_y_shift = zero 
)

Read turbine location and specification tables.

Parameters
[in]windfarm_loc_tablePath to the location table.
[in]windfarm_spec_tablePath to the specification table.
[in]x_yWhether to use Cartesian coordinates.
[in]lat_lonWhether to use latitude and longitude coordinates.
[in]windfarm_x_shiftX-coordinate shift.
[in]windfarm_y_shiftY-coordinate shift.

Read in the turbine locations in latitude-longitude from windturbines.txt and convert it into x and y coordinates in meters

Parameters
levInteger specifying the current level
24 {
25  amrex::Print() << "Reading wind turbine locations table" << "\n";
26  read_windfarm_locations_table(windfarm_loc_table,
27  x_y, lat_lon,
28  windfarm_x_shift, windfarm_y_shift);
29 
30  amrex::Print() << "Reading wind turbine specifications table" << "\n";
31  read_windfarm_spec_table(windfarm_spec_table);
32 }
void read_windfarm_spec_table(const std::string windfarm_spec_table)
Read the turbine specification table.
Definition: ERF_WindFarm.cpp:218
void read_windfarm_locations_table(const std::string windfarm_loc_table, bool x_y, bool lat_lon, const amrex::Real windfarm_x_shift=zero, const amrex::Real windfarm_y_shift=zero)
Read the turbine location table.
Definition: ERF_WindFarm.cpp:44

◆ read_windfarm_airfoil_tables()

void WindFarm::read_windfarm_airfoil_tables ( const std::string  windfarm_airfoil_tables,
const std::string  windfarm_blade_table 
)

Read the airfoil tables.

Parameters
[in]windfarm_airfoil_tablesPath to the airfoil tables.
[in]windfarm_blade_tablePath to the blade table.

Read airfoil data from a directory of tables.

Parameters
[in]windfarm_airfoil_tablesPath to the directory containing airfoil tables.
[in]windfarm_blade_tablePath to the turbine blade properties table.
372 {
373  DIR* dir;
374  struct dirent* entry;
375  std::vector<std::string> files;
376 
377  // Check if directory exists
378  if ((dir = opendir(windfarm_airfoil_tables.c_str())) == nullptr) {
379  Abort("You are using a generalized actuator disk model based on blade element theory. This needs info of airfoil"
380  " cross sections over the span of the blade. There needs to be an entry erf.airfoil_tables which is the directory that"
381  " contains the angle of attack, Cl, Cd data for each airfoil cross-section. Either the entry is missing or the directory specified"
382  " in the entry - " + windfarm_airfoil_tables + " is missing. Exiting...");
383  }
384 
385  // Loop through directory entries and collect filenames
386  while ((entry = readdir(dir)) != nullptr) {
387  // Skip special directory entries "." and ".."
388  if (std::string(entry->d_name) == "." || std::string(entry->d_name) == "..") {
389  continue;
390  }
391  files.emplace_back(windfarm_airfoil_tables + "/" + entry->d_name); // Add file path to vector
392  }
393 
394  // Close the directory
395  closedir(dir);
396 
397  if (files.empty()) {
398  Abort("It seems the directory containing the info of airfoil cross sections of the blades - " + windfarm_airfoil_tables +
399  " is empty. Exiting...");
400  }
401 
402  if(files.size() != static_cast<long double>(n_bld_sections)) {
403  printf("There are %d airfoil sections in the last column of %s. But the number"
404  " of files in %s is only %ld.\n", n_bld_sections, windfarm_blade_table.c_str(),
405  windfarm_airfoil_tables.c_str(), files.size());
406  Abort("The number of blade sections from " + windfarm_blade_table + " should match the number of"
407  " files in " + windfarm_airfoil_tables + ". Exiting...");
408  }
409 
410  // Sort filenames in lexicographical (alphabetical) order
411  std::sort(files.begin(), files.end());
412 
413  // Process each file
414  int count = 0;
415  // assign, not resize, which would keep the inner vectors of a previous read (#5180)
416  bld_airfoil_aoa.assign(n_bld_sections, {});
417  bld_airfoil_Cl.assign(n_bld_sections, {});
418  bld_airfoil_Cd.assign(n_bld_sections, {});
419  for (const auto& filePath : files) {
420  std::ifstream filename(filePath.c_str());
421 
422  // Every file in this directory is one blade section, and the sections are
423  // filled in sorted order, so one that cannot be read cannot be skipped over:
424  // doing so would shift every later section into the wrong slot.
425  if (!filename.is_open()) {
426  Abort("Could not open the airfoil section file " + filePath + " found in the directory " +
427  windfarm_airfoil_tables + ". Exiting...");
428  }
429 
430  std::cout << "Reading file: " << filePath << std::endl;
431 
432  std::string line;
433  for (int i = 0; i < 54; ++i) {
434  if (std::getline(filename, line)) { // Read one line into the array
435  }
436  }
437 
438  Real var1, var2, var3, temp;
439 
440  while(filename >> var1 >> var2 >> var3 >> temp) {
441  bld_airfoil_aoa[count].push_back(var1);
442  bld_airfoil_Cl[count].push_back(var2);
443  bld_airfoil_Cd[count].push_back(var3);
444  //int idx = bld_airfoil_aoa.size()-1;
445  //printf("Values are = %0.15g %0.15g %0.15g\n", bld_airfoil_aoa[idx], bld_airfoil_Cl[idx], bld_airfoil_Cd[idx]);
446  }
447  count++;
448  }
449 
451 }
int count
Definition: ERF_ActuatorSpreading.cpp:264
amrex::Vector< amrex::Vector< amrex::Real > > bld_airfoil_Cl
Definition: ERF_WindFarm.H:305
amrex::Vector< amrex::Vector< amrex::Real > > bld_airfoil_aoa
Definition: ERF_WindFarm.H:305
amrex::Vector< amrex::Vector< amrex::Real > > bld_airfoil_Cd
Definition: ERF_WindFarm.H:305
int n_bld_sections
Definition: ERF_WindFarm.H:306
void set_blade_airfoil_spec(const amrex::Vector< amrex::Vector< amrex::Real >> &a_bld_airfoil_aoa, const amrex::Vector< amrex::Vector< amrex::Real >> &a_bld_airfoil_Cl, const amrex::Vector< amrex::Vector< amrex::Real >> &a_bld_airfoil_Cd) override
Set blade airfoil specifications.
Definition: ERF_WindFarm.H:274

◆ read_windfarm_blade_table()

void WindFarm::read_windfarm_blade_table ( const std::string  windfarm_blade_table)

Read the turbine blade table.

Parameters
[in]windfarm_blade_tablePath to the blade table.

Read turbine blade geometry and properties from a table.

Parameters
[in]windfarm_blade_tablePath to the turbine blade properties table.
282 {
283  // Re-reading the table must not append to a previous read (#5180)
284  bld_rad_loc.clear(); bld_twist.clear(); bld_chord.clear();
285 
286  std::ifstream filename(windfarm_blade_table);
287  std::string line;
288  Real temp, var1, var2, var3;
289  if (!filename.is_open()) {
290  Error("You are using a generalized actuator disk model based on blade element theory. This needs info of blades."
291  " An entry erf.windfarm_blade_table is needed. Either the entry is missing or the file specified"
292  " in the entry - " + windfarm_blade_table + " is missing.");
293  }
294  else {
295  Print() << "Reading in wind farm blade table: " << windfarm_blade_table << "\n";
296 
297  // First 6 lines are comments
298 
299  for (int i = 0; i < 6; ++i) {
300  if (std::getline(filename, line)) { // Read one line into the array
301  }
302  }
303 
304  while(filename >> var1 >> temp >> temp >> temp >> var2 >> var3 >> temp) {
305  bld_rad_loc.push_back(var1);
306  bld_twist.push_back(var2);
307  bld_chord.push_back(var3);
308  //int idx = bld_rad_loc.size()-1;
309  //printf("Values are = %0.15g %0.15g %0.15g\n", bld_rad_loc[idx], bld_twist[idx], bld_chord[idx]);
310  }
312  n_bld_sections = bld_rad_loc.size();
313  }
314 }
void set_blade_spec(const amrex::Vector< amrex::Real > &a_bld_rad_loc, const amrex::Vector< amrex::Real > &a_bld_twist, const amrex::Vector< amrex::Real > &a_bld_chord) override
Set blade specifications.
Definition: ERF_WindFarm.H:261
amrex::Vector< amrex::Real > bld_twist
Definition: ERF_WindFarm.H:304
amrex::Vector< amrex::Real > bld_chord
Definition: ERF_WindFarm.H:304
amrex::Vector< amrex::Real > bld_rad_loc
Definition: ERF_WindFarm.H:304

◆ read_windfarm_locations_table()

void WindFarm::read_windfarm_locations_table ( const std::string  windfarm_loc_table,
bool  x_y,
bool  lat_lon,
const amrex::Real  windfarm_x_shift = zero,
const amrex::Real  windfarm_y_shift = zero 
)

Read the turbine location table.

Parameters
[in]windfarm_loc_tablePath to the location table.
[in]x_yWhether to use Cartesian coordinates.
[in]lat_lonWhether to use latitude and longitude coordinates.
[in]windfarm_x_shiftX-coordinate shift.
[in]windfarm_y_shiftY-coordinate shift.

Read turbine locations from a table and convert them to Cartesian coordinates.

Parameters
[in]windfarm_loc_tablePath to the turbine locations table.
[in]x_yBoolean indicating if locations are provided as x and y coordinates.
[in]lat_lonBoolean indicating if locations are provided as latitude and longitude.
[in]windfarm_x_shiftShift applied to the resulting x coordinates.
[in]windfarm_y_shiftShift applied to the resulting y coordinates.
48 {
49  if(x_y) {
50  init_windfarm_x_y(windfarm_loc_table);
51  }
52  else if(lat_lon) {
53  init_windfarm_lat_lon(windfarm_loc_table, windfarm_x_shift, windfarm_y_shift);
54  }
55  else {
56  amrex::Abort("Are you using windfarms? For windfarm simulations, the inputs need to have an"
57  " entry erf.windfarm_loc_type which should be either lat_lon or x_y. \n");
58  }
59 
61 }
void set_turb_loc(const amrex::Vector< amrex::Real > &a_xloc, const amrex::Vector< amrex::Real > &a_yloc) override
Set turbine locations.
Definition: ERF_WindFarm.H:231
void init_windfarm_x_y(const std::string windfarm_loc_table)
Initialize wind farm using Cartesian coordinates.
Definition: ERF_WindFarm.cpp:187
void init_windfarm_lat_lon(const std::string windfarm_loc_table, const amrex::Real windfarm_x_shift, const amrex::Real windfarm_y_shift)
Initialize wind farm using latitude and longitude coordinates.
Definition: ERF_WindFarm.cpp:71

◆ read_windfarm_spec_table()

void WindFarm::read_windfarm_spec_table ( const std::string  windfarm_spec_table)

Read the turbine specification table.

Parameters
[in]windfarm_spec_tablePath to the specification table.

Read turbine performance specifications from a table.

Parameters
[in]windfarm_spec_tablePath to the turbine specifications table.
219 {
220  //The first line is the number of pairs entries for the power curve and thrust coefficient.
221  //The second line gives first the height in meters of the turbine hub, second, the diameter in
222  //meters of the rotor, third the standing thrust coefficient, and fourth the nominal power of
223  //the turbine in MW.
224  //The remaining lines contain the three values of: wind speed, thrust coefficient, and power production in kW.
225 
226  // Read turbine data from wind-turbine-1.tbl
227  std::ifstream file_turb_table(windfarm_spec_table);
228  if (!file_turb_table.is_open()) {
229  Error("Wind farm specifications table not found. Either the inputs is missing the "
230  "erf.windfarm_spec_table entry or the file specified in the entry - " + windfarm_spec_table + " is missing.");
231  }
232  else {
233  Print() << "Reading in wind farm specifications table: " << windfarm_spec_table << "\n";
234  }
235 
236  // The power curve is interpolated (and extrapolated) linearly, which needs two points
237  int nlines = 0;
238  if (!(file_turb_table >> nlines) || nlines < 2) {
239  Abort("The first line of " + windfarm_spec_table + " must be the number of power-curve "
240  "entries, at least 2. Aborting.....");
241  }
242  wind_speed.resize(nlines);
243  thrust_coeff.resize(nlines);
244  power.resize(nlines);
245 
246  Real rotor_dia;
247  if (!(file_turb_table >> hub_height >> rotor_dia >> thrust_coeff_standing >> nominal_power)) {
248  Abort("Could not read the hub height, rotor diameter, standing thrust coefficient and "
249  "nominal power from the second line of " + windfarm_spec_table + ". Aborting.....");
250  }
251  rotor_rad = rotor_dia*myhalf;
252  if(rotor_rad > hub_height) {
253  Abort("The blade length is more than the hub height. Check the second line in wind-turbine-1.tbl. Aborting.....");
254  }
255  if(thrust_coeff_standing > one) {
256  Abort("The standing thrust coefficient is greater than one. Check the second line in wind-turbine-1.tbl. Aborting.....");
257  }
258 
259  for(int iline=0;iline<nlines;iline++){
260  if (!(file_turb_table >> wind_speed[iline] >> thrust_coeff[iline] >> power[iline])) {
261  Abort(windfarm_spec_table + " has fewer than the " + std::to_string(nlines) +
262  " power-curve entries its first line gives. Aborting.....");
263  }
264  if(thrust_coeff[iline] > one) {
265  Abort("The thrust coefficient is greater than one. Check wind-turbine-1.tbl. Aborting.....");
266  }
267  }
268  file_turb_table.close();
269 
272 
273 }
amrex::Vector< amrex::Real > wind_speed
Definition: ERF_WindFarm.H:303
amrex::Vector< amrex::Real > thrust_coeff
Definition: ERF_WindFarm.H:303
amrex::Real nominal_power
Definition: ERF_WindFarm.H:302
void set_turb_spec(const amrex::Real &a_rotor_rad, const amrex::Real &a_hub_height, const amrex::Real &a_thrust_coeff_standing, const amrex::Vector< amrex::Real > &a_wind_speed, const amrex::Vector< amrex::Real > &a_thrust_coeff, const amrex::Vector< amrex::Real > &a_power) override
Set general turbine specifications.
Definition: ERF_WindFarm.H:217
amrex::Real thrust_coeff_standing
Definition: ERF_WindFarm.H:302
amrex::Vector< amrex::Real > power
Definition: ERF_WindFarm.H:303

◆ read_windfarm_spec_table_extra()

void WindFarm::read_windfarm_spec_table_extra ( const std::string  windfarm_spec_table_extra)

Read extra turbine specifications.

Parameters
[in]windfarm_spec_table_extraPath to the extra specification table.

Read extended turbine performance specifications from a table.

Parameters
[in]windfarm_spec_table_extraPath to the extended turbine specifications table.
323 {
324  // Re-reading the table must not append to a previous read (#5180)
325  velocity.clear(); C_P.clear(); C_T.clear(); rotor_RPM.clear(); blade_pitch.clear();
326 
327  // Open the file
328  std::ifstream file(windfarm_spec_table_extra);
329 
330  // Check if file opened successfully
331  if (!file.is_open()) {
332  Abort("Error: You are using generalized wind farms option. This requires an input file erf.windfarm_spec_table_extra."
333  " Either this entry is missing in the inputs or the file specified -" + windfarm_spec_table_extra + " does"
334  " not exist. Exiting...");
335  } else {
336  printf("Reading in windfarm_spec_table_extra %s", windfarm_spec_table_extra.c_str());
337  }
338 
339  // Ignore the first line (header)
340  std::string header;
341  std::getline(file, header);
342 
343  // Variables to hold each row's values
344  double V, Cp, Ct, rpm, pitch, temp;
345 
346  // Read the file row by row
347  while (file >> V) {
348  char comma; // To ignore the commas
349  file >> comma >> Cp >> comma >> Ct >> comma >> temp >> comma >> temp >> comma
350  >> temp >> comma >> rpm >> comma >> pitch >> comma >> temp;
351 
352  velocity.push_back(V);
353  C_P.push_back(Cp);
354  C_T.push_back(Ct);
355  rotor_RPM.push_back(rpm);
356  blade_pitch.push_back(pitch);
357  }
358 
360 }
amrex::Vector< amrex::Real > blade_pitch
Definition: ERF_WindFarm.H:307
void set_turb_spec_extra(const amrex::Vector< amrex::Real > &a_velocity, const amrex::Vector< amrex::Real > &a_C_P, const amrex::Vector< amrex::Real > &a_C_T, const amrex::Vector< amrex::Real > &a_rotor_RPM, const amrex::Vector< amrex::Real > &a_blade_pitch) override
Set extra turbine specifications.
Definition: ERF_WindFarm.H:289
amrex::Vector< amrex::Real > velocity
Definition: ERF_WindFarm.H:307
amrex::Vector< amrex::Real > C_P
Definition: ERF_WindFarm.H:307
amrex::Vector< amrex::Real > C_T
Definition: ERF_WindFarm.H:307
amrex::Vector< amrex::Real > rotor_RPM
Definition: ERF_WindFarm.H:307
@ V
Definition: ERF_IndexDefines.H:179

◆ set_blade_airfoil_spec()

void WindFarm::set_blade_airfoil_spec ( const amrex::Vector< amrex::Vector< amrex::Real >> &  a_bld_airfoil_aoa,
const amrex::Vector< amrex::Vector< amrex::Real >> &  a_bld_airfoil_Cl,
const amrex::Vector< amrex::Vector< amrex::Real >> &  a_bld_airfoil_Cd 
)
inlineoverridevirtual

Set blade airfoil specifications.

Parameters
[in]a_bld_airfoil_aoaAngle of attack.
[in]a_bld_airfoil_ClLift coefficient.
[in]a_bld_airfoil_CdDrag coefficient.

Reimplemented from NullWindFarm.

277  {
278  m_windfarm_model[0]->set_blade_airfoil_spec(a_bld_airfoil_aoa, a_bld_airfoil_Cl, a_bld_airfoil_Cd);
279  }

◆ set_blade_spec()

void WindFarm::set_blade_spec ( const amrex::Vector< amrex::Real > &  a_bld_rad_loc,
const amrex::Vector< amrex::Real > &  a_bld_twist,
const amrex::Vector< amrex::Real > &  a_bld_chord 
)
inlineoverridevirtual

Set blade specifications.

Parameters
[in]a_bld_rad_locBlade radial locations.
[in]a_bld_twistBlade twist.
[in]a_bld_chordBlade chord.

Reimplemented from NullWindFarm.

264  {
265  m_windfarm_model[0]->set_blade_spec(a_bld_rad_loc, a_bld_twist, a_bld_chord);
266  }

◆ set_turb_disk_angle()

void WindFarm::set_turb_disk_angle ( const amrex::Real &  a_turb_disk_angle)
inlineoverridevirtual

Set the turbine disk angle.

Parameters
[in]a_turb_disk_angleDisk angle.

Reimplemented from NullWindFarm.

251  {
252  m_windfarm_model[0]->set_turb_disk_angle(a_turb_disk_angle);
253  }

◆ set_turb_loc()

void WindFarm::set_turb_loc ( const amrex::Vector< amrex::Real > &  a_xloc,
const amrex::Vector< amrex::Real > &  a_yloc 
)
inlineoverridevirtual

Set turbine locations.

Parameters
[in]a_xlocX locations.
[in]a_ylocY locations.

Reimplemented from NullWindFarm.

233  {
234  m_windfarm_model[0]->set_turb_loc(a_xloc, a_yloc);
235  }

◆ set_turb_spec()

void WindFarm::set_turb_spec ( const amrex::Real &  a_rotor_rad,
const amrex::Real &  a_hub_height,
const amrex::Real &  a_thrust_coeff_standing,
const amrex::Vector< amrex::Real > &  a_wind_speed,
const amrex::Vector< amrex::Real > &  a_thrust_coeff,
const amrex::Vector< amrex::Real > &  a_power 
)
inlineoverridevirtual

Set general turbine specifications.

Parameters
[in]a_rotor_radRotor radius.
[in]a_hub_heightHub height.
[in]a_thrust_coeff_standingStanding thrust coefficient.
[in]a_wind_speedWind speed vector.
[in]a_thrust_coeffThrust coefficient vector.
[in]a_powerPower vector.

Reimplemented from NullWindFarm.

221  {
222  m_windfarm_model[0]->set_turb_spec(a_rotor_rad, a_hub_height, a_thrust_coeff_standing,
223  a_wind_speed, a_thrust_coeff, a_power);
224  }

◆ set_turb_spec_extra()

void WindFarm::set_turb_spec_extra ( const amrex::Vector< amrex::Real > &  a_velocity,
const amrex::Vector< amrex::Real > &  a_C_P,
const amrex::Vector< amrex::Real > &  a_C_T,
const amrex::Vector< amrex::Real > &  a_rotor_RPM,
const amrex::Vector< amrex::Real > &  a_blade_pitch 
)
inlineoverridevirtual

Set extra turbine specifications.

Parameters
[in]a_velocityVelocity.
[in]a_C_PPower coefficient.
[in]a_C_TThrust coefficient.
[in]a_rotor_RPMRotor RPM.
[in]a_blade_pitchBlade pitch.

Reimplemented from NullWindFarm.

294  {
295  m_windfarm_model[0]->set_turb_spec_extra(a_velocity, a_C_P, a_C_T, a_rotor_RPM, a_blade_pitch);
296  }

◆ set_turb_zloc()

void WindFarm::set_turb_zloc ( const amrex::Vector< amrex::Real > &  a_zloc)
inlineoverridevirtual

Set the ground elevation under each turbine.

Parameters
[in]a_zlocGround elevations.

Reimplemented from NullWindFarm.

242  {
243  m_windfarm_model[0]->set_turb_zloc(a_zloc);
244  }

◆ SetModel()

template<class NewWindFarmModel >
void WindFarm::SetModel ( )
inlineprotected

Create and set the specified windfarm model.

312  {
313  for (int lev(0); lev<m_windfarm_model.size(); ++lev) {
314  m_windfarm_model[lev] = std::make_unique<NewWindFarmModel>();
315  }
316  }

◆ write_actuator_disks_vtk()

void WindFarm::write_actuator_disks_vtk ( const amrex::Geometry &  geom,
const amrex::Real &  sampling_distance_by_D 
)

Write actuator disks to a VTK file.

Parameters
[in]geomGeometry
[in]sampling_distance_by_DSampling distance normalized by rotor diameter.

Write the actuator disks and sampling disks to VTK files.

Parameters
[in]geomGeometry defining the domain.
[in]sampling_distance_by_DNormalized sampling distance.
888 {
889 
890  Real sampling_distance = sampling_distance_by_D*two*rotor_rad;
891 
892  if (ParallelDescriptor::IOProcessor()){
893  FILE *file_actuator_disks_all, *file_actuator_disks_in_dom, *file_averaging_disks_in_dom;
894  file_actuator_disks_all = fopen("actuator_disks_all.vtk","w");
895  fprintf(file_actuator_disks_all, "%s\n","# vtk DataFile Version 3.0");
896  fprintf(file_actuator_disks_all, "%s\n","Actuator Disks");
897  fprintf(file_actuator_disks_all, "%s\n","ASCII");
898  fprintf(file_actuator_disks_all, "%s\n","DATASET POLYDATA");
899 
900  file_actuator_disks_in_dom = fopen("actuator_disks_in_dom.vtk","w");
901  fprintf(file_actuator_disks_in_dom, "%s\n","# vtk DataFile Version 3.0");
902  fprintf(file_actuator_disks_in_dom, "%s\n","Actuator Disks");
903  fprintf(file_actuator_disks_in_dom, "%s\n","ASCII");
904  fprintf(file_actuator_disks_in_dom, "%s\n","DATASET POLYDATA");
905 
906  file_averaging_disks_in_dom = fopen("averaging_disks_in_dom.vtk","w");
907  fprintf(file_averaging_disks_in_dom, "%s\n","# vtk DataFile Version 3.0");
908  fprintf(file_averaging_disks_in_dom, "%s\n","Actuator Disks");
909  fprintf(file_averaging_disks_in_dom, "%s\n","ASCII");
910  fprintf(file_averaging_disks_in_dom, "%s\n","DATASET POLYDATA");
911 
912 
913  int npts = 100;
914  fprintf(file_actuator_disks_all, "%s %ld %s\n", "POINTS", xloc.size()*npts, "float");
915  auto ProbLoArr = geom.ProbLoArray();
916  auto ProbHiArr = geom.ProbHiArray();
917  int num_turb_in_dom = 0;
918 
919  // Find the number of turbines inside the specified computational domain
920 
921  for(int it=0; it<xloc.size(); it++){
922  Real x = xloc[it];
923  Real y = yloc[it];
924  if(x > ProbLoArr[0] and x < ProbHiArr[0] and y > ProbLoArr[1] and y < ProbHiArr[1]) {
925  num_turb_in_dom++;
926  }
927  }
928  fprintf(file_actuator_disks_in_dom, "%s %ld %s\n", "POINTS", static_cast<long int>(num_turb_in_dom*npts), "float");
929  fprintf(file_averaging_disks_in_dom, "%s %ld %s\n", "POINTS", static_cast<long int>(num_turb_in_dom*npts), "float");
930 
931  Real nx = std::cos(my_turb_disk_angle+myhalf*M_PI);
932  Real ny = std::sin(my_turb_disk_angle+myhalf*M_PI);
933 
934  Real nx1 = -std::cos(my_turb_disk_angle);
935  Real ny1 = -std::sin(my_turb_disk_angle);
936 
937  for(int it=0; it<xloc.size(); it++){
938  for(int pt=0;pt<100;pt++){
939  Real x, y, z, xavg, yavg;
940  Real theta = two*M_PI/npts*pt;
941  x = xloc[it] + rotor_rad*cos(theta)*nx;
942  y = yloc[it] + rotor_rad*cos(theta)*ny;
943  z = hub_height + zloc[it] + rotor_rad*sin(theta);
944 
945  xavg = xloc[it] + sampling_distance*nx1 + rotor_rad*cos(theta)*nx;
946  yavg = yloc[it] + sampling_distance*ny1 + rotor_rad*cos(theta)*ny;
947 
948  fprintf(file_actuator_disks_all, "%0.15g %0.15g %0.15g\n", x, y, z);
949  if(xloc[it] > ProbLoArr[0] and xloc[it] < ProbHiArr[0] and yloc[it] > ProbLoArr[1] and yloc[it] < ProbHiArr[1]) {
950  fprintf(file_actuator_disks_in_dom, "%0.15g %0.15g %0.15g\n", x, y, z);
951  fprintf(file_averaging_disks_in_dom, "%0.15g %0.15g %0.15g\n", xavg, yavg, z);
952  }
953  }
954  }
955  fprintf(file_actuator_disks_all, "%s %ld %ld\n", "LINES", xloc.size()*(npts-1), static_cast<long int>(xloc.size()*(npts-1)*3));
956  fprintf(file_actuator_disks_in_dom, "%s %ld %ld\n", "LINES", static_cast<long int>(num_turb_in_dom*(npts-1)), static_cast<long int>(num_turb_in_dom*(npts-1)*3));
957  fprintf(file_averaging_disks_in_dom, "%s %ld %ld\n", "LINES", static_cast<long int>(num_turb_in_dom*(npts-1)), static_cast<long int>(num_turb_in_dom*(npts-1)*3));
958  for(int it=0; it<xloc.size(); it++){
959  for(int pt=0;pt<99;pt++){
960  fprintf(file_actuator_disks_all, "%ld %ld %ld\n",
961  static_cast<long int>(2),
962  static_cast<long int>(it*npts+pt),
963  static_cast<long int>(it*npts+pt+1));
964  }
965  }
966  for(int it=0; it<num_turb_in_dom; it++){
967  for(int pt=0;pt<99;pt++){
968  fprintf(file_actuator_disks_in_dom, "%ld %ld %ld\n",
969  static_cast<long int>(2),
970  static_cast<long int>(it*npts+pt),
971  static_cast<long int>(it*npts+pt+1));
972  }
973  }
974 
975  for(int it=0; it<num_turb_in_dom; it++){
976  for(int pt=0;pt<99;pt++){
977  fprintf(file_averaging_disks_in_dom, "%ld %ld %ld\n",
978  static_cast<long int>(2),
979  static_cast<long int>(it*npts+pt),
980  static_cast<long int>(it*npts+pt+1));
981  }
982  }
983 
984  fclose(file_actuator_disks_all);
985  fclose(file_actuator_disks_in_dom);
986  fclose(file_averaging_disks_in_dom);
987  }
988 }

◆ write_turbine_locations_vtk()

void WindFarm::write_turbine_locations_vtk ( )

Write turbine locations to a VTK file.

Write the turbine hub locations to a VTK file.

862 {
863  if (ParallelDescriptor::IOProcessor()){
864  FILE* file_turbloc_vtk;
865  file_turbloc_vtk = fopen("turbine_locations.vtk","w");
866  fprintf(file_turbloc_vtk, "%s\n","# vtk DataFile Version 3.0");
867  fprintf(file_turbloc_vtk, "%s\n","Wind turbine locations");
868  fprintf(file_turbloc_vtk, "%s\n","ASCII");
869  fprintf(file_turbloc_vtk, "%s\n","DATASET POLYDATA");
870  fprintf(file_turbloc_vtk, "%s %ld %s\n", "POINTS", xloc.size(), "float");
871  for(int it=0; it<xloc.size(); it++){
872  fprintf(file_turbloc_vtk, "%0.15g %0.15g %0.15g\n", xloc[it], yloc[it], hub_height);
873  }
874  fclose(file_turbloc_vtk);
875  }
876 }

Member Data Documentation

◆ blade_pitch

amrex::Vector<amrex::Real> WindFarm::blade_pitch
protected

◆ bld_airfoil_aoa

amrex::Vector<amrex::Vector<amrex::Real> > WindFarm::bld_airfoil_aoa
protected

◆ bld_airfoil_Cd

amrex::Vector<amrex::Vector<amrex::Real> > WindFarm::bld_airfoil_Cd
protected

◆ bld_airfoil_Cl

amrex::Vector<amrex::Vector<amrex::Real> > WindFarm::bld_airfoil_Cl
protected

◆ bld_chord

amrex::Vector<amrex::Real> WindFarm::bld_chord
protected

◆ bld_rad_loc

amrex::Vector<amrex::Real> WindFarm::bld_rad_loc
protected

◆ bld_twist

amrex::Vector<amrex::Real> WindFarm::bld_twist
protected

◆ C_P

amrex::Vector<amrex::Real> WindFarm::C_P
protected

◆ C_T

amrex::Vector<amrex::Real> WindFarm::C_T
protected

◆ hub_height

amrex::Real WindFarm::hub_height
protected

◆ m_windfarm_model

amrex::Vector<std::unique_ptr<NullWindFarm> > WindFarm::m_windfarm_model
private

◆ my_turb_disk_angle

amrex::Real WindFarm::my_turb_disk_angle
protected

◆ n_bld_sections

int WindFarm::n_bld_sections
protected

◆ nominal_power

amrex::Real WindFarm::nominal_power
protected

◆ power

amrex::Vector<amrex::Real> WindFarm::power
protected

◆ rotor_rad

amrex::Real WindFarm::rotor_rad
protected

◆ rotor_RPM

amrex::Vector<amrex::Real> WindFarm::rotor_RPM
protected

◆ thrust_coeff

amrex::Vector<amrex::Real> WindFarm::thrust_coeff
protected

◆ thrust_coeff_standing

amrex::Real WindFarm::thrust_coeff_standing
protected

◆ velocity

amrex::Vector<amrex::Real> WindFarm::velocity
protected

◆ wind_speed

amrex::Vector<amrex::Real> WindFarm::wind_speed
protected

◆ xloc

amrex::Vector<amrex::Real> WindFarm::xloc
protected

◆ yloc

amrex::Vector<amrex::Real> WindFarm::yloc
protected

◆ zloc

amrex::Vector<amrex::Real> WindFarm::zloc
protected

The documentation for this class was generated from the following files: