ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_ReadFromERFBdy.cpp File Reference
#include "ERF_ReadFromERFBdy.H"
#include <AMReX_VisMF.H>
#include <AMReX_ParallelDescriptor.H>
#include <AMReX_Print.H>
#include <fstream>
Include dependency graph for ERF_ReadFromERFBdy.cpp:

Functions

Real read_times_from_erfbdy (const std::string &bdy_file_name, int &ntimes, int &nvars, int &real_width, Vector< Real > &bdy_times, Real &start_bdy_time, Real &final_bdy_time)
 
void read_from_erfbdy (int itime, const std::string &bdy_file_name, Vector< Vector< FArrayBox >> &bdy_data_xlo, Vector< Vector< FArrayBox >> &bdy_data_xhi, Vector< Vector< FArrayBox >> &bdy_data_ylo, Vector< Vector< FArrayBox >> &bdy_data_yhi, int nvars, int real_width)
 

Function Documentation

◆ read_from_erfbdy()

void read_from_erfbdy ( int  itime,
const std::string &  bdy_file_name,
Vector< Vector< FArrayBox >> &  bdy_data_xlo,
Vector< Vector< FArrayBox >> &  bdy_data_xhi,
Vector< Vector< FArrayBox >> &  bdy_data_ylo,
Vector< Vector< FArrayBox >> &  bdy_data_yhi,
int  nvars,
int  real_width 
)
72 {
73  Print() << "Reading ERF boundary data for time index " << itime << std::endl;
74  std::string time_dir = bdy_file_name + "/Time_" + Concatenate("", itime, 6);
75 
76  Arena* Arena_Used = The_Arena();
77 #ifdef AMREX_USE_GPU
78  Arena_Used = The_Pinned_Arena();
79 #endif
80 
81  if (bdy_data_xlo[itime].empty()) {
82  bdy_data_xlo[itime].resize(nvars);
83  bdy_data_xhi[itime].resize(nvars);
84  bdy_data_ylo[itime].resize(nvars);
85  bdy_data_yhi[itime].resize(nvars);
86  }
87 
88  for (int ivar = 0; ivar < nvars; ++ivar)
89  {
90  { // X-low boundary
91  std::string filename = time_dir + "/BdyData_xlo_var" + std::to_string(ivar);
92  std::ifstream ifs(filename.c_str(), std::ios::in | std::ios::binary);
93  FArrayBox tmp_fab;
94  tmp_fab.readFrom(ifs);
95  bdy_data_xlo[itime][ivar].resize(tmp_fab.box(), tmp_fab.nComp(), Arena_Used);
96  bdy_data_xlo[itime][ivar].template copy<RunOn::Host>(tmp_fab, 0, 0, tmp_fab.nComp());
97  ifs.close();
98  }
99 
100  { // X-high boundary
101  std::string filename = time_dir + "/BdyData_xhi_var" + std::to_string(ivar);
102  std::ifstream ifs(filename.c_str(), std::ios::in | std::ios::binary);
103  FArrayBox tmp_fab;
104  tmp_fab.readFrom(ifs);
105  bdy_data_xhi[itime][ivar].resize(tmp_fab.box(), tmp_fab.nComp(), Arena_Used);
106  bdy_data_xhi[itime][ivar].template copy<RunOn::Host>(tmp_fab, 0, 0, tmp_fab.nComp());
107  ifs.close();
108  }
109 
110  { // Y-low boundary
111  std::string filename = time_dir + "/BdyData_ylo_var" + std::to_string(ivar);
112  std::ifstream ifs(filename.c_str(), std::ios::in | std::ios::binary);
113  FArrayBox tmp_fab;
114  tmp_fab.readFrom(ifs);
115  bdy_data_ylo[itime][ivar].resize(tmp_fab.box(), tmp_fab.nComp(), Arena_Used);
116  bdy_data_ylo[itime][ivar].template copy<RunOn::Host>(tmp_fab, 0, 0, tmp_fab.nComp());
117  ifs.close();
118  }
119 
120  { // Y-high boundary
121  std::string filename = time_dir + "/BdyData_yhi_var" + std::to_string(ivar);
122  std::ifstream ifs(filename.c_str(), std::ios::in | std::ios::binary);
123  FArrayBox tmp_fab;
124  tmp_fab.readFrom(ifs);
125  bdy_data_yhi[itime][ivar].resize(tmp_fab.box(), tmp_fab.nComp(), Arena_Used);
126  bdy_data_yhi[itime][ivar].template copy<RunOn::Host>(tmp_fab, 0, 0, tmp_fab.nComp());
127  ifs.close();
128  }
129  }
130 
131  // Barrier to ensure all reads complete.
132  ParallelDescriptor::Barrier();
133 }
@ nvars
Definition: ERF_DataStruct.H:98
struct @28 in
Arena * Arena_Used
Definition: ERF_Morrison_Advance_F.H:17

Referenced by ERF::ReadCheckpointFile(), and ERF::timeStep().

Here is the caller graph for this function:

◆ read_times_from_erfbdy()

Real read_times_from_erfbdy ( const std::string &  bdy_file_name,
int &  ntimes,
int &  nvars,
int &  real_width,
Vector< Real > &  bdy_times,
Real start_bdy_time,
Real final_bdy_time 
)
17 {
18  std::string HeaderFileName = bdy_file_name + "/Header";
19 
20  // Read header file.
21  std::ifstream HeaderFile;
22  HeaderFile.open(HeaderFileName.c_str(), std::ifstream::in);
23 
24  if (!HeaderFile.good()) {
25  amrex::FileOpenFailed(HeaderFileName);
26  }
27 
28  std::string line;
29 
30  // Read title line.
31  std::getline(HeaderFile, line);
32 
33  // Read metadata.
34  HeaderFile >> ntimes;
35  HeaderFile >> nvars;
36  HeaderFile >> real_width;
37 
38  // Read boundary times.
39  bdy_times.resize(ntimes);
40  for (int i = 0; i < ntimes; ++i) {
41  HeaderFile >> bdy_times[i];
42  }
43 
44  // Read domain box (stored but not used here).
45  int sml[3], big[3];
46  HeaderFile >> sml[0] >> sml[1] >> sml[2];
47  HeaderFile >> big[0] >> big[1] >> big[2];
48 
49  HeaderFile.close();
50 
51  // Ensure the file holds at least two times.
52  AMREX_ALWAYS_ASSERT(ntimes >= 2);
53 
54  // Set the first and last boundary times.
55  start_bdy_time = bdy_times[0];
56  final_bdy_time = bdy_times[ntimes - 1];
57 
58  // Calculate the interval between boundary times.
59  Real bdy_time_interval = bdy_times[1] - bdy_times[0];
60 
61  return bdy_time_interval;
62 }
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
amrex::Real Real
Definition: ERF_ShocInterface.H:19

Referenced by ERF::ReadCheckpointFile().

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