29 amrex::Print() <<
"Loading " <<
field_name <<
" from rivers NetCDF file(s)" << std::endl;
38 for (
int ifile = 0; ifile <
file_names.size(); ++ifile) {
39 const std::string& file_name =
file_names[ifile];
43 if (amrex::ParallelDescriptor::IOProcessor())
45 if (unit_str.find(
"days") == std::string::npos) {
46 amrex::Print() <<
"Units of river_time given as: " << unit_str << std::endl;
47 amrex::Abort(
"Units must be in days.");
53 amrex::Vector<RARRAY> array_ts(1);
55 if (amrex::ParallelDescriptor::IOProcessor())
57 int ntimes_io = array_ts[0].get_vshape()[0];
58 for (
int nt(0); nt < ntimes_io; nt++)
61 river_times.push_back((*(array_ts[0].get_data() + nt)) * amrex::Real(60.0) * amrex::Real(60.0) * amrex::Real(24.0));
69 if (amrex::ParallelDescriptor::IOProcessor()) {
72 amrex::Error(
"River data must be given at at least two times");
75 int ioproc = amrex::ParallelDescriptor::IOProcessorNumber();
76 amrex::ParallelDescriptor::Bcast(&ntimes,1,ioproc);
77 if (!(amrex::ParallelDescriptor::IOProcessor())) {
87 if (amrex::ParallelDescriptor::IOProcessor())
89 std::vector<MPI_Offset> shape = ncf.var(
field_name).shape();
90 if (shape.size() == 2) {
93 }
else if (shape.size() == 3) {
97 amrex::Abort(
"River field shape not 2 or 3");
100 amrex::ParallelDescriptor::Bcast(&
has_z, 1, ioproc);
101 amrex::ParallelDescriptor::Bcast(&
nriv, 1, ioproc);
103 amrex::Box vshape_box(amrex::IntVect(0,0,0),amrex::IntVect(
nriv,0,
nz));
105 amrex::Vector<amrex::FArrayBox*> NC_fabs;
106 amrex::Vector<std::string> NC_names;
107 amrex::Vector<enum NC_Data_Dims_Type> NC_dim_types;
108 amrex::Print() <<
"Reading in river_Vshape from " <<
file_names[0] << std::endl;
111 NC_fabs.push_back(
fab_vshape); NC_names.push_back(
"river_Vshape");
113 BuildFABsFromNetCDFFile<amrex::FArrayBox,amrex::Real>(vshape_box,
file_names[0], NC_names, NC_dim_types, NC_fabs);
117 amrex::Box riv_box(amrex::IntVect(0,0,0),amrex::IntVect(
nriv,0,
nzbox));
120 fab_before =
new amrex::FArrayBox(riv_box,1,amrex::The_Pinned_Arena());
121 fab_after =
new amrex::FArrayBox(riv_box,1,amrex::The_Pinned_Arena());
122 fab_interp =
new amrex::FArrayBox(riv_box,1,amrex::The_Pinned_Arena());
125 fab_after =
new amrex::FArrayBox(riv_box,1);
160 amrex::Box fab_domain(amrex::IntVect(0,0,0), amrex::IntVect(
nriv-1,0,
nzbox-1));
164 amrex::ParallelFor(fab_domain, [=] AMREX_GPU_DEVICE (
int r,
int ,
int k) {
165 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;
170 amrex::FArrayBox NC_fab;
171 amrex::Vector<amrex::FArrayBox*> NC_fabs;
172 amrex::Vector<std::string> NC_names;
173 amrex::Vector<enum NC_Data_Dims_Type> NC_dim_types;
179 amrex::Print() <<
"Reading in " <<
field_name <<
" at time index " << itime
180 <<
" from " << file_name << std::endl;
182 NC_fabs.push_back(&NC_fab) ; NC_names.push_back(
field_name);
190 amrex::Box riv_domain(amrex::IntVect(0,0,0), amrex::IntVect(
nriv-1,0,
nz-1));
191 amrex::Box fab_domain(amrex::IntVect(0,0,0), amrex::IntVect(
nriv-1,0,
nzbox-1));
193 BuildFABsFromNetCDFFile<amrex::FArrayBox,amrex::Real>(riv_domain, file_name, NC_names, NC_dim_types, NC_fabs,
true, itime_offset);
195 auto dat_array = fab_dat->array();
196 auto tmp_array = NC_fabs[0]->const_array();
198 amrex::ParallelFor(fab_domain, [=] AMREX_GPU_DEVICE (
int r,
int ,
int k) {
199 dat_array(r,0,k) = tmp_array(r,0,k);
202 auto array_vshape =
fab_vshape->const_array();
203 amrex::ParallelFor(fab_domain, [=] AMREX_GPU_DEVICE (
int r,
int ,
int k) {
204 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.