4#include "AMReX_ParallelDescriptor.H"
8#ifdef REMORA_USE_NETCDF
19 const std::string a_time_name,
20 const amrex::Box& a_domain,
21 amrex::MultiFab* a_mf_var,
bool a_is2d,
bool a_save_interpolated) {
33 amrex::Print() <<
"Loading " <<
field_name <<
" from NetCDF file " <<
file_name << std::endl;
39 if (
field_name.find(
"wind") != std::string::npos) {
52 if (amrex::ParallelDescriptor::IOProcessor())
54 if (unit_str.find(
"days") == std::string::npos) {
55 amrex::Print() <<
"Units of ocean_time given as: " << unit_str << std::endl;
56 amrex::Abort(
"Units must be in days.");
61 amrex::Vector<RARRAY> array_ts(1);
63 if (amrex::ParallelDescriptor::IOProcessor())
65 int ntimes_io = array_ts[0].get_vshape()[0];
66 for (
int nt(0); nt < ntimes_io; nt++)
69 ocean_times.push_back((*(array_ts[0].get_data() + nt)) * amrex::Real(60.0) * amrex::Real(60.0) * amrex::Real(24.0));
74 int ioproc = amrex::ParallelDescriptor::IOProcessorNumber();
75 amrex::ParallelDescriptor::Bcast(&ntimes,1,ioproc);
76 if (!(amrex::ParallelDescriptor::IOProcessor())) {
122 auto nodality =
mf_var->ixType();
125#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
127 for (amrex::MFIter mfi(*
mf_var,
true); mfi.isValid(); ++mfi) {
129 amrex::Box bx = mfi.growntilebox(amrex::IntVect(1-nodality[0],1-nodality[1],0));
136 amrex::Array4<amrex::Real> to_fill = mf_to_fill->array(mfi);
137 amrex::Array4<const amrex::Real> before =
mf_before->const_array(mfi);
138 amrex::Array4<const amrex::Real> after =
mf_after->const_array(mfi);
139 amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k)
141 to_fill(i,j,k) = before(i,j,k) + (time - time_before_copy) * (after(i,j,k) - before(i,j,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;
157 amrex::Print() <<
"Reading in " <<
field_name <<
" at time index " << itime <<
" from " <<
file_name << std::endl;
159 NC_fabs.push_back(&NC_fab) ; NC_names.push_back(
field_name);
167 BuildFABsFromNetCDFFile<amrex::FArrayBox,amrex::Real>(
domain,
file_name, NC_names, NC_dim_types, NC_fabs,
true, itime);
170#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
174 for ( amrex::MFIter mfi(*mf,
false); mfi.isValid(); ++mfi )
176 amrex::FArrayBox &fab = (*mf)[mfi];
182 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.
bool is2d
Whether the field we're reading in is 2d.
void read_in_at_time(amrex::MultiFab *mf, int itime)
Read in data from file at time index itime and fill into mf.
amrex::Real time_after
Time in ocean_times immediately after the last time interpolated to.
amrex::Real time_before
Time in ocean_times immediately before the last time interpolated to.
void Initialize()
Read in time array from file and allocate data arrays.
amrex::MultiFab * mf_before
Multifab to store data at time_before.
int i_time_before
Time index immediately before the last time interpolated to.
std::string field_name
Field name in netcdf file.
amrex::MultiFab * mf_after
Multifab to store data at time_after.
amrex::MultiFab * mf_interpolated
std::string time_name
Field name for time series in netcdf file.
std::string file_name
File name to read from.
void update_interpolated_to_time(amrex::Real time)
Calculate interpolated values at time, reading in data as necessary.
amrex::Vector< amrex::Real > ocean_times
Time points in netcdf file.
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.
NDArray is the datatype designed to hold any data, including scalars, multidimensional arrays,...