From bcf491ca9d26e17f0131d4f0cd92e5cd33638c8a Mon Sep 17 00:00:00 2001 From: ampdes Date: Fri, 26 Jul 2024 16:08:50 +0200 Subject: [PATCH] Fix errors --- cpp/demo/checkpointing/main.cpp | 21 +++++++++++++-------- cpp/dolfinx/io/checkpointing.cpp | 27 +++++++++++++++++++++------ cpp/dolfinx/io/checkpointing.h | 6 ++++++ 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/cpp/demo/checkpointing/main.cpp b/cpp/demo/checkpointing/main.cpp index 198d0b426ff..b525f0cacab 100644 --- a/cpp/demo/checkpointing/main.cpp +++ b/cpp/demo/checkpointing/main.cpp @@ -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 topo_imap @@ -42,14 +45,16 @@ int main(int argc, char* argv[]) std::vector entities_array(num_entities * num_dofs_per_entity); std::vector entities_offsets(num_entities + 1); std::uint64_t offset = topo_imap->local_range()[0]; - std::vector values(num_entities); + std::vector 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) @@ -58,14 +63,14 @@ int main(int argc, char* argv[]) graph::AdjacencyList entities_local(entities_array, entities_offsets); - auto meshtags = std::make_shared>( - mesh::create_meshtags(topology, dim, entities_local, values)); + auto meshtags = std::make_shared>( + mesh::create_meshtags(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; diff --git a/cpp/dolfinx/io/checkpointing.cpp b/cpp/dolfinx/io/checkpointing.cpp index 6ae3242f6f3..ae4701510f4 100644 --- a/cpp/dolfinx/io/checkpointing.cpp +++ b/cpp/dolfinx/io/checkpointing.cpp @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include using namespace dolfinx; @@ -128,11 +130,23 @@ void _write_mesh(ADIOS2Engine& adios2engine, template void _write_meshtags(ADIOS2Engine& adios2engine, + std::shared_ptr> mesh, std::shared_ptr> 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(); @@ -164,8 +178,7 @@ void _write_meshtags(ADIOS2Engine& adios2engine, MPI_UINT64_T, MPI_SUM, mesh->comm()); auto values = meshtags->values(); - const std::span local_values(values.begin(), - num_saved_tag_entities); + const std::span local_values(values.begin(), num_saved_tag_entities); std::vector entities_to_geometry = mesh::entities_to_geometry(*mesh, dim, tag_entities, false); @@ -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("meshtags_name", meshtags->name); - io->DefineAttribute("meshtags_dim", dim); + io->DefineAttribute("meshtags_dim", dim); adios2::Variable var_num_tag_entities_global = io->DefineVariable("num_tag_entities_global"); @@ -230,19 +243,21 @@ void dolfinx::io::checkpointing::write_mesh( //----------------------------------------------------------------------------- void dolfinx::io::checkpointing::write_meshtags( ADIOS2Engine& adios2engine, + std::shared_ptr> mesh, std::shared_ptr> meshtags) { - _write_meshtags(adios2engine, meshtags); + _write_meshtags(adios2engine, mesh, meshtags); } //----------------------------------------------------------------------------- void dolfinx::io::checkpointing::write_meshtags( ADIOS2Engine& adios2engine, + std::shared_ptr> mesh, std::shared_ptr> meshtags) { - _write_meshtags(adios2engine, meshtags); + _write_meshtags(adios2engine, mesh, meshtags); } #endif diff --git a/cpp/dolfinx/io/checkpointing.h b/cpp/dolfinx/io/checkpointing.h index 36854cbb956..2d1df79905a 100644 --- a/cpp/dolfinx/io/checkpointing.h +++ b/cpp/dolfinx/io/checkpointing.h @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include /// @file checkpointing.h @@ -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> mesh, std::shared_ptr> 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> mesh, std::shared_ptr> meshtags); } // namespace dolfinx::io::checkpointing