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

#include <ERF_ReadBndryPlanes.H>

Collaboration diagram for ReadBndryPlanes:

Public Member Functions

 ReadBndryPlanes (const amrex::Geometry &geom, const amrex::Real &rdOcp_in)
 
void define_level_data (int lev)
 
void read_time_file ()
 
void read_input_files (double time, double dt, amrex::Array< amrex::Array< amrex::Real, AMREX_SPACEDIM *2 >, AMREX_SPACEDIM+NBCVAR_max > m_bc_extdir_vals)
 
void read_file (int idx, amrex::Vector< std::unique_ptr< PlaneVector >> &data_to_fill, amrex::Array< amrex::Array< amrex::Real, AMREX_SPACEDIM *2 >, AMREX_SPACEDIM+NBCVAR_max > m_bc_extdir_vals)
 
amrex::Vector< std::unique_ptr< PlaneVector > > & interp_in_time (const double &time)
 
amrex::Vector< std::unique_ptr< PlaneVector > > & get_tendency (const double &time)
 
double tinterp () const
 
int ingested_velocity () const
 
int ingested_theta () const
 
int ingested_density () const
 
int ingested_scalar () const
 
int ingested_q1 () const
 
int ingested_q2 () const
 
int ingested_KE () const
 

Private Attributes

double m_tn
 The times for which we currently have data. More...
 
double m_tnp1
 
double m_tnp2
 
amrex::Vector< std::unique_ptr< PlaneVector > > m_data_n
 Data at time m_tn. More...
 
amrex::Vector< std::unique_ptr< PlaneVector > > m_data_np1
 Data at time m_tnp1. More...
 
amrex::Vector< std::unique_ptr< PlaneVector > > m_data_np2
 Data at time m_tnp2. More...
 
amrex::Vector< std::unique_ptr< PlaneVector > > m_data_interp
 Data interpolated to the time requested. More...
 
amrex::Vector< std::unique_ptr< PlaneVector > > m_data_tendency
 Tendency between the n and np1 data. More...
 
double m_tinterp {-1.0}
 Time for plane at interpolation. More...
 
amrex::Geometry m_geom
 Geometry at level 0. More...
 
std::string m_filename {""}
 File name for IO. More...
 
std::string m_time_file {""}
 File name for file holding timesteps and times. More...
 
amrex::Vector< double > m_in_times
 The timesteps / times that we read from time.dat. More...
 
amrex::Vector< int > m_in_timesteps
 
amrex::Vector< std::string > m_var_names
 Variables to be read in. More...
 
int m_in_rad = 1
 Controls extents on native bndry output. More...
 
const int m_out_rad = 1
 
const int m_extent_rad = 0
 
bool m_use_real_bcs = false
 Are real BCs being used? More...
 
const amrex::Real m_rdOcp
 R_d/c_p is needed for reading boundary files. More...
 
int is_velocity_read
 
int is_density_read
 
int is_temperature_read
 
int is_theta_read
 
int is_scalar_read
 
int is_q1_read
 
int is_q2_read
 
int is_KE_read
 
int last_file_read
 

Detailed Description

Collection of data structures and operations for reading data

This class contains the inlet data structures and operations to read and interpolate inflow data.

Constructor & Destructor Documentation

◆ ReadBndryPlanes()

ReadBndryPlanes::ReadBndryPlanes ( const amrex::Geometry &  geom,
const amrex::Real &  rdOcp_in 
)
explicit

ReadBndryPlanes class constructor. Handles initialization from inputs file parameters.

Parameters
geomGeometry for the domain
rdOcp_inReal constant for the Rhydberg constant ($R_d$) divided by the specific heat at constant pressure ($c_p$)
218 :
219  m_geom(geom),
220  m_rdOcp(rdOcp_in)
221 {
222  ParmParse pp("erf");
223 
224  // Get the radius inside the domain
225  pp.queryAdd("in_rad",m_in_rad);
226 
227  // Are we using real bcs?
228  pp.queryAdd("use_real_bcs", m_use_real_bcs);
229 
230  last_file_read = -1;
231 
232  m_tinterp = -1.0;
233 
234  // What folder will the time series of planes be read from
235  pp.get("bndry_file", m_filename);
236 
237  is_velocity_read = 0;
238  is_density_read = 0;
240  is_theta_read = 0;
241  is_scalar_read = 0;
242  is_q1_read = 0;
243  is_q2_read = 0;
244  is_KE_read = 0;
245 
246  if (pp.contains("bndry_input_var_names"))
247  {
248  int num_vars = pp.countval("bndry_input_var_names");
249  m_var_names.resize(num_vars);
250  pp.queryarr("bndry_input_var_names",m_var_names,0,num_vars);
251  for (int i = 0; i < m_var_names.size(); i++) {
252  if (m_var_names[i] == "velocity") is_velocity_read = 1;
253  if (m_var_names[i] == "density") is_density_read = 1;
254  if (m_var_names[i] == "temperature") is_temperature_read = 1;
255  if (m_var_names[i] == "theta") is_theta_read = 1;
256  if (m_var_names[i] == "scalar") is_scalar_read = 1;
257  if (m_var_names[i] == "qv") is_q1_read = 1;
258  if (m_var_names[i] == "qc") is_q2_read = 1;
259  if (m_var_names[i] == "ke") is_KE_read = 1;
260  const bool known = m_var_names[i] == "velocity" || m_var_names[i] == "density" ||
261  m_var_names[i] == "temperature" || m_var_names[i] == "theta" ||
262  m_var_names[i] == "scalar" || m_var_names[i] == "qv" ||
263  m_var_names[i] == "qc" || m_var_names[i] == "ke";
264  if (!known) {
265  Abort("erf.bndry_input_var_names: unknown variable \"" + m_var_names[i] +
266  "\"; the names read are velocity, density, temperature, theta, scalar, qv, qc and ke");
267  }
268  }
269  }
270 
271  // time.dat will be in the same folder as the time series of data
272  m_time_file = m_filename + "/time.dat";
273 
274  // each pointer (at at given time) has 6 components, one for each orientation
275  // TODO: we really only need 4 not 6
276  int size = 2*AMREX_SPACEDIM;
277  m_data_n.resize(size);
278  m_data_np1.resize(size);
279  m_data_np2.resize(size);
280  m_data_interp.resize(size);
281  m_data_tendency.resize(size);
282 }
ParmParse pp("prob")
int is_velocity_read
Definition: ERF_ReadBndryPlanes.H:107
int is_q2_read
Definition: ERF_ReadBndryPlanes.H:113
int is_theta_read
Definition: ERF_ReadBndryPlanes.H:110
bool m_use_real_bcs
Are real BCs being used?
Definition: ERF_ReadBndryPlanes.H:102
std::string m_filename
File name for IO.
Definition: ERF_ReadBndryPlanes.H:84
int is_temperature_read
Definition: ERF_ReadBndryPlanes.H:109
int is_density_read
Definition: ERF_ReadBndryPlanes.H:108
amrex::Vector< std::unique_ptr< PlaneVector > > m_data_np2
Data at time m_tnp2.
Definition: ERF_ReadBndryPlanes.H:69
amrex::Vector< std::unique_ptr< PlaneVector > > m_data_interp
Data interpolated to the time requested.
Definition: ERF_ReadBndryPlanes.H:72
int last_file_read
Definition: ERF_ReadBndryPlanes.H:116
int is_KE_read
Definition: ERF_ReadBndryPlanes.H:114
const amrex::Real m_rdOcp
R_d/c_p is needed for reading boundary files.
Definition: ERF_ReadBndryPlanes.H:105
std::string m_time_file
File name for file holding timesteps and times.
Definition: ERF_ReadBndryPlanes.H:87
amrex::Vector< std::unique_ptr< PlaneVector > > m_data_tendency
Tendency between the n and np1 data.
Definition: ERF_ReadBndryPlanes.H:75
amrex::Vector< std::string > m_var_names
Variables to be read in.
Definition: ERF_ReadBndryPlanes.H:94
int is_scalar_read
Definition: ERF_ReadBndryPlanes.H:111
int is_q1_read
Definition: ERF_ReadBndryPlanes.H:112
amrex::Vector< std::unique_ptr< PlaneVector > > m_data_n
Data at time m_tn.
Definition: ERF_ReadBndryPlanes.H:63
amrex::Vector< std::unique_ptr< PlaneVector > > m_data_np1
Data at time m_tnp1.
Definition: ERF_ReadBndryPlanes.H:66
int m_in_rad
Controls extents on native bndry output.
Definition: ERF_ReadBndryPlanes.H:97
amrex::Geometry m_geom
Geometry at level 0.
Definition: ERF_ReadBndryPlanes.H:81
double m_tinterp
Time for plane at interpolation.
Definition: ERF_ReadBndryPlanes.H:78
Here is the call graph for this function:

Member Function Documentation

◆ define_level_data()

void ReadBndryPlanes::define_level_data ( int  lev)

Function in ReadBndryPlanes class for allocating space for the boundary plane data ERF will need.

48 {
49  Print() << "ReadBndryPlanes::define_level_data" << std::endl;
50  // *********************************************************
51  // Allocate space for all of the boundary planes we may need
52  // *********************************************************
53  int ncomp = BCVars::NumTypes;
54  const Box& domain = m_geom.Domain();
55  for (OrientationIter oit; oit != nullptr; ++oit) {
56  auto ori = oit();
57  if (ori.coordDir() < 2) {
58 
59  m_data_n[ori] = std::make_unique<PlaneVector>();
60  m_data_np1[ori] = std::make_unique<PlaneVector>();
61  m_data_np2[ori] = std::make_unique<PlaneVector>();
62  m_data_interp[ori] = std::make_unique<PlaneVector>();
63  m_data_tendency[ori] = std::make_unique<PlaneVector>();
64 
65  const auto& lo = domain.loVect();
66  const auto& hi = domain.hiVect();
67 
68  IntVect plo(lo);
69  IntVect phi(hi);
70  const int normal = ori.coordDir();
71  plo[normal] = ori.isHigh() ? hi[normal] - (m_in_rad - 1) : -m_out_rad;
72  phi[normal] = ori.isHigh() ? hi[normal] + (m_out_rad ) : (m_in_rad - 1);
73  const Box pbx(plo, phi);
74  m_data_n[ori]->push_back(FArrayBox(pbx, ncomp));
75  m_data_np1[ori]->push_back(FArrayBox(pbx, ncomp));
76  m_data_np2[ori]->push_back(FArrayBox(pbx, ncomp));
77  m_data_interp[ori]->push_back(FArrayBox(pbx, ncomp));
78  m_data_tendency[ori]->push_back(FArrayBox(pbx, ncomp));
79  }
80  }
81 }
const int m_out_rad
Definition: ERF_ReadBndryPlanes.H:98
@ NumTypes
Definition: ERF_IndexDefines.H:111

Referenced by read_time_file().

Here is the caller graph for this function:

◆ get_tendency()

Vector< std::unique_ptr< PlaneVector > > & ReadBndryPlanes::get_tendency ( const double &  time_in)

Function in ReadBndryPlanes class for interpolating boundary data in time.

