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 (amrex::Real time, amrex::Real dt, amrex::Array< amrex::Array< amrex::Real, AMREX_SPACEDIM *2 >, AMREX_SPACEDIM+NVAR_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+NVAR_max > m_bc_extdir_vals)
 
amrex::Vector< std::unique_ptr< PlaneVector > > & interp_in_time (const amrex::Real &time)
 
amrex::Real 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
 
int ingested_QKE () const
 

Private Attributes

amrex::Real m_tn
 The times for which we currently have data. More...
 
amrex::Real m_tnp1
 
amrex::Real 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::Real 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< amrex::Real > 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...
 
const int m_in_rad = 1
 controls extents on native bndry output More...
 
const int m_out_rad = 1
 
const int m_extent_rad = 0
 
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 is_QKE_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$)
141 :
142  m_geom(geom),
143  m_rdOcp(rdOcp_in)
144 {
145  ParmParse pp("erf");
146 
147  last_file_read = -1;
148 
149  m_tinterp = -1.;
150 
151  // What folder will the time series of planes be read from
152  pp.get("bndry_file", m_filename);
153 
154  is_velocity_read = 0;
155  is_density_read = 0;
157  is_theta_read = 0;
158  is_scalar_read = 0;
159  is_q1_read = 0;
160  is_q2_read = 0;
161  is_KE_read = 0;
162  is_QKE_read = 0;
163 
164  if (pp.contains("bndry_input_var_names"))
165  {
166  int num_vars = pp.countval("bndry_input_var_names");
167  m_var_names.resize(num_vars);
168  pp.queryarr("bndry_input_var_names",m_var_names,0,num_vars);
169  for (int i = 0; i < m_var_names.size(); i++) {
170  if (m_var_names[i] == "velocity") is_velocity_read = 1;
171  if (m_var_names[i] == "density") is_density_read = 1;
172  if (m_var_names[i] == "temperature") is_temperature_read = 1;
173  if (m_var_names[i] == "theta") is_theta_read = 1;
174  if (m_var_names[i] == "scalar") is_scalar_read = 1;
175  if (m_var_names[i] == "qv") is_q1_read = 1;
176  if (m_var_names[i] == "qc") is_q2_read = 1;
177  if (m_var_names[i] == "ke") is_KE_read = 1;
178  if (m_var_names[i] == "qke") is_QKE_read = 1;
179  }
180  }
181 
182  // time.dat will be in the same folder as the time series of data
183  m_time_file = m_filename + "/time.dat";
184 
185  // each pointer (at at given time) has 6 components, one for each orientation
186  // TODO: we really only need 4 not 6
187  int size = 2*AMREX_SPACEDIM;
188  m_data_n.resize(size);
189  m_data_np1.resize(size);
190  m_data_np2.resize(size);
191  m_data_interp.resize(size);
192 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real pp(amrex::Real y)
Definition: Microphysics_Utils.H:183
int is_velocity_read
Definition: ERF_ReadBndryPlanes.H:96
int is_q2_read
Definition: ERF_ReadBndryPlanes.H:102
int is_theta_read
Definition: ERF_ReadBndryPlanes.H:99
std::string m_filename
File name for IO.
Definition: ERF_ReadBndryPlanes.H:76
amrex::Real m_tinterp
Time for plane at interpolation.
Definition: ERF_ReadBndryPlanes.H:70
int is_temperature_read
Definition: ERF_ReadBndryPlanes.H:98
int is_density_read
Definition: ERF_ReadBndryPlanes.H:97
amrex::Vector< std::unique_ptr< PlaneVector > > m_data_np2
Data at time m_tnp2.
Definition: ERF_ReadBndryPlanes.H:64
amrex::Vector< std::unique_ptr< PlaneVector > > m_data_interp
Data interpolated to the time requested.
Definition: ERF_ReadBndryPlanes.H:67
int last_file_read
Definition: ERF_ReadBndryPlanes.H:106
int is_KE_read
Definition: ERF_ReadBndryPlanes.H:103
const amrex::Real m_rdOcp
R_d/c_p is needed for reading boundary files.
Definition: ERF_ReadBndryPlanes.H:94
std::string m_time_file
File name for file holding timesteps and times.
Definition: ERF_ReadBndryPlanes.H:79
int is_QKE_read
Definition: ERF_ReadBndryPlanes.H:104
amrex::Vector< std::string > m_var_names
Variables to be read in.
Definition: ERF_ReadBndryPlanes.H:86
int is_scalar_read
Definition: ERF_ReadBndryPlanes.H:100
int is_q1_read
Definition: ERF_ReadBndryPlanes.H:101
amrex::Vector< std::unique_ptr< PlaneVector > > m_data_n
Data at time m_tn.
Definition: ERF_ReadBndryPlanes.H:58
amrex::Vector< std::unique_ptr< PlaneVector > > m_data_np1
Data at time m_tnp1.
Definition: ERF_ReadBndryPlanes.H:61
amrex::Geometry m_geom
Geometry at level 0.
Definition: ERF_ReadBndryPlanes.H:73
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.

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

Referenced by read_time_file().

Here is the caller graph for this function:

◆ ingested_density()

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

Referenced by read_file().

Here is the caller graph for this function:

◆ ingested_KE()

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

◆ ingested_q1()

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

◆ ingested_q2()

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

◆ ingested_QKE()

int ReadBndryPlanes::ingested_QKE ( ) const
inline
48 {return is_QKE_read;}

◆ ingested_scalar()

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

◆ ingested_theta()

int ReadBndryPlanes::ingested_theta ( ) const
inline

◆ ingested_velocity()

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

◆ interp_in_time()

Vector< std::unique_ptr< PlaneVector > > & ReadBndryPlanes::interp_in_time ( const amrex::Real &  time)

Function in ReadBndryPlanes class for interpolating boundary data in time.

Parameters
timeConstant specifying the time for interpolation
85 {
86  AMREX_ALWAYS_ASSERT(m_tn <= time && time <= m_tnp2);
87 
88  //Print() << "interp_in_time at time " << time << " given " << m_tn << " " << m_tnp1 << " " << m_tnp2 << std::endl;
89  //Print() << "m_tinterp " << m_tinterp << std::endl;
90 
91  if (time == m_tinterp) {
92  // We have already interpolated to this time
93  return m_data_interp;
94 
95  } else {
96 
97  // We must now interpolate to a new time
98  m_tinterp = time;
99 
100  if (time < m_tnp1) {
101  for (OrientationIter oit; oit != nullptr; ++oit) {
102  auto ori = oit();
103  if (ori.coordDir() < 2) {
104  const int nlevels = m_data_n[ori]->size();
105  for (int lev = 0; lev < nlevels; ++lev) {
106  const auto& datn = (*m_data_n[ori])[lev];
107  const auto& datnp1 = (*m_data_np1[ori])[lev];
108  auto& dati = (*m_data_interp[ori])[lev];
109  dati.linInterp<RunOn::Device>(
110  datn, 0, datnp1, 0, m_tn, m_tnp1, m_tinterp, datn.box(), 0, dati.nComp());
111  }
112  }
113  }
114  } else {
115  for (OrientationIter oit; oit != nullptr; ++oit) {
116  auto ori = oit();
117  if (ori.coordDir() < 2) {
118  const int nlevels = m_data_n[ori]->size();
119  for (int lev = 0; lev < nlevels; ++lev) {
120  const auto& datnp1 = (*m_data_np1[ori])[lev];
121  const auto& datnp2 = (*m_data_np2[ori])[lev];
122  auto& dati = (*m_data_interp[ori])[lev];
123  dati.linInterp<RunOn::Device>(
124  datnp1, 0, datnp2, 0, m_tnp1, m_tnp2, m_tinterp, datnp1.box(), 0,
125  dati.nComp());
126  }
127  }
128  }
129  }
130  }
131  return m_data_interp;
132 }
amrex::Real m_tnp1
Definition: ERF_ReadBndryPlanes.H:54
amrex::Real m_tnp2
Definition: ERF_ReadBndryPlanes.H:55
amrex::Real m_tn
The times for which we currently have data.
Definition: ERF_ReadBndryPlanes.H:53

◆ 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+NVAR_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
345 {
346  const int t_step = m_in_timesteps[idx];
347  const std::string chkname1 = m_filename + Concatenate("/bndry_output", t_step);
348 
349  const std::string level_prefix = "Level_";
350  const int lev = 0;
351 
352  const Box& domain = m_geom.Domain();
353  BoxArray ba(domain);
354  DistributionMapping dm{ba};
355 
356  GpuArray<GpuArray<Real, AMREX_SPACEDIM*2>, AMREX_SPACEDIM+NVAR_max> l_bc_extdir_vals_d;
357 
358  for (int i = 0; i < BCVars::NumTypes; i++)
359  {
360  for (OrientationIter oit; oit != nullptr; ++oit) {
361  auto ori = oit();
362  l_bc_extdir_vals_d[i][ori] = m_bc_extdir_vals[i][ori];
363  }
364  }
365 
366  int n_for_density = -1;
367  for (int i = 0; i < m_var_names.size(); i++)
368  {
369  if (m_var_names[i] == "density") n_for_density = i;
370  }
371 
372  // We need to initialize all the components because we may not fill all of them from files,
373  // but the loop in the interpolate routine goes over all the components anyway
374  int ncomp_for_bc = BCVars::NumTypes;
375  for (OrientationIter oit; oit != nullptr; ++oit) {
376  auto ori = oit();
377  if (ori.coordDir() < 2) {
378  FArrayBox& d = (*data_to_fill[ori])[lev];
379  const auto& bx = d.box();
380  Array4<Real> d_arr = d.array();
381  ParallelFor(
382  bx, ncomp_for_bc, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept {
383  d_arr(i,j,k,n) = 0.;
384  });
385  }
386  }
387 
388  // Read density for primitive to conserved conversions
389  std::string filenamer = MultiFabFileFullPrefix(lev, chkname1, level_prefix, "density");
390  BndryRegister bndry_r(ba, dm, m_in_rad, m_out_rad, m_extent_rad, 1);
391  bndry_r.setVal(1.0e13);
392  for (OrientationIter oit; oit != nullptr; ++oit) {
393  auto ori = oit();
394  if (ori.coordDir() < 2) {
395  std::string facenamer = Concatenate(filenamer + '_', ori, 1);
396  bndry_r[ori].read(facenamer);
397  }
398  }
399 
400  for (int ivar = 0; ivar < m_var_names.size(); ivar++)
401  {
402  std::string var_name = m_var_names[ivar];
403 
404  std::string filename1 = MultiFabFileFullPrefix(lev, chkname1, level_prefix, var_name);
405 
406  int ncomp;
407  if (var_name == "velocity") {
408  ncomp = AMREX_SPACEDIM;
409  } else {
410  ncomp = 1;
411  }
412 
413  int n_offset;
414  if (var_name == "density") n_offset = BCVars::Rho_bc_comp;
415  if (var_name == "theta") n_offset = BCVars::RhoTheta_bc_comp;
416  if (var_name == "temperature") n_offset = BCVars::RhoTheta_bc_comp;
417  if (var_name == "ke") n_offset = BCVars::RhoKE_bc_comp;
418  if (var_name == "qke") n_offset = BCVars::RhoQKE_bc_comp;
419  if (var_name == "scalar") n_offset = BCVars::RhoScalar_bc_comp;
420  if (var_name == "qv") n_offset = BCVars::RhoQ1_bc_comp;
421  if (var_name == "qc") n_offset = BCVars::RhoQ2_bc_comp;
422  if (var_name == "velocity") n_offset = BCVars::xvel_bc;
423 
424  // Print() << "Reading " << chkname1 << " for variable " << var_name << " with n_offset == " << n_offset << std::endl;
425 
426  BndryRegister bndry(ba, dm, m_in_rad, m_out_rad, m_extent_rad, ncomp);
427  bndry.setVal(1.0e13);
428 
429  // *********************************************************
430  // Read in the BndryReg for all non-z faces
431  // *********************************************************
432  for (OrientationIter oit; oit != nullptr; ++oit) {
433  auto ori = oit();
434  if (ori.coordDir() < 2) {
435 
436  std::string facename1 = Concatenate(filename1 + '_', ori, 1);
437  bndry[ori].read(facename1);
438 
439  const int normal = ori.coordDir();
440  const IntVect v_offset = offset(ori.faceDir(), normal);
441 
442  const auto& bbx = (*data_to_fill[ori])[lev].box();
443 
444  // *********************************************************
445  // Copy from the BndryReg into a MultiFab then use copyTo
446  // to write from the MultiFab to a single FAB for each face
447  // *********************************************************
448  MultiFab bndryMF(
449  bndry[ori].boxArray(), bndry[ori].DistributionMap(),
450  ncomp, 0, MFInfo());
451 
452  for (MFIter mfi(bndryMF); mfi.isValid(); ++mfi) {
453 
454  const auto& vbx = mfi.validbox();
455  const auto& bndry_read_arr = bndry[ori].array(mfi);
456  const auto& bndry_read_r_arr = bndry_r[ori].array(mfi);
457  const auto& bndry_mf_arr = bndryMF.array(mfi);
458 
459  const auto& bx = bbx & vbx;
460  if (bx.isEmpty()) {
461  continue;
462  }
463 
464  // We average the two cell-centered data points in the normal direction
465  // to define a Dirichlet value on the face itself.
466 
467  // This is the scalars -- they all get multiplied by rho, and in the case of
468  // reading in temperature, we must convert to theta first
469  Real rdOcp = m_rdOcp;
470  if (n_for_density >= 0) {
471  if (var_name == "temperature") {
472  ParallelFor(
473  bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
474  Real R1 = bndry_read_r_arr(i, j, k, 0);
475  Real R2 = bndry_read_r_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2],0);
476  Real T1 = bndry_read_arr(i, j, k, 0);
477  Real T2 = bndry_read_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2],0);
478  Real Th1 = getThgivenRandT(R1,T1,rdOcp);
479  Real Th2 = getThgivenRandT(R2,T2,rdOcp);
480  bndry_mf_arr(i, j, k, 0) = 0.5 * (R1*Th1 + R2*Th2);
481  });
482  } else if (var_name == "scalar" || var_name == "qv" || var_name == "qc" ||
483  var_name == "ke" || var_name == "qke") {
484  ParallelFor(
485  bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
486  Real R1 = bndry_read_r_arr(i, j, k, 0);
487  Real R2 = bndry_read_r_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2],0);
488  bndry_mf_arr(i, j, k, 0) = 0.5 *
489  ( R1 * bndry_read_arr(i, j, k, 0) +
490  R2 * bndry_read_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2], 0));
491  });
492  } else if (var_name == "density") {
493  ParallelFor(
494  bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
495  bndry_mf_arr(i, j, k, 0) = 0.5 *
496  ( bndry_read_arr(i, j, k, 0) +
497  bndry_read_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2], 0));
498  });
499  }
500  } else if (!ingested_density()) {
501  if (var_name == "temperature") {
502  ParallelFor(
503  bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
504  Real R1 = l_bc_extdir_vals_d[BCVars::Rho_bc_comp][ori];
505  Real R2 = l_bc_extdir_vals_d[BCVars::Rho_bc_comp][ori];
506  Real T1 = bndry_read_arr(i, j, k, 0);
507  Real T2 = bndry_read_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2], 0);
508  Real Th1 = getThgivenRandT(R1,T1,rdOcp);
509  Real Th2 = getThgivenRandT(R2,T2,rdOcp);
510  bndry_mf_arr(i, j, k, 0) = 0.5 * (R1*Th1 + R2*Th2);
511  });
512  } else if (var_name == "scalar" || var_name == "qv" || var_name == "qc" ||
513  var_name == "ke" || var_name == "qke") {
514  ParallelFor(
515  bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
516  Real R1 = l_bc_extdir_vals_d[BCVars::Rho_bc_comp][ori];
517  Real R2 = l_bc_extdir_vals_d[BCVars::Rho_bc_comp][ori];
518  bndry_mf_arr(i, j, k, 0) = 0.5 *
519  (R1 * bndry_read_arr(i, j, k, 0) +
520  R2 * bndry_read_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2], 0));
521  });
522  }
523  }
524 
525  // This is velocity
526  if (var_name == "velocity") {
527  ParallelFor(
528  bx, ncomp, [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept {
529  bndry_mf_arr(i, j, k, n) = 0.5 *
530  (bndry_read_arr(i, j, k, n) +
531  bndry_read_arr(i+v_offset[0],j+v_offset[1],k+v_offset[2], n));
532  });
533  }
534 
535  } // mfi
536  bndryMF.copyTo((*data_to_fill[ori])[lev], 0, n_offset, ncomp);
537  } // coordDir < 2
538  } // ori
539  } // var_name
540 }
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=0.0)
Definition: EOS.H:47
AMREX_FORCE_INLINE IntVect offset(const int face_dir, const int normal)
Definition: ERF_ReadBndryPlanes.cpp:28
#define NVAR_max
Definition: IndexDefines.H:27
amrex::Vector< int > m_in_timesteps
Definition: ERF_ReadBndryPlanes.H:83
const int m_in_rad
controls extents on native bndry output
Definition: ERF_ReadBndryPlanes.H:89
int ingested_density() const
Definition: ERF_ReadBndryPlanes.H:43
const int m_out_rad
Definition: ERF_ReadBndryPlanes.H:90
const int m_extent_rad
Definition: ERF_ReadBndryPlanes.H:91
@ RhoScalar_bc_comp
Definition: IndexDefines.H:52
@ RhoQ1_bc_comp
Definition: IndexDefines.H:53
@ RhoKE_bc_comp
Definition: IndexDefines.H:50
@ RhoQKE_bc_comp
Definition: IndexDefines.H:51
@ RhoTheta_bc_comp
Definition: IndexDefines.H:49
@ RhoQ2_bc_comp
Definition: IndexDefines.H:54
@ Rho_bc_comp
Definition: IndexDefines.H:48
@ xvel_bc
Definition: IndexDefines.H:55

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 ( amrex::Real  time,
amrex::Real  dt,
amrex::Array< amrex::Array< amrex::Real, AMREX_SPACEDIM *2 >, AMREX_SPACEDIM+NVAR_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
271 {
272  BL_PROFILE("ERF::ReadBndryPlanes::read_input_files");
273 
274  // Assert that both the current time and the next time are within the bounds
275  // of the data that we can read
276  AMREX_ALWAYS_ASSERT((m_in_times[0] <= time) && (time <= m_in_times.back()));
277  AMREX_ALWAYS_ASSERT((m_in_times[0] <= time+dt) && (time+dt <= m_in_times.back()));
278 
279  int ncomp = 1;
280 
281  const Box& domain = m_geom.Domain();
282  BoxArray ba(domain);
283  DistributionMapping dm{ba};
284  BndryRegister bndryn(ba, dm, m_in_rad, m_out_rad, m_extent_rad, ncomp);
285  bndryn.setVal(1.0e13);
286 
287  // The first time we enter this routine we read the first three files
288  if (last_file_read == -1)
289  {
290  int idx_init = 0;
291  read_file(idx_init,m_data_n,m_bc_extdir_vals);
292  read_file(idx_init,m_data_interp,m_bc_extdir_vals); // We want to start with this filled
293  m_tn = m_in_times[idx_init];
294 
295  idx_init = 1;
296  read_file(idx_init,m_data_np1,m_bc_extdir_vals);
297  m_tnp1 = m_in_times[idx_init];
298 
299  idx_init = 2;
300  read_file(idx_init,m_data_np2,m_bc_extdir_vals);
301  m_tnp2 = m_in_times[idx_init];
302 
303  last_file_read = idx_init;
304  }
305 
306  // Compute the index such that time falls between times[idx] and times[idx+1]
307  const int idx = closest_index(m_in_times, time);
308 
309  // Now we need to read another file
310  if (idx >= last_file_read-1 && last_file_read != m_in_times.size()-1) {
311  int new_read = last_file_read+1;
312 
313  // We need to change which data the pointers point to before we read in the new data
314  // This doesn't actually move the data, just swaps the pointers
315  for (OrientationIter oit; oit != nullptr; ++oit) {
316  auto ori = oit();
317  std::swap(m_data_n[ori] ,m_data_np1[ori]);
318  std::swap(m_data_np1[ori],m_data_np2[ori]);
319  }
320 
321  // Set the times corresponding to the post-swap pointers
322  m_tn = m_tnp1;
323  m_tnp1 = m_tnp2;
324  m_tnp2 = m_in_times[new_read];
325 
326  read_file(new_read,m_data_np2,m_bc_extdir_vals);
327  last_file_read = new_read;
328  }
329 
330  AMREX_ASSERT(time >= m_tn && time <= m_tnp2);
331  AMREX_ASSERT(time+dt >= m_tn && time+dt <= m_tnp2);
332 }
AMREX_FORCE_INLINE int closest_index(const Vector< Real > &vec, const Real value)
Definition: ERF_ReadBndryPlanes.cpp:15
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+NVAR_max > m_bc_extdir_vals)
Definition: ERF_ReadBndryPlanes.cpp:342
amrex::Vector< amrex::Real > m_in_times
The timesteps / times that we read from time.dat.
Definition: ERF_ReadBndryPlanes.H:82
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.

199 {
200  BL_PROFILE("ERF::ReadBndryPlanes::read_time_file");
201 
202  // *********************************************************
203  // Read the time.data file and store the timesteps and times
204  // *********************************************************
205  int time_file_length = 0;
206 
207  if (ParallelDescriptor::IOProcessor()) {
208 
209  std::string line;
210  std::ifstream time_file(m_time_file);
211  if (!time_file.good()) {
212  Abort("Cannot find time file: " + m_time_file);
213  }
214  while (std::getline(time_file, line)) {
215  ++time_file_length;
216  }
217 
218  time_file.close();
219  }
220 
221  ParallelDescriptor::Bcast(
222  &time_file_length, 1,
223  ParallelDescriptor::IOProcessorNumber(),
224  ParallelDescriptor::Communicator());
225 
226  m_in_times.resize(time_file_length);
227  m_in_timesteps.resize(time_file_length);
228 
229  if (ParallelDescriptor::IOProcessor()) {
230  std::ifstream time_file(m_time_file);
231  for (int i = 0; i < time_file_length; ++i) {
232  time_file >> m_in_timesteps[i] >> m_in_times[i];
233  }
234  // Sanity check that there are no duplicates or mis-orderings
235  for (int i = 1; i < time_file_length; ++i) {
236  if (m_in_timesteps[i] <= m_in_timesteps[i-1])
237  Error("Bad timestep in time.dat file");
238  if (m_in_times[i] <= m_in_times[i-1])
239  Error("Bad time in time.dat file");
240  }
241  time_file.close();
242  }
243 
244  ParallelDescriptor::Bcast(
245  m_in_timesteps.data(), time_file_length,
246  ParallelDescriptor::IOProcessorNumber(),
247  ParallelDescriptor::Communicator());
248 
249  ParallelDescriptor::Bcast(
250  m_in_times.data(), time_file_length,
251  ParallelDescriptor::IOProcessorNumber(),
252  ParallelDescriptor::Communicator());
253 
254  // Allocate data we will need -- for now just at one level
255  int lev = 0;
256  define_level_data(lev);
257  Print() << "Successfully read time file and allocated data" << std::endl;
258 }
void define_level_data(int lev)
Definition: ERF_ReadBndryPlanes.cpp:43
Here is the call graph for this function:

◆ tinterp()

amrex::Real ReadBndryPlanes::tinterp ( ) const
inline
39 { 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_QKE_read

int ReadBndryPlanes::is_QKE_read
private

Referenced by ingested_QKE(), 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_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

const int ReadBndryPlanes::m_in_rad = 1
private

controls extents on native bndry output

Referenced by read_file(), and read_input_files().

◆ m_in_times

amrex::Vector<amrex::Real> 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

amrex::Real ReadBndryPlanes::m_tinterp {-1.0}
private

Time for plane at interpolation.

Referenced by ReadBndryPlanes(), and tinterp().

◆ m_tn

amrex::Real ReadBndryPlanes::m_tn
private

The times for which we currently have data.

Referenced by read_input_files().

◆ m_tnp1

amrex::Real ReadBndryPlanes::m_tnp1
private

Referenced by read_input_files().

◆ m_tnp2

amrex::Real ReadBndryPlanes::m_tnp2
private

Referenced by read_input_files().

◆ 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: