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

#include <ERF_EWP.H>

Inheritance diagram for EWP:
Collaboration diagram for EWP:

Public Member Functions

 EWP ()
 
virtual ~EWP ()=default
 
void advance (const amrex::Geometry &geom, const double &dt_advance, amrex::MultiFab &cons_in, amrex::MultiFab &mf_vars_ewp, 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 source_terms_cellcentered (const amrex::Geometry &geom, const amrex::MultiFab &cons_in, amrex::MultiFab &mf_vars, const amrex::MultiFab &U_old, const amrex::MultiFab &V_old, const amrex::MultiFab &W_old, const amrex::MultiFab &mf_Nturb, const amrex::MultiFab *z_phys_nd)
 
void update (const double &dt_advance, amrex::MultiFab &cons_in, amrex::MultiFab &U_old, amrex::MultiFab &V_old, const amrex::MultiFab &mf_vars_ewp)
 
void compute_power_output (const amrex::MultiFab &cons_in, const amrex::MultiFab &U_old, const amrex::MultiFab &V_old, const amrex::MultiFab &W_old, const amrex::MultiFab &mf_SMark, const amrex::MultiFab &mf_Nturb, 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 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
 
- 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

◆ EWP()

EWP::EWP ( )
inline
13 {}

◆ ~EWP()

virtual EWP::~EWP ( )
virtualdefault

Member Function Documentation

◆ advance()

void EWP::advance ( const amrex::Geometry &  geom,
const double &  dt_advance,
amrex::MultiFab &  cons_in,
amrex::MultiFab &  mf_vars_ewp,
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(mf_SMark.nComp() > 0);
25  AMREX_ALWAYS_ASSERT(time > -one);
26  amrex::ignore_unused(z_phys_cc);
27  source_terms_cellcentered(geom, cons_in, mf_vars_ewp, U_old, V_old, W_old, mf_Nturb, z_phys_nd);
28  update(dt_advance, cons_in, U_old, V_old, mf_vars_ewp);
29  compute_power_output(cons_in, U_old, V_old, W_old, mf_SMark, mf_Nturb, time);
30 }
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
void compute_power_output(const amrex::MultiFab &cons_in, const amrex::MultiFab &U_old, const amrex::MultiFab &V_old, const amrex::MultiFab &W_old, const amrex::MultiFab &mf_SMark, const amrex::MultiFab &mf_Nturb, const double &time)
Definition: ERF_AdvanceEWP.cpp:34
void update(const double &dt_advance, amrex::MultiFab &cons_in, amrex::MultiFab &U_old, amrex::MultiFab &V_old, const amrex::MultiFab &mf_vars_ewp)
Definition: ERF_AdvanceEWP.cpp:104
void source_terms_cellcentered(const amrex::Geometry &geom, const amrex::MultiFab &cons_in, amrex::MultiFab &mf_vars, const amrex::MultiFab &U_old, const amrex::MultiFab &V_old, const amrex::MultiFab &W_old, const amrex::MultiFab &mf_Nturb, const amrex::MultiFab *z_phys_nd)
Definition: ERF_AdvanceEWP.cpp:138
Here is the call graph for this function:

◆ compute_power_output()

void EWP::compute_power_output ( const amrex::MultiFab &  cons_in,
const amrex::MultiFab &  U_old,
const amrex::MultiFab &  V_old,
const amrex::MultiFab &  W_old,
const amrex::MultiFab &  mf_SMark,
const amrex::MultiFab &  mf_Nturb,
const double &  time 
)
41 {
45 
46  const int n_spec_table = static_cast<int>(wind_speed.size());
47 
48  Gpu::DeviceVector<Real> d_wind_speed(wind_speed.size());
49  Gpu::DeviceVector<Real> d_power(wind_speed.size());
50  Gpu::copy(Gpu::hostToDevice, wind_speed.begin(), wind_speed.end(), d_wind_speed.begin());
51  Gpu::copy(Gpu::hostToDevice, power.begin(), power.end(), d_power.begin());
52 
53  Gpu::DeviceScalar<Real> d_total_power(zero);
54  Real* d_total_power_ptr = d_total_power.dataPtr();
55 
56  const Real* d_wind_speed_ptr = d_wind_speed.dataPtr();
57  const Real* d_power_ptr = d_power.dataPtr();
58 
59  for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
60 
61  auto SMark_array = mf_SMark.array(mfi);
62  auto Nturb_array = mf_Nturb.array(mfi);
63  auto u_vel = U_old.array(mfi);
64  auto v_vel = V_old.array(mfi);
65  auto w_vel = W_old.array(mfi);
66  // NOTE: this reduction is driven by the cell-centered SMark/Nturb, so it
67  // must run over the cell-centered tilebox. Using nodaltilebox(0)
68  // here would include the plane at bigEnd(0)+1, which is a ghost
69  // cell of this box and a valid cell of its x-neighbor, and so
70  // would count that plane twice in the power sum below.
71  Box tbx = mfi.tilebox();
72 
73  ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
74 
75  if(SMark_array(i,j,k,0) == one) {
76  Real avg_vel = std::pow(u_vel(i,j,k)*u_vel(i,j,k) +
77  v_vel(i,j,k)*v_vel(i,j,k) +
78  w_vel(i,j,k)*w_vel(i,j,k),myhalf);
79  Real turb_power = interpolate_1d(d_wind_speed_ptr, d_power_ptr, avg_vel, n_spec_table);
80  turb_power = turb_power*Nturb_array(i,j,k,0);
81  Gpu::Atomic::Add(d_total_power_ptr,turb_power);
82  }
83  });
84  }
85 
86  Real h_total_power = zero;
87  Gpu::copy(Gpu::deviceToHost, d_total_power.dataPtr(), d_total_power.dataPtr()+1, &h_total_power);
88 
89  amrex::ParallelAllReduce::Sum(&h_total_power, 1, amrex::ParallelContext::CommunicatorAll());
90 
91  if (ParallelDescriptor::IOProcessor()){
92  static std::ofstream file("power_output_EWP.txt", std::ios::app);
93  // Check if the file opened successfully
94  if (!file.is_open()) {
95  std::cerr << "Error opening file!" << std::endl;
96  Abort("Could not open file to write power output in ERF_AdvanceSimpleAD.cpp");
97  }
98  file << time << " " << h_total_power << "\n";
99  file.flush();
100  }
101 }
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
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::Real thrust_coeff_standing
Definition: ERF_EWP.H:55
amrex::Real hub_height
Definition: ERF_EWP.H:55
amrex::Vector< amrex::Real > wind_speed
Definition: ERF_EWP.H:56
amrex::Vector< amrex::Real > xloc
Definition: ERF_EWP.H:54
amrex::Vector< amrex::Real > thrust_coeff
Definition: ERF_EWP.H:56
amrex::Vector< amrex::Real > power
Definition: ERF_EWP.H:56
amrex::Real rotor_rad
Definition: ERF_EWP.H:55
amrex::Vector< amrex::Real > yloc
Definition: ERF_EWP.H:54
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
void get_turb_loc(amrex::Vector< amrex::Real > &xloc, amrex::Vector< amrex::Real > &yloc)
Definition: ERF_NullWindFarm.H:123
Here is the call graph for this function:

