2#include "AMReX_FArrayBox.H"
7#ifdef REMORA_USE_NETCDF
20 const std::string&
fname,
24 amrex::Print() <<
"Loading initial solution data from NetCDF file " <<
fname << std::endl;
52 const std::string&
fname,
57 amrex::Print() <<
"Loading initial solution data from NetCDF file " <<
fname << std::endl;
82 const std::string&
fname,
90 amrex::Print() <<
"Loading initial biology data from NetCDF file " <<
fname << std::endl;
115 const std::string&
fname,
124 amrex::Print() <<
"Loading high resolution biology data from NetCDF file " <<
fname << std::endl;
156 const IntVect&
ngrow)
160 const long need_x =
static_cast<long>(domain.length(0)) + 2L *
ngrow[0];
161 const long need_y =
static_cast<long>(domain.length(1)) + 2L *
ngrow[1];
165 if (amrex::ParallelDescriptor::IOProcessor())
173 const std::vector<MPI_Offset> shape =
ncf.var(
var_name).shape();
174 if (shape.size() >= 2) {
175 found_y =
static_cast<long>(shape[shape.size()-2]);
176 found_x =
static_cast<long>(shape[shape.size()-1]);
183 const int ioproc = amrex::ParallelDescriptor::IOProcessorNumber();
190 amrex::Abort(
"High-resolution file " +
fname +
" has no variable " +
var_name
191 +
". With remora.hires_grid_level set, that file is the only source for it: "
192 "level 0 is coarsened down from it rather than read. Regenerate the file "
193 "with " +
var_name +
" in it (Tests/tools/make_hires_test_data.py writes h, "
194 "pm, pn and mask_rho), or, if this is mask_rho and the run wants no "
195 "land/sea mask, set remora.mask_type = none.");
199 amrex::Abort(
"High-resolution file " +
fname +
" is too small: " +
var_name +
" is "
201 +
" (xi x eta) but covering the refined domain ("
202 + std::to_string(domain.length(0)) +
" x " + std::to_string(domain.length(1))
203 +
" cells) with " + std::to_string(
ngrow[0]) +
" x " + std::to_string(
ngrow[1])
204 +
" grow cells requires at least " + std::to_string(
need_x) +
" x "
205 + std::to_string(
need_y) +
". Regenerate the file with the grow cells the "
206 "cumulative refinement ratio implies, or lower the refinement ratio.");
234 const std::string&
fname,
264 amrex::Print() <<
"Initial file " <<
fname <<
" does not contain";
265 for (
const auto& name :
missing) { amrex::Print() <<
" " << name; }
266 amrex::Print() <<
"; those passive scalars start at zero" << std::endl;
272 amrex::Print() <<
"Loading " << (
full_domain ?
"high resolution " :
"initial ")
273 <<
"passive scalar data from NetCDF file " <<
fname << std::endl;
296 const std::string&
fname,
302 false, IntVect(0,0,0));
317 const std::string&
fname,
336 const std::string&
fname,
339 amrex::Print() <<
"Loading initial sea surface height from NetCDF file " <<
fname << std::endl;
361 const std::string&
fname,
365 amrex::Print() <<
"Loading initial sea surface height from NetCDF file " <<
fname << std::endl;
386 const std::string&
fname,
389 amrex::Print() <<
"Loading initial bathymetry from NetCDF file " <<
fname << std::endl;
419 const std::string&
fname,
426 amrex::Print() <<
"Loading grid variables from NetCDF file " <<
fname << std::endl;
464 const std::string&
fname,
472 amrex::Print() <<
"Grid file " <<
fname <<
" has no lon_psi/lat_psi; "
473 <<
"spherical psi coordinates unavailable" << std::endl;
477 amrex::Print() <<
"Loading spherical psi coordinates from NetCDF file " <<
fname << std::endl;
497 const std::string&
fname,
500 amrex::Print() <<
"Loading high resolution bathymetry from NetCDF file " <<
fname << std::endl;
524 const std::string&
fname,
527 amrex::Print() <<
"Loading high resolution land/sea mask from NetCDF file " <<
fname << std::endl;
549 const std::string&
fname,
553 amrex::Print() <<
"Loading high resolution grid variables from NetCDF file " <<
fname << std::endl;
574 const std::string&
fname,
577 amrex::Print() <<
"Loading initial coriolis from NetCDF file " <<
fname << std::endl;
602 const std::string&
fname,
605 amrex::Print() <<
"Loading masks from NetCDF file " <<
fname << std::endl;
634 const std::string&
fname,
635 bool do_m2_clim_nudg,
636 bool do_m3_clim_nudg,
637 const amrex::Vector<int>& do_cons_clim_nudg,
638 const amrex::Vector<std::string>& cons_names,
644 amrex::Print() <<
"Loading nudging coefficients from NetCDF file " <<
fname << std::endl;
646 const int l_ncons = do_cons_clim_nudg.size();
652 if (do_m3_clim_nudg) {
655 if (do_m2_clim_nudg) {
665 if (!do_cons_clim_nudg[
icomp]) {
continue; }
675 amrex::Print() <<
"Nudging coefficient file " <<
fname <<
" does not contain";
676 for (
const auto& name :
missing) { amrex::Print() <<
" " << name; }
677 amrex::Print() <<
"; those tracers will use the constant coefficient from remora.tnudg"
697 amrex::Print() <<
"Reading " << field_name <<
" from NetCDF file" << std::endl;
703 if (amrex::ParallelDescriptor::IOProcessor())
706 for (
int i(0);
i < n;
i++)
712 int ioproc = amrex::ParallelDescriptor::IOProcessorNumber();
714 if (!(amrex::ParallelDescriptor::IOProcessor())) {
mf_h setVal(geomdata.ProbHi(2))
AMREX_ALWAYS_ASSERT(!NSPeriodic||!EWPeriodic)
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.
bool QueryNetCDFHasVars(const std::string &fname, const amrex::Vector< std::string > &var_names)
Helper function for testing whether a file carries every named variable.
void read_zeta_full_domain_from_netcdf(int, const Box &domain, const std::string &fname, FArrayBox &NC_zeta_fab, IntVect ngrow)
helper function to read high-resolution full-domain sea surface height from netcdf
void read_bathymetry_from_netcdf(int, const Box &domain, const std::string &fname, FArrayBox &NC_h_fab)
helper function to read bathymetry from netcdf
void read_masks_full_domain_from_netcdf(const Box &domain, const std::string &fname, FArrayBox &NC_mskr_fab, IntVect ngrow)
helper function to read full-domain high resolution land/sea mask from netcdf
void read_vec_from_netcdf(int, const amrex::Vector< std::string > &fnames, const std::string &field_name, amrex::Vector< int > &vec_dat)
helper function to read in vector of data from netcdf
void read_scalars_full_domain_from_netcdf(int, const Box &domain, const std::string &fname, const Vector< std::string > &scalar_names, Vector< FArrayBox > &NC_scalar_fab, Vector< int > &scalar_in_file, IntVect ngrow)
helper function for reading in full domain high-resolution initial passive (dye) scalar data from net...
void read_data_full_domain_from_netcdf(int, const Box &domain, const std::string &fname, FArrayBox &NC_temp_fab, FArrayBox &NC_salt_fab, FArrayBox &NC_xvel_fab, FArrayBox &NC_yvel_fab, IntVect ngrow)
helper function for reading in full domain high-resolution initial state data from netcdf
void check_hires_dims_from_netcdf(const std::string &fname, const std::string &var_name, const Box &domain, const IntVect &ngrow)
helper function checking that a high-resolution file covers the refined domain plus grow cells
void read_grid_vars_from_netcdf(int, const Box &domain, const std::string &fname, FArrayBox &NC_pm_fab, FArrayBox &NC_pn_fab, FArrayBox &NC_xr_fab, FArrayBox &NC_yr_fab, FArrayBox &NC_xu_fab, FArrayBox &NC_yu_fab, FArrayBox &NC_xv_fab, FArrayBox &NC_yv_fab, FArrayBox &NC_xp_fab, FArrayBox &NC_yp_fab)
helper function to read grid variables from netcdf
void read_biology_from_netcdf(int, const Box &domain, const std::string &fname, const Vector< std::string > &biology_names, Vector< FArrayBox > &NC_biology_fab)
helper function for reading in initial biology data from netcdf
void read_bathymetry_full_domain_from_netcdf(const Box &domain, const std::string &fname, FArrayBox &NC_h_fab, IntVect ngrow)
helper function to read full-domain high resolution bathymetry from netcdf
void read_clim_nudg_coeff_from_netcdf(int, const Box &domain, const std::string &fname, bool do_m2_clim_nudg, bool do_m3_clim_nudg, const amrex::Vector< int > &do_cons_clim_nudg, const amrex::Vector< std::string > &cons_names, FArrayBox &NC_M2NC_fab, FArrayBox &NC_M3NC_fab, amrex::Vector< FArrayBox > &NC_ConsNC_fab, amrex::Vector< int > &cons_coeff_in_file)
helper function to read climatology nudging from netcdf
void read_coriolis_from_netcdf(int, const Box &domain, const std::string &fname, FArrayBox &NC_fcor_fab)
helper function to read coriolis factor from netcdf
void read_biology_full_domain_from_netcdf(int, const Box &domain, const std::string &fname, const Vector< std::string > &biology_names, Vector< FArrayBox > &NC_biology_fab, IntVect ngrow)
helper function for reading in full domain high-resolution initial biology data from netcdf
void read_zeta_from_netcdf(int, const Box &domain, const std::string &fname, FArrayBox &NC_zeta_fab)
helper function to read sea surface height from netcdf
void read_masks_from_netcdf(int, const Box &domain, const std::string &fname, FArrayBox &NC_mskr_fab)
helper function for reading in the rho-point land-sea mask from netcdf
bool read_spherical_grid_vars_from_netcdf(int, const Box &domain, const std::string &fname, FArrayBox &NC_lonp_fab, FArrayBox &NC_latp_fab)
helper function to read optional spherical psi coordinates from netcdf
void read_data_from_netcdf(int, const Box &domain, const std::string &fname, FArrayBox &NC_temp_fab, FArrayBox &NC_salt_fab, FArrayBox &NC_xvel_fab, FArrayBox &NC_yvel_fab)
helper function for reading in initial state data from netcdf
void read_scalars_from_netcdf(int, const Box &domain, const std::string &fname, const Vector< std::string > &scalar_names, Vector< FArrayBox > &NC_scalar_fab, Vector< int > &scalar_in_file)
helper function for reading in initial passive (dye) scalar data from netcdf
void read_grid_vars_full_domain_from_netcdf(const Box &domain, const std::string &fname, FArrayBox &NC_pm_fab, FArrayBox &NC_pn_fab, IntVect ngrow)
helper function to read full-domain high resolution grid variables from netcdf
static NCFile open(const std::string &name, const int cmode=NC_NOWRITE, MPI_Comm comm=MPI_COMM_WORLD, MPI_Info info=MPI_INFO_NULL)
Open an existing file.
NDArray is the datatype designed to hold any data, including scalars, multidimensional arrays,...