Parameters
time_inConstant specifying the time for interpolation
156 {
157  // A restart that lands exactly on a boundary-plane time can request a time a few
158  // ULP outside [m_tn, m_tnp2] because per-level t_new drifts under subcycling.
159  // Tolerate that drift, then clamp into the valid window before interpolating.
160  const double eps = 1.0e-8 * (m_tnp2 - m_tn);
161  AMREX_ALWAYS_ASSERT(m_tn - eps <= time_in && time_in <= m_tnp2 + eps);
162  const double time = std::min(std::max(time_in, m_tn), m_tnp2);
163 
164  if (time < m_tnp1) {
165  Real idt = static_cast<Real>(1.0 / (m_tnp1 - m_tn));
166  for (OrientationIter oit; oit != nullptr; ++oit) {
167  auto ori = oit();
168  if (ori.coordDir() < 2) {
169  const int nlevels = static_cast<int>(m_data_n[ori]->size());
170  for (int lev = 0; lev < nlevels; ++lev) {
171  auto& fabt = (*m_data_tendency[ori])[lev];
172  Box bx = fabt.box();
173  int ncomp = fabt.nComp();
174 
175  const auto& datt = fabt.array();
176  const auto& datn = (*m_data_n[ori])[lev].array();
177  const auto& datnp1 = (*m_data_np1[ori])[lev].array();
178  ParallelFor(bx, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
179  {
180  datt(i,j,k,n) = (datnp1(i,j,k,n) - datn(i,j,k,n)) * idt;
181  });
182  }
183  }
184  }
185  } else {
186  Real idt = static_cast<Real>(1.0 / (m_tnp2 - m_tnp1));
187  for (OrientationIter oit; oit != nullptr; ++oit) {
188  auto ori = oit();
189  if (ori.coordDir() < 2) {
190  const int nlevels = static_cast<int>(m_data_n[ori]->size());
191  for (int lev = 0; lev < nlevels; ++lev) {
192  auto& fabt = (*m_data_tendency[ori])[lev];
193  Box bx = fabt.box();
194  int ncomp = fabt.nComp();
195 
196  const auto& datt = fabt.array();
197  const auto& datnp1 = (*m_data_np1[ori])[lev].array();
198  const auto& datnp2 = (*m_data_np2[ori])[lev].array();
199  ParallelFor(bx, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
200  {
201  datt(i,j,k,n) = (datnp2(i,j,k,n) - datnp1(i,j,k,n)) * idt;
202  });
203  }
204  }
205  }
206  }
207 
208  return m_data_tendency;
209 }
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
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);})
amrex::Real Real
Definition: ERF_ShocInterface.H:19
double m_tnp1
Definition: ERF_ReadBndryPlanes.H:59
double m_tnp2
Definition: ERF_ReadBndryPlanes.H:60
double m_tn
The times for which we currently have data.
Definition: ERF_ReadBndryPlanes.H:58
Here is the call graph for this function:

◆ ingested_density()

int ReadBndryPlanes::ingested_density ( ) const
inline
49 {return is_density_read;}

Referenced by read_file().

Here is the caller graph for this function:

◆ ingested_KE()

int ReadBndryPlanes::ingested_KE ( ) const
inline
53 {return is_KE_read;}

◆ ingested_q1()

int ReadBndryPlanes::ingested_q1 ( ) const
inline
51 {return is_q1_read;}

◆ ingested_q2()

int ReadBndryPlanes::ingested_q2 ( ) const
inline
52 {return is_q2_read;}

◆ ingested_scalar()

int ReadBndryPlanes::ingested_scalar ( ) const
inline
50 {return is_scalar_read;}

◆ ingested_theta()

int ReadBndryPlanes::ingested_theta ( ) const
inline

◆ ingested_velocity()

int ReadBndryPlanes::ingested_velocity ( ) const
inline
47 {return is_velocity_read;}

◆ interp_in_time()

Vector< std::unique_ptr< PlaneVector > > & ReadBndryPlanes::interp_in_time ( const double &  time_in)

Function in ReadBndryPlanes class for interpolating boundary data in time.

Parameters
time_inConstant specifying the time for interpolation
91 {
92  // A restart that lands exactly on a boundary-plane time can request a time a few
93  // ULP outside [m_tn, m_tnp2] because per-level t_new drifts under subcycling.
94  // Tolerate that drift, then clamp into the valid window before interpolating.
95  const double eps = 1.0e-8 * (m_tnp2 - m_tn);
96  AMREX_ALWAYS_ASSERT(m_tn - eps <= time_in && time_in <= m_tnp2 + eps);
97  const double time = std::min(std::max(time_in, m_tn), m_tnp2);
98 
99  //Print() << "interp_in_time at time " << time << " given " << m_tn << " " << m_tnp1 << " " << m_tnp2 << std::endl;
100  //Print() << "m_tinterp " << m_tinterp << std::endl;
101 
102  if (time == m_tinterp) {
103  // We have already interpolated to this time
104  return m_data_interp;
105 
106  } else {
107 
108  // We must now interpolate to a new time
109  m_tinterp = time;
110 
111  if (time < m_tnp1) {
112  for (OrientationIter oit; oit != nullptr; ++oit) {
113  auto ori = oit();
114  if (ori.coordDir() < 2) {
115  const int nlevels = static_cast<int>(m_data_n[ori]->size());
116  for (int lev = 0; lev < nlevels; ++lev) {
117  const auto& datn = (*m_data_n[ori])[lev];
118  const auto& datnp1 = (*m_data_np1[ori])[lev];
119  auto& dati = (*m_data_interp[ori])[lev];
120  dati.linInterp<RunOn::Device>(datn, 0, datnp1, 0,
121  static_cast<Real>(m_tn), static_cast<Real>(m_tnp1),
122  static_cast<Real>(m_tinterp),
123  datn.box(), 0, dati.nComp());
124  }
125  }
126  }
127  } else {
128  for (OrientationIter oit; oit != nullptr; ++oit) {
129  auto ori = oit();
130  if (ori.coordDir() < 2) {
131  const int nlevels = static_cast<int>(m_data_n[ori]->size());
132  for (int lev = 0; lev < nlevels; ++lev) {
133  const auto& datnp1 = (*m_data_np1[ori])[lev];
134  const auto& datnp2 = (*m_data_np2[ori])[lev];
135  auto& dati = (*m_data_interp[ori])[lev];
136  dati.linInterp<RunOn::Device>(datnp1, 0, datnp2, 0,
137  static_cast<Real>(m_tnp1), static_cast<Real>(m_tnp2),
138  static_cast<Real>(m_tinterp),
139  datnp1.box(), 0, dati.nComp());
140  }
141  }
142  }
143  }
144  }
145  return m_data_interp;
146 }
Here is the call graph for this function:

◆ read_file()

void ReadBndryPlanes::read_file ( int  idx,
amrex::Vector< std::unique_ptr< PlaneVector >> &  data_to_fill,
amrex::Array< amrex::Array< amrex::Real, AMREX_SPACEDIM *2 >, AMREX_SPACEDIM+NBCVAR_max >  m_bc_extdir_vals 
)

Function in ReadBndryPlanes to read boundary data for each face and variable from files.

Parameters
idxSpecifies the index corresponding to the timestep we want
data_to_fillContainer for face data on boundaries
m_bc_extdir_valsContainer storing the external dirichlet boundary conditions we are reading from the input files
435 {
436  if (idx >= m_in_timesteps.size()) {
437  Print() << "Asking for index " << idx << " but m_in_timesteps only has size " << m_in_timesteps.size() << std::endl;
438  Abort();
439  }
440  const int t_step = m_in_timesteps[idx];
441  const std::string chkname1 = m_filename + Concatenate("/bndry_output", t_step);
442 
443  const std::string level_prefix = "Level_";
444  const int lev = 0;
445 
446  const Box& domain = m_geom.Domain();
447  BoxArray ba(domain);
448  DistributionMapping dm{ba};
449 
450  GpuArray<GpuArray<Real, AMREX_SPACEDIM*2>, AMREX_SPACEDIM+NBCVAR_max> l_bc_extdir_vals_d;
451 
452  for (int i = 0; i < BCVars::NumTypes; i++)
453  {
454  for (OrientationIter oit; oit != nullptr; ++oit) {
455  auto ori = oit();
456  l_bc_extdir_vals_d[i][ori] = m_bc_extdir_vals[i][ori];
457  }
458  }
459 
460  int n_for_density = -1;
461  for (int i = 0; i < m_var_names.size(); i++)
462  {
463  if (m_var_names[i] == "density") n_for_density = i;
464  }
465 
466  // We need to initialize all the components because we may not fill all of them from files,
467  // but the loop in the interpolate routine goes over all the components anyway
468  int ncomp_for_bc = BCVars::NumTypes;
469  for (OrientationIter oit; oit != nullptr; ++oit) {
470  auto ori = oit();
471  if (ori.coordDir() < 2) {
472  FArrayBox& d = (*data_to_fill[ori])[lev];
473  const auto& bx = d.box();
474  Array4<Real> d_arr = d.array();
475  ParallelFor(
476  bx, ncomp_for_bc, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept {
477  d_arr(i,j,k,n) = zero;
478  });
479  }
480  }
481 
482  // Read density for primitive to conserved conversions
483  std::string filenamer = MultiFabFileFullPrefix(lev, chkname1, level_prefix, "density");
484  BndryRegister bndry_r(ba, dm, m_in_rad, m_out_rad, m_extent_rad, 1);
485  bndry_r.setVal(bogus_large_value);
486  for (OrientationIter oit; oit != nullptr; ++oit) {
487  auto ori = oit();
488  if (ori.coordDir() < 2) {
489  std::string facenamer = Concatenate(filenamer + '_', ori, 1);
490  bndry_r[ori].read(facenamer);
491  }
492  }
493 
494  // Expose for GPU
495  bool real_bcs = m_use_real_bcs;
496 
497  for (int ivar = 0; ivar < m_var_names.size(); ivar++)
498  {
499  std::string var_name = m_var_names[ivar];
500 
501  std::string filename1 = MultiFabFileFullPrefix(lev, chkname1, level_prefix, var_name);
502 
503  int ncomp;
504  if (var_name == "velocity") {
505  ncomp = AMREX_SPACEDIM;
506  } else {
507  ncomp = 1;
508  }
509 
510  // Every name was checked against this list in the constructor; the -1 only
511  // keeps the compiler from seeing an unset value.
512  int n_offset = -1;
513  if (var_name == "density") n_offset = BCVars::Rho_bc_comp;
514  if (var_name == "theta") n_offset = BCVars::RhoTheta_bc_comp;
515  if (var_name == "temperature") n_offset = BCVars::RhoTheta_bc_comp;
516  if (var_name == "ke") n_offset = BCVars::RhoKE_bc_comp;
517  if (var_name == "scalar") n_offset = BCVars::RhoScalar_bc_comp;
518  if (var_name == "qv") n_offset = BCVars::RhoQ1_bc_comp;
519  if (var_name == "qc") n_offset = BCVars::RhoQ2_bc_comp;
520  if (var_name == "velocity") n_offset = BCVars::xvel_bc;
521 
522  // Print() << "Reading " << chkname1 << " for variable " << var_name << " with n_offset == " << n_offset << std::endl;
523 
524  BndryRegister bndry(ba, dm, m_in_rad, m_out_rad, m_extent_rad, ncomp);
525  bndry.setVal(bogus_large_value);
526 
527  // *********************************************************
528  // Read in the BndryReg for all non-z faces
529  // *********************************************************
530  for (OrientationIter oit; oit != nullptr; ++oit) {
531  auto ori = oit();
532  if (ori.coordDir() < 2) {
533 
534  std::string facename1 = Concatenate(filename1 + '_', ori, 1);
535  bndry[ori].read(facename1);
536 
537  int normal = ori.coordDir();
538  IntVect v_offset = offset(ori.faceDir(), normal);
539  if (real_bcs) { v_offset = IntVect(0); }
540 
541  const auto& bbx = (*data_to_fill[ori])[lev].box();
542 
543  // *********************************************************
544  // Copy from the BndryReg into a MultiFab then use copyTo
545  // to write from the MultiFab to a single FAB for each face
546  // *********************************************************
547  MultiFab bndryMF(
548  bndry[ori].boxArray(), bndry[ori].DistributionMap(),
549  ncomp, 0, MFInfo());
550 
551  for (MFIter mfi(bndryMF); mfi.isValid(); ++mfi) {
552 
553  const auto& vbx = mfi.validbox();
554  const auto& bndry_read_arr = bndry[ori].array(mfi);
555  const auto& bndry_read_r_arr = bndry_r[ori].array(mfi);
556  const auto& bndry_mf_arr = bndryMF.array(mfi);
557 
558  const auto& bx = bbx & vbx;
559  if (bx.isEmpty()) {
560  continue;
561  }
562 
563  // Split the 2-cell-thick working box into ghost and interior
564  // slots so the (i+v_offset) neighbor access stays in-bounds.
565  // Both slots are filled with the same face-averaged Dirichlet
566  // value; the interior slot just needs the opposite neighbor.
567  Box bx_ghost = bx;
568  Box bx_int = bx;
569  if (ori.isLow()) {
570  bx_ghost.setBig (normal, domain.smallEnd(normal) - 1);
571  bx_int .setSmall(normal, domain.smallEnd(normal));
572  } else {
573  bx_ghost.setSmall(normal, domain.bigEnd(normal) + 1);
574  bx_int .setBig (normal, domain.bigEnd(normal));
575  }
576  const IntVect v_offset_int = -v_offset;
577 
578  // We average the two cell-centered data points in the normal direction
579  // to define a Dirichlet value on the face itself.
580 
581  // This is the scalars -- they all get multiplied by rho, and in the case of
582  // reading in temperature, we must convert to theta first
583  Real rdOcp = m_rdOcp;
584  if (n_for_density >= 0) {
585  if (var_name == "temperature") {
586  ParallelFor(
587  bx_ghost, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
588  Real R1 = bndry_read_r_arr(i, j, k, 0);
589  Real R2 = bndry_read_r_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2],0);
590  Real T1 = bndry_read_arr(i, j, k, 0);
591  Real T2 = bndry_read_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2],0);
592  Real Th1 = getThgivenRandT(R1,T1,rdOcp);
593  Real Th2 = getThgivenRandT(R2,T2,rdOcp);
594  bndry_mf_arr(i, j, k, 0) = (real_bcs) ? bndry_read_arr(i, j, k, 0) :
595  myhalf * (R1*Th1 + R2*Th2);
596  });
597  } else if (var_name == "theta" || var_name == "ke" || var_name == "scalar" ||
598  var_name == "qv" || var_name == "qc") {
599  ParallelFor(
600  bx_ghost, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
601  Real R1 = bndry_read_r_arr(i, j, k, 0);
602  Real R2 = bndry_read_r_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2],0);
603  bndry_mf_arr(i, j, k, 0) = (real_bcs) ? bndry_read_arr(i, j, k, 0) :
604  myhalf * ( R1 * bndry_read_arr(i, j, k, 0) +
605  R2 * bndry_read_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2], 0));
606  });
607  } else if (var_name == "density") {
608  ParallelFor(
609  bx_ghost, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
610  bndry_mf_arr(i, j, k, 0) = (real_bcs) ? bndry_read_arr(i, j, k, 0) :
611  myhalf * ( bndry_read_arr(i, j, k, 0) +
612  bndry_read_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2], 0));
613  });
614  }
615  } else if (!ingested_density()) {
616  if (var_name == "temperature") {
617  ParallelFor(
618  bx_ghost, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
619  Real R1 = l_bc_extdir_vals_d[BCVars::Rho_bc_comp][ori];
620  Real R2 = l_bc_extdir_vals_d[BCVars::Rho_bc_comp][ori];
621  Real T1 = bndry_read_arr(i, j, k, 0);
622  Real T2 = bndry_read_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2], 0);
623  Real Th1 = getThgivenRandT(R1,T1,rdOcp);
624  Real Th2 = getThgivenRandT(R2,T2,rdOcp);
625  bndry_mf_arr(i, j, k, 0) = (real_bcs) ? bndry_read_arr(i, j, k, 0) :
626  myhalf * (R1*Th1 + R2*Th2);
627  });
628  } else if (var_name == "theta" || var_name == "ke" || var_name == "scalar" ||
629  var_name == "qv" || var_name == "qc") {
630  ParallelFor(
631  bx_ghost, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
632  Real R1 = l_bc_extdir_vals_d[BCVars::Rho_bc_comp][ori];
633  Real R2 = l_bc_extdir_vals_d[BCVars::Rho_bc_comp][ori];
634  bndry_mf_arr(i, j, k, 0) = (real_bcs) ? bndry_read_arr(i, j, k, 0) :
635  myhalf * (R1 * bndry_read_arr(i, j, k, 0) +
636  R2 * bndry_read_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2], 0));
637  });
638  }
639  }
640 
641  // This is velocity
642  if (var_name == "velocity") {
643  ParallelFor(
644  bx_ghost, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept {
645  bndry_mf_arr(i, j, k, n) = (real_bcs) ? bndry_read_arr(i, j, k, n) :
646  myhalf * (bndry_read_arr(i, j, k, n) +
647  bndry_read_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2], n));
648  });
649  }
650 
651  // --- interior-slot fill (same face-averaged Dirichlet value;
652  // neighbor offset is flipped because the "other cell"
653  // is now on the opposite side of the boundary face) ---
654  if (n_for_density >= 0) {
655  if (var_name == "temperature") {
656  ParallelFor(
657  bx_int, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
658  Real R1 = bndry_read_r_arr(i, j, k, 0);
659  Real R2 = bndry_read_r_arr(i+v_offset_int[0],j+v_offset_int[1],k+v_offset_int[2],0);
660  Real T1 = bndry_read_arr(i, j, k, 0);
661  Real T2 = bndry_read_arr(i+v_offset_int[0],j+v_offset_int[1],k+v_offset_int[2],0);
662  Real Th1 = getThgivenRandT(R1,T1,rdOcp);
663  Real Th2 = getThgivenRandT(R2,T2,rdOcp);
664  bndry_mf_arr(i, j, k, 0) = (real_bcs) ? bndry_read_arr(i, j, k, 0) :
665  myhalf * (R1*Th1 + R2*Th2);
666  });
667  } else if (var_name == "theta" || var_name == "ke" || var_name == "scalar" ||
668  var_name == "qv" || var_name == "qc") {
669  ParallelFor(
670  bx_int, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
671  Real R1 = bndry_read_r_arr(i, j, k, 0);
672  Real R2 = bndry_read_r_arr(i+v_offset_int[0],j+v_offset_int[1],k+v_offset_int[2],0);
673  bndry_mf_arr(i, j, k, 0) = (real_bcs) ? bndry_read_arr(i, j, k, 0) :
674  myhalf * ( R1 * bndry_read_arr(i, j, k, 0) +
675  R2 * bndry_read_arr(i+v_offset_int[0],j+v_offset_int[1],k+v_offset_int[2], 0));
676  });
677  } else if (var_name == "density") {
678  ParallelFor(
679  bx_int, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
680  bndry_mf_arr(i, j, k, 0) = (real_bcs) ? bndry_read_arr(i, j, k, 0) :
681  myhalf * ( bndry_read_arr(i, j, k, 0) +
682  bndry_read_arr(i+v_offset_int[0],j+v_offset_int[1],k+v_offset_int[2], 0));
683  });
684  }
685  } else if (!ingested_density()) {
686  if (var_name == "temperature") {
687  ParallelFor(
688  bx_int, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
689  Real R1 = l_bc_extdir_vals_d[BCVars::Rho_bc_comp][ori];
690  Real R2 = l_bc_extdir_vals_d[BCVars::Rho_bc_comp][ori];
691  Real T1 = bndry_read_arr(i, j, k, 0);
692  Real T2 = bndry_read_arr(i+v_offset_int[0],j+v_offset_int[1],k+v_offset_int[2], 0);
693  Real Th1 = getThgivenRandT(R1,T1,rdOcp);
694  Real Th2 = getThgivenRandT(R2,T2,rdOcp);
695  bndry_mf_arr(i, j, k, 0) = (real_bcs) ? bndry_read_arr(i, j, k, 0) :
696  myhalf * (R1*Th1 + R2*Th2);
697  });
698  } else if (var_name == "theta" || var_name == "ke" || var_name == "scalar" ||
699  var_name == "qv" || var_name == "qc") {
700  ParallelFor(
701  bx_int, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
702  Real R1 = l_bc_extdir_vals_d[BCVars::Rho_bc_comp][ori];
703  Real R2 = l_bc_extdir_vals_d[BCVars::Rho_bc_comp][ori];
704  bndry_mf_arr(i, j, k, 0) = (real_bcs) ? bndry_read_arr(i, j, k, 0) :
705  myhalf * (R1 * bndry_read_arr(i, j, k, 0) +
706  R2 * bndry_read_arr(i+v_offset_int[0],j+v_offset_int[1],k+v_offset_int[2], 0));
707  });
708  }
709  }
710 
711  if (var_name == "velocity") {
712  ParallelFor(
713  bx_int, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept {
714  bndry_mf_arr(i, j, k, n) = (real_bcs) ? bndry_read_arr(i, j, k, n) :
715  myhalf * (bndry_read_arr(i, j, k, n) +
716  bndry_read_arr(i+v_offset_int[0],j+v_offset_int[1],k+v_offset_int[2], n));
717  });
718  }
719 
720  } // mfi
721  bndryMF.copyTo((*data_to_fill[ori])[lev], 0, n_offset, ncomp);
722  } // coordDir < 2
723  } // ori
724  } // var_name
725 }
constexpr amrex::Real bogus_large_value
Definition: ERF_Constants.H:19
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getThgivenRandT(const amrex::Real rho, const amrex::Real T, const amrex::Real rdOcp, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:64
#define NBCVAR_max
Definition: ERF_IndexDefines.H:32
const Real rdOcp
Definition: ERF_InitCustomPert_ABL.H:72
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int idx(int i, int j, int k, int nx, int ny)
Definition: ERF_InitForEnsemble.cpp:396
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
AMREX_FORCE_INLINE IntVect offset(const int face_dir, const int normal)
Definition: ERF_ReadBndryPlanes.cpp:32
amrex::Vector< int > m_in_timesteps
Definition: ERF_ReadBndryPlanes.H:91
int ingested_density() const
Definition: ERF_ReadBndryPlanes.H:49
const int m_extent_rad
Definition: ERF_ReadBndryPlanes.H:99
@ RhoScalar_bc_comp
Definition: ERF_IndexDefines.H:96
@ RhoQ1_bc_comp
Definition: ERF_IndexDefines.H:97
@ RhoKE_bc_comp
Definition: ERF_IndexDefines.H:95
@ RhoTheta_bc_comp
Definition: ERF_IndexDefines.H:94
@ RhoQ2_bc_comp
Definition: ERF_IndexDefines.H:98
@ Rho_bc_comp
Definition: ERF_IndexDefines.H:93
@ xvel_bc
Definition: ERF_IndexDefines.H:108

Referenced by read_input_files().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_input_files()

void ReadBndryPlanes::read_input_files ( double  time,
double  dt,
amrex::Array< amrex::Array< amrex::Real, AMREX_SPACEDIM *2 >, AMREX_SPACEDIM+NBCVAR_max >  m_bc_extdir_vals 
)

Function in ReadBndryPlanes for reading boundary data at a specific time and at the next timestep from input files.

Parameters
timeCurrent time
dtCurrent timestep
m_bc_extdir_valsContainer storing the external dirichlet boundary conditions we are reading from the input files
361 {
362  BL_PROFILE("ERF::ReadBndryPlanes::read_input_files");
363 
364  // Assert that both the current time and the next time are within the bounds
365  // of the data that we can read
366  AMREX_ALWAYS_ASSERT((m_in_times[0] <= time) && (time <= m_in_times.back()));
367  AMREX_ALWAYS_ASSERT((m_in_times[0] <= time+dt) && (time+dt <= m_in_times.back()));
368 
369  int ncomp = 1;
370 
371  const Box& domain = m_geom.Domain();
372  BoxArray ba(domain);
373  DistributionMapping dm{ba};
374  BndryRegister bndryn(ba, dm, m_in_rad, m_out_rad, m_extent_rad, ncomp);
375  bndryn.setVal(bogus_large_value);
376 
377  // The first time we enter this routine we read the first three files
378  if (last_file_read == -1)
379  {
380  int idx_init = 0;
381  read_file(idx_init,m_data_n ,m_bc_extdir_vals);
382  read_file(idx_init,m_data_interp,m_bc_extdir_vals); // We want to start with this filled
383  m_tn = m_in_times[idx_init];
384 
385  idx_init = 1;
386  read_file(idx_init,m_data_np1,m_bc_extdir_vals);
387  m_tnp1 = m_in_times[idx_init];
388 
389  idx_init = 2;
390  read_file(idx_init,m_data_np2,m_bc_extdir_vals);
391  m_tnp2 = m_in_times[idx_init];
392 
393  last_file_read = idx_init;
394  }
395 
396  // Compute the index such that time falls between times[idx] and times[idx+1]
397  const int idx = closest_index(m_in_times, time);
398 
399  // Advance the read window until it spans the requested time.
400  while (idx >= last_file_read-1 && last_file_read != m_in_times.size()-1) {
401  int new_read = last_file_read+1;
402 
403  // We need to change which data the pointers point to before we read in the new data
404  // This doesn't actually move the data, just swaps the pointers
405  for (OrientationIter oit; oit != nullptr; ++oit) {
406  auto ori = oit();
407  std::swap(m_data_n[ori] ,m_data_np1[ori]);
408  std::swap(m_data_np1[ori],m_data_np2[ori]);
409  }
410 
411  // Set the times corresponding to the post-swap pointers
412  m_tn = m_tnp1;
413  m_tnp1 = m_tnp2;
414  m_tnp2 = m_in_times[new_read];
415 
416  read_file(new_read,m_data_np2,m_bc_extdir_vals);
417  last_file_read = new_read;
418  }
419 
420  AMREX_ASSERT(time >= m_tn && time <= m_tnp2);
421  AMREX_ASSERT(time+dt >= m_tn && time+dt <= m_tnp2);
422 }
AMREX_FORCE_INLINE int closest_index(const Vector< double > &vec, const double value)
Definition: ERF_ReadBndryPlanes.cpp:19
amrex::Vector< double > m_in_times
The timesteps / times that we read from time.dat.
Definition: ERF_ReadBndryPlanes.H:90
void read_file(int idx, amrex::Vector< std::unique_ptr< PlaneVector >> &data_to_fill, amrex::Array< amrex::Array< amrex::Real, AMREX_SPACEDIM *2 >, AMREX_SPACEDIM+NBCVAR_max > m_bc_extdir_vals)
Definition: ERF_ReadBndryPlanes.cpp:432
Here is the call graph for this function:

◆ read_time_file()

void ReadBndryPlanes::read_time_file ( )

Function in ReadBndryPlanes class for reading the external file specifying time data and broadcasting this data across MPI ranks.

289 {
290  BL_PROFILE("ERF::ReadBndryPlanes::read_time_file");
291 
292  // *********************************************************
293  // Read the time.data file and store the timesteps and times
294  // *********************************************************
295  int time_file_length = 0;
296 
297  if (ParallelDescriptor::IOProcessor()) {
298 
299  std::string line;
300  std::ifstream time_file(m_time_file);
301  if (!time_file.good()) {
302  Abort("Cannot find time file: " + m_time_file);
303  }
304  while (std::getline(time_file, line)) {
305  ++time_file_length;
306  }
307 
308  time_file.close();
309  }
310 
311  ParallelDescriptor::Bcast(
312  &time_file_length, 1,
313  ParallelDescriptor::IOProcessorNumber(),
314  ParallelDescriptor::Communicator());
315 
316  m_in_times.resize(time_file_length);
317  m_in_timesteps.resize(time_file_length);
318 
319  if (ParallelDescriptor::IOProcessor()) {
320  std::ifstream time_file(m_time_file);
321  for (int i = 0; i < time_file_length; ++i) {
322  time_file >> m_in_timesteps[i] >> m_in_times[i];
323  }
324  // Sanity check that there are no duplicates or mis-orderings
325  for (int i = 1; i < time_file_length; ++i) {
326  if (m_in_timesteps[i] <= m_in_timesteps[i-1])
327  Error("Bad timestep in time.dat file");
328  if (m_in_times[i] <= m_in_times[i-1])
329  Error("Bad time in time.dat file");
330  }
331  time_file.close();
332  }
333 
334  ParallelDescriptor::Bcast(
335  m_in_timesteps.data(), time_file_length,
336  ParallelDescriptor::IOProcessorNumber(),
337  ParallelDescriptor::Communicator());
338 
339  ParallelDescriptor::Bcast(
340  m_in_times.data(), time_file_length,
341  ParallelDescriptor::IOProcessorNumber(),
342  ParallelDescriptor::Communicator());
343 
344  // Allocate data we will need -- for now just at one level
345  int lev = 0;
346  define_level_data(lev);
347  Print() << "Successfully read time file and allocated data" << std::endl;
348 }
void define_level_data(int lev)
Definition: ERF_ReadBndryPlanes.cpp:47
Here is the call graph for this function:

◆ tinterp()

double ReadBndryPlanes::tinterp ( ) const
inline
45 { return m_tinterp; }

Member Data Documentation

◆ is_density_read

int ReadBndryPlanes::is_density_read
private

◆ is_KE_read

int ReadBndryPlanes::is_KE_read
private

Referenced by ingested_KE(), and ReadBndryPlanes().

◆ is_q1_read

int ReadBndryPlanes::is_q1_read
private

Referenced by ingested_q1(), and ReadBndryPlanes().

◆ is_q2_read

int ReadBndryPlanes::is_q2_read
private

Referenced by ingested_q2(), and ReadBndryPlanes().

◆ is_scalar_read

int ReadBndryPlanes::is_scalar_read
private

Referenced by ingested_scalar(), and ReadBndryPlanes().

◆ is_temperature_read

int ReadBndryPlanes::is_temperature_read
private

Referenced by ingested_theta(), and ReadBndryPlanes().

◆ is_theta_read

int ReadBndryPlanes::is_theta_read
private

Referenced by ingested_theta(), and ReadBndryPlanes().

◆ is_velocity_read

int ReadBndryPlanes::is_velocity_read
private

◆ last_file_read

int ReadBndryPlanes::last_file_read
private

◆ m_data_interp

amrex::Vector<std::unique_ptr<PlaneVector> > ReadBndryPlanes::m_data_interp
private

Data interpolated to the time requested.

Referenced by read_input_files(), and ReadBndryPlanes().

◆ m_data_n

amrex::Vector<std::unique_ptr<PlaneVector> > ReadBndryPlanes::m_data_n
private

Data at time m_tn.

Referenced by read_input_files(), and ReadBndryPlanes().

◆ m_data_np1

amrex::Vector<std::unique_ptr<PlaneVector> > ReadBndryPlanes::m_data_np1
private

Data at time m_tnp1.

Referenced by read_input_files(), and ReadBndryPlanes().

◆ m_data_np2

amrex::Vector<std::unique_ptr<PlaneVector> > ReadBndryPlanes::m_data_np2
private

Data at time m_tnp2.

Referenced by read_input_files(), and ReadBndryPlanes().

◆ m_data_tendency

amrex::Vector<std::unique_ptr<PlaneVector> > ReadBndryPlanes::m_data_tendency
private

Tendency between the n and np1 data.

Referenced by ReadBndryPlanes().

◆ m_extent_rad

const int ReadBndryPlanes::m_extent_rad = 0
private

Referenced by read_file(), and read_input_files().

◆ m_filename

std::string ReadBndryPlanes::m_filename {""}
private

File name for IO.

Referenced by read_file(), and ReadBndryPlanes().

◆ m_geom

amrex::Geometry ReadBndryPlanes::m_geom
private

Geometry at level 0.

Referenced by read_file(), and read_input_files().

◆ m_in_rad

int ReadBndryPlanes::m_in_rad = 1
private

Controls extents on native bndry output.

Referenced by read_file(), read_input_files(), and ReadBndryPlanes().

◆ m_in_times

amrex::Vector<double> ReadBndryPlanes::m_in_times
private

The timesteps / times that we read from time.dat.

Referenced by read_input_files(), and read_time_file().

◆ m_in_timesteps

amrex::Vector<int> ReadBndryPlanes::m_in_timesteps
private

Referenced by read_file(), and read_time_file().

◆ m_out_rad

const int ReadBndryPlanes::m_out_rad = 1
private

Referenced by read_file(), and read_input_files().

◆ m_rdOcp

const amrex::Real ReadBndryPlanes::m_rdOcp
private

R_d/c_p is needed for reading boundary files.

Referenced by read_file().

◆ m_time_file

std::string ReadBndryPlanes::m_time_file {""}
private

File name for file holding timesteps and times.

Referenced by read_time_file(), and ReadBndryPlanes().

◆ m_tinterp

double ReadBndryPlanes::m_tinterp {-1.0}
private

Time for plane at interpolation.

Referenced by ReadBndryPlanes(), and tinterp().

◆ m_tn

double ReadBndryPlanes::m_tn
private

The times for which we currently have data.

Referenced by read_input_files().

◆ m_tnp1

double ReadBndryPlanes::m_tnp1
private

Referenced by read_input_files().

◆ m_tnp2

double ReadBndryPlanes::m_tnp2
private

Referenced by read_input_files().

◆ m_use_real_bcs

bool ReadBndryPlanes::m_use_real_bcs = false
private

Are real BCs being used?

Referenced by read_file(), and ReadBndryPlanes().

◆ m_var_names

amrex::Vector<std::string> ReadBndryPlanes::m_var_names
private

Variables to be read in.

Referenced by read_file(), and ReadBndryPlanes().


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