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 amrex::Real &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::Real &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)
 
void update (const amrex::Real &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 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 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::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 amrex::Real &  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::Real &  time 
)
overridevirtual

Implements NullWindFarm.

19  {
20  AMREX_ALWAYS_ASSERT(mf_SMark.nComp() > 0);
21  AMREX_ALWAYS_ASSERT(time > -1.0);
22  source_terms_cellcentered(geom, cons_in, mf_vars_ewp, U_old, V_old, W_old, mf_Nturb);
23  update(dt_advance, cons_in, U_old, V_old, mf_vars_ewp);
24  compute_power_output(cons_in, U_old, V_old, W_old, mf_SMark, mf_Nturb, time);
25 }
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)
Definition: ERF_AdvanceEWP.cpp:128
void update(const amrex::Real &dt_advance, amrex::MultiFab &cons_in, amrex::MultiFab &U_old, amrex::MultiFab &V_old, const amrex::MultiFab &mf_vars_ewp)
Definition: ERF_AdvanceEWP.cpp:94
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 amrex::Real &time)
Definition: ERF_AdvanceEWP.cpp:29

◆ 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 amrex::Real &  time 
)
36 {
40 
41  const int n_spec_table = wind_speed.size();
42 
43  Gpu::DeviceVector<Real> d_wind_speed(wind_speed.size());
44  Gpu::DeviceVector<Real> d_power(wind_speed.size());
45  Gpu::copy(Gpu::hostToDevice, wind_speed.begin(), wind_speed.end(), d_wind_speed.begin());
46  Gpu::copy(Gpu::hostToDevice, power.begin(), power.end(), d_power.begin());
47 
48  Gpu::DeviceScalar<Real> d_total_power(0.0);
49  Real* d_total_power_ptr = d_total_power.dataPtr();
50 
51  const Real* d_wind_speed_ptr = d_wind_speed.dataPtr();
52  const Real* d_power_ptr = d_power.dataPtr();
53 
54  for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
55 
56  auto SMark_array = mf_SMark.array(mfi);
57  auto Nturb_array = mf_Nturb.array(mfi);
58  auto u_vel = U_old.array(mfi);
59  auto v_vel = V_old.array(mfi);
60  auto w_vel = W_old.array(mfi);
61  Box tbx = mfi.nodaltilebox(0);
62 
63  ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
64 
65  if(SMark_array(i,j,k,0) == 1.0) {
66  Real avg_vel = std::pow(u_vel(i,j,k)*u_vel(i,j,k) +
67  v_vel(i,j,k)*v_vel(i,j,k) +
68  w_vel(i,j,k)*w_vel(i,j,k),0.5);
69  Real turb_power = interpolate_1d(d_wind_speed_ptr, d_power_ptr, avg_vel, n_spec_table);
70  turb_power = turb_power*Nturb_array(i,j,k,0);
71  Gpu::Atomic::Add(d_total_power_ptr,turb_power);
72  }
73  });
74  }
75 
76  Real h_total_power = 0.0;
77  Gpu::copy(Gpu::deviceToHost, d_total_power.dataPtr(), d_total_power.dataPtr()+1, &h_total_power);
78 
79  amrex::ParallelAllReduce::Sum(&h_total_power, 1, amrex::ParallelContext::CommunicatorAll());
80 
81  if (ParallelDescriptor::IOProcessor()){
82  static std::ofstream file("power_output_EWP.txt", std::ios::app);
83  // Check if the file opened successfully
84  if (!file.is_open()) {
85  std::cerr << "Error opening file!" << std::endl;
86  Abort("Could not open file to write power output in ERF_AdvanceSimpleAD.cpp");
87  }
88  file << time << " " << h_total_power << "\n";
89  file.flush();
90  }
91 }
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
amrex::Real thrust_coeff_standing
Definition: ERF_EWP.H:52
amrex::Real hub_height
Definition: ERF_EWP.H:52
amrex::Vector< amrex::Real > wind_speed
Definition: ERF_EWP.H:53
amrex::Vector< amrex::Real > xloc
Definition: ERF_EWP.H:51
amrex::Vector< amrex::Real > thrust_coeff
Definition: ERF_EWP.H:53
amrex::Vector< amrex::Real > power
Definition: ERF_EWP.H:53
amrex::Real rotor_rad
Definition: ERF_EWP.H:52
amrex::Vector< amrex::Real > yloc
Definition: ERF_EWP.H:51
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
void get_turb_loc(amrex::Vector< amrex::Real > &xloc, amrex::Vector< amrex::Real > &yloc)
Definition: ERF_NullWindFarm.H:96
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 
)
135 {
136 
139 
140  auto dx = geom.CellSizeArray();
141  auto ProbLoArr = geom.ProbLoArray();
142  Real sigma_0 = 1.7*rotor_rad;
143 
144  Real d_rotor_rad = rotor_rad;
145  Real d_hub_height = hub_height;
146 
147  Gpu::DeviceVector<Real> d_wind_speed(wind_speed.size());
148  Gpu::DeviceVector<Real> d_thrust_coeff(thrust_coeff.size());
149 
150  // Copy data from host vectors to device vectors
151  Gpu::copy(Gpu::hostToDevice, wind_speed.begin(), wind_speed.end(), d_wind_speed.begin());
152  Gpu::copy(Gpu::hostToDevice, thrust_coeff.begin(), thrust_coeff.end(), d_thrust_coeff.begin());
153 
154 
155  // Domain valid box
156  const amrex::Box& domain = geom.Domain();
157  int domlo_z = domain.smallEnd(2);
158  int domhi_z = domain.bigEnd(2) + 1;
159 
160  // The order of variables are - Vabs dVabsdt, dudt, dvdt, dTKEdt
161  mf_vars_ewp.setVal(0.0);
162 
163  for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
164 
165  const Box& gbx = mfi.growntilebox(1);
166  auto ewp_array = mf_vars_ewp.array(mfi);
167  auto Nturb_array = mf_Nturb.array(mfi);
168  auto u_vel = U_old.array(mfi);
169  auto v_vel = V_old.array(mfi);
170  auto w_vel = W_old.array(mfi);
171 
172  const Real* wind_speed_d = d_wind_speed.dataPtr();
173  const Real* thrust_coeff_d = d_thrust_coeff.dataPtr();
174  const int n_spec_table = d_wind_speed.size();
175 
176  ParallelFor(gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
177 
178  int kk = amrex::min(amrex::max(k, domlo_z), domhi_z);
179  Real z = ProbLoArr[2] + (kk+0.5) * dx[2];
180 
181  // Compute Fitch source terms
182 
183  Real Vabs = std::pow(u_vel(i,j,k)*u_vel(i,j,k) +
184  v_vel(i,j,k)*v_vel(i,j,k) +
185  w_vel(i,j,kk)*w_vel(i,j,kk), 0.5);
186 
187  Real C_T = interpolate_1d(wind_speed_d, thrust_coeff_d, Vabs, n_spec_table);
188 
189  Real C_TKE = 0.0;
190  Real K_turb = 6.0;
191 
192  Real L_wake = std::pow(dx[0]*dx[1],0.5)/2.0;
193  Real sigma_e = Vabs/(3.0*K_turb*L_wake)*
194  (std::pow(2.0*K_turb*L_wake/Vabs + std::pow(sigma_0,2),3.0/2.0) - std::pow(sigma_0,3));
195 
196  Real phi = std::atan2(v_vel(i,j,k),u_vel(i,j,k)); // Wind direction w.r.t the x-dreiction
197  Real fac = -std::pow(PI/8.0,0.5)*C_T*std::pow(d_rotor_rad,2)*
198  std::pow(Vabs,2)/(dx[0]*dx[1]*sigma_e)*
199  std::exp(-0.5*std::pow((z - d_hub_height)/sigma_e,2));
200  ewp_array(i,j,k,0) = fac*std::cos(phi)*Nturb_array(i,j,k);
201  ewp_array(i,j,k,1) = fac*std::sin(phi)*Nturb_array(i,j,k);
202  ewp_array(i,j,k,2) = C_TKE*0.0;
203  });
204  }
205 }
constexpr amrex::Real PI
Definition: ERF_Constants.H:6
Here is the call graph for this function:

◆ update()

void EWP::update ( const amrex::Real &  dt_advance,
amrex::MultiFab &  cons_in,
amrex::MultiFab &  U_old,
amrex::MultiFab &  V_old,
const amrex::MultiFab &  mf_vars_ewp 
)
98 {
99 
100  for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
101 
102  Box bx = mfi.tilebox();
103  Box tbx = mfi.nodaltilebox(0);
104  Box tby = mfi.nodaltilebox(1);
105 
106  auto cons_array = cons_in.array(mfi);
107  auto ewp_array = mf_vars_ewp.array(mfi);
108  auto u_vel = U_old.array(mfi);
109  auto v_vel = V_old.array(mfi);
110 
111  ParallelFor(tbx, tby, bx,
112  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
113  {
114  u_vel(i,j,k) = u_vel(i,j,k) + (ewp_array(i-1,j,k,0) + ewp_array(i,j,k,0))/2.0*dt_advance;
115  },
116  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
117  {
118  v_vel(i,j,k) = v_vel(i,j,k) + (ewp_array(i,j-1,k,1) + ewp_array(i,j,k,1))/2.0*dt_advance;
119  },
120  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
121  {
122  cons_array(i,j,k,RhoKE_comp) = cons_array(i,j,k,RhoKE_comp) + ewp_array(i,j,k,2)*dt_advance;
123  });
124  }
125 }
#define RhoKE_comp
Definition: ERF_IndexDefines.H:38

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: