6HNSPTE4TIMYKW63HKOVYZAZHTNC5I6BSVWO56PKEEUPS5I3BLEAC
static Timer timer_meta("InputSilo.meta");
auto interval_meta = make_unique<Interval>(timer_meta);
// Read metadata
if (read_metafile) {
const string metafilename =
pathname + "/" + make_filename(simulation_name, cctk_iteration);
// We could use DB_UNKNOWN instead of DB_HDF5
const DB::ptr<DBfile> metafile =
DB::make(DBOpen(metafilename.c_str(), DB_HDF5, DB_READ));
assert(metafile);
// Read internal driver state
// TODO: Only do this when recovering. But then, we should also do
// this as a file reader option!
{
const string dirname = DB::legalize_name(driver_name);
// Read number of levels
const int nlevels = [&] {
const string varname = dirname + "/" + DB::legalize_name("nlevels");
const int vartype = DBGetVarType(metafile.get(), varname.c_str());
assert(vartype == DB_INT);
const int varlength = DBGetVarLength(metafile.get(), varname.c_str());
assert(varlength == 1);
int result;
ierr = DBReadVar(metafile.get(), varname.c_str(), &result);
assert(!ierr);
return result;
}();
// Read FabArrayBase (component positions and shapes)
vector<vector<amrex::Box> > boxes(nlevels);
for (int level = 0; level < nlevels; ++level) {
const string varname = dirname + "/" + make_fabarraybasename(level);
const int vartype = DBGetVarType(metafile.get(), varname.c_str());
assert(vartype == DB_INT);
int vardims[2];
const int varndims =
DBGetVarDims(metafile.get(), varname.c_str(), 2, vardims);
assert(varndims >= 0);
assert(varndims == 2);
assert(vardims[1] == 2 * ndims);
const int nfabs = vardims[0];
assert(nfabs >= 0);
vector<int> data(2 * ndims * nfabs);
ierr = DBReadVar(metafile.get(), varname.c_str(), data.data());
auto &levboxes = boxes.at(level);
levboxes.resize(nfabs);
assert(!ierr);
for (int component = 0; component < nfabs; ++component) {
const amrex::IntVect small(&data.at(2 * ndims * component));
const amrex::IntVect big(&data.at(ndims + 2 * ndims * component));
levboxes.at(component) = amrex::Box(small, big);
}
}
}
}
interval_meta = nullptr;
const string dirname = DB::legalize_name(driver_name);
ierr = DBMkDir(metafile.get(), dirname.c_str());
assert(!ierr);
// Write number of levels
{
const int dims = 1;
const int value = ghext->leveldata.size();
const string varname = dirname + "/" + DB::legalize_name("nlevels");
ierr =
DBWrite(metafile.get(), varname.c_str(), &value, &dims, 1, DB_INT);
assert(!ierr);
}
// Write FabArrayBase (component positions and shapes)
for (const auto &leveldata : ghext->leveldata) {
const amrex::FabArrayBase &fab = *leveldata.fab;
const int nfabs = fab.size();
vector<int> boxes(2 * ndims * nfabs);
for (int component = 0; component < nfabs; ++component) {
const amrex::Box &fabbox = fab.box(component); // valid region
for (int d = 0; d < ndims; ++d)
boxes[d + 2 * ndims * component] = fabbox.smallEnd(d);
for (int d = 0; d < ndims; ++d)
boxes[d + ndims + 2 * ndims * component] = fabbox.bigEnd(d);
}
const int dims[2] = {nfabs, 2 * ndims};
const string varname =
dirname + "/" + make_fabarraybasename(leveldata.level);
ierr = DBWrite(metafile.get(), varname.c_str(), boxes.data(), dims, 2,
DB_INT);
assert(!ierr);
}
}
{