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$)
217 :
218  m_geom(geom),
219  m_rdOcp(rdOcp_in)
220 {
221  ParmParse pp("erf");
222 
223  // Get the radius inside the domain
224  pp.query("in_rad",m_in_rad);
225 
226  // Are we using real bcs?
227  pp.query("use_real_bcs", m_use_real_bcs);
228 
229  last_file_read = -1;
230 
231  m_tinterp = -1.0;
232 
233  // What folder will the time series of planes be read from
234  pp.get("bndry_file", m_filename);
235 
236  is_velocity_read = 0;
237  is_density_read = 0;
239  is_theta_read = 0;
240  is_scalar_read = 0;
241  is_q1_read = 0;
242  is_q2_read = 0;
243  is_KE_read = 0;
244 
245  if (pp.contains("bndry_input_var_names"))
246  {
247  int num_vars = pp.countval("bndry_input_var_names");
248  m_var_names.resize(num_vars);
249  pp.queryarr("bndry_input_var_names",m_var_names,0,num_vars);
250  for (int i = 0; i < m_var_names.size(); i++) {
251  if (m_var_names[i] == "velocity") is_velocity_read = 1;
252  if (m_var_names[i] == "density") is_density_read = 1;
253  if (m_var_names[i] == "temperature") is_temperature_read = 1;
254  if (m_var_names[i] == "theta") is_theta_read = 1;
255  if (m_var_names[i] == "scalar") is_scalar_read = 1;
256  if (m_var_names[i] == "qv") is_q1_read = 1;
257  if (m_var_names[i] == "qc") is_q2_read = 1;
258  if (m_var_names[i] == "ke") is_KE_read = 1;
259  }
260  }
261 
262  // time.dat will be in the same folder as the time series of data
263  m_time_file = m_filename + "/time.dat";
264 
265  // each pointer (at at given time) has 6 components, one for each orientation
266  // TODO: we really only need 4 not 6
267  int size = 2*AMREX_SPACEDIM;
268  m_data_n.resize(size);
269  m_data_np1.resize(size);
270  m_data_np2.resize(size);
271  m_data_interp.resize(size);
272  m_data_tendency.resize(size);
273 }
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.

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

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
155 {
156  // A restart that lands exactly on a boundary-plane time can request a time a few
157  // ULP outside [m_tn, m_tnp2] because per-level t_new drifts under subcycling.
158  // Tolerate that drift, then clamp into the valid window before interpolating.
159  const double eps = 1.0e-8 * (m_tnp2 - m_tn);
160  AMREX_ALWAYS_ASSERT(m_tn - eps <= time_in && time_in <= m_tnp2 + eps);
161  const double time = std::min(std::max(time_in, m_tn), m_tnp2);
162 
163  if (time < m_tnp1) {
164  Real idt = static_cast<Real>(1.0 / (m_tnp1 - m_tn));
165  for (OrientationIter oit; oit != nullptr; ++oit) {
166  auto ori = oit();
167  if (ori.coordDir() < 2) {
168  const int nlevels = static_cast<int>(m_data_n[ori]->size());
169  for (int lev = 0; lev < nlevels; ++lev) {
170  auto& fabt = (*m_data_tendency[ori])[lev];
171  Box bx = fabt.box();
172  int ncomp = fabt.nComp();
173 
174  const auto& datt = fabt.array();
175  const auto& datn = (*m_data_n[ori])[lev].array();
176  const auto& datnp1 = (*m_data_np1[ori])[lev].array();
177  ParallelFor(bx, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
178  {
179  datt(i,j,k,n) = (datnp1(i,j,k,n) - datn(i,j,k,n)) * idt;
180  });
181  }
182  }
183  }
184  } else {
185  Real idt = static_cast<Real>(1.0 / (m_tnp2 - m_tnp1));
186  for (OrientationIter oit; oit != nullptr; ++oit) {
187  auto ori = oit();
188  if (ori.coordDir() < 2) {
189  const int nlevels = static_cast<int>(m_data_n[ori]->size());
190  for (int lev = 0; lev < nlevels; ++lev) {
191  auto& fabt = (*m_data_tendency[ori])[lev];
192  Box bx = fabt.box();
193  int ncomp = fabt.nComp();
194 
195  const auto& datt = fabt.array();
196  const auto& datnp1 = (*m_data_np1[ori])[lev].array();
197  const auto& datnp2 = (*m_data_np2[ori])[lev].array();
198  ParallelFor(bx, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
199  {
200  datt(i,j,k,n) = (datnp2(i,j,k,n) - datnp1(i,j,k,n)) * idt;
201  });
202  }
203  }
204  }
205  }
206 
207  return m_data_tendency;
208 }
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
90 {
91  // A restart that lands exactly on a boundary-plane time can request a time a few
92  // ULP outside [m_tn, m_tnp2] because per-level t_new drifts under subcycling.
93  // Tolerate that drift, then clamp into the valid window before interpolating.
94  const double eps = 1.0e-8 * (m_tnp2 - m_tn);
95  AMREX_ALWAYS_ASSERT(m_tn - eps <= time_in && time_in <= m_tnp2 + eps);
96  const double time = std::min(std::max(time_in, m_tn), m_tnp2);
97 
98  //Print() << "interp_in_time at time " << time << " given " << m_tn << " " << m_tnp1 << " " << m_tnp2 << std::endl;
99  //Print() << "m_tinterp " << m_tinterp << std::endl;
100 
101  if (time == m_tinterp) {
102  // We have already interpolated to this time
103  return m_data_interp;
104 
105  } else {
106 
107  // We must now interpolate to a new time
108  m_tinterp = time;
109 
110  if (time < m_tnp1) {
111  for (OrientationIter oit; oit != nullptr; ++oit) {
112  auto ori = oit();
113  if (ori.coordDir() < 2) {
114  const int nlevels = static_cast<int>(m_data_n[ori]->size());
115  for (int lev = 0; lev < nlevels; ++lev) {
116  const auto& datn = (*m_data_n[ori])[lev];
117  const auto& datnp1 = (*m_data_np1[ori])[lev];
118  auto& dati = (*m_data_interp[ori])[lev];
119  dati.linInterp<RunOn::Device>(datn, 0, datnp1, 0,
120  static_cast<Real>(m_tn), static_cast<Real>(m_tnp1),
121  static_cast<Real>(m_tinterp),
122  datn.box(), 0, dati.nComp());
123  }
124  }
125  }
126  } else {
127  for (OrientationIter oit; oit != nullptr; ++oit) {
128  auto ori = oit();
129  if (ori.coordDir() < 2) {
130  const int nlevels = static_cast<int>(m_data_n[ori]->size());
131  for (int lev = 0; lev < nlevels; ++lev) {
132  const auto& datnp1 = (*m_data_np1[ori])[lev];
133  const auto& datnp2 = (*m_data_np2[ori])[lev];
134  auto& dati = (*m_data_interp[ori])[lev];
135  dati.linInterp<RunOn::Device>(datnp1, 0, datnp2, 0,
136  static_cast<Real>(m_tnp1), static_cast<Real>(m_tnp2),
137  static_cast<Real>(m_tinterp),
138  datnp1.box(), 0, dati.nComp());
139  }
140  }
141  }
142  }
143  }
144  return m_data_interp;
145 }
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
426 {
427  if (idx >= m_in_timesteps.size()) {
428  Print() << "Asking for index " << idx << " but m_in_timesteps only has size " << m_in_timesteps.size() << std::endl;
429  Abort();
430  }
431  const int t_step = m_in_timesteps[idx];
432  const std::string chkname1 = m_filename + Concatenate("/bndry_output", t_step);
433 
434  const std::string level_prefix = "Level_";
435  const int lev = 0;
436 
437  const Box& domain = m_geom.Domain();
438  BoxArray ba(domain);
439  DistributionMapping dm{ba};
440 
441  GpuArray<GpuArray<Real, AMREX_SPACEDIM*2>, AMREX_SPACEDIM+NBCVAR_max> l_bc_extdir_vals_d;
442 
443  for (int i = 0; i < BCVars::NumTypes; i++)
444  {
445  for (OrientationIter oit; oit != nullptr; ++oit) {
446  auto ori = oit();
447  l_bc_extdir_vals_d[i][ori] = m_bc_extdir_vals[i][ori];
448  }
449  }
450 
451  int n_for_density = -1;
452  for (int i = 0; i < m_var_names.size(); i++)
453  {
454  if (m_var_names[i] == "density") n_for_density = i;
455  }
456 
457  // We need to initialize all the components because we may not fill all of them from files,
458  // but the loop in the interpolate routine goes over all the components anyway
459  int ncomp_for_bc = BCVars::NumTypes;
460  for (OrientationIter oit; oit != nullptr; ++oit) {
461  auto ori = oit();
462  if (ori.coordDir() < 2) {
463  FArrayBox& d = (*data_to_fill[ori])[lev];
464  const auto& bx = d.box();
465  Array4<Real> d_arr = d.array();
466  ParallelFor(
467  bx, ncomp_for_bc, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept {
468  d_arr(i,j,k,n) = zero;
469  });
470  }
471  }
472 
473  // Read density for primitive to conserved conversions
474  std::string filenamer = MultiFabFileFullPrefix(lev, chkname1, level_prefix, "density");
475  BndryRegister bndry_r(ba, dm, m_in_rad, m_out_rad, m_extent_rad, 1);
476  bndry_r.setVal(bogus_large_value);
477  for (OrientationIter oit; oit != nullptr; ++oit) {
478  auto ori = oit();
479  if (ori.coordDir() < 2) {
480  std::string facenamer = Concatenate(filenamer + '_', ori, 1);
481  bndry_r[ori].read(facenamer);
482  }
483  }
484 
485  // Expose for GPU
486  bool real_bcs = m_use_real_bcs;
487 
488  for (int ivar = 0; ivar < m_var_names.size(); ivar++)
489  {
490  std::string var_name = m_var_names[ivar];
491 
492  std::string filename1 = MultiFabFileFullPrefix(lev, chkname1, level_prefix, var_name);
493 
494  int ncomp;
495  if (var_name == "velocity") {
496  ncomp = AMREX_SPACEDIM;
497  } else {
498  ncomp = 1;
499  }
500 
501  int n_offset;
502  if (var_name == "density") n_offset = BCVars::Rho_bc_comp;
503  if (var_name == "theta") n_offset = BCVars::RhoTheta_bc_comp;
504  if (var_name == "temperature") n_offset = BCVars::RhoTheta_bc_comp;
505  if (var_name == "ke") n_offset = BCVars::RhoKE_bc_comp;
506  if (var_name == "scalar") n_offset = BCVars::RhoScalar_bc_comp;
507  if (var_name == "qv") n_offset = BCVars::RhoQ1_bc_comp;
508  if (var_name == "qc") n_offset = BCVars::RhoQ2_bc_comp;
509  if (var_name == "velocity") n_offset = BCVars::xvel_bc;
510 
511  // Print() << "Reading " << chkname1 << " for variable " << var_name << " with n_offset == " << n_offset << std::endl;
512 
513  BndryRegister bndry(ba, dm, m_in_rad, m_out_rad, m_extent_rad, ncomp);
514  bndry.setVal(bogus_large_value);
515 
516  // *********************************************************
517  // Read in the BndryReg for all non-z faces
518  // *********************************************************
519  for (OrientationIter oit; oit != nullptr; ++oit) {
520  auto ori = oit();
521  if (ori.coordDir() < 2) {
522 
523  std::string facename1 = Concatenate(filename1 + '_', ori, 1);
524  bndry[ori].read(facename1);
525 
526  int normal = ori.coordDir();
527  IntVect v_offset = offset(ori.faceDir(), normal);
528  if (real_bcs) { v_offset = IntVect(0); }
529 
530  const auto& bbx = (*data_to_fill[ori])[lev].box();
531 
532  // *********************************************************
533  // Copy from the BndryReg into a MultiFab then use copyTo
534  // to write from the MultiFab to a single FAB for each face
535  // *********************************************************
536  MultiFab bndryMF(
537  bndry[ori].boxArray(), bndry[ori].DistributionMap(),
538  ncomp, 0, MFInfo());
539 
540  for (MFIter mfi(bndryMF); mfi.isValid(); ++mfi) {
541 
542  const auto& vbx = mfi.validbox();
543  const auto& bndry_read_arr = bndry[ori].array(mfi);
544  const auto& bndry_read_r_arr = bndry_r[ori].array(mfi);
545  const auto& bndry_mf_arr = bndryMF.array(mfi);
546 
547  const auto& bx = bbx & vbx;
548  if (bx.isEmpty()) {
549  continue;
550  }
551 
552  // Split the 2-cell-thick working box into ghost and interior
553  // slots so the (i+v_offset) neighbor access stays in-bounds.
554  // Both slots are filled with the same face-averaged Dirichlet
555  // value; the interior slot just needs the opposite neighbor.
556  Box bx_ghost = bx;
557  Box bx_int = bx;
558  if (ori.isLow()) {
559  bx_ghost.setBig (normal, domain.smallEnd(normal) - 1);
560  bx_int .setSmall(normal, domain.smallEnd(normal));
561  } else {
562  bx_ghost.setSmall(normal, domain.bigEnd(normal) + 1);
563  bx_int .setBig (normal, domain.bigEnd(normal));
564  }
565  const IntVect v_offset_int = -v_offset;
566 
567  // We average the two cell-centered data points in the normal direction
568  // to define a Dirichlet value on the face itself.
569 
570  // This is the scalars -- they all get multiplied by rho, and in the case of
571  // reading in temperature, we must convert to theta first
572  Real rdOcp = m_rdOcp;
573  if (n_for_density >= 0) {
574  if (var_name == "temperature") {
575  ParallelFor(
576  bx_ghost, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
577  Real R1 = bndry_read_r_arr(i, j, k, 0);
578  Real R2 = bndry_read_r_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2],0);
579  Real T1 = bndry_read_arr(i, j, k, 0);
580  Real T2 = bndry_read_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2],0);
581  Real Th1 = getThgivenRandT(R1,T1,rdOcp);
582  Real Th2 = getThgivenRandT(R2,T2,rdOcp);
583  bndry_mf_arr(i, j, k, 0) = (real_bcs) ? bndry_read_arr(i, j, k, 0) :
584  myhalf * (R1*Th1 + R2*Th2);
585  });
586  } else if (var_name == "theta" || var_name == "ke" || var_name == "scalar" ||
587  var_name == "qv" || var_name == "qc") {
588  ParallelFor(
589  bx_ghost, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
590  Real R1 = bndry_read_r_arr(i, j, k, 0);
591  Real R2 = bndry_read_r_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2],0);
592  bndry_mf_arr(i, j, k, 0) = (real_bcs) ? bndry_read_arr(i, j, k, 0) :
593  myhalf * ( R1 * bndry_read_arr(i, j, k, 0) +
594  R2 * bndry_read_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2], 0));
595  });
596  } else if (var_name == "density") {
597  ParallelFor(
598  bx_ghost, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
599  bndry_mf_arr(i, j, k, 0) = (real_bcs) ? bndry_read_arr(i, j, k, 0) :
600  myhalf * ( bndry_read_arr(i, j, k, 0) +
601  bndry_read_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2], 0));
602  });
603  }
604  } else if (!ingested_density()) {
605  if (var_name == "temperature") {
606  ParallelFor(
607  bx_ghost, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
608  Real R1 = l_bc_extdir_vals_d[BCVars::Rho_bc_comp][ori];
609  Real R2 = l_bc_extdir_vals_d[BCVars::Rho_bc_comp][ori];
610  Real T1 = bndry_read_arr(i, j, k, 0);
611  Real T2 = bndry_read_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2], 0);
612  Real Th1 = getThgivenRandT(R1,T1,rdOcp);
613  Real Th2 = getThgivenRandT(R2,T2,rdOcp);
614  bndry_mf_arr(i, j, k, 0) = (real_bcs) ? bndry_read_arr(i, j, k, 0) :
615  myhalf * (R1*Th1 + R2*Th2);
616  });
617  } else if (var_name == "theta" || var_name == "ke" || var_name == "scalar" ||
618  var_name == "qv" || var_name == "qc") {
619  ParallelFor(
620  bx_ghost, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
621  Real R1 = l_bc_extdir_vals_d[BCVars::Rho_bc_comp][ori];
622  Real R2 = l_bc_extdir_vals_d[BCVars::Rho_bc_comp][ori];
623  bndry_mf_arr(i, j, k, 0) = (real_bcs) ? bndry_read_arr(i, j, k, 0) :
624  myhalf * (R1 * bndry_read_arr(i, j, k, 0) +
625  R2 * bndry_read_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2], 0));
626  });
627  }
628  }
629 
630  // This is velocity
631  if (var_name == "velocity") {
632  ParallelFor(
633  bx_ghost, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept {
634  bndry_mf_arr(i, j, k, n) = (real_bcs) ? bndry_read_arr(i, j, k, n) :
635  myhalf * (bndry_read_arr(i, j, k, n) +
636  bndry_read_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2], n));
637  });
638  }
639 
640  // --- interior-slot fill (same face-averaged Dirichlet value;
641  // neighbor offset is flipped because the "other cell"
642  // is now on the opposite side of the boundary face) ---
643  if (n_for_density >= 0) {
644  if (var_name == "temperature") {
645  ParallelFor(
646  bx_int, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
647  Real R1 = bndry_read_r_arr(i, j, k, 0);
648  Real R2 = bndry_read_r_arr(i+v_offset_int[0],j+v_offset_int[1],k+v_offset_int[2],0);
649  Real T1 = bndry_read_arr(i, j, k, 0);
650  Real T2 = bndry_read_arr(i+v_offset_int[0],j+v_offset_int[1],k+v_offset_int[2],0);
651  Real Th1 = getThgivenRandT(R1,T1,rdOcp);
652  Real Th2 = getThgivenRandT(R2,T2,rdOcp);
653  bndry_mf_arr(i, j, k, 0) = (real_bcs) ? bndry_read_arr(i, j, k, 0) :
654  myhalf * (R1*Th1 + R2*Th2);
655  });
656  } else if (var_name == "theta" || var_name == "ke" || var_name == "scalar" ||
657  var_name == "qv" || var_name == "qc") {
658  ParallelFor(
659  bx_int, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
660  Real R1 = bndry_read_r_arr(i, j, k, 0);
661  Real R2 = bndry_read_r_arr(i+v_offset_int[0],j+v_offset_int[1],k+v_offset_int[2],0);
662  bndry_mf_arr(i, j, k, 0) = (real_bcs) ? bndry_read_arr(i, j, k, 0) :
663  myhalf * ( R1 * bndry_read_arr(i, j, k, 0) +
664  R2 * bndry_read_arr(i+v_offset_int[0],j+v_offset_int[1],k+v_offset_int[2], 0));
665  });
666  } else if (var_name == "density") {
667  ParallelFor(
668  bx_int, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
669  bndry_mf_arr(i, j, k, 0) = (real_bcs) ? bndry_read_arr(i, j, k, 0) :
670  myhalf * ( bndry_read_arr(i, j, k, 0) +
671  bndry_read_arr(i+v_offset_int[0],j+v_offset_int[1],k+v_offset_int[2], 0));
672  });
673  }
674  } else if (!ingested_density()) {
675  if (var_name == "temperature") {
676  ParallelFor(
677  bx_int, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
678  Real R1 = l_bc_extdir_vals_d[BCVars::Rho_bc_comp][ori];
679  Real R2 = l_bc_extdir_vals_d[BCVars::Rho_bc_comp][ori];
680  Real T1 = bndry_read_arr(i, j, k, 0);
681  Real T2 = bndry_read_arr(i+v_offset_int[0],j+v_offset_int[1],k+v_offset_int[2], 0);
682  Real Th1 = getThgivenRandT(R1,T1,rdOcp);
683  Real Th2 = getThgivenRandT(R2,T2,rdOcp);
684  bndry_mf_arr(i, j, k, 0) = (real_bcs) ? bndry_read_arr(i, j, k, 0) :
685  myhalf * (R1*Th1 + R2*Th2);
686  });
687  } else if (var_name == "theta" || var_name == "ke" || var_name == "scalar" ||
688  var_name == "qv" || var_name == "qc") {
689  ParallelFor(
690  bx_int, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
691  Real R1 = l_bc_extdir_vals_d[BCVars::Rho_bc_comp][ori];
692  Real R2 = l_bc_extdir_vals_d[BCVars::Rho_bc_comp][ori];
693  bndry_mf_arr(i, j, k, 0) = (real_bcs) ? bndry_read_arr(i, j, k, 0) :
694  myhalf * (R1 * bndry_read_arr(i, j, k, 0) +
695  R2 * bndry_read_arr(i+v_offset_int[0],j+v_offset_int[1],k+v_offset_int[2], 0));
696  });
697  }
698  }
699 
700  if (var_name == "velocity") {
701  ParallelFor(
702  bx_int, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept {
703  bndry_mf_arr(i, j, k, n) = (real_bcs) ? bndry_read_arr(i, j, k, n) :
704  myhalf * (bndry_read_arr(i, j, k, n) +
705  bndry_read_arr(i+v_offset_int[0],j+v_offset_int[1],k+v_offset_int[2], n));
706  });
707  }
708 
709  } // mfi
710  bndryMF.copyTo((*data_to_fill[ori])[lev], 0, n_offset, ncomp);
711  } // coordDir < 2
712  } // ori
713  } // var_name
714 }
constexpr amrex::Real bogus_large_value
Definition: ERF_Constants.H:26
constexpr amrex::Real zero
Definition: ERF_Constants.H:8
constexpr amrex::Real myhalf
Definition: ERF_Constants.H:13
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:29
const Real rdOcp
Definition: ERF_InitCustomPert_Bomex.H:16
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int idx(int i, int j, int k, int nx, int ny)
Definition: ERF_InitForEnsemble.cpp:365
AMREX_FORCE_INLINE IntVect offset(const int face_dir, const int normal)
Definition: ERF_ReadBndryPlanes.cpp:31
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:90
@ RhoQ1_bc_comp
Definition: ERF_IndexDefines.H:91
@ RhoKE_bc_comp
Definition: ERF_IndexDefines.H:89
@ RhoTheta_bc_comp
Definition: ERF_IndexDefines.H:88
@ RhoQ2_bc_comp
Definition: ERF_IndexDefines.H:92
@ Rho_bc_comp
Definition: ERF_IndexDefines.H:87
@ xvel_bc
Definition: ERF_IndexDefines.H:102

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
352 {
353  BL_PROFILE("ERF::ReadBndryPlanes::read_input_files");
354 
355  // Assert that both the current time and the next time are within the bounds
356  // of the data that we can read
357  AMREX_ALWAYS_ASSERT((m_in_times[0] <= time) && (time <= m_in_times.back()));
358  AMREX_ALWAYS_ASSERT((m_in_times[0] <= time+dt) && (time+dt <= m_in_times.back()));
359 
360  int ncomp = 1;
361 
362  const Box& domain = m_geom.Domain();
363  BoxArray ba(domain);
364  DistributionMapping dm{ba};
365  BndryRegister bndryn(ba, dm, m_in_rad, m_out_rad, m_extent_rad, ncomp);
366  bndryn.setVal(bogus_large_value);
367 
368  // The first time we enter this routine we read the first three files
369  if (last_file_read == -1)
370  {
371  int idx_init = 0;
372  read_file(idx_init,m_data_n ,m_bc_extdir_vals);
373  read_file(idx_init,m_data_interp,m_bc_extdir_vals); // We want to start with this filled
374  m_tn = m_in_times[idx_init];
375 
376  idx_init = 1;
377  read_file(idx_init,m_data_np1,m_bc_extdir_vals);
378  m_tnp1 = m_in_times[idx_init];
379 
380  idx_init = 2;
381  read_file(idx_init,m_data_np2,m_bc_extdir_vals);
382  m_tnp2 = m_in_times[idx_init];
383 
384  last_file_read = idx_init;
385  }
386 
387  // Compute the index such that time falls between times[idx] and times[idx+1]
388  const int idx = closest_index(m_in_times, time);
389 
390  // Advance the read window until it spans the requested time.
391  while (idx >= last_file_read-1 && last_file_read != m_in_times.size()-1) {
392  int new_read = last_file_read+1;
393 
394  // We need to change which data the pointers point to before we read in the new data
395  // This doesn't actually move the data, just swaps the pointers
396  for (OrientationIter oit; oit != nullptr; ++oit) {
397  auto ori = oit();
398  std::swap(m_data_n[ori] ,m_data_np1[ori]);
399  std::swap(m_data_np1[ori],m_data_np2[ori]);
400  }
401 
402  // Set the times corresponding to the post-swap pointers
403  m_tn = m_tnp1;
404  m_tnp1 = m_tnp2;
405  m_tnp2 = m_in_times[new_read];
406 
407  read_file(new_read,m_data_np2,m_bc_extdir_vals);
408  last_file_read = new_read;
409  }
410 
411  AMREX_ASSERT(time >= m_tn && time <= m_tnp2);
412  AMREX_ASSERT(time+dt >= m_tn && time+dt <= m_tnp2);
413 }
AMREX_FORCE_INLINE int closest_index(const Vector< double > &vec, const double value)
Definition: ERF_ReadBndryPlanes.cpp:18
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:423
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.

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