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));
54 amrex::Print() <<
"ntimes " << ntimes << std::endl;
55 int ioproc = amrex::ParallelDescriptor::IOProcessorNumber();
56 amrex::ParallelDescriptor::Bcast(&ntimes,1,ioproc);
57 if (!(amrex::ParallelDescriptor::IOProcessor())) {
63 if (amrex::ParallelDescriptor::IOProcessor())
65 std::vector<MPI_Offset> shape = ncf.var(
field_name).shape();
66 if (shape.size() == 2) {
69 }
else if (shape.size() == 3) {
73 amrex::Abort(
"River field shape not 2 or 3");
76 amrex::ParallelDescriptor::Bcast(&
has_z, 1, ioproc);
77 amrex::ParallelDescriptor::Bcast(&
nriv, 1, ioproc);
79 amrex::Box vshape_box(amrex::IntVect(0,0,0),amrex::IntVect(
nriv,0,
nz));
81 amrex::Vector<amrex::FArrayBox*> NC_fabs;
82 amrex::Vector<std::string> NC_names;
83 amrex::Vector<enum NC_Data_Dims_Type> NC_dim_types;
84 amrex::Print() <<
"Reading in river_Vshape from " <<
file_name << std::endl;
87 NC_fabs.push_back(
fab_vshape); NC_names.push_back(
"river_Vshape");
89 BuildFABsFromNetCDFFile<amrex::FArrayBox,amrex::Real>(vshape_box,
file_name, NC_names, NC_dim_types, NC_fabs);
93 amrex::Box riv_box(amrex::IntVect(0,0,0),amrex::IntVect(
nriv,0,
nzbox));
96 fab_before =
new amrex::FArrayBox(riv_box,1,amrex::The_Pinned_Arena());
97 fab_after =
new amrex::FArrayBox(riv_box,1,amrex::The_Pinned_Arena());
98 fab_interp =
new amrex::FArrayBox(riv_box,1,amrex::The_Pinned_Arena());
101 fab_after =
new amrex::FArrayBox(riv_box,1);
136 amrex::Box fab_domain(amrex::IntVect(0,0,0), amrex::IntVect(
nriv-1,0,
nzbox-1));
140 amrex::ParallelFor(fab_domain, [=] AMREX_GPU_DEVICE (
int r,
int ,
int k) {
141 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;
146 amrex::FArrayBox NC_fab;
147 amrex::Vector<amrex::FArrayBox*> NC_fabs;
148 amrex::Vector<std::string> NC_names;
149 amrex::Vector<enum NC_Data_Dims_Type> NC_dim_types;
152 amrex::Print() <<
"Reading in " <<
field_name <<
" at time index " << itime <<
" from " <<
file_name << std::endl;
154 NC_fabs.push_back(&NC_fab) ; NC_names.push_back(
field_name);
162 amrex::Box riv_domain(amrex::IntVect(0,0,0), amrex::IntVect(
nriv-1,0,
nz-1));
163 amrex::Box fab_domain(amrex::IntVect(0,0,0), amrex::IntVect(
nriv-1,0,
nzbox-1));
165 BuildFABsFromNetCDFFile<amrex::FArrayBox,amrex::Real>(riv_domain,
file_name, NC_names, NC_dim_types, NC_fabs,
true, itime);
167 auto dat_array = fab_dat->array();
168 auto tmp_array = NC_fabs[0]->const_array();
170 amrex::ParallelFor(fab_domain, [=] AMREX_GPU_DEVICE (
int r,
int ,
int k) {
171 dat_array(r,0,k) = tmp_array(r,0,k);
174 auto array_vshape =
fab_vshape->const_array();
175 amrex::ParallelFor(fab_domain, [=] AMREX_GPU_DEVICE (
int r,
int ,
int k) {
176 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.