Skip to content

Commit

Permalink
Bump OPMD version and add delim
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrete committed Sep 4, 2024
1 parent c0d7f11 commit b2d7525
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ if (PARTHENON_ENABLE_OPENPMD)
FetchContent_Declare(openPMD
GIT_REPOSITORY "https://github.com/openPMD/openPMD-api.git"
# we need newer than the latest 0.15.2 release to support writing attriutes from a subset of ranks
GIT_TAG "bda3544") # develop as of 2024-07-12
GIT_TAG "1c7d7ff") # develop as of 2024-09-02
FetchContent_MakeAvailable(openPMD)
install(TARGETS openPMD EXPORT parthenonTargets)
endif()
Expand Down
3 changes: 2 additions & 1 deletion src/outputs/parthenon_opmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ using namespace OutputUtils;

template <typename T>
void WriteAllParamsOfType(std::shared_ptr<StateDescriptor> pkg, openPMD::Iteration *it) {
const std::string prefix = "Params/" + pkg->label() + "/";
using OpenPMDUtils::delim;
const std::string prefix = "Params" + delim + pkg->label() + delim;
const auto &params = pkg->AllParams();
for (const auto &key : params.GetKeys()) {
const auto type = params.GetType(key);
Expand Down
7 changes: 7 additions & 0 deletions src/outputs/parthenon_opmd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ namespace parthenon {

namespace OpenPMDUtils {

// Deliminter to separate packages and parameters in attributes.
// More or less a workaround as the OpenPMD API does currently not expose
// access to non-standard groups (such as "Params" versus the standard "meshes").
// TODO(pgrete & reviewer) (agree on delim and add check for package name and keys) OR
// better use of opmd-api
inline static const std::string delim = "+";

// Construct OpenPMD Mesh "record" name and comonnent identifier.
// - comp_idx is a flattended index over all components of the vectors and tensors, i.e.,
// the typical v,u,t indices.
Expand Down
11 changes: 10 additions & 1 deletion src/outputs/restart_opmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,20 @@ std::size_t RestartReaderOPMD::GetSwarmCounts(const std::string &swarm,

template <typename T>
void RestartReaderOPMD::ReadAllParamsOfType(const std::string &pkg_name, Params &params) {
using OpenPMDUtils::delim;
for (const auto &key : params.GetKeys()) {
const auto type = params.GetType(key);
auto mutability = params.GetMutability(key);
if (type == std::type_index(typeid(T)) && mutability == Params::Mutability::Restart) {
auto val = it->getAttribute("Params/" + pkg_name + "/" + key).get<T>();
auto attrs = it->attributes();
for (const auto & attr : attrs) {
std::cout << "Contains attribute: " << attr << std::endl;
}
std::cout << "Reading '"
<< "Params" + delim + pkg_name + delim + key << "' with type: " << typeid(T).name()
<< std::endl;

auto val = it->getAttribute("Params" + delim + pkg_name + delim + key).get<T>();
params.Update(key, val);
}
}
Expand Down

0 comments on commit b2d7525

Please sign in to comment.