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

#include <ERF_Fitch.H>

Inheritance diagram for Fitch:
Collaboration diagram for Fitch:

Public Member Functions

 Fitch ()
 
virtual ~Fitch ()=default
 
void advance (const amrex::Geometry &geom, const double &dt_advance, amrex::MultiFab &cons_in, amrex::MultiFab &mf_vars_fitch, 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_ewp, 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_fitch)
 
void compute_power_output (const amrex::MultiFab &cons_in, const amrex::MultiFab &U_old, const amrex::MultiFab &V_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 > hub_height_velocity
 
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

◆ Fitch()

Fitch::Fitch ( )
inline
13 {}

◆ ~Fitch()

virtual Fitch::~Fitch ( )
virtualdefault

Member Function Documentation

◆ advance()

void Fitch::advance ( const amrex::Geometry &  geom,
const double &  dt_advance,
amrex::MultiFab &  cons_in,
amrex::MultiFab &  mf_vars_fitch,
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.

62 {
63  AMREX_ALWAYS_ASSERT(W_old.nComp() > 0);
64  AMREX_ALWAYS_ASSERT(mf_SMark.nComp() > 0);
65  AMREX_ALWAYS_ASSERT(time > -one);
66  amrex::ignore_unused(z_phys_cc);
67  source_terms_cellcentered(geom, cons_in, mf_vars_fitch, U_old, V_old, W_old, mf_Nturb, z_phys_nd);
68  update(dt_advance, cons_in, U_old, V_old, mf_vars_fitch);
69  compute_power_output(cons_in, U_old, V_old, mf_SMark, mf_Nturb, time);
70 }
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, amrex::MultiFab &mf_vars_ewp, 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_AdvanceFitch.cpp:173
void compute_power_output(const amrex::MultiFab &cons_in, const amrex::MultiFab &U_old, const amrex::MultiFab &V_old, const amrex::MultiFab &mf_SMark, const amrex::MultiFab &mf_Nturb, const double &time)
Definition: ERF_AdvanceFitch.cpp:107
void update(const double &dt_advance, amrex::MultiFab &cons_in, amrex::MultiFab &U_old, amrex::MultiFab &V_old, const amrex::MultiFab &mf_vars_fitch)
Definition: ERF_AdvanceFitch.cpp:73
Here is the call graph for this function:

◆ compute_power_output()

void Fitch::compute_power_output ( const amrex::MultiFab &  cons_in,
const amrex::MultiFab &  U_old,
const amrex::MultiFab &  V_old,
const amrex::MultiFab &  mf_SMark,
const amrex::MultiFab &  mf_Nturb,
const double &  time 
)
113 {
117 
118  const int n_spec_table = static_cast<int>(wind_speed.size());
119 
120  Gpu::DeviceVector<Real> d_wind_speed(wind_speed.size());
121  Gpu::DeviceVector<Real> d_power(wind_speed.size());
122  Gpu::copy(Gpu::hostToDevice, wind_speed.begin(), wind_speed.end(), d_wind_speed.begin());
123  Gpu::copy(Gpu::hostToDevice, power.begin(), power.end(), d_power.begin());
124 
125  Gpu::DeviceScalar<Real> d_total_power(zero);
126  Real* d_total_power_ptr = d_total_power.dataPtr();
127 
128  const Real* d_wind_speed_ptr = d_wind_speed.dataPtr();
129  const Real* d_power_ptr = d_power.dataPtr();
130 
131  for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
132 
133  auto SMark_array = mf_SMark.array(mfi);
134  auto Nturb_array = mf_Nturb.array(mfi);
135  auto u_vel = U_old.array(mfi);
136  auto v_vel = V_old.array(mfi);
137  // NOTE: this reduction is driven by the cell-centered SMark/Nturb, so it
138  // must run over the cell-centered tilebox. Using nodaltilebox(0)
139  // here would include the plane at bigEnd(0)+1, which is a ghost
140  // cell of this box and a valid cell of its x-neighbor, and so
141  // would count that plane twice in the power sum below.
142  Box tbx = mfi.tilebox();
143 
144  ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
145 
146  if(SMark_array(i,j,k,0) == one) {
147  Real avg_vel = std::pow(u_vel(i,j,k)*u_vel(i,j,k) + v_vel(i,j,k)*v_vel(i,j,k),myhalf);
148  Real turb_power = interpolate_1d(d_wind_speed_ptr, d_power_ptr, avg_vel, n_spec_table);
149  turb_power = turb_power*Nturb_array(i,j,k,0);
150  Gpu::Atomic::Add(d_total_power_ptr,turb_power);
151  }
152  });
153  }
154 
155  Real h_total_power = zero;
156  Gpu::copy(Gpu::deviceToHost, d_total_power.dataPtr(), d_total_power.dataPtr()+1, &h_total_power);
157 
158  amrex::ParallelAllReduce::Sum(&h_total_power, 1, amrex::ParallelContext::CommunicatorAll());
159 
160  if (ParallelDescriptor::IOProcessor()){
161  static std::ofstream file("power_output_Fitch.txt", std::ios::app);
162  // Check if the file opened successfully
163  if (!file.is_open()) {
164  std::cerr << "Error opening file!" << std::endl;
165  Abort("Could not open file to write power output in ERF_AdvanceSimpleAD.cpp");
166  }
167  file << time << " " << h_total_power << "\n";
168  file.flush();
169  }
170 }
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::Vector< amrex::Real > yloc
Definition: ERF_Fitch.H:53
amrex::Vector< amrex::Real > xloc
Definition: ERF_Fitch.H:53
amrex::Vector< amrex::Real > thrust_coeff
Definition: ERF_Fitch.H:55
amrex::Vector< amrex::Real > power
Definition: ERF_Fitch.H:55
amrex::Real rotor_rad
Definition: ERF_Fitch.H:54
amrex::Real thrust_coeff_standing
Definition: ERF_Fitch.H:54
amrex::Real hub_height
Definition: ERF_Fitch.H:54
amrex::Vector< amrex::Real > wind_speed
Definition: ERF_Fitch.H:55
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 Fitch::source_terms_cellcentered ( const amrex::Geometry &  geom,
const amrex::MultiFab &  cons_in,
amrex::MultiFab &  mf_vars_ewp,
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 
)
181 {
182 
185 
186  // dx in place of a dy over one cell, and the reverse (only dz is used as a spacing)
187  auto dx = LengthScaleCellSize(geom);
188 
189  // Domain valid box
190  const amrex::Box& domain = geom.Domain();
191  int domlo_z = domain.smallEnd(2);
192  int domhi_z = domain.bigEnd(2) + 1;
193  // Cells for the heights: kc+1 stays a node of the domain
194  int domhi_cc = domain.bigEnd(2);
195 
196 
197  //Real sum = zero;
198  //Real *sum_area = &sum;
199 
200  // The order of variables are - Vabs dVabsdt, dudt, dvdt, dTKEdt
201  mf_vars_fitch.setVal(0.0);
202  Real d_hub_height = hub_height;
203  Real d_rotor_rad = rotor_rad;
204  Gpu::DeviceVector<Real> d_wind_speed(wind_speed.size());
205  Gpu::DeviceVector<Real> d_thrust_coeff(thrust_coeff.size());
206 
207  // Copy data from host vectors to device vectors
208  Gpu::copy(Gpu::hostToDevice, wind_speed.begin(), wind_speed.end(), d_wind_speed.begin());
209  Gpu::copy(Gpu::hostToDevice, thrust_coeff.begin(), thrust_coeff.end(), d_thrust_coeff.begin());
210 
211  for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
212 
213  const Box& gbx = mfi.growntilebox(1);
214  auto fitch_array = mf_vars_fitch.array(mfi);
215  auto Nturb_array = mf_Nturb.array(mfi);
216  auto u_vel = U_old.array(mfi);
217  auto v_vel = V_old.array(mfi);
218  auto w_vel = W_old.array(mfi);
219  // Physical node heights (#5182); without them, uniform dz above the domain bottom
220  const Array4<const Real> zp = (z_phys_nd) ? z_phys_nd->const_array(mfi) : Array4<const Real>{};
221 
222  const Real* wind_speed_d = d_wind_speed.dataPtr();
223  const Real* thrust_coeff_d = d_thrust_coeff.dataPtr();
224  const int n_spec_table = static_cast<int>(d_wind_speed.size());
225 
226  ParallelFor(gbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
227  int kk = amrex::min(amrex::max(k, domlo_z), domhi_z);
228  int kc = amrex::min(amrex::max(k, domlo_z), domhi_cc);
229 
230  // Heights of the bottom and top faces of the cell above the ground, which is
231  // where the hub height is measured from (as in the SMark fill)
232  Real z_k = windfarm_face_height_above_ground(zp, i, j, kc , domlo_z, dx[2]);
233  Real z_kp1 = windfarm_face_height_above_ground(zp, i, j, kc+1, domlo_z, dx[2]);
234 
235  Real A_ijk = compute_Aijk(z_k, z_kp1, d_hub_height, d_rotor_rad);
236 
237  // Compute Fitch source terms
238 
239  Real Vabs = std::pow(u_vel(i,j,k)*u_vel(i,j,k) +
240  v_vel(i,j,k)*v_vel(i,j,k) +
241  w_vel(i,j,kk)*w_vel(i,j,kk), myhalf);
242 
243  Real C_T = interpolate_1d(wind_speed_d, thrust_coeff_d, Vabs, n_spec_table);
244  Real C_TKE = zero;
245 
246  fitch_array(i,j,k,0) = Vabs;
247  fitch_array(i,j,k,1) = -myhalf*Nturb_array(i,j,k)/(dx[0]*dx[1])*C_T*Vabs*Vabs*A_ijk/(z_kp1 - z_k);
248  // With no wind the thrust is zero; avoid 0/0 in the direction cosines
249  fitch_array(i,j,k,2) = (Vabs > zero) ? u_vel(i,j,k)/Vabs*fitch_array(i,j,k,1) : zero;
250  fitch_array(i,j,k,3) = (Vabs > zero) ? v_vel(i,j,k)/Vabs*fitch_array(i,j,k,1) : zero;
251  fitch_array(i,j,k,4) = myhalf*Nturb_array(i,j,k)/(dx[0]*dx[1])*C_TKE*amrex::Math::powi<3>(Vabs)*A_ijk/(z_kp1 - z_k);
252 
253  //amrex::Gpu::Atomic::Add(sum_area, A_ijk);
254  });
255  }
256  //std::cout << "Checking sum here...." <<"\n";
257  //printf("%0.15g, %0.15g\n", *sum_area , PI*R*R);
258  //exit(0);
259 }
GpuArray< Real, AMREX_SPACEDIM > dx
Definition: ERF_ActuatorSpreading.cpp:131
AMREX_FORCE_INLINE AMREX_GPU_DEVICE Real compute_Aijk(const Real z_k, const Real z_kp1, const Real hub_height, const Real rotor_rad)
Definition: ERF_AdvanceFitch.cpp:27
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
Here is the call graph for this function:

