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

#include <ERF_GeneralAD.H>

Inheritance diagram for GeneralAD:
Collaboration diagram for GeneralAD:

Public Member Functions

 GeneralAD ()
 
virtual ~GeneralAD ()=default
 
void advance (const amrex::Geometry &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
 
void compute_freestream_velocity (const amrex::MultiFab &cons_in, const amrex::MultiFab &U_old, const amrex::MultiFab &V_old, const amrex::MultiFab &mf_SMark)
 
void source_terms_cellcentered (const amrex::Geometry &geom, const amrex::MultiFab &cons_in, const amrex::MultiFab &mf_Smark, amrex::MultiFab &mf_vars_generalAD, const amrex::MultiFab *z_phys_cc)
 
void update (const double &dt_advance, amrex::MultiFab &cons_in, amrex::MultiFab &U_old, amrex::MultiFab &V_old, amrex::MultiFab &W_old, const amrex::MultiFab &mf_vars)
 
void compute_power_output (const double &time)
 
- Public Member Functions inherited from NullWindFarm
 NullWindFarm ()
 
virtual ~NullWindFarm ()=default
 
virtual void set_turb_spec (const amrex::Real &rotor_rad, const amrex::Real &hub_height, const amrex::Real &thrust_coeff_standing, const amrex::Vector< amrex::Real > &wind_speed, const amrex::Vector< amrex::Real > &thrust_coeff, const amrex::Vector< amrex::Real > &power)
 
virtual void set_turb_loc (const amrex::Vector< amrex::Real > &xloc, const amrex::Vector< amrex::Real > &yloc)
 
virtual void set_turb_zloc (const amrex::Vector< amrex::Real > &zloc)
 Ground elevation under each turbine (the hub is hub_height above it) More...
 
virtual void set_turb_disk_angle (const amrex::Real &turb_disk_angle)
 
virtual void set_blade_spec (const amrex::Vector< amrex::Real > &bld_rad_loc, const amrex::Vector< amrex::Real > &bld_twist, const amrex::Vector< amrex::Real > &bld_chord)
 
virtual void set_blade_airfoil_spec (const amrex::Vector< amrex::Vector< amrex::Real >> &bld_airfoil_aoa, const amrex::Vector< amrex::Vector< amrex::Real >> &bld_airfoil_Cl, const amrex::Vector< amrex::Vector< amrex::Real >> &bld_airfoil_Cd)
 
virtual void set_turb_spec_extra (const amrex::Vector< amrex::Real > &velocity, const amrex::Vector< amrex::Real > &C_P, const amrex::Vector< amrex::Real > &C_T, const amrex::Vector< amrex::Real > &rotor_RPM, const amrex::Vector< amrex::Real > &blade_pitch)
 
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 Attributes

amrex::Vector< amrex::Real > xloc
 
amrex::Vector< amrex::Real > yloc
 
amrex::Real 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 > freestream_velocity
 
amrex::Vector< amrex::Real > freestream_phi
 
amrex::Vector< amrex::Real > disk_cell_count
 
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
 
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
 

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)
 

Constructor & Destructor Documentation

◆ GeneralAD()

GeneralAD::GeneralAD ( )
inline
12 {}

◆ ~GeneralAD()

virtual GeneralAD::~GeneralAD ( )
virtualdefault

Member Function Documentation

◆ advance()

void GeneralAD::advance ( const amrex::Geometry &  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 
)
overridevirtual

Implements NullWindFarm.

