35 amrex::Print() <<
"Loading " <<
field_name <<
" from NetCDF file " <<
file_name << std::endl;
41 if (
field_name.find(
"wind") != std::string::npos) {
54 if (amrex::ParallelDescriptor::IOProcessor())
56 if (unit_str.find(
"days") == std::string::npos) {
57 amrex::Print() <<
"Units of ocean_time given as: " << unit_str << std::endl;
58 amrex::Abort(
"Units must be in days.");
63 amrex::Vector<RARRAY> array_ts(1);
65 if (amrex::ParallelDescriptor::IOProcessor())
67 int ntimes_io = array_ts[0].get_vshape()[0];
68 for (
int nt(0); nt < ntimes_io; nt++)
71 ocean_times.push_back((*(array_ts[0].get_data() + nt)) * amrex::Real(60.0) * amrex::Real(60.0) * amrex::Real(24.0));
77 if (amrex::ParallelDescriptor::IOProcessor()) {
80 amrex::Error(
"Time series data must be given at at least two times");
83 int ioproc = amrex::ParallelDescriptor::IOProcessorNumber();
84 amrex::ParallelDescriptor::Bcast(&ntimes,1,ioproc);
85 if (!(amrex::ParallelDescriptor::IOProcessor())) {
104 amrex::MultiFab* mf_lev,
105 const amrex::Vector<amrex::Geometry>& geom,
106 const amrex::Vector<amrex::IntVect>& ref_ratio) {
135#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
137 for (amrex::MFIter mfi(*
mf_interp_lev0,
true); mfi.isValid(); ++mfi) {
139 amrex::Box bx = mfi.growntilebox(amrex::IntVect(1-nodality[0],1-nodality[1],0));
145 amrex::Array4<amrex::Real> to_fill = mf_to_fill->array(mfi);
146 amrex::Array4<const amrex::Real> before =
mf_before->const_array(mfi);
147 amrex::Array4<const amrex::Real> after =
mf_after->const_array(mfi);
148 amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
150 to_fill(i,j,k) = before(i,j,k) + (time - time_before_copy) * (after(i,j,k) - before(i,j,k)) / dt;
154 amrex::MultiFab* mf_to_fill_lev = mf_lev;
163 mf_lev->boxArray(), mf_lev->DistributionMap(), 1, mf_lev->nGrowVect());
169 amrex::MultiFab::Copy(*mf_to_fill_lev, *
mf_interp_lev0, 0, 0, 1, mf_to_fill_lev->nGrowVect());
174 amrex::Vector<amrex::BCRec> null_dom_bcs(1);
175 for (
int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
176 null_dom_bcs[0].setLo(dir, amrex::BCType::int_dir);
177 null_dom_bcs[0].setHi(dir, amrex::BCType::int_dir);
180 amrex::Interpolater* mapper =
nullptr;
181 const auto& idx_type = mf_to_fill_lev->ixType();
182 if (idx_type == amrex::IndexType(amrex::IntVect(0,0,0))) {
183 mapper = &amrex::cell_cons_interp;
185 mapper = &amrex::face_cons_linear_interp;
188 amrex::InterpFromCoarseLevel(*mf_to_fill_lev, amrex::Real(0.0), *
mf_interp_lev0,
193 mapper, null_dom_bcs, 0);
195 mf_to_fill_lev->FillBoundary(geom[lev].periodicity());
200 const amrex::Vector<amrex::IntVect>& ref_ratio)
const {
201 amrex::IntVect rr(1,1,1);
202 for (
int l = 0; l < lev; ++l) {
203 rr[0] *= ref_ratio[l][0];
204 rr[1] *= ref_ratio[l][1];
205 rr[2] *= ref_ratio[l][2];
224 amrex::FArrayBox NC_fab;
225 amrex::Vector<amrex::FArrayBox*> NC_fabs;
226 amrex::Vector<std::string> NC_names;
227 amrex::Vector<enum NC_Data_Dims_Type> NC_dim_types;
229 amrex::Print() <<
"Reading in " <<
field_name <<
" at time index " << itime <<
" from " <<
file_name << std::endl;
231 NC_fabs.push_back(&NC_fab) ; NC_names.push_back(
field_name);
239 BuildFABsFromNetCDFFile<amrex::FArrayBox,amrex::Real>(
domain,
file_name, NC_names, NC_dim_types, NC_fabs,
true, itime);
242#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
246 for ( amrex::MFIter mfi(*mf,
false); mfi.isValid(); ++mfi )
248 amrex::FArrayBox &fab = (*mf)[mfi];
254 fab.template copy<amrex::RunOn::Device>(NC_fab);
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.
void update_interpolated_to_time(amrex::Real time, int lev, amrex::MultiFab *mf_lev, const amrex::Vector< amrex::Geometry > &geom, const amrex::Vector< amrex::IntVect > &ref_ratio)
Calculate interpolated values at time and fill data for level lev.
NCTimeSeries(const std::string a_file_name, const std::string a_field_name, const std::string a_time_name, const amrex::Box &a_domain, amrex::MultiFab *a_mf_var, bool a_is2d, bool a_save_interpolated)
Constructor.