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  }
261  }
262 
263  // time.dat will be in the same folder as the time series of data
264  m_time_file = m_filename + "/time.dat";
265 
266  // each pointer (at at given time) has 6 components, one for each orientation
267  // TODO: we really only need 4 not 6
268  int size = 2*AMREX_SPACEDIM;
269  m_data_n.resize(size);
270  m_data_np1.resize(size);
271  m_data_np2.resize(size);
272  m_data_interp.resize(size);
273  m_data_tendency.resize(size);
274 }
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:108

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

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

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