Skip to content

Commit

Permalink
Fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ampdes committed Jul 26, 2024
1 parent ec05f4c commit bcf491c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
21 changes: 13 additions & 8 deletions cpp/demo/checkpointing/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ int main(int argc, char* argv[])
mesh::CellType::quadrilateral, part));

// Create cell meshtags
auto geometry = mesh->geometry();
auto topology = mesh->topology();

int dim = geometry.dim();
topology->create_entities(dim);
const std::shared_ptr<const dolfinx::common::IndexMap> topo_imap
Expand All @@ -42,14 +45,16 @@ int main(int argc, char* argv[])
std::vector<int32_t> entities_array(num_entities * num_dofs_per_entity);
std::vector<int32_t> entities_offsets(num_entities + 1);
std::uint64_t offset = topo_imap->local_range()[0];
std::vector<double> values(num_entities);
std::vector<float> values(num_entities);

for (int i = 0; i < values.size(); ++i)
for (int i = 0; i < (int)num_entities; ++i)
{
values[i] = (double)(i + offset);
values[i] = (float)(i + offset);
}

for (int i = 0; i < values.size() + 1; ++i)
auto entities = topology->connectivity(dim, 0);

for (int i = 0; i < (int)num_entities + 1; ++i)
entities_offsets[i] = entities->offsets()[i];

for (int i = 0; i < (int)(num_entities * num_dofs_per_entity); ++i)
Expand All @@ -58,14 +63,14 @@ int main(int argc, char* argv[])
graph::AdjacencyList<std::int32_t> entities_local(entities_array,
entities_offsets);

auto meshtags = std::make_shared<mesh::MeshTags<U>>(
mesh::create_meshtags<U>(topology, dim, entities_local, values));
auto meshtags = std::make_shared<mesh::MeshTags<float>>(
mesh::create_meshtags<float>(topology, dim, entities_local, values));

auto writer = ADIOS2Engine(mesh->comm(), "mesh.bp", "mesh-write", "BP5",
adios2::Mode::Write);

io::checkpointing::write(writer, mesh);
io::checkpointing::write(writer, meshtags);
io::checkpointing::write_mesh(writer, mesh);
io::checkpointing::write_meshtags(writer, mesh, meshtags);

MPI_Finalize();
return 0;
Expand Down
27 changes: 21 additions & 6 deletions cpp/dolfinx/io/checkpointing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <adios2.h>
#include <basix/finite-element.h>
#include <dolfinx/mesh/Mesh.h>
#include <dolfinx/mesh/MeshTags.h>
#include <dolfinx/mesh/utils.h>
#include <mpi.h>

using namespace dolfinx;
Expand Down Expand Up @@ -128,11 +130,23 @@ void _write_mesh(ADIOS2Engine& adios2engine,

template <std::floating_point T>
void _write_meshtags(ADIOS2Engine& adios2engine,
std::shared_ptr<dolfinx::mesh::Mesh<T>> mesh,
std::shared_ptr<dolfinx::mesh::MeshTags<T>> meshtags)
{
auto io = adios2engine.io();
auto writer = adios2engine.engine();

auto geometry = mesh->geometry();
auto topology = mesh->topology();

// meshtagsdata
auto tag_entities = meshtags->indices();
auto dim = meshtags->dim();

auto cmap = mesh->geometry().cmap();
auto geom_layout = cmap.create_dof_layout();
std::uint32_t num_dofs_per_entity = geom_layout.num_entity_closure_dofs(dim);

std::uint32_t num_tag_entities_local
= meshtags->topology()->index_map(dim)->size_local();

Expand Down Expand Up @@ -164,8 +178,7 @@ void _write_meshtags(ADIOS2Engine& adios2engine,
MPI_UINT64_T, MPI_SUM, mesh->comm());

auto values = meshtags->values();
const std::span<const double> local_values(values.begin(),
num_saved_tag_entities);
const std::span<const T> local_values(values.begin(), num_saved_tag_entities);

std::vector<std::int32_t> entities_to_geometry
= mesh::entities_to_geometry(*mesh, dim, tag_entities, false);
Expand All @@ -177,10 +190,10 @@ void _write_meshtags(ADIOS2Engine& adios2engine,

imap->local_to_global(entities_to_geometry, topology_array);

std::string name = "meshtags_" + meshtags->name;
std::string name = meshtags->name;

io->DefineAttribute<std::string>("meshtags_name", meshtags->name);
io->DefineAttribute<std::string>("meshtags_dim", dim);
io->DefineAttribute<std::int16_t>("meshtags_dim", dim);

adios2::Variable<std::uint64_t> var_num_tag_entities_global
= io->DefineVariable<std::uint64_t>("num_tag_entities_global");
Expand Down Expand Up @@ -230,19 +243,21 @@ void dolfinx::io::checkpointing::write_mesh(
//-----------------------------------------------------------------------------
void dolfinx::io::checkpointing::write_meshtags(
ADIOS2Engine& adios2engine,
std::shared_ptr<dolfinx::mesh::Mesh<float>> mesh,
std::shared_ptr<dolfinx::mesh::MeshTags<float>> meshtags)
{

_write_meshtags(adios2engine, meshtags);
_write_meshtags(adios2engine, mesh, meshtags);
}

//-----------------------------------------------------------------------------
void dolfinx::io::checkpointing::write_meshtags(
ADIOS2Engine& adios2engine,
std::shared_ptr<dolfinx::mesh::Mesh<double>> mesh,
std::shared_ptr<dolfinx::mesh::MeshTags<double>> meshtags)
{

_write_meshtags(adios2engine, meshtags);
_write_meshtags(adios2engine, mesh, meshtags);
}

#endif
6 changes: 6 additions & 0 deletions cpp/dolfinx/io/checkpointing.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <adios2.h>
#include <basix/finite-element.h>
#include <dolfinx/mesh/Mesh.h>
#include <dolfinx/mesh/MeshTags.h>
#include <dolfinx/mesh/utils.h>
#include <mpi.h>

/// @file checkpointing.h
Expand All @@ -37,15 +39,19 @@ void write_mesh(ADIOS2Engine& adios2engine,
/// @brief Write meshtags to a file.
///
/// @param[in] adios2engine ADIOS2Engine
/// @param[in] mesh Mesh of type float to write to the file
/// @param[in] meshtags MeshTags of type float to write to the file
void write_meshtags(ADIOS2Engine& adios2engine,
std::shared_ptr<dolfinx::mesh::Mesh<float>> mesh,
std::shared_ptr<dolfinx::mesh::MeshTags<float>> meshtags);

/// @brief Write meshtags to a file.
///
/// @param[in] adios2engine ADIOS2Engine
/// @param[in] mesh Mesh of type double to write to the file
/// @param[in] meshtags MeshTags of type double to write to the file
void write_meshtags(ADIOS2Engine& adios2engine,
std::shared_ptr<dolfinx::mesh::Mesh<double>> mesh,
std::shared_ptr<dolfinx::mesh::MeshTags<double>> meshtags);

} // namespace dolfinx::io::checkpointing
Expand Down

0 comments on commit bcf491c

Please sign in to comment.