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

#include <ERF_SimpleAD.H>

Inheritance diagram for SimpleAD:
Collaboration diagram for SimpleAD:

Public Member Functions

 SimpleAD ()
 
virtual ~SimpleAD ()=default
 
void advance (const amrex::Geometry &geom, const amrex::Real &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::Real &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_simpleAD)
 
void update (const amrex::Real &dt_advance, amrex::MultiFab &cons_in, amrex::MultiFab &U_old, amrex::MultiFab &V_old, const amrex::MultiFab &mf_vars)
 
void compute_power_output (const amrex::Real &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_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
 
- Protected Attributes inherited from NullWindFarm
amrex::Vector< amrex::Real > m_xloc
 
amrex::Vector< amrex::Real > m_yloc
 
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

◆ SimpleAD()

SimpleAD::SimpleAD ( )
inline
12 {}

◆ ~SimpleAD()

virtual SimpleAD::~SimpleAD ( )
virtualdefault

Member Function Documentation

◆ advance()

void SimpleAD::advance ( const amrex::Geometry &  geom,
const amrex::Real &  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::Real &  time 
)
overridevirtual

Implements NullWindFarm.

18 {
19  AMREX_ALWAYS_ASSERT(W_old.nComp() > 0);
20  AMREX_ALWAYS_ASSERT(mf_Nturb.nComp() > 0);
21  compute_freestream_velocity(cons_in, U_old, V_old, mf_SMark);
22  source_terms_cellcentered(geom, cons_in, mf_SMark, mf_vars_simpleAD);
23  update(dt_advance, cons_in, U_old, V_old, mf_vars_simpleAD);
25 }
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_AdvanceSimpleAD.cpp:84
void update(const amrex::Real &dt_advance, amrex::MultiFab &cons_in, amrex::MultiFab &U_old, amrex::MultiFab &V_old, const amrex::MultiFab &mf_vars)
Definition: ERF_AdvanceSimpleAD.cpp:57
void compute_power_output(const amrex::Real &time)
Definition: ERF_AdvanceSimpleAD.cpp:28
void source_terms_cellcentered(const amrex::Geometry &geom, const amrex::MultiFab &cons_in, const amrex::MultiFab &mf_Smark, amrex::MultiFab &mf_vars_simpleAD)
Definition: ERF_AdvanceSimpleAD.cpp:160

◆ compute_freestream_velocity()

void SimpleAD::compute_freestream_velocity ( const amrex::MultiFab &  cons_in,
const amrex::MultiFab &  U_old,
const amrex::MultiFab &  V_old,
const amrex::MultiFab &  mf_SMark 
)
88 {
90  freestream_velocity.clear();
91  freestream_phi.clear();
92  disk_cell_count.clear();
93  freestream_velocity.resize(xloc.size(),0.0);
94  freestream_phi.resize(xloc.size(),0.0);
95  disk_cell_count.resize(xloc.size(),0.0);
96 
97  Gpu::DeviceVector<Real> d_freestream_velocity(xloc.size());
98  Gpu::DeviceVector<Real> d_freestream_phi(yloc.size());
99  Gpu::DeviceVector<Real> d_disk_cell_count(yloc.size());
100  Gpu::copy(Gpu::hostToDevice, freestream_velocity.begin(), freestream_velocity.end(), d_freestream_velocity.begin());
101  Gpu::copy(Gpu::hostToDevice, freestream_phi.begin(), freestream_phi.end(), d_freestream_phi.begin());
102  Gpu::copy(Gpu::hostToDevice, disk_cell_count.begin(), disk_cell_count.end(), d_disk_cell_count.begin());
103 
104  Real* d_freestream_velocity_ptr = d_freestream_velocity.data();
105  Real* d_freestream_phi_ptr = d_freestream_phi.data();
106  Real* d_disk_cell_count_ptr = d_disk_cell_count.data();
107 
108 
109  for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
110 
111  auto SMark_array = mf_SMark.array(mfi);
112  auto u_vel = U_old.array(mfi);
113  auto v_vel = V_old.array(mfi);
114  Box tbx = mfi.nodaltilebox(0);
115 
116  ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
117 
118  if(SMark_array(i,j,k,0) != -1.0) {
119  int turb_index = static_cast<int>(SMark_array(i,j,k,0));
120  Real phi = std::atan2(v_vel(i,j,k),u_vel(i,j,k)); // Wind direction w.r.t the x-dreiction
121  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),0.5));
122  Gpu::Atomic::Add(&d_disk_cell_count_ptr[turb_index],1.0);
123  Gpu::Atomic::Add(&d_freestream_phi_ptr[turb_index],phi);
124  }
125  });
126  }
127 
128  // Copy back to host
129  Gpu::copy(Gpu::deviceToHost, d_freestream_velocity.begin(), d_freestream_velocity.end(), freestream_velocity.begin());
130  Gpu::copy(Gpu::deviceToHost, d_freestream_phi.begin(), d_freestream_phi.end(), freestream_phi.begin());
131  Gpu::copy(Gpu::deviceToHost, d_disk_cell_count.begin(), d_disk_cell_count.end(), disk_cell_count.begin());
132 
133  // Reduce the data on every processor
134  amrex::ParallelAllReduce::Sum(freestream_velocity.data(),
135  freestream_velocity.size(),
136  amrex::ParallelContext::CommunicatorAll());
137 
138  amrex::ParallelAllReduce::Sum(freestream_phi.data(),
139  freestream_phi.size(),
140  amrex::ParallelContext::CommunicatorAll());
141 
142 
143  amrex::ParallelAllReduce::Sum(disk_cell_count.data(),
144  disk_cell_count.size(),
145  amrex::ParallelContext::CommunicatorAll());
146 
148  /*if (ParallelDescriptor::IOProcessor()){
149  for(int it=0; it<xloc.size(); it++){
150 
151  std::cout << "turbine index, freestream velocity is " << it << " " << freestream_velocity[it] << " " <<
152  disk_cell_count[it] << " " <<
153  freestream_velocity[it]/(disk_cell_count[it] + 1e-10) << " " <<
154  freestream_phi[it]/(disk_cell_count[it] + 1e-10) << "\n";
155  }
156  }*/
157 }
void get_turb_loc(amrex::Vector< amrex::Real > &xloc, amrex::Vector< amrex::Real > &yloc)
Definition: ERF_NullWindFarm.H:96
amrex::Vector< amrex::Real > disk_cell_count
Definition: ERF_SimpleAD.H:50
amrex::Vector< amrex::Real > freestream_velocity
Definition: ERF_SimpleAD.H:50
amrex::Vector< amrex::Real > xloc
Definition: ERF_SimpleAD.H:46
amrex::Vector< amrex::Real > yloc
Definition: ERF_SimpleAD.H:46
amrex::Vector< amrex::Real > freestream_phi
Definition: ERF_SimpleAD.H:50

◆ compute_power_output()

void SimpleAD::compute_power_output ( const amrex::Real &  time)
29 {
33 
34  const int n_spec_table = wind_speed.size();
35  // Compute power based on the look-up table
36 
37  if (ParallelDescriptor::IOProcessor()){
38  static std::ofstream file("power_output_SimpleAD.txt", std::ios::app);
39  // Check if the file opened successfully
40  if (!file.is_open()) {
41  std::cerr << "Error opening file!" << std::endl;
42  Abort("Could not open file to write power output in ERF_AdvanceSimpleAD.cpp");
43  }
44  Real total_power = 0.0;
45  for(int it=0; it<xloc.size(); it++){
46  Real avg_vel = freestream_velocity[it]/(disk_cell_count[it] + 1e-10);
47  Real turb_power = interpolate_1d(wind_speed.data(), power.data(), avg_vel, n_spec_table);
48  total_power = total_power + turb_power;
49  //printf("avg vel and power is %d %0.15g, %0.15g\n", it, avg_vel, turb_power);
50  }
51  file << time << " " << total_power << "\n";
52  file.flush();
53  }
54 }
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:12
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:84
amrex::Real rotor_rad
Definition: ERF_SimpleAD.H:48
amrex::Vector< amrex::Real > thrust_coeff
Definition: ERF_SimpleAD.H:49
amrex::Real thrust_coeff_standing
Definition: ERF_SimpleAD.H:48
amrex::Vector< amrex::Real > wind_speed
Definition: ERF_SimpleAD.H:49
amrex::Vector< amrex::Real > power
Definition: ERF_SimpleAD.H:49
amrex::Real hub_height
Definition: ERF_SimpleAD.H:48
Here is the call graph for this function:

◆ source_terms_cellcentered()

void SimpleAD::source_terms_cellcentered ( const amrex::Geometry &  geom,
const amrex::MultiFab &  cons_in,
const amrex::MultiFab &  mf_Smark,
amrex::MultiFab &  mf_vars_simpleAD 
)
164 {
165 
169 
170  Gpu::DeviceVector<Real> d_xloc(xloc.size());
171  Gpu::DeviceVector<Real> d_yloc(yloc.size());
172  Gpu::copy(Gpu::hostToDevice, xloc.begin(), xloc.end(), d_xloc.begin());
173  Gpu::copy(Gpu::hostToDevice, yloc.begin(), yloc.end(), d_yloc.begin());
174 
175  auto dx = geom.CellSizeArray();
176 
177  // Domain valid box
178  const amrex::Box& domain = geom.Domain();
179  int domlo_x = domain.smallEnd(0);
180  int domhi_x = domain.bigEnd(0) + 1;
181  int domlo_y = domain.smallEnd(1);
182  int domhi_y = domain.bigEnd(1) + 1;
183  int domlo_z = domain.smallEnd(2);
184  int domhi_z = domain.bigEnd(2) + 1;
185 
186  // The order of variables are - Vabs dVabsdt, dudt, dvdt, dTKEdt
187  mf_vars_simpleAD.setVal(0.0);
188 
189  long unsigned int nturbs = xloc.size();
190 
191  Gpu::DeviceVector<Real> d_freestream_velocity(nturbs);
192  Gpu::DeviceVector<Real> d_freestream_phi(nturbs);
193  Gpu::DeviceVector<Real> d_disk_cell_count(nturbs);
194  Gpu::copy(Gpu::hostToDevice, freestream_velocity.begin(), freestream_velocity.end(), d_freestream_velocity.begin());
195  Gpu::copy(Gpu::hostToDevice, freestream_phi.begin(), freestream_phi.end(), d_freestream_phi.begin());
196  Gpu::copy(Gpu::hostToDevice, disk_cell_count.begin(), disk_cell_count.end(), d_disk_cell_count.begin());
197 
198  Real* d_freestream_velocity_ptr = d_freestream_velocity.data();
199  Real* d_freestream_phi_ptr = d_freestream_phi.data();
200  Real* d_disk_cell_count_ptr = d_disk_cell_count.data();
201 
203  Real nx = -std::cos(turb_disk_angle);
204  Real ny = -std::sin(turb_disk_angle);
205  Real d_turb_disk_angle = turb_disk_angle;
206 
207  Gpu::DeviceVector<Real> d_wind_speed(wind_speed.size());
208  Gpu::DeviceVector<Real> d_thrust_coeff(thrust_coeff.size());
209 
210  // Copy data from host vectors to device vectors
211  Gpu::copy(Gpu::hostToDevice, wind_speed.begin(), wind_speed.end(), d_wind_speed.begin());
212  Gpu::copy(Gpu::hostToDevice, thrust_coeff.begin(), thrust_coeff.end(), d_thrust_coeff.begin());
213 
214  const Real* wind_speed_d = d_wind_speed.dataPtr();
215  const Real* thrust_coeff_d = d_thrust_coeff.dataPtr();
216  const int n_spec_table = d_wind_speed.size();
217 
218  for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
219 
220  const Box& gbx = mfi.growntilebox(1);
221  auto SMark_array = mf_SMark.array(mfi);
222  auto simpleAD_array = mf_vars_simpleAD.array(mfi);
223 
224  ParallelFor(gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
225  int ii = amrex::min(amrex::max(i, domlo_x), domhi_x);
226  int jj = amrex::min(amrex::max(j, domlo_y), domhi_y);
227  int kk = amrex::min(amrex::max(k, domlo_z), domhi_z);
228 
229 
230  Real source_x = 0.0;
231  Real source_y = 0.0;
232 
233  int it = static_cast<int>(SMark_array(ii,jj,kk,1));
234 
235  if(it != -1) {
236  Real avg_vel = d_freestream_velocity_ptr[it]/(d_disk_cell_count_ptr[it] + 1e-10);
237  Real phi = d_freestream_phi_ptr[it]/(d_disk_cell_count_ptr[it] + 1e-10);
238 
239  Real C_T = interpolate_1d(wind_speed_d, thrust_coeff_d, avg_vel, n_spec_table);
240  Real a;
241  if(C_T <= 1) {
242  a = 0.5 - 0.5*std::pow(1.0-C_T,0.5);
243  }
244  Real Uinfty_dot_nhat = avg_vel*(std::cos(phi)*nx + std::sin(phi)*ny);
245  if(C_T <= 1) {
246  source_x = -2.0*std::pow(Uinfty_dot_nhat, 2.0)*a*(1.0-a)*dx[1]*dx[2]*std::cos(d_turb_disk_angle)/(dx[0]*dx[1]*dx[2])*std::cos(phi);
247  source_y = -2.0*std::pow(Uinfty_dot_nhat, 2.0)*a*(1.0-a)*dx[1]*dx[2]*std::cos(d_turb_disk_angle)/(dx[0]*dx[1]*dx[2])*std::sin(phi);
248  }
249  else {
250  source_x = -0.5*C_T*std::pow(Uinfty_dot_nhat, 2.0)*dx[1]*dx[2]*std::cos(d_turb_disk_angle)/(dx[0]*dx[1]*dx[2])*std::cos(phi);
251  source_y = -0.5*C_T*std::pow(Uinfty_dot_nhat, 2.0)*dx[1]*dx[2]*std::cos(d_turb_disk_angle)/(dx[0]*dx[1]*dx[2])*std::sin(phi);
252  }
253  }
254 
255  simpleAD_array(i,j,k,0) = source_x;
256  simpleAD_array(i,j,k,1) = source_y;
257  });
258  }
259 }
void get_turb_disk_angle(amrex::Real &turb_disk_angle)
Definition: ERF_NullWindFarm.H:103
amrex::Real turb_disk_angle
Definition: ERF_SimpleAD.H:47
Here is the call graph for this function:

