2#include "AMReX_FArrayBox.H"
7#ifdef REMORA_USE_NETCDF
20 const std::string& fname,
21 FArrayBox& NC_temp_fab, FArrayBox& NC_salt_fab,
22 FArrayBox& NC_xvel_fab, FArrayBox& NC_yvel_fab)
24 amrex::Print() <<
"Loading initial solution data from NetCDF file " << fname << std::endl;
26 Vector<FArrayBox*> NC_fabs;
27 Vector<std::string> NC_names;
28 Vector<enum NC_Data_Dims_Type> NC_dim_types;
36 BuildFABsFromNetCDFFile<FArrayBox,Real>(domain, fname, NC_names, NC_dim_types, NC_fabs);
52 const std::string& fname,
53 FArrayBox& NC_temp_fab, FArrayBox& NC_salt_fab,
54 FArrayBox& NC_xvel_fab, FArrayBox& NC_yvel_fab,
57 amrex::Print() <<
"Loading initial solution data from NetCDF file " << fname << std::endl;
59 Vector<FArrayBox*> NC_fabs;
60 Vector<std::string> NC_names;
61 Vector<enum NC_Data_Dims_Type> NC_dim_types;
69 BuildFABsFromNetCDFFile<FArrayBox,Real>(domain, fname, NC_names, NC_dim_types, NC_fabs,
false, 0, ngrow);
81 const std::string& fname,
82 FArrayBox& NC_zeta_fab)
84 amrex::Print() <<
"Loading initial sea surface height from NetCDF file " << fname << std::endl;
86 Vector<FArrayBox*> NC_fabs;
87 Vector<std::string> NC_names;
88 Vector<enum NC_Data_Dims_Type> NC_dim_types;
93 BuildFABsFromNetCDFFile<FArrayBox,Real>(domain, fname, NC_names, NC_dim_types, NC_fabs);
106 const std::string& fname,
107 FArrayBox& NC_zeta_fab,
110 amrex::Print() <<
"Loading initial sea surface height from NetCDF file " << fname << std::endl;
112 Vector<FArrayBox*> NC_fabs;
113 Vector<std::string> NC_names;
114 Vector<enum NC_Data_Dims_Type> NC_dim_types;
119 BuildFABsFromNetCDFFile<FArrayBox,Real>(domain, fname, NC_names, NC_dim_types, NC_fabs,
false, 0, ngrow);
131 const std::string& fname,
134 amrex::Print() <<
"Loading initial bathymetry from NetCDF file " << fname << std::endl;
136 Vector<FArrayBox*> NC_fabs;
137 Vector<std::string> NC_names;
138 Vector<enum NC_Data_Dims_Type> NC_dim_types;
143 BuildFABsFromNetCDFFile<FArrayBox,Real>(domain, fname, NC_names, NC_dim_types, NC_fabs);
164 const std::string& fname,
165 FArrayBox& NC_pm_fab, FArrayBox& NC_pn_fab,
166 FArrayBox& NC_xr_fab, FArrayBox& NC_yr_fab,
167 FArrayBox& NC_xu_fab, FArrayBox& NC_yu_fab,
168 FArrayBox& NC_xv_fab, FArrayBox& NC_yv_fab,
169 FArrayBox& NC_xp_fab, FArrayBox& NC_yp_fab)
171 amrex::Print() <<
"Loading grid variables from NetCDF file " << fname << std::endl;
173 Vector<FArrayBox*> NC_fabs;
174 Vector<std::string> NC_names;
175 Vector<enum NC_Data_Dims_Type> NC_dim_types;
189 BuildFABsFromNetCDFFile<FArrayBox,Real>(domain, fname, NC_names, NC_dim_types, NC_fabs);
209 const std::string& fname,
210 FArrayBox& NC_lonp_fab, FArrayBox& NC_latp_fab)
212 Vector<std::string> NC_names;
213 NC_names.push_back(
"lon_psi");
214 NC_names.push_back(
"lat_psi");
217 amrex::Print() <<
"Grid file " << fname <<
" has no lon_psi/lat_psi; "
218 <<
"spherical psi coordinates unavailable" << std::endl;
222 amrex::Print() <<
"Loading spherical psi coordinates from NetCDF file " << fname << std::endl;
224 Vector<FArrayBox*> NC_fabs;
225 Vector<enum NC_Data_Dims_Type> NC_dim_types;
230 BuildFABsFromNetCDFFile<FArrayBox,Real>(domain, fname, NC_names, NC_dim_types, NC_fabs);
242 const std::string& fname,
243 FArrayBox& NC_h_fab, IntVect ngrow)
245 amrex::Print() <<
"Loading high resolution bathymetry from NetCDF file " << fname << std::endl;
247 Vector<FArrayBox*> NC_fabs;
248 Vector<std::string> NC_names;
249 Vector<enum NC_Data_Dims_Type> NC_dim_types;
254 BuildFABsFromNetCDFFile<FArrayBox,Real>(domain, fname, NC_names, NC_dim_types, NC_fabs,
false, 0, ngrow);
267 const std::string& fname,
268 FArrayBox& NC_pm_fab, FArrayBox& NC_pn_fab,
271 amrex::Print() <<
"Loading high resolution grid variables from NetCDF file " << fname << std::endl;
273 Vector<FArrayBox*> NC_fabs;
274 Vector<std::string> NC_names;
275 Vector<enum NC_Data_Dims_Type> NC_dim_types;
280 BuildFABsFromNetCDFFile<FArrayBox,Real>(domain, fname, NC_names, NC_dim_types, NC_fabs,
false, 0, ngrow);
292 const std::string& fname,
293 FArrayBox& NC_fcor_fab)
295 amrex::Print() <<
"Loading initial coriolis from NetCDF file " << fname << std::endl;
297 Vector<FArrayBox*> NC_fabs;
298 Vector<std::string> NC_names;
299 Vector<enum NC_Data_Dims_Type> NC_dim_types;
304 BuildFABsFromNetCDFFile<FArrayBox,Real>(domain, fname, NC_names, NC_dim_types, NC_fabs);
318 const std::string& fname,
319 FArrayBox& NC_mskr_fab,
320 FArrayBox& NC_msku_fab,
321 FArrayBox& NC_mskv_fab)
323 amrex::Print() <<
"Loading masks from NetCDF file " << fname << std::endl;
325 Vector<FArrayBox*> NC_fabs;
326 Vector<std::string> NC_names;
327 Vector<enum NC_Data_Dims_Type> NC_dim_types;
329 NC_fabs.push_back(&NC_mskr_fab ) ; NC_names.push_back(
"mask_rho") ; NC_dim_types.push_back(
NC_Data_Dims_Type::SN_WE);
334 BuildFABsFromNetCDFFile<FArrayBox,Real>(domain, fname, NC_names, NC_dim_types, NC_fabs);
353 const std::string& fname,
354 bool do_m2_clim_nudg,
355 bool do_m3_clim_nudg,
356 bool do_temp_clim_nudg,
357 bool do_salt_clim_nudg,
358 FArrayBox& NC_M2NC_fab,
359 FArrayBox& NC_M3NC_fab,
360 FArrayBox& NC_TempNC_fab,
361 FArrayBox& NC_SaltNC_fab)
363 amrex::Print() <<
"Loading nudging coefficients from NetCDF file " << fname << std::endl;
365 Vector<FArrayBox*> NC_fabs;
366 Vector<std::string> NC_names;
367 Vector<enum NC_Data_Dims_Type> NC_dim_types;
369 if (do_m3_clim_nudg) {
372 if (do_m2_clim_nudg) {
373 NC_fabs.push_back(&NC_M2NC_fab ); NC_names.push_back(
"M2_NudgeCoef"); NC_dim_types.push_back(
NC_Data_Dims_Type::SN_WE);
375 if (do_temp_clim_nudg) {
378 if (do_salt_clim_nudg) {
382 BuildFABsFromNetCDFFile<FArrayBox,Real>(domain, fname, NC_names, NC_dim_types, NC_fabs);
392void read_vec_from_netcdf (
int ,
const amrex::Vector<std::string>& fnames,
const std::string& field_name, amrex::Vector<int>& vec_dat)
395 const std::string& fname = fnames[0];
397 amrex::Print() <<
"Reading " << field_name <<
" from NetCDF file" << std::endl;
401 amrex::Vector<ARRAY> array_dat(1);
403 if (amrex::ParallelDescriptor::IOProcessor())
405 int n = array_dat[0].get_vshape()[0];
406 for (
int i(0); i < n; i++)
408 vec_dat.push_back((*(array_dat[0].get_data() + i)));
411 int nvals = vec_dat.size();
412 int ioproc = amrex::ParallelDescriptor::IOProcessorNumber();
413 amrex::ParallelDescriptor::Bcast(&nvals,1,ioproc);
414 if (!(amrex::ParallelDescriptor::IOProcessor())) {
415 vec_dat.resize(nvals);
417 amrex::ParallelDescriptor::Bcast(vec_dat.data(), vec_dat.size(), ioproc);
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_clim_nudg_coeff_from_netcdf(int, const Box &domain, const std::string &fname, bool do_m2_clim_nudg, bool do_m3_clim_nudg, bool do_temp_clim_nudg, bool do_salt_clim_nudg, FArrayBox &NC_M2NC_fab, FArrayBox &NC_M3NC_fab, FArrayBox &NC_TempNC_fab, FArrayBox &NC_SaltNC_fab)
helper function to read climatology nudging from netcdf
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_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_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 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_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_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_masks_from_netcdf(int, const Box &domain, const std::string &fname, FArrayBox &NC_mskr_fab, FArrayBox &NC_msku_fab, FArrayBox &NC_mskv_fab)
helper function for reading in land-sea masks 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
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_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
NDArray is the datatype designed to hold any data, including scalars, multidimensional arrays,...