◆ source_terms_cellcentered()

void EWP::source_terms_cellcentered ( const amrex::Geometry &  geom,
const amrex::MultiFab &  cons_in,
amrex::MultiFab &  mf_vars,
const amrex::MultiFab &  U_old,
const amrex::MultiFab &  V_old,
const amrex::MultiFab &  W_old,
const amrex::MultiFab &  mf_Nturb,
const amrex::MultiFab *  z_phys_nd 
)
146 {
147 
150 
151  // dx in place of a dy over one cell, and the reverse (only dz is used as a spacing)
152  auto dx = LengthScaleCellSize(geom);
153  Real sigma_0 = Real(1.7)*rotor_rad;
154 
155  Real d_rotor_rad = rotor_rad;
156  Real d_hub_height = hub_height;
157 
158  Gpu::DeviceVector<Real> d_wind_speed(wind_speed.size());
159  Gpu::DeviceVector<Real> d_thrust_coeff(thrust_coeff.size());
160 
161  // Copy data from host vectors to device vectors
162  Gpu::copy(Gpu::hostToDevice, wind_speed.begin(), wind_speed.end(), d_wind_speed.begin());
163  Gpu::copy(Gpu::hostToDevice, thrust_coeff.begin(), thrust_coeff.end(), d_thrust_coeff.begin());
164 
165 
166  // Domain valid box
167  const amrex::Box& domain = geom.Domain();
168  int domlo_z = domain.smallEnd(2);
169  int domhi_z = domain.bigEnd(2) + 1;
170  // Cells for the heights: kc+1 stays a node of the domain
171  int domhi_cc = domain.bigEnd(2);
172 
173  // The order of variables are - Vabs dVabsdt, dudt, dvdt, dTKEdt
174  mf_vars_ewp.setVal(0.0);
175 
176  for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
177 
178  const Box& gbx = mfi.growntilebox(1);
179  auto ewp_array = mf_vars_ewp.array(mfi);
180  auto Nturb_array = mf_Nturb.array(mfi);
181  auto u_vel = U_old.array(mfi);
182  auto v_vel = V_old.array(mfi);
183  auto w_vel = W_old.array(mfi);
184  // Physical node heights (#5182); without them, uniform dz above the domain bottom
185  const Array4<const Real> zp = (z_phys_nd) ? z_phys_nd->const_array(mfi) : Array4<const Real>{};
186 
187  const Real* wind_speed_d = d_wind_speed.dataPtr();
188  const Real* thrust_coeff_d = d_thrust_coeff.dataPtr();
189  const int n_spec_table = static_cast<int>(d_wind_speed.size());
190 
191  ParallelFor(gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
192 
193  int kk = amrex::min(amrex::max(k, domlo_z), domhi_z);
194  int kc = amrex::min(amrex::max(k, domlo_z), domhi_cc);
195  // Cell-center height above the ground, where the hub height is measured from
196  Real z = myhalf * (windfarm_face_height_above_ground(zp, i, j, kc , domlo_z, dx[2]) +
197  windfarm_face_height_above_ground(zp, i, j, kc+1, domlo_z, dx[2]));
198 
199  // Compute Fitch source terms
200 
201  Real Vabs = std::pow(u_vel(i,j,k)*u_vel(i,j,k) +
202  v_vel(i,j,k)*v_vel(i,j,k) +
203  w_vel(i,j,kk)*w_vel(i,j,kk), myhalf);
204 
205  Real C_T = interpolate_1d(wind_speed_d, thrust_coeff_d, Vabs, n_spec_table);
206 
207  Real C_TKE = zero;
208  Real K_turb = Real(6.0);
209 
210  Real L_wake = std::pow(dx[0]*dx[1],myhalf)/two;
211 
212  // With no wind the source is zero (fac ~ Vabs^(5/2) as Vabs -> 0);
213  // avoid the 0 * inf in sigma_e
214  Real fac = zero;
215  if (Vabs > zero) {
216  Real sigma_e = Vabs/(three*K_turb*L_wake)*
217  (std::pow(two*K_turb*L_wake/Vabs + std::pow(sigma_0,2),three/two) - amrex::Math::powi<3>(sigma_0));
218 
219  fac = -std::pow(PI/Real(8.0),myhalf)*C_T*amrex::Math::powi<2>(d_rotor_rad)*
220  amrex::Math::powi<2>(Vabs)/(dx[0]*dx[1]*sigma_e)*
221  std::exp(-myhalf*amrex::Math::powi<2>((z - d_hub_height)/sigma_e));
222  }
223 
224  Real phi = std::atan2(v_vel(i,j,k),u_vel(i,j,k)); // Wind direction w.r.t the x-dreiction
225  ewp_array(i,j,k,0) = fac*std::cos(phi)*Nturb_array(i,j,k);
226  ewp_array(i,j,k,1) = fac*std::sin(phi)*Nturb_array(i,j,k);
227  ewp_array(i,j,k,2) = C_TKE*zero;
228  });
229  }
230 }
GpuArray< Real, AMREX_SPACEDIM > dx
Definition: ERF_ActuatorSpreading.cpp:131
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > LengthScaleCellSize(const amrex::Geometry &geom)
Definition: ERF_LengthScaleCellSize.H:28
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real windfarm_face_height_above_ground(const amrex::Array4< const amrex::Real > &zp, int i, int j, int kf, int klo, amrex::Real dz) noexcept
Definition: ERF_NullWindFarm.H:16
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_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:

◆ update()

void EWP::update ( const double &  dt_advance,
amrex::MultiFab &  cons_in,
amrex::MultiFab &  U_old,
amrex::MultiFab &  V_old,
const amrex::MultiFab &  mf_vars_ewp 
)
108 {
109 
110  for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
111 
112  Box bx = mfi.tilebox();
113  Box tbx = mfi.nodaltilebox(0);
114  Box tby = mfi.nodaltilebox(1);
115 
116  auto cons_array = cons_in.array(mfi);
117  auto ewp_array = mf_vars_ewp.array(mfi);
118  auto u_vel = U_old.array(mfi);
119  auto v_vel = V_old.array(mfi);
120 
121  ParallelFor(tbx, tby, bx,
122  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
123  {
124  u_vel(i,j,k) = u_vel(i,j,k) + (ewp_array(i-1,j,k,0) + ewp_array(i,j,k,0))/two*dt_advance;
125  },
126  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
127  {
128  v_vel(i,j,k) = v_vel(i,j,k) + (ewp_array(i,j-1,k,1) + ewp_array(i,j,k,1))/two*dt_advance;
129  },
130  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
131  {
132  cons_array(i,j,k,RhoKE_comp) = cons_array(i,j,k,RhoKE_comp) + ewp_array(i,j,k,2)*dt_advance;
133  });
134  }
135 }
#define RhoKE_comp
Definition: ERF_IndexDefines.H:63
Here is the call graph for this function:

Member Data Documentation

◆ hub_height

amrex::Real EWP::hub_height
protected

◆ nominal_power

amrex::Real EWP::nominal_power
protected

◆ power

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

◆ rotor_rad

amrex::Real EWP::rotor_rad
protected

◆ thrust_coeff

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

◆ thrust_coeff_standing

amrex::Real EWP::thrust_coeff_standing
protected

◆ wind_speed

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

◆ xloc

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

◆ yloc

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

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