◆ update()

void SimpleAD::update ( const amrex::Real &  dt_advance,
amrex::MultiFab &  cons_in,
amrex::MultiFab &  U_old,
amrex::MultiFab &  V_old,
const amrex::MultiFab &  mf_vars 
)
61 {
62 
63  for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
64 
65  Box tbx = mfi.nodaltilebox(0);
66  Box tby = mfi.nodaltilebox(1);
67 
68  auto simpleAD_array = mf_vars_simpleAD.array(mfi);
69  auto u_vel = U_old.array(mfi);
70  auto v_vel = V_old.array(mfi);
71 
72  ParallelFor(tbx, tby,
73  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
74  {
75  u_vel(i,j,k) = u_vel(i,j,k) + (simpleAD_array(i-1,j,k,0) + simpleAD_array(i,j,k,0))/2.0*dt_advance;
76  },
77  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
78  {
79  v_vel(i,j,k) = v_vel(i,j,k) + (simpleAD_array(i,j-1,k,1) + simpleAD_array(i,j,k,1))/2.0*dt_advance;
80  });
81  }
82 }

Member Data Documentation

◆ disk_cell_count

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

◆ freestream_phi

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

◆ freestream_velocity

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

◆ hub_height

amrex::Real SimpleAD::hub_height
protected

◆ nominal_power

amrex::Real SimpleAD::nominal_power
protected

◆ power

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

◆ rotor_rad

amrex::Real SimpleAD::rotor_rad
protected

◆ thrust_coeff

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

◆ thrust_coeff_standing

amrex::Real SimpleAD::thrust_coeff_standing
protected

◆ turb_disk_angle

amrex::Real SimpleAD::turb_disk_angle
protected

◆ wind_speed

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

◆ xloc

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

◆ yloc

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

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