23 {
24  AMREX_ALWAYS_ASSERT(W_old.nComp() > 0);
25  AMREX_ALWAYS_ASSERT(mf_Nturb.nComp() > 0);
26  AMREX_ALWAYS_ASSERT(mf_vars_generalAD.nComp() > 0);
27  AMREX_ALWAYS_ASSERT(time > -one);
28  amrex::ignore_unused(z_phys_nd);
29  compute_freestream_velocity(cons_in, U_old, V_old, mf_SMark);
30  source_terms_cellcentered(geom, cons_in, mf_SMark, mf_vars_generalAD, z_phys_cc);
31  update(dt_advance, cons_in, U_old, V_old, W_old, mf_vars_generalAD);
33 }
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
void source_terms_cellcentered(const amrex::Geometry &geom, const amrex::MultiFab &cons_in, const amrex::MultiFab &mf_Smark, amrex::MultiFab &mf_vars_generalAD, const amrex::MultiFab *z_phys_cc)
Definition: ERF_AdvanceGeneralAD.cpp:327
void update(const double &dt_advance, amrex::MultiFab &cons_in, amrex::MultiFab &U_old, amrex::MultiFab &V_old, amrex::MultiFab &W_old, const amrex::MultiFab &mf_vars)
Definition: ERF_AdvanceGeneralAD.cpp:65
void compute_freestream_velocity(const amrex::MultiFab &cons_in, const amrex::MultiFab &U_old, const amrex::MultiFab &V_old, const amrex::MultiFab &mf_SMark)
Definition: ERF_AdvanceGeneralAD.cpp:101
void compute_power_output(const double &time)
Definition: ERF_AdvanceGeneralAD.cpp:36
Here is the call graph for this function:

◆ compute_freestream_velocity()

void GeneralAD::compute_freestream_velocity ( const amrex::MultiFab &  cons_in,
const amrex::MultiFab &  U_old,
const amrex::MultiFab &  V_old,
const amrex::MultiFab &  mf_SMark 
)
105 {
107  freestream_velocity.clear();
108  freestream_phi.clear();
109  disk_cell_count.clear();
110  freestream_velocity.resize(xloc.size(),zero);
111  freestream_phi.resize(xloc.size(),zero);
112  disk_cell_count.resize(xloc.size(),zero);
113 
114  Gpu::DeviceVector<Real> d_freestream_velocity(xloc.size());
115  Gpu::DeviceVector<Real> d_freestream_phi(yloc.size());
116  Gpu::DeviceVector<Real> d_disk_cell_count(yloc.size());
117  Gpu::copy(Gpu::hostToDevice, freestream_velocity.begin(), freestream_velocity.end(), d_freestream_velocity.begin());
118  Gpu::copy(Gpu::hostToDevice, freestream_phi.begin(), freestream_phi.end(), d_freestream_phi.begin());
119  Gpu::copy(Gpu::hostToDevice, disk_cell_count.begin(), disk_cell_count.end(), d_disk_cell_count.begin());
120 
121  Real* d_freestream_velocity_ptr = d_freestream_velocity.data();
122  Real* d_freestream_phi_ptr = d_freestream_phi.data();
123  Real* d_disk_cell_count_ptr = d_disk_cell_count.data();
124 
125 
126  for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
127 
128  auto SMark_array = mf_SMark.array(mfi);
129  auto u_vel = U_old.array(mfi);
130  auto v_vel = V_old.array(mfi);
131  // NOTE: this reduction is driven by the cell-centered SMark, so it must
132  // run over the cell-centered tilebox. Using nodaltilebox(0) here
133  // would include the plane at bigEnd(0)+1, which is a ghost cell of
134  // this box and a valid cell of its x-neighbor, and so would count
135  // that plane twice in the sums below.
136  Box tbx = mfi.tilebox();
137 
138  ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
139 
140  if(SMark_array(i,j,k,0) != -one) {
141  int turb_index = static_cast<int>(SMark_array(i,j,k,0));
142  Real phi = std::atan2(v_vel(i,j,k),u_vel(i,j,k)); // Wind direction w.r.t the x-direction
143  Gpu::Atomic::Add(&d_freestream_velocity_ptr[turb_index],std::pow(u_vel(i,j,k)*u_vel(i,j,k) + v_vel(i,j,k)*v_vel(i,j,k),myhalf));
144  Gpu::Atomic::Add(&d_disk_cell_count_ptr[turb_index],one);
145  Gpu::Atomic::Add(&d_freestream_phi_ptr[turb_index],phi);
146  }
147  });
148  }
149 
150  // Copy back to host
151  Gpu::copy(Gpu::deviceToHost, d_freestream_velocity.begin(), d_freestream_velocity.end(), freestream_velocity.begin());
152  Gpu::copy(Gpu::deviceToHost, d_freestream_phi.begin(), d_freestream_phi.end(), freestream_phi.begin());
153  Gpu::copy(Gpu::deviceToHost, d_disk_cell_count.begin(), d_disk_cell_count.end(), disk_cell_count.begin());
154 
155  // Reduce the data on every processor
156  amrex::ParallelAllReduce::Sum(freestream_velocity.data(),
157  static_cast<int>(freestream_velocity.size()),
158  amrex::ParallelContext::CommunicatorAll());
159 
160  amrex::ParallelAllReduce::Sum(freestream_phi.data(),
161  static_cast<int>(freestream_phi.size()),
162  amrex::ParallelContext::CommunicatorAll());
163 
164 
165  amrex::ParallelAllReduce::Sum(disk_cell_count.data(),
166  static_cast<int>(disk_cell_count.size()),
167  amrex::ParallelContext::CommunicatorAll());
168 
170 
171 
172  /*if (ParallelDescriptor::IOProcessor()){
173  for(int it=0; it<xloc.size(); it++){
174  std::cout << "turbine index, freestream velocity is " << it << " " << freestream_velocity[it] << " " <<
175  disk_cell_count[it] << " " <<
176  freestream_velocity[it]/(disk_cell_count[it] + 1e-10) << " " <<
177  freestream_phi[it]/(disk_cell_count[it] + 1e-10) << "\n";
178  }
179  }*/
180 }
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
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
amrex::Vector< amrex::Real > freestream_velocity
Definition: ERF_GeneralAD.H:54
amrex::Vector< amrex::Real > xloc
Definition: ERF_GeneralAD.H:50
amrex::Vector< amrex::Real > disk_cell_count
Definition: ERF_GeneralAD.H:54
amrex::Vector< amrex::Real > freestream_phi
Definition: ERF_GeneralAD.H:54
amrex::Vector< amrex::Real > yloc
Definition: ERF_GeneralAD.H:50
void get_turb_loc(amrex::Vector< amrex::Real > &xloc, amrex::Vector< amrex::Real > &yloc)
Definition: ERF_NullWindFarm.H:123
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real phi(amrex::Real d, amrex::Real z0, amrex::Real psi) noexcept
Definition: ERF_ImmersedWallCell.H:176
Here is the call graph for this function:

