Skip to content

Commit

Permalink
making output capable of default handling many outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
mtao committed Nov 29, 2024
1 parent 2c47a4c commit 413ed13
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,12 @@ NamedMultiMesh::NamedMultiMesh(const NamedMultiMesh& o)
{}


std::unique_ptr<nlohmann::json> NamedMultiMesh::get_names_json() const
std::unique_ptr<nlohmann::json> NamedMultiMesh::get_names_json(const std::string_view& path) const
{
auto js_ptr = std::make_unique<nlohmann::json>();
auto& js = *js_ptr;
js = *m_name_root;
const auto id = get_id(path);
js = get_node(id);


return js_ptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class NamedMultiMesh
void set_root(Mesh& m);
void append_child_mesh_names(const Mesh& parent, const NamedMultiMesh& o);

std::unique_ptr<nlohmann::json> get_names_json() const;
std::unique_ptr<nlohmann::json> get_names_json(const std::string_view& path) const;

std::string_view root_name() const;
std::string name(const std::vector<int64_t>& id) const;
Expand Down
20 changes: 17 additions & 3 deletions components/output/wmtk/components/output/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <fmt/std.h>
#include <type_traits>
#include <wmtk/Mesh.hpp>
#include <wmtk/components/multimesh/MeshCollection.hpp>
#include <wmtk/components/multimesh/NamedMultiMesh.hpp>
#include <wmtk/components/utils/resolve_path.hpp>
#include <wmtk/io/HDF5Writer.hpp>
Expand Down Expand Up @@ -77,14 +78,27 @@ void output(const Mesh& mesh, const OutputOptions& opts)
fmt::format("Unable to write file [{}] of extension [{}]", opts.path, opts.type));
}

void output(const multimesh::NamedMultiMesh& mesh, const OutputOptions& opts)
void output(
const multimesh::NamedMultiMesh& mesh,
const OutputOptions& opts,
const std::string_view& mesh_path)
{
output(mesh.root(), opts);
output(mesh.get_mesh(mesh_path), opts);

if (opts.mesh_name_path.has_value()) {
const auto& path = opts.mesh_name_path.value();
std::ofstream ofs(path);
ofs << *mesh.get_names_json();
ofs << *mesh.get_names_json(mesh_path);
}
}

void output(
const multimesh::MeshCollection& mesh_col,
const std::map<std::string, OutputOptions>& opts)
{
for (const auto& [path, single_opts] : opts) {
const multimesh::NamedMultiMesh& nmm = mesh_col.get_named_multimesh(path);
output(nmm, single_opts, path);
}
}

Expand Down
8 changes: 7 additions & 1 deletion components/output/wmtk/components/output/output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace wmtk::components {
namespace multimesh {
class NamedMultiMesh;
class MeshCollection;
}

namespace output {
Expand Down Expand Up @@ -68,7 +69,12 @@ void output(

void output(
const multimesh::NamedMultiMesh& mesh,
const OutputOptions&);
const OutputOptions&, const std::string_view& mesh_path = "");


void output(
const multimesh::MeshCollection& mesh,
const std::map<std::string, OutputOptions>&);

/**
* @brief Write the mesh to file.
Expand Down

0 comments on commit 413ed13

Please sign in to comment.