1#ifndef _REMORA_NCFILE_H_
2#define _REMORA_NCFILE_H_
9#include "AMReX_FArrayBox.H"
10#include "AMReX_IArrayBox.H"
34template <
typename DataType>
37 using DType =
typename std::remove_const<DataType>::type;
79 std::shared_ptr<DType[]>
data;
90template<
typename DType>
98 if (amrex::ParallelDescriptor::IOProcessor())
115 for (
auto n=0; n<
arrays.size(); ++n) {
121 amrex::Print() <<
"Variable name " <<
vname_to_read <<
" not found!" << std::endl;
128 std::vector<MPI_Offset>
start(shape.size(), 0);
132 "Cannot read one time step from a scalar NetCDF variable");
175 const amrex::Vector<std::string>&
var_names);
187template<
class FAB,
typename DType>
229 amrex::Abort(
"Dont know this NC_Data_Dims_Type");
237 my_box.setSmall(amrex::IntVect(0,-1,0));
239 my_box.setType(amrex::IndexType(amrex::IntVect(1,0,0)));
244 my_box.setSmall(amrex::IntVect(-1,0,0));
246 my_box.setType(amrex::IndexType(amrex::IntVect(0,1,0)));
251 my_box.setSmall(amrex::IntVect(0,0,0));
253 my_box.setType(amrex::IndexType(amrex::IntVect(1,1,0)));
258 my_box.setSmall(amrex::IntVect(0,0,0));
263 my_box.setSmall(amrex::IntVect(-1,-1,0));
273 temp.resize(
my_box,1,amrex::The_Pinned_Arena());
279 int ioff =
temp.box().smallEnd()[0];
280 int joff =
temp.box().smallEnd()[1];
308template<
class FAB,
typename DType>
311 const std::string &
fname,
312 amrex::Vector<std::string> nc_var_names,
318 int ioproc = amrex::ParallelDescriptor::IOProcessorNumber();
320 amrex::Vector<NDArray<amrex::Real>>
nc_arrays(nc_var_names.size());
325 for (
int iv = 0;
iv < nc_var_names.size();
iv++)
328 if (amrex::ParallelDescriptor::IOProcessor()) {
333 amrex::Box
box =
tmp.box();
335 amrex::ParallelDescriptor::Bcast(&
box, 1,
ioproc);
336 amrex::ParallelDescriptor::Bcast(&
ncomp, 1,
ioproc);
338 if (!amrex::ParallelDescriptor::IOProcessor()) {
346 amrex::ParallelDescriptor::Bcast(
tmp.dataPtr(),
tmp.size(),
ioproc);
355 amrex::Gpu::copy(amrex::Gpu::hostToDevice,
356 tmp.dataPtr(),
tmp.dataPtr() +
tmp.size(),
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.
void BuildFABsFromNetCDFFile(const amrex::Box &domain, const std::string &fname, amrex::Vector< std::string > nc_var_names, amrex::Vector< enum NC_Data_Dims_Type > NC_dim_types, amrex::Vector< FAB * > fab_vars, bool one_time=false, int fill_time=0, amrex::IntVect custom_ngrow=amrex::IntVect(1, 1, 0))
Function to read NetCDF variables and fill the corresponding Array4's.
bool QueryNetCDFHasVars(const std::string &fname, const amrex::Vector< std::string > &var_names)
Helper function for testing whether a file carries every named variable.
bool QueryNetCDFVarAttrStr(const std::string &fname, const std::string &var_name, const std::string &attr_name)
Helper function for testing for the presence of a single variable attribute.
void fill_fab_from_arrays(int iv, amrex::Vector< NDArray< amrex::Real > > &nc_arrays, const std::string &var_name, NC_Data_Dims_Type &NC_dim_type, FAB &temp, amrex::IntVect custom_ngrow)
Helper function for reading data from NetCDF file into a provided FAB.
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.
amrex::Vector< amrex::FArrayBox > PlaneVector
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,...
std::shared_ptr< DType[]> data
size_t ndim()
return the total number of data
NDArray()
default constructor
std::string get_vname()
get the variable name
std::vector< MPI_Offset > shape
NDArray(const std::string vname, const std::vector< MPI_Offset > &vshape)
constructor
typename std::remove_const< DataType >::type DType
decltype(auto) get_data()
get the data pointer
void set_vshape(std::vector< MPI_Offset > vshape)
set the data shape information
std::vector< MPI_Offset > get_vshape()
get the variable data shape