◆ compute_power_output()

void GeneralAD::compute_power_output ( const double &  time)
37 {
41 
42  const int n_spec_table = static_cast<int>(wind_speed.size());
43  // Compute power based on the look-up table
44 
45  if (ParallelDescriptor::IOProcessor()){
46  static std::ofstream file("power_output_GeneralAD.txt", std::ios::app);
47  // Check if the file opened successfully
48  if (!file.is_open()) {
49  std::cerr << "Error opening file!" << std::endl;
50  Abort("Could not open file to write power output in ERF_AdvanceSimpleAD.cpp");
51  }
52  Real total_power = zero;
53  for(int it=0; it<static_cast<int>(xloc.size()); it++){
54  Real avg_vel = freestream_velocity[it]/(disk_cell_count[it] + Real(1e-10));
55  Real turb_power = interpolate_1d(wind_speed.data(), power.data(), avg_vel, n_spec_table);
56  total_power = total_power + turb_power;
57  }
58  file << time << " " << total_power << "\n";
59  file.flush();
60  }
61 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real interpolate_1d(const amrex::Real *alpha, const amrex::Real *beta, const amrex::Real alpha_interp, const int alpha_size)
Definition: ERF_Interpolation_1D.H:15
amrex::Vector< amrex::Real > wind_speed
Definition: ERF_GeneralAD.H:53
amrex::Vector< amrex::Real > power
Definition: ERF_GeneralAD.H:53
amrex::Vector< amrex::Real > thrust_coeff
Definition: ERF_GeneralAD.H:53
amrex::Real rotor_rad
Definition: ERF_GeneralAD.H:52
amrex::Real hub_height
Definition: ERF_GeneralAD.H:52
amrex::Real thrust_coeff_standing
Definition: ERF_GeneralAD.H:52
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)
Definition: ERF_NullWindFarm.H:111
Here is the call graph for this function:

