Skip to content

Commit

Permalink
writing multiple meshes with prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
seegyoung committed Dec 30, 2024
1 parent 5627b34 commit 1971fe0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
52 changes: 35 additions & 17 deletions src/Omega_h_adios2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Omega_h_inertia.hpp" //<inertia::Rib>
#include "Omega_h_timer.hpp"
#include "Omega_h_tag.hpp"
#include <map>

using namespace std;

Expand Down Expand Up @@ -389,7 +390,7 @@ void write_sets(adios2::IO &io, adios2::Engine &writer, Mesh* mesh, std::string
}
}

void read_sets(adios2::IO &io, adios2::Engine &reader, Mesh* mesh, std::string pref)
void read_sets(adios2::IO & io, adios2::Engine &reader, Mesh* mesh, std::string pref)
{
std::string name = pref+"gclas_size";
int32_t n;
Expand Down Expand Up @@ -461,25 +462,12 @@ void read_parents(adios2::IO &io, adios2::Engine &reader, Mesh* mesh, std::strin
}
}

void write_adios2(filesystem::path const& path, Mesh *mesh, std::string pref)
void write_adios2(adios2::IO &io, adios2::Engine & writer,
Mesh* mesh, std::string pref)
{
comm_size = mesh->comm()->size();
rank = mesh->comm()->rank();

if (path.extension().string() != ".bp" && can_print(mesh)) {
std::cout
<< "it is strongly recommended to end Omega_h paths in \".bp\",\n";
std::cout << "instead of just \"" << path << "\"\n";
}
filesystem::create_directory(path);

adios2::ADIOS adios(mesh->comm()->get_impl());
adios2::IO io = adios.DeclareIO("mesh-writer");

std::string filename=path.c_str();

adios2::Engine writer = io.Open(filename, adios2::Mode::Write);
writer.BeginStep();
write_meta(io, writer, mesh, pref);
int32_t nverts = mesh->nverts();
std::string name=pref+"nverts";
Expand All @@ -488,19 +476,49 @@ void write_adios2(filesystem::path const& path, Mesh *mesh, std::string pref)
for (int32_t d = 1; d <= mesh->dim(); ++d)
write_down(io, writer, mesh, d, pref);

for (Int d = 0; d <= mesh->dim(); ++d)
for (Int d = 0; d <= mesh->dim(); ++d)
{
write_tags(io, writer, mesh, d, pref);
write_pbdry(io, writer, mesh, d, pref);
}

write_sets(io, writer, mesh, pref);
write_parents(io, writer, mesh, pref);
}

void write_adios2(filesystem::path const& path,
std::map<Mesh*, std::string>& mesh_map)
{
std::map<Mesh*, std::string>::iterator it=mesh_map.begin();
Mesh* mesh=it->first;

if (path.extension().string() != ".bp" && can_print(mesh)) {
std::cout
<< "it is strongly recommended to end Omega_h paths in \".bp\",\n";
std::cout << "instead of just \"" << path << "\"\n";
}
filesystem::create_directory(path);

adios2::ADIOS adios(mesh->comm()->get_impl());
adios2::IO io = adios.DeclareIO("mesh-writer");
std::string filename=path.c_str();

adios2::Engine writer = io.Open(filename, adios2::Mode::Write);
writer.BeginStep();
for (; it!=mesh_map.end(); ++it)
write_adios2(io, writer, it->first, it->second);
writer.EndStep();
writer.Close();
}


void write_adios2(filesystem::path const& path, Mesh* mesh, std::string pref)
{
std::map<Mesh*, std::string> mesh_map;
mesh_map[mesh] = pref;
write_adios2(path, mesh_map);
}

Mesh read_adios2(filesystem::path const& path, Library* lib, std::string pref)
{
comm_size = lib->world()->size();
Expand Down
4 changes: 2 additions & 2 deletions src/Omega_h_adios2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
namespace Omega_h {

template <typename T>
void write_value(adios2::IO &io, adios2::Engine &writer,
void write_value(adios2::IO &, adios2::Engine &writer,
T val, std::string &name, bool global=false);

template <typename T>
void read_value(adios2::IO &io, adios2::Engine &reader,
void read_value(adios2::IO &, adios2::Engine &reader,
T *val, std::string &name, bool global=false);

void write_adios2(filesystem::path const& path, Mesh *mesh, std::string pref="");
Expand Down

0 comments on commit 1971fe0

Please sign in to comment.