21 amrex::Print() <<
"Loading " <<
field_name <<
" from rivers NetCDF file " <<
file_name << std::endl;
32 if (amrex::ParallelDescriptor::IOProcessor())
34 if (unit_str.find(
"days") == std::string::npos) {
35 amrex::Print() <<
"Units of river_time given as: " << unit_str << std::endl;
36 amrex::Abort(
"Units must be in days.");
41 amrex::Vector<RARRAY> array_ts(1);
43 if (amrex::ParallelDescriptor::IOProcessor())
45 int ntimes_io = array_ts[0].get_vshape()[0];
46 for (
int nt(0); nt < ntimes_io; nt++)
49 river_times.push_back((*(array_ts[0].get_data() + nt)) * amrex::Real(60.0) * amrex::Real(60.0) * amrex::Real(24.0));
55 if (amrex::ParallelDescriptor::IOProcessor()) {
58 amrex::Error(
"River data must be given at at least two times");
61 int ioproc = amrex::ParallelDescriptor::IOProcessorNumber();
62 amrex::ParallelDescriptor::Bcast(&ntimes,1,ioproc);
63 if (!(amrex::ParallelDescriptor::IOProcessor())) {
69 if (amrex::ParallelDescriptor::IOProcessor())
71 std::vector<MPI_Offset> shape = ncf.var(
field_name).shape();
72 if (shape.size() == 2) {
75 }
else if (shape.size() == 3) {
79 amrex::Abort(
"River field shape not 2 or 3");
82 amrex::ParallelDescriptor::Bcast(&
has_z, 1, ioproc);
83 amrex::ParallelDescriptor::Bcast(&
nriv, 1, ioproc);
85 amrex::Box vshape_box(amrex::IntVect(0,0,0),amrex::IntVect(
nriv,0,
nz));
87 amrex::Vector<amrex::FArrayBox*> NC_fabs;
88 amrex::Vector<std::string> NC_names;
89 amrex::Vector<enum NC_Data_Dims_Type> NC_dim_types;
90 amrex::Print() <<
"Reading in river_Vshape from " <<
file_name << std::endl;
93 NC_fabs.push_back(
fab_vshape); NC_names.push_back(
"river_Vshape");
95 BuildFABsFromNetCDFFile<amrex::FArrayBox,amrex::Real>(vshape_box,
file_name, NC_names, NC_dim_types, NC_fabs);
99 amrex::Box riv_box(amrex::IntVect(0,0,0),amrex::IntVect(
nriv,0,
nzbox));
102 fab_before =
new amrex::FArrayBox(riv_box,1,amrex::The_Pinned_Arena());
103 fab_after =
new amrex::FArrayBox(riv_box,1,amrex::The_Pinned_Arena());
104 fab_interp =
new amrex::FArrayBox(riv_box,1,amrex::The_Pinned_Arena());
107 fab_after =
new amrex::FArrayBox(riv_box,1);
142 amrex::Box fab_domain(amrex::IntVect(0,0,0), amrex::IntVect(
nriv-1,0,
nzbox-1));
146 amrex::ParallelFor(fab_domain, [=] AMREX_GPU_DEVICE (
int r,
int ,
int k) {
147 interp_array(r,0,k) = before_array(r,0,k) + (time - time_before_copy) * (after_array(r,0,k) - before_array(r,0,k)) / dt;
152 amrex::FArrayBox NC_fab;
153 amrex::Vector<amrex::FArrayBox*> NC_fabs;
154 amrex::Vector<std::string> NC_names;
155 amrex::Vector<enum NC_Data_Dims_Type> NC_dim_types;
158 amrex::Print() <<
"Reading in " <<
field_name <<
" at time index " << itime <<
" from " <<
file_name << std::endl;
160 NC_fabs.push_back(&NC_fab) ; NC_names.push_back(
field_name);
168 amrex::Box riv_domain(amrex::IntVect(0,0,0), amrex::IntVect(
nriv-1,0,
nz-1));
169 amrex::Box fab_domain(amrex::IntVect(0,0,0), amrex::IntVect(
nriv-1,0,
nzbox-1));
171 BuildFABsFromNetCDFFile<amrex::FArrayBox,amrex::Real>(riv_domain,
file_name, NC_names, NC_dim_types, NC_fabs,
true, itime);
173 auto dat_array = fab_dat->array();
174 auto tmp_array = NC_fabs[0]->const_array();
176 amrex::ParallelFor(fab_domain, [=] AMREX_GPU_DEVICE (
int r,
int ,
int k) {
177 dat_array(r,0,k) = tmp_array(r,0,k);
180 auto array_vshape =
fab_vshape->const_array();
181 amrex::ParallelFor(fab_domain, [=] AMREX_GPU_DEVICE (
int r,
int ,
int k) {
182 dat_array(r,0,k) = tmp_array(r,0,0) * array_vshape(r,0,k);
void ReadNetCDFFile(const std::string &fname, amrex::Vector< std::string > names, amrex::Vector< NDArray< DType > > &arrays, bool one_time=false, int fill_time=0)
Read in data from netcdf file and save to data arrays.
std::string ReadNetCDFVarAttrStr(const std::string &fname, const std::string &var_name, const std::string &attr_name)
Helper function for reading a single variable attribute.