◆ source_terms_cellcentered()

void GeneralAD::source_terms_cellcentered ( const amrex::Geometry &  geom,
const amrex::MultiFab &  cons_in,
const amrex::MultiFab &  mf_Smark,
amrex::MultiFab &  mf_vars_generalAD,
const amrex::MultiFab *  z_phys_cc 
)
332 {
333 
335 
338 
340 
342 
344 
345  Real d_hub_height = hub_height;
346  Real d_rotor_rad = rotor_rad;
347 
348  Gpu::DeviceVector<Real> d_xloc(xloc.size());
349  Gpu::DeviceVector<Real> d_yloc(yloc.size());
350  Gpu::copy(Gpu::hostToDevice, xloc.begin(), xloc.end(), d_xloc.begin());
351  Gpu::copy(Gpu::hostToDevice, yloc.begin(), yloc.end(), d_yloc.begin());
352 
353  // Ground elevation under each turbine, which SMark's disk is centered hub_height above
354  // (#5181); zero when it was never set
355  Vector<Real> zloc_h(xloc.size(), zero);
356  if (m_zloc.size() == xloc.size()) { zloc_h = m_zloc; }
357  Gpu::DeviceVector<Real> d_zloc(zloc_h.size());
358  Gpu::copy(Gpu::hostToDevice, zloc_h.begin(), zloc_h.end(), d_zloc.begin());
359 
360  auto dx = geom.CellSizeArray();
361  // The kernel thickness takes dy in place of a dx over one cell
362  const Real dx_kernel = LengthScaleCellSize(geom)[0];
363 
364  // Domain valid box
365  const amrex::Box& domain = geom.Domain();
366  auto ProbLoArr = geom.ProbLoArray();
367  int domlo_x = domain.smallEnd(0);
368  int domhi_x = domain.bigEnd(0) + 1;
369  int domlo_y = domain.smallEnd(1);
370  int domhi_y = domain.bigEnd(1) + 1;
371  int domlo_z = domain.smallEnd(2);
372  int domhi_z = domain.bigEnd(2) + 1;
373 
374  // The order of variables are - Vabs dVabsdt, dudt, dvdt, dTKEdt
375  mf_vars_generalAD.setVal(0.0);
376 
377  long unsigned int nturbs = static_cast<long unsigned int>(xloc.size());
378 
379  // This is the angle phi in Fig. 10 in Mirocha et. al. 2014
380  // set_turb_disk angle in ERF_InitWindFarm.cpp sets this phi as
381  // the turb_disk_angle
383  Real d_turb_disk_angle = turb_disk_angle;
384 
385  Gpu::DeviceVector<Real> d_freestream_velocity(nturbs);
386  Gpu::DeviceVector<Real> d_disk_cell_count(nturbs);
387  Gpu::copy(Gpu::hostToDevice, freestream_velocity.begin(), freestream_velocity.end(), d_freestream_velocity.begin());
388  Gpu::copy(Gpu::hostToDevice, disk_cell_count.begin(), disk_cell_count.end(), d_disk_cell_count.begin());
389 
390  Real* d_xloc_ptr = d_xloc.data();
391  Real* d_yloc_ptr = d_yloc.data();
392  Real* d_zloc_ptr = d_zloc.data();
393  Real* d_freestream_velocity_ptr = d_freestream_velocity.data();
394  Real* d_disk_cell_count_ptr = d_disk_cell_count.data();
395 
396  int n_bld_sections = static_cast<int>(bld_rad_loc.size());
397 
398  Gpu::DeviceVector<Real> d_bld_rad_loc(n_bld_sections);
399  Gpu::DeviceVector<Real> d_bld_twist(n_bld_sections);
400  Gpu::DeviceVector<Real> d_bld_chord(n_bld_sections);
401 
402  Gpu::copy(Gpu::hostToDevice, bld_rad_loc.begin(), bld_rad_loc.end(), d_bld_rad_loc.begin());
403  Gpu::copy(Gpu::hostToDevice, bld_twist.begin(), bld_twist.end(), d_bld_twist.begin());
404  Gpu::copy(Gpu::hostToDevice, bld_chord.begin(), bld_chord.end(), d_bld_chord.begin());
405 
406  Real* bld_rad_loc_ptr = d_bld_rad_loc.data();
407  Real* bld_twist_ptr = d_bld_twist.data();
408  Real* bld_chord_ptr = d_bld_chord.data();
409 
410  Vector<Gpu::DeviceVector<Real>> d_bld_airfoil_aoa(n_bld_sections);
411  Vector<Gpu::DeviceVector<Real>> d_bld_airfoil_Cl(n_bld_sections);
412  Vector<Gpu::DeviceVector<Real>> d_bld_airfoil_Cd(n_bld_sections);
413 
414  Vector<int> h_n_pts_airfoil(n_bld_sections);
415  Gpu::DeviceVector<int> d_n_pts_airfoil(n_bld_sections);
416 
417  for (int i = 0; i < n_bld_sections; ++i) {
418  h_n_pts_airfoil[i] = static_cast<int>(bld_airfoil_aoa[i].size());
419 
420  d_bld_airfoil_aoa[i].resize(bld_airfoil_aoa[i].size());
421  d_bld_airfoil_Cl[i].resize(bld_airfoil_Cl[i].size());
422  d_bld_airfoil_Cd[i].resize(bld_airfoil_Cd[i].size());
423 
424  Gpu::copy(Gpu::hostToDevice,
425  bld_airfoil_aoa[i].begin(), bld_airfoil_aoa[i].end(),
426  d_bld_airfoil_aoa[i].begin());
427 
428  Gpu::copy(Gpu::hostToDevice,
429  bld_airfoil_Cl[i].begin(), bld_airfoil_Cl[i].end(),
430  d_bld_airfoil_Cl[i].begin());
431 
432  Gpu::copy(Gpu::hostToDevice,
433  bld_airfoil_Cd[i].begin(), bld_airfoil_Cd[i].end(),
434  d_bld_airfoil_Cd[i].begin());
435  }
436 
437  Gpu::copy(Gpu::hostToDevice,
438  h_n_pts_airfoil.begin(), h_n_pts_airfoil.end(),
439  d_n_pts_airfoil.begin());
440 
441  int* d_n_pts_airfoil_ptr = d_n_pts_airfoil.data();
442 
443  Vector<Real*> hp_bld_airfoil_aoa, hp_bld_airfoil_Cl, hp_bld_airfoil_Cd;
444  for (auto & v :d_bld_airfoil_aoa) {
445  hp_bld_airfoil_aoa.push_back(v.data());
446  }
447  for (auto & v :d_bld_airfoil_Cl) {
448  hp_bld_airfoil_Cl.push_back(v.data());
449  }
450  for (auto & v :d_bld_airfoil_Cd) {
451  hp_bld_airfoil_Cd.push_back(v.data());
452  }
453 
454  Gpu::AsyncArray<Real*> aoa(hp_bld_airfoil_aoa.data(), n_bld_sections);
455  Gpu::AsyncArray<Real*> Cl(hp_bld_airfoil_Cl.data(), n_bld_sections);
456  Gpu::AsyncArray<Real*> Cd(hp_bld_airfoil_Cd.data(), n_bld_sections);
457 
458  auto d_bld_airfoil_aoa_ptr = aoa.data();
459  auto d_bld_airfoil_Cl_ptr = Cl.data();
460  auto d_bld_airfoil_Cd_ptr = Cd.data();
461 
462  int n_spec_extra = static_cast<int>(velocity.size());
463 
464  Gpu::DeviceVector<Real> d_velocity(n_spec_extra);
465  Gpu::DeviceVector<Real> d_rotor_RPM(n_spec_extra);
466  Gpu::DeviceVector<Real> d_blade_pitch(n_spec_extra);
467 
468  Gpu::copy(Gpu::hostToDevice, velocity.begin(), velocity.end(), d_velocity.begin());
469  Gpu::copy(Gpu::hostToDevice, rotor_RPM.begin(), rotor_RPM.end(), d_rotor_RPM.begin());
470  Gpu::copy(Gpu::hostToDevice, blade_pitch.begin(), blade_pitch.end(), d_blade_pitch.begin());
471 
472  auto d_velocity_ptr = d_velocity.data();
473  auto d_rotor_RPM_ptr = d_rotor_RPM.data();
474  auto d_blade_pitch_ptr = d_blade_pitch.data();
475 
476  for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
477 
478  const Box& gbx = mfi.growntilebox(1);
479  auto SMark_array = mf_SMark.array(mfi);
480  auto generalAD_array = mf_vars_generalAD.array(mfi);
481  // Physical cell-center heights, as fill_SMark_multifab marks the disk with (#5181)
482  const Array4<const Real> z_cc = (z_phys_cc) ? z_phys_cc->const_array(mfi) : Array4<const Real>{};
483 
484  ParallelFor(gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
485  int ii = amrex::min(amrex::max(i, domlo_x), domhi_x);
486  int jj = amrex::min(amrex::max(j, domlo_y), domhi_y);
487  int kk = amrex::min(amrex::max(k, domlo_z), domhi_z);
488 
489  Real x = ProbLoArr[0] + (ii+myhalf)*dx[0];
490  Real y = ProbLoArr[1] + (jj+myhalf)*dx[1];
491  // ?? Density needed here
492 
493  int check_int = 0;
494 
495  Real source_x = zero, source_y = zero, source_z = zero;
496  std::array<Real,2> Fn_and_Ft;
497 
498  for(long unsigned int it=0;it<nturbs;it++) {
499  Real avg_vel = d_freestream_velocity_ptr[it]/(d_disk_cell_count_ptr[it] + Real(1e-10));
500  Real phi = d_turb_disk_angle;
501 
502  // This if check makes sure it is a point on the actuator disk
503  if(SMark_array(ii,jj,kk,1) == static_cast<double>(it)) {
504  check_int++;
505 
506  // Height of the point above the hub: the hub is d_hub_height above the
507  // ground under the turbine. Without physical heights, uniform dz above
508  // the domain bottom.
509  Real dzh = (z_cc) ? z_cc(ii,jj,kk) - (d_hub_height + d_zloc_ptr[it])
510  : (kk - domlo_z + myhalf)*dx[2] - d_hub_height;
511 
512  // Find radial distance of the point and the zeta angle
513  Real rad = std::pow( (x-d_xloc_ptr[it])*(x-d_xloc_ptr[it]) +
514  (y-d_yloc_ptr[it])*(y-d_yloc_ptr[it]) +
515  dzh*dzh, myhalf );
516 
517  int index = find_rad_loc_index(rad, bld_rad_loc_ptr, n_bld_sections);
518 
519  // This if check makes sure it is a point with radial distance
520  // between the hub radius and the rotor radius.
521  // ?? hub radius needed here
522  if(rad >= two and rad <= d_rotor_rad) {
523  //AMREX_ASSERT( dzh <= rad );
524  // Consider the vector that joines the point and the turbine center.
525  // Dot it on to the vector that joins the turbine center and along
526  // the plane of the disk. See fig. 10 in Mirocha et. al. Real(2014.)
527 
528  Real vec_proj = (x-d_xloc_ptr[it])*(std::sin(phi)) +
529  (y-d_yloc_ptr[it])*(-std::cos(phi));
530 
531 
532  Real zeta = std::atan2(dzh, vec_proj);
533  //printf("zeta val is %0.15g\n", zeta*Real(180.0)/PI);
534  Fn_and_Ft = compute_source_terms_Fn_Ft(rad, avg_vel,
535  bld_rad_loc_ptr,
536  bld_twist_ptr,
537  bld_chord_ptr,
538  n_bld_sections,
539  d_bld_airfoil_aoa_ptr[index],
540  d_bld_airfoil_Cl_ptr[index],
541  d_bld_airfoil_Cd_ptr[index],
542  d_n_pts_airfoil_ptr[index],
543  d_velocity_ptr,
544  d_rotor_RPM_ptr,
545  d_blade_pitch_ptr,
546  n_spec_extra);
547 
548  Real Fn = three*Fn_and_Ft[0];
549  Real Ft = three*Fn_and_Ft[1];
550  // Compute the source terms - pass in radial distance, free stream velocity
551 
552  Real Fx = Fn*std::cos(phi) + Ft*std::sin(zeta)*std::sin(phi);
553  Real Fy = Fn*std::sin(phi) - Ft*std::sin(zeta)*std::cos(phi);
554  Real Fz = -Ft*std::cos(zeta);
555 
556  //Real dn = (
557 
558  source_x = -Fx/(two*PI*rad*dx_kernel)*one/std::pow(two*PI,myhalf);
559  source_y = -Fy/(two*PI*rad*dx_kernel)*one/std::pow(two*PI,myhalf);
560  source_z = -Fz/(two*PI*rad*dx_kernel)*one/std::pow(two*PI,myhalf);
561 
562 
563  //printf("Val source_x, is %0.15g, %0.15g, %0.15g %0.15g %0.15g %0.15g\n", rad, Fn, Ft, source_x, source_y, source_z);
564  }
565  }
566  }
567 
568  if(check_int > 1){
569  amrex::Error("Actuator disks are overlapping. Visualize actuator_disks.vtk "
570  "and check the windturbine locations input file. Exiting..");
571  }
572 
573  generalAD_array(i,j,k,0) = source_x;
574  generalAD_array(i,j,k,1) = source_y;
575  generalAD_array(i,j,k,2) = source_z;
576  });
577  }
578 }
GpuArray< Real, AMREX_SPACEDIM > dx
Definition: ERF_ActuatorSpreading.cpp:131
AMREX_FORCE_INLINE AMREX_GPU_DEVICE int find_rad_loc_index(const Real rad, const Real *bld_rad_loc, const int n_bld_sections)
Definition: ERF_AdvanceGeneralAD.cpp:184
AMREX_FORCE_INLINE AMREX_GPU_DEVICE std::array< Real, 2 > compute_source_terms_Fn_Ft(const Real rad, const Real avg_vel, const Real *bld_rad_loc, const Real *bld_twist, const Real *bld_chord, int n_bld_sections, const Real *bld_airfoil_aoa, const Real *bld_airfoil_Cl, const Real *bld_airfoil_Cd, const int n_pts_airfoil, const Real *velocity, const Real *rotor_RPM, const Real *blade_pitch, const int n_spec_extra)
Definition: ERF_AdvanceGeneralAD.cpp:217
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > LengthScaleCellSize(const amrex::Geometry &geom)
Definition: ERF_LengthScaleCellSize.H:28
constexpr amrex::Real three
Definition: ERF_NumericalConstants.H:39
constexpr amrex::Real two
Definition: ERF_NumericalConstants.H:38
constexpr amrex::Real PI
Definition: ERF_NumericalConstants.H:46
amrex::Vector< amrex::Vector< amrex::Real > > bld_airfoil_Cl
Definition: ERF_GeneralAD.H:56
amrex::Vector< amrex::Real > velocity
Definition: ERF_GeneralAD.H:57
amrex::Vector< amrex::Real > blade_pitch
Definition: ERF_GeneralAD.H:57
amrex::Vector< amrex::Real > C_P
Definition: ERF_GeneralAD.H:57
amrex::Vector< amrex::Real > bld_twist
Definition: ERF_GeneralAD.H:55
amrex::Vector< amrex::Real > bld_chord
Definition: ERF_GeneralAD.H:55
amrex::Vector< amrex::Real > bld_rad_loc
Definition: ERF_GeneralAD.H:55
amrex::Real turb_disk_angle
Definition: ERF_GeneralAD.H:51
amrex::Vector< amrex::Real > C_T
Definition: ERF_GeneralAD.H:57
amrex::Vector< amrex::Vector< amrex::Real > > bld_airfoil_aoa
Definition: ERF_GeneralAD.H:56
amrex::Vector< amrex::Real > rotor_RPM
Definition: ERF_GeneralAD.H:57
amrex::Vector< amrex::Vector< amrex::Real > > bld_airfoil_Cd
Definition: ERF_GeneralAD.H:56
amrex::Vector< amrex::Real > m_zloc
Definition: ERF_NullWindFarm.H:209
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)
Definition: ERF_NullWindFarm.H:153
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)
Definition: ERF_NullWindFarm.H:144
void get_turb_disk_angle(amrex::Real &turb_disk_angle)
Definition: ERF_NullWindFarm.H:130
void get_blade_spec(amrex::Vector< amrex::Real > &bld_rad_loc, amrex::Vector< amrex::Real > &bld_twist, amrex::Vector< amrex::Real > &bld_chord)
Definition: ERF_NullWindFarm.H:135
Here is the call graph for this function:

◆ update()

void GeneralAD::update ( const double &  dt_advance,
amrex::MultiFab &  cons_in,
amrex::MultiFab &  U_old,
amrex::MultiFab &  V_old,
amrex::MultiFab &  W_old,
const amrex::MultiFab &  mf_vars 
)
71 {
72 
73  for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
74 
75  Box tbx = mfi.nodaltilebox(0);
76  Box tby = mfi.nodaltilebox(1);
77  Box tbz = mfi.nodaltilebox(2);
78 
79  auto generalAD_array = mf_vars_generalAD.array(mfi);
80  auto u_vel = U_old.array(mfi);
81  auto v_vel = V_old.array(mfi);
82  auto w_vel = W_old.array(mfi);
83 
84  ParallelFor(tbx, tby, tbz,
85  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
86  {
87  u_vel(i,j,k) = u_vel(i,j,k) + (generalAD_array(i-1,j,k,0) + generalAD_array(i,j,k,0))/two*dt_advance;
88  },
89  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
90  {
91  v_vel(i,j,k) = v_vel(i,j,k) + (generalAD_array(i,j-1,k,1) + generalAD_array(i,j,k,1))/two*dt_advance;
92  },
93  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
94  {
95  w_vel(i,j,k) = w_vel(i,j,k) + (generalAD_array(i,j,k-1,2) + generalAD_array(i,j,k,2))/two*dt_advance;
96  });
97 
98  }
99 }
Here is the call graph for this function:

Member Data Documentation

◆ blade_pitch

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

◆ bld_airfoil_aoa

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

◆ bld_airfoil_Cd

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

◆ bld_airfoil_Cl

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

◆ bld_chord

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

◆ bld_rad_loc

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

◆ bld_twist

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

◆ C_P

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

◆ C_T

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

◆ disk_cell_count

amrex::Vector<amrex::Real> GeneralAD::disk_cell_count
protected

◆ freestream_phi

amrex::Vector<amrex::Real> GeneralAD::freestream_phi
protected

◆ freestream_velocity

amrex::Vector<amrex::Real> GeneralAD::freestream_velocity
protected

◆ hub_height

amrex::Real GeneralAD::hub_height
protected

◆ nominal_power

amrex::Real GeneralAD::nominal_power
protected

◆ power

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

◆ rotor_rad

amrex::Real GeneralAD::rotor_rad
protected

◆ rotor_RPM

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

◆ thrust_coeff

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

◆ thrust_coeff_standing

amrex::Real GeneralAD::thrust_coeff_standing
protected

◆ turb_disk_angle

amrex::Real GeneralAD::turb_disk_angle
protected

◆ velocity

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

◆ wind_speed

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

◆ xloc

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

◆ yloc

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

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