Skip to content

Commit

Permalink
Initialize Dataset definitions from template
Browse files Browse the repository at this point in the history
Only RecordComponent type for now, missing: ParticlePatches, maybe
MeshRecordComponents?
  • Loading branch information
franzpoeschel committed Jul 21, 2022
1 parent aa2c564 commit 6527acf
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
13 changes: 13 additions & 0 deletions src/auxiliary/TemplateFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ namespace
copyAttributes(initializeMe, fromTemplate);
}

void initializeFromTemplate(
RecordComponent &initializeMe, RecordComponent const &fromTemplate)
{
if (fromTemplate.getDatatype() != Datatype::UNDEFINED)
{
initializeMe.resetDataset(
Dataset{fromTemplate.getDatatype(), fromTemplate.getExtent()});
}
initializeFromTemplate(
static_cast<BaseRecordComponent &>(initializeMe),
static_cast<BaseRecordComponent const &>(fromTemplate));
}

void initializeFromTemplate(
ParticleSpecies &initializeMe, ParticleSpecies const &fromTemplate)
{
Expand Down
42 changes: 33 additions & 9 deletions test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2726,21 +2726,21 @@ TEST_CASE("git_hdf5_sample_structure_test", "[serial][hdf5]")

TEST_CASE("git_hdf5_sample_attribute_test", "[serial][hdf5]")
{
try
{
Series o = Series("../samples/git-sample/data%T.h5", Access::READ_ONLY);

auto verifySeries = [](Series o, bool this_is_the_original_file) {
REQUIRE(o.openPMD() == "1.1.0");
REQUIRE(o.openPMDextension() == 1);
REQUIRE(o.basePath() == "/data/%T/");
REQUIRE(o.meshesPath() == "fields/");
REQUIRE(o.particlesPath() == "particles/");
REQUIRE(o.iterationEncoding() == IterationEncoding::fileBased);
REQUIRE(o.iterationFormat() == "data%T.h5");
REQUIRE(o.name() == "data%T");
if (this_is_the_original_file)
{
REQUIRE(o.iterationEncoding() == IterationEncoding::fileBased);
REQUIRE(o.iterationFormat() == "data%T.h5");
REQUIRE(o.name() == "data%T");

REQUIRE(o.iterations.size() == 5);
REQUIRE(o.iterations.count(100) == 1);
REQUIRE(o.iterations.size() == 5);
REQUIRE(o.iterations.count(100) == 1);
}

Iteration &iteration_100 = o.iterations[100];
REQUIRE(iteration_100.time<double>() == 3.2847121452090077e-14);
Expand Down Expand Up @@ -2970,6 +2970,30 @@ TEST_CASE("git_hdf5_sample_attribute_test", "[serial][hdf5]")
REQUIRE(weighting_scalar.getDatatype() == Datatype::DOUBLE);
REQUIRE(weighting_scalar.getDimensionality() == 1);
REQUIRE(weighting_scalar.getExtent() == e);
};

try
{
{
Series o =
Series("../samples/git-sample/data%T.h5", Access::READ_ONLY);
verifySeries(o, true);

Series fromTemplate(
"../samples/initialized_from_git_sample.json",
Access::CREATE,
R"(json.mode = "template")");
auxiliary::initializeFromTemplate(fromTemplate, o, 100);
fromTemplate.flush();
}

{
Series o(
"../samples/initialized_from_git_sample.json",
Access::READ_ONLY,
R"(json.mode = "template")");
verifySeries(o, false);
}
}
catch (no_such_file_error &e)
{
Expand Down

0 comments on commit 6527acf

Please sign in to comment.