Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
need to update gold because metadata names changed:
NumVariables => NumComponents
VariableNames => ComponentNames
  • Loading branch information
jlippuner committed Apr 29, 2021
1 parent e5038f0 commit 7aa68b7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
28 changes: 16 additions & 12 deletions src/interface/params.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ class Params {

#ifdef HDF5OUTPUT

private:
// will write all params with type T to the given HDF5 group as an attribute
template <typename T>
void WriteToHDF5(const std::string &prefix, const HDF5::H5G &group) const {
void WriteToHDF5AllParamsOfTypeT(const std::string &prefix,
const HDF5::H5G &group) const {
for (const auto &p : myParams_) {
const auto &key = p.first;
const auto type = myTypes_.at(key);
Expand All @@ -128,20 +130,22 @@ class Params {
}

template <typename T>
void WriteTVecToHDF5(const std::string &prefix, const HDF5::H5G &group) const {
WriteToHDF5<T>(prefix, group);
WriteToHDF5<std::vector<T>>(prefix, group);
void WriteToHDF5AllParamsOfTypeTOrVecT(const std::string &prefix,
const HDF5::H5G &group) const {
WriteToHDF5AllParamsOfTypeT<T>(prefix, group);
WriteToHDF5AllParamsOfTypeT<std::vector<T>>(prefix, group);
}

public:
void WriteAllToHDF5(const std::string &prefix, const HDF5::H5G &group) const {
WriteTVecToHDF5<bool>(prefix, group);
WriteTVecToHDF5<int32_t>(prefix, group);
WriteTVecToHDF5<int64_t>(prefix, group);
WriteTVecToHDF5<uint32_t>(prefix, group);
WriteTVecToHDF5<uint64_t>(prefix, group);
WriteTVecToHDF5<float>(prefix, group);
WriteTVecToHDF5<double>(prefix, group);
WriteTVecToHDF5<std::string>(prefix, group);
WriteToHDF5AllParamsOfTypeTOrVecT<bool>(prefix, group);
WriteToHDF5AllParamsOfTypeTOrVecT<int32_t>(prefix, group);
WriteToHDF5AllParamsOfTypeTOrVecT<int64_t>(prefix, group);
WriteToHDF5AllParamsOfTypeTOrVecT<uint32_t>(prefix, group);
WriteToHDF5AllParamsOfTypeTOrVecT<uint64_t>(prefix, group);
WriteToHDF5AllParamsOfTypeTOrVecT<float>(prefix, group);
WriteToHDF5AllParamsOfTypeTOrVecT<double>(prefix, group);
WriteToHDF5AllParamsOfTypeTOrVecT<std::string>(prefix, group);
}

#endif // ifdef HDF5OUTPUT
Expand Down
20 changes: 10 additions & 10 deletions src/outputs/parthenon_hdf5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -955,27 +955,27 @@ void PHDF5Output::WriteOutputFileImpl(Mesh *pm, ParameterInput *pin, SimTime *tm
}
}

// NumVariables - number of variables within each dataset
std::vector<size_t> numVariables;
// VariablesNames - Names of variables within each dataset
std::vector<std::string> variableNames;
// number of components within each dataset
std::vector<size_t> num_components;
// names of components within each dataset
std::vector<std::string> component_names;

for (const auto &vi : all_unique_vars) {
const auto &component_labels = vi.component_labels;

if (component_labels.size() > 0) {
numVariables.push_back(component_labels.size());
num_components.push_back(component_labels.size());
for (const auto &label : component_labels) {
variableNames.push_back(label);
component_names.push_back(label);
}
} else {
numVariables.push_back(1);
variableNames.push_back(vi.label);
num_components.push_back(1);
component_names.push_back(vi.label);
}
}

HDF5WriteAttribute("NumVariables", numVariables, info_group);
HDF5WriteAttribute("VariableNames", variableNames, info_group);
HDF5WriteAttribute("NumComponents", num_components, info_group);
HDF5WriteAttribute("ComponentNames", component_names, info_group);

// write SparseInfo and SparseFields (we can't write a zero-size dataset, so only write
// this if we have sparse fields)
Expand Down
2 changes: 1 addition & 1 deletion src/parthenon_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void ParthenonManager::RestartPackages(Mesh &rm, RestartReader &resfile) {

// Get list of variables, assumed same for all blocks

// TODO(JL) this doesn't work anymore, will update this in sparse update
// TODO(JL) this won't work when reading true sparse variables, will be updated in PR #383

auto ciX = MeshBlockDataIterator<Real>(
mb.meshblock_data.Get(),
Expand Down

0 comments on commit 7aa68b7

Please sign in to comment.