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

double read_times_from_erfbdy (const std::string &bdy_file_name, int &ntimes, int &nvars, int &real_width, Vector< double > &bdy_times, double &start_bdy_time, double &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)
 

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   
)
75 {
76  Print() << "Reading ERF boundary data for time index " << itime << std::endl;
77  std::string time_dir = bdy_file_name + "/Time_" + Concatenate("", itime, 6);
78 
79  Arena* Arena_Used = The_Arena();
80 #ifdef AMREX_USE_GPU
81  Arena_Used = The_Pinned_Arena();
82 #endif
83 
84  if (bdy_data_xlo[itime].empty()) {
85  bdy_data_xlo[itime].resize(nvars);
86  bdy_data_xhi[itime].resize(nvars);
87  bdy_data_ylo[itime].resize(nvars);
88  bdy_data_yhi[itime].resize(nvars);
89  }
90 
91  for (int ivar = 0; ivar < nvars; ++ivar)
92  {
93  { // X-low boundary
94  std::string filename = time_dir + "/BdyData_xlo_var" + std::to_string(ivar);
95  std::ifstream ifs(filename.c_str(), std::ios::in | std::ios::binary);
96 
97  // A default-constructed FArrayBox allocates from The_Arena(), which is DEVICE
98  // memory unless amrex.the_arena_is_managed=true. readFrom() then htod_memcpy's
99  // into it and the copy<RunOn::Host> below host-reads that device pointer.
100  FArrayBox tmp_fab(amrex::The_Pinned_Arena());
101 
102  tmp_fab.readFrom(ifs);
103  bdy_data_xlo[itime][ivar].resize(tmp_fab.box(), tmp_fab.nComp(), Arena_Used);
104  bdy_data_xlo[itime][ivar].template copy<RunOn::Host>(tmp_fab, 0, 0, tmp_fab.nComp());
105  ifs.close();
106  }
107 
108  { // X-high boundary
109  std::string filename = time_dir + "/BdyData_xhi_var" + std::to_string(ivar);
110  std::ifstream ifs(filename.c_str(), std::ios::in | std::ios::binary);
111 
112  // A default-constructed FArrayBox allocates from The_Arena(), which is DEVICE
113  // memory unless amrex.the_arena_is_managed=true. readFrom() then htod_memcpy's
114  // into it and the copy<RunOn::Host> below host-reads that device pointer.
115  FArrayBox tmp_fab(amrex::The_Pinned_Arena());
116 
117  tmp_fab.readFrom(ifs);
118  bdy_data_xhi[itime][ivar].resize(tmp_fab.box(), tmp_fab.nComp(), Arena_Used);
119  bdy_data_xhi[itime][ivar].template copy<RunOn::Host>(tmp_fab, 0, 0, tmp_fab.nComp());
120  ifs.close();
121  }
122 
123  { // Y-low boundary
124  std::string filename = time_dir + "/BdyData_ylo_var" + std::to_string(ivar);
125  std::ifstream ifs(filename.c_str(), std::ios::in | std::ios::binary);
126 
127  // A default-constructed FArrayBox allocates from The_Arena(), which is DEVICE
128  // memory unless amrex.the_arena_is_managed=true. readFrom() then htod_memcpy's
129  // into it and the copy<RunOn::Host> below host-reads that device pointer.
130  FArrayBox tmp_fab(amrex::The_Pinned_Arena());
131 
132  tmp_fab.readFrom(ifs);
133  bdy_data_ylo[itime][ivar].resize(tmp_fab.box(), tmp_fab.nComp(), Arena_Used);
134  bdy_data_ylo[itime][ivar].template copy<RunOn::Host>(tmp_fab, 0, 0, tmp_fab.nComp());
135  ifs.close();
136  }
137 
138  { // Y-high boundary
139  std::string filename = time_dir + "/BdyData_yhi_var" + std::to_string(ivar);
140  std::ifstream ifs(filename.c_str(), std::ios::in | std::ios::binary);
141 
142  // A default-constructed FArrayBox allocates from The_Arena(), which is DEVICE
143  // memory unless amrex.the_arena_is_managed=true. readFrom() then htod_memcpy's
144  // into it and the copy<RunOn::Host> below host-reads that device pointer.
145  FArrayBox tmp_fab(amrex::The_Pinned_Arena());
146 
147  tmp_fab.readFrom(ifs);
148  bdy_data_yhi[itime][ivar].resize(tmp_fab.box(), tmp_fab.nComp(), Arena_Used);
149  bdy_data_yhi[itime][ivar].template copy<RunOn::Host>(tmp_fab, 0, 0, tmp_fab.nComp());
150  ifs.close();
151  }
152  }
153 
154  // Barrier to ensure all reads complete.
155  ParallelDescriptor::Barrier();
156 }
@ nvars
Definition: ERF_DataStruct.H:152
struct @28 in
Arena * Arena_Used
Definition: ERF_Morrison_Advance_F.H:23

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

Here is the caller graph for this function:

◆ read_times_from_erfbdy()

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

Referenced by ERF::ReadCheckpointFile().

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