◆ update()

void Fitch::update ( const double &  dt_advance,
amrex::MultiFab &  cons_in,
amrex::MultiFab &  U_old,
amrex::MultiFab &  V_old,
const amrex::MultiFab &  mf_vars_fitch 
)
77 {
78 
79  for ( MFIter mfi(cons_in,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
80 
81  Box bx = mfi.tilebox();
82  Box tbx = mfi.nodaltilebox(0);
83  Box tby = mfi.nodaltilebox(1);
84 
85  auto cons_array = cons_in.array(mfi);
86  auto fitch_array = mf_vars_fitch.array(mfi);
87  auto u_vel = U_old.array(mfi);
88  auto v_vel = V_old.array(mfi);
89 
90  ParallelFor(tbx, tby, bx,
91  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
92  {
93  u_vel(i,j,k) = u_vel(i,j,k) + (fitch_array(i-1,j,k,2) + fitch_array(i,j,k,2))/two*dt_advance;
94  },
95  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
96  {
97  v_vel(i,j,k) = v_vel(i,j,k) + (fitch_array(i,j-1,k,3) + fitch_array(i,j,k,3))/two*dt_advance;
98  },
99  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
100  {
101  cons_array(i,j,k,RhoKE_comp) = cons_array(i,j,k,RhoKE_comp) + fitch_array(i,j,k,4)*dt_advance;
102  });
103  }
104 }
#define RhoKE_comp
Definition: ERF_IndexDefines.H:63
constexpr amrex::Real two
Definition: ERF_NumericalConstants.H:38
Here is the call graph for this function:

Member Data Documentation

◆ hub_height

amrex::Real Fitch::hub_height
protected

◆ hub_height_velocity

amrex::Vector<amrex::Real> Fitch::hub_height_velocity
protected

◆ nominal_power

amrex::Real Fitch::nominal_power
protected

◆ power

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

◆ rotor_rad

amrex::Real Fitch::rotor_rad
protected

◆ thrust_coeff

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

◆ thrust_coeff_standing

amrex::Real Fitch::thrust_coeff_standing
protected

◆ wind_speed

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

◆ xloc

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

◆ yloc

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

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