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+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 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
 

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 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 
163  if (pp.contains("bndry_input_var_names"))
164  {
165  int num_vars = pp.countval("bndry_input_var_names");
166  m_var_names.resize(num_vars);
167  pp.queryarr("bndry_input_var_names",m_var_names,0,num_vars);
168  for (int i = 0; i < m_var_names.size(); i++) {
169  if (m_var_names[i] == "velocity") is_velocity_read = 1;
170  if (m_var_names[i] == "density") is_density_read = 1;
171  if (m_var_names[i] == "temperature") is_temperature_read = 1;
172  if (m_var_names[i] == "theta") is_theta_read = 1;
173  if (m_var_names[i] == "scalar") is_scalar_read = 1;
174  if (m_var_names[i] == "qv") is_q1_read = 1;
175  if (m_var_names[i] == "qc") is_q2_read = 1;
176  if (m_var_names[i] == "ke") is_KE_read = 1;
177  }
178  }
179 
180  // time.dat will be in the same folder as the time series of data
181  m_time_file = m_filename + "/time.dat";
182 
183  // each pointer (at at given time) has 6 components, one for each orientation
184  // TODO: we really only need 4 not 6
185  int size = 2*AMREX_SPACEDIM;
186  m_data_n.resize(size);
187  m_data_np1.resize(size);
188  m_data_np2.resize(size);
189  m_data_interp.resize(size);
190 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real pp(amrex::Real y)
Definition: ERF_MicrophysicsUtils.H:219
int is_velocity_read
Definition: ERF_ReadBndryPlanes.H:95
int is_q2_read
Definition: ERF_ReadBndryPlanes.H:101
int is_theta_read
Definition: ERF_ReadBndryPlanes.H:98
std::string m_filename
File name for IO.
Definition: ERF_ReadBndryPlanes.H:75
amrex::Real m_tinterp
Time for plane at interpolation.
Definition: ERF_ReadBndryPlanes.H:69
int is_temperature_read
Definition: ERF_ReadBndryPlanes.H:97
int is_density_read
Definition: ERF_ReadBndryPlanes.H:96
amrex::Vector< std::unique_ptr< PlaneVector > > m_data_np2
Data at time m_tnp2.
Definition: ERF_ReadBndryPlanes.H:63
amrex::Vector< std::unique_ptr< PlaneVector > > m_data_interp
Data interpolated to the time requested.
Definition: ERF_ReadBndryPlanes.H:66
int last_file_read
Definition: ERF_ReadBndryPlanes.H:104
int is_KE_read
Definition: ERF_ReadBndryPlanes.H:102
const amrex::Real m_rdOcp
R_d/c_p is needed for reading boundary files.
Definition: ERF_ReadBndryPlanes.H:93
std::string m_time_file
File name for file holding timesteps and times.
Definition: ERF_ReadBndryPlanes.H:78
amrex::Vector< std::string > m_var_names
Variables to be read in.
Definition: ERF_ReadBndryPlanes.H:85
int is_scalar_read
Definition: ERF_ReadBndryPlanes.H:99
int is_q1_read
Definition: ERF_ReadBndryPlanes.H:100
amrex::Vector< std::unique_ptr< PlaneVector > > m_data_n
Data at time m_tn.
Definition: ERF_ReadBndryPlanes.H:57
amrex::Vector< std::unique_ptr< PlaneVector > > m_data_np1
Data at time m_tnp1.
Definition: ERF_ReadBndryPlanes.H:60
amrex::Geometry m_geom
Geometry at level 0.
Definition: ERF_ReadBndryPlanes.H:72
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: ERF_IndexDefines.H:91

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_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:53
amrex::Real m_tnp2
Definition: ERF_ReadBndryPlanes.H:54
amrex::Real m_tn
The times for which we currently have data.
Definition: ERF_ReadBndryPlanes.H:52

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

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

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