From 95ba335bc970b28e46c067a32db405f05b5accd2 Mon Sep 17 00:00:00 2001 From: Massimiliano Leoni Date: Mon, 8 Aug 2022 13:12:17 +0200 Subject: [PATCH 01/12] Allow to reuse mesh --- cpp/dolfinx/io/ADIOS2Writers.cpp | 7 +++++-- cpp/dolfinx/io/ADIOS2Writers.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cpp/dolfinx/io/ADIOS2Writers.cpp b/cpp/dolfinx/io/ADIOS2Writers.cpp index 5aa9ad1ad07..776a689007c 100644 --- a/cpp/dolfinx/io/ADIOS2Writers.cpp +++ b/cpp/dolfinx/io/ADIOS2Writers.cpp @@ -777,7 +777,7 @@ FidesWriter::FidesWriter(MPI_Comm comm, const std::filesystem::path& filename, fides_initialize_function_attributes(*_io, u); } //----------------------------------------------------------------------------- -void FidesWriter::write(double t) +void FidesWriter::write(double t, bool writeMesh) { assert(_io); assert(_engine); @@ -786,7 +786,10 @@ void FidesWriter::write(double t) adios2::Variable var_step = define_variable(*_io, "step"); _engine->Put(var_step, t); - fides_write_mesh(*_io, *_engine, *_mesh); + if (writeMesh) + { + fides_write_mesh(*_io, *_engine, *_mesh); + } for (auto& v : _u) std::visit([&](const auto& u) { fides_write_data(*_io, *_engine, *u); }, v); diff --git a/cpp/dolfinx/io/ADIOS2Writers.h b/cpp/dolfinx/io/ADIOS2Writers.h index 1ac4980834a..d36f3d3668c 100644 --- a/cpp/dolfinx/io/ADIOS2Writers.h +++ b/cpp/dolfinx/io/ADIOS2Writers.h @@ -146,7 +146,7 @@ class FidesWriter : public ADIOS2Writer /// @brief Write data with a given time /// @param[in] t The time step - void write(double t); + void write(double t, bool writeMesh = true); }; /// @brief Writer for meshes and functions using the ADIOS2 VTX format, see From c9366e69a0379c9783e6c6e3d0e1b2cd49d64ac0 Mon Sep 17 00:00:00 2001 From: Massimiliano Leoni Date: Mon, 8 Aug 2022 13:24:24 +0200 Subject: [PATCH 02/12] Update doc --- cpp/dolfinx/io/ADIOS2Writers.h | 1 + 1 file changed, 1 insertion(+) diff --git a/cpp/dolfinx/io/ADIOS2Writers.h b/cpp/dolfinx/io/ADIOS2Writers.h index d36f3d3668c..5964fa10e56 100644 --- a/cpp/dolfinx/io/ADIOS2Writers.h +++ b/cpp/dolfinx/io/ADIOS2Writers.h @@ -146,6 +146,7 @@ class FidesWriter : public ADIOS2Writer /// @brief Write data with a given time /// @param[in] t The time step + /// @param[in] writeMesh True to save the mesh at this time, false otherwise void write(double t, bool writeMesh = true); }; From 909e1d28e89b984ceab4cd9c80288837e0cf6a60 Mon Sep 17 00:00:00 2001 From: Massimiliano Leoni Date: Tue, 13 Sep 2022 12:14:12 +0200 Subject: [PATCH 03/12] Decide on mesh reuse policy at construction time --- cpp/dolfinx/io/ADIOS2Writers.cpp | 19 +++++++++++++------ cpp/dolfinx/io/ADIOS2Writers.h | 16 ++++++++++++---- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/cpp/dolfinx/io/ADIOS2Writers.cpp b/cpp/dolfinx/io/ADIOS2Writers.cpp index 53f93760633..47c03409ec3 100644 --- a/cpp/dolfinx/io/ADIOS2Writers.cpp +++ b/cpp/dolfinx/io/ADIOS2Writers.cpp @@ -701,8 +701,10 @@ void ADIOS2Writer::close() } //----------------------------------------------------------------------------- FidesWriter::FidesWriter(MPI_Comm comm, const std::filesystem::path& filename, - std::shared_ptr mesh) - : ADIOS2Writer(comm, filename, "Fides mesh writer", mesh) + std::shared_ptr mesh, + const bool reuse_mesh) + : ADIOS2Writer(comm, filename, "Fides mesh writer", mesh), + _reuse_mesh(reuse_mesh) { assert(_io); assert(mesh); @@ -710,8 +712,9 @@ FidesWriter::FidesWriter(MPI_Comm comm, const std::filesystem::path& filename, } //----------------------------------------------------------------------------- FidesWriter::FidesWriter(MPI_Comm comm, const std::filesystem::path& filename, - const ADIOS2Writer::U& u) - : ADIOS2Writer(comm, filename, "Fides function writer", u) + const ADIOS2Writer::U& u, const bool reuse_mesh) + : ADIOS2Writer(comm, filename, "Fides function writer", u), + _reuse_mesh(reuse_mesh) { if (u.empty()) throw std::runtime_error("FidesWriter fem::Function list is empty"); @@ -777,22 +780,26 @@ FidesWriter::FidesWriter(MPI_Comm comm, const std::filesystem::path& filename, fides_initialize_function_attributes(*_io, u); } //----------------------------------------------------------------------------- -void FidesWriter::write(double t, bool writeMesh) +void FidesWriter::write(double t) { assert(_io); assert(_engine); + static bool first_write = true; + _engine->BeginStep(); adios2::Variable var_step = define_variable(*_io, "step"); _engine->Put(var_step, t); - if (writeMesh) + if (_reuse_mesh == false or first_write == true) { fides_write_mesh(*_io, *_engine, *_mesh); } for (auto& v : _u) std::visit([&](const auto& u) { fides_write_data(*_io, *_engine, *u); }, v); + first_write = false; + _engine->EndStep(); } //----------------------------------------------------------------------------- diff --git a/cpp/dolfinx/io/ADIOS2Writers.h b/cpp/dolfinx/io/ADIOS2Writers.h index 5964fa10e56..d9b1fc12b38 100644 --- a/cpp/dolfinx/io/ADIOS2Writers.h +++ b/cpp/dolfinx/io/ADIOS2Writers.h @@ -115,10 +115,12 @@ class FidesWriter : public ADIOS2Writer /// @param[in] comm The MPI communicator to open the file on /// @param[in] filename Name of output file /// @param[in] mesh The mesh. The mesh must a degree 1 mesh. + /// @param[in] reuse_mesh True to save the mesh only at the first + /// write, false to save the mesh at each write /// @note The mesh geometry can be updated between write steps but the /// topology should not be changed between write steps FidesWriter(MPI_Comm comm, const std::filesystem::path& filename, - std::shared_ptr mesh); + std::shared_ptr mesh, const bool reuse_mesh = false); /// @brief Create Fides writer for list of functions /// @param[in] comm The MPI communicator @@ -126,8 +128,10 @@ class FidesWriter : public ADIOS2Writer /// @param[in] u List of functions. The functions must (1) share the /// same mesh (degree 1) and (2) be degree 1 Lagrange. @note All /// functions in `u` must share the same Mesh + /// @param[in] reuse_mesh True to save the mesh only at the first + /// write, false to save the mesh at each write FidesWriter(MPI_Comm comm, const std::filesystem::path& filename, - const ADIOS2Writer::U& u); + const ADIOS2Writer::U& u, const bool reuse_mesh = false); // Copy constructor FidesWriter(const FidesWriter&) = delete; @@ -146,8 +150,12 @@ class FidesWriter : public ADIOS2Writer /// @brief Write data with a given time /// @param[in] t The time step - /// @param[in] writeMesh True to save the mesh at this time, false otherwise - void write(double t, bool writeMesh = true); + void write(double t); + +private: + /// @brief If true, the mesh is saved only at the first write and then reused, + /// otherwise the mesh will be saved at each write + bool _reuse_mesh; }; /// @brief Writer for meshes and functions using the ADIOS2 VTX format, see From bf76ed728897e7a94ba91def9e8c72c3b3b7dd6a Mon Sep 17 00:00:00 2001 From: Massimiliano Leoni Date: Tue, 13 Sep 2022 12:17:10 +0200 Subject: [PATCH 04/12] More sensible behaviour --- cpp/dolfinx/io/ADIOS2Writers.cpp | 5 ++--- cpp/dolfinx/io/ADIOS2Writers.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cpp/dolfinx/io/ADIOS2Writers.cpp b/cpp/dolfinx/io/ADIOS2Writers.cpp index 47c03409ec3..75c4d6441c2 100644 --- a/cpp/dolfinx/io/ADIOS2Writers.cpp +++ b/cpp/dolfinx/io/ADIOS2Writers.cpp @@ -701,10 +701,9 @@ void ADIOS2Writer::close() } //----------------------------------------------------------------------------- FidesWriter::FidesWriter(MPI_Comm comm, const std::filesystem::path& filename, - std::shared_ptr mesh, - const bool reuse_mesh) + std::shared_ptr mesh) : ADIOS2Writer(comm, filename, "Fides mesh writer", mesh), - _reuse_mesh(reuse_mesh) + _reuse_mesh(false) { assert(_io); assert(mesh); diff --git a/cpp/dolfinx/io/ADIOS2Writers.h b/cpp/dolfinx/io/ADIOS2Writers.h index d9b1fc12b38..c34d9c7063c 100644 --- a/cpp/dolfinx/io/ADIOS2Writers.h +++ b/cpp/dolfinx/io/ADIOS2Writers.h @@ -120,7 +120,7 @@ class FidesWriter : public ADIOS2Writer /// @note The mesh geometry can be updated between write steps but the /// topology should not be changed between write steps FidesWriter(MPI_Comm comm, const std::filesystem::path& filename, - std::shared_ptr mesh, const bool reuse_mesh = false); + std::shared_ptr mesh); /// @brief Create Fides writer for list of functions /// @param[in] comm The MPI communicator From 8e9256059d3bcfa01dd672c8413c57c53c20ea98 Mon Sep 17 00:00:00 2001 From: Massimiliano Leoni Date: Tue, 13 Sep 2022 13:16:13 +0200 Subject: [PATCH 05/12] Fix doc --- cpp/dolfinx/io/ADIOS2Writers.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/cpp/dolfinx/io/ADIOS2Writers.h b/cpp/dolfinx/io/ADIOS2Writers.h index c34d9c7063c..303e9d46707 100644 --- a/cpp/dolfinx/io/ADIOS2Writers.h +++ b/cpp/dolfinx/io/ADIOS2Writers.h @@ -115,8 +115,6 @@ class FidesWriter : public ADIOS2Writer /// @param[in] comm The MPI communicator to open the file on /// @param[in] filename Name of output file /// @param[in] mesh The mesh. The mesh must a degree 1 mesh. - /// @param[in] reuse_mesh True to save the mesh only at the first - /// write, false to save the mesh at each write /// @note The mesh geometry can be updated between write steps but the /// topology should not be changed between write steps FidesWriter(MPI_Comm comm, const std::filesystem::path& filename, From fed76114f156adbd81d59161a4dfde343eba93a5 Mon Sep 17 00:00:00 2001 From: Massimiliano Leoni Date: Tue, 20 Sep 2022 17:42:49 +0200 Subject: [PATCH 06/12] Fixing subtle bug --- cpp/dolfinx/io/ADIOS2Writers.cpp | 2 -- cpp/dolfinx/io/ADIOS2Writers.h | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/dolfinx/io/ADIOS2Writers.cpp b/cpp/dolfinx/io/ADIOS2Writers.cpp index 75c4d6441c2..1984c9dac3d 100644 --- a/cpp/dolfinx/io/ADIOS2Writers.cpp +++ b/cpp/dolfinx/io/ADIOS2Writers.cpp @@ -784,8 +784,6 @@ void FidesWriter::write(double t) assert(_io); assert(_engine); - static bool first_write = true; - _engine->BeginStep(); adios2::Variable var_step = define_variable(*_io, "step"); _engine->Put(var_step, t); diff --git a/cpp/dolfinx/io/ADIOS2Writers.h b/cpp/dolfinx/io/ADIOS2Writers.h index 303e9d46707..41e5ce4c023 100644 --- a/cpp/dolfinx/io/ADIOS2Writers.h +++ b/cpp/dolfinx/io/ADIOS2Writers.h @@ -154,6 +154,8 @@ class FidesWriter : public ADIOS2Writer /// @brief If true, the mesh is saved only at the first write and then reused, /// otherwise the mesh will be saved at each write bool _reuse_mesh; + /// @brief Auxiliary flag + bool first_write = true; }; /// @brief Writer for meshes and functions using the ADIOS2 VTX format, see From f09b235e64dbb01efbae44816112447804ca4fda Mon Sep 17 00:00:00 2001 From: Massimiliano Leoni Date: Wed, 21 Sep 2022 15:50:06 +0200 Subject: [PATCH 07/12] Removing unnecessary bool flag and introducing enum --- cpp/dolfinx/io/ADIOS2Writers.cpp | 12 ++++++------ cpp/dolfinx/io/ADIOS2Writers.h | 14 ++++++++++---- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/cpp/dolfinx/io/ADIOS2Writers.cpp b/cpp/dolfinx/io/ADIOS2Writers.cpp index 1984c9dac3d..f46edd676d1 100644 --- a/cpp/dolfinx/io/ADIOS2Writers.cpp +++ b/cpp/dolfinx/io/ADIOS2Writers.cpp @@ -703,7 +703,7 @@ void ADIOS2Writer::close() FidesWriter::FidesWriter(MPI_Comm comm, const std::filesystem::path& filename, std::shared_ptr mesh) : ADIOS2Writer(comm, filename, "Fides mesh writer", mesh), - _reuse_mesh(false) + _mesh_reuse_policy(MeshReusePolicy::DoNotReuse) { assert(_io); assert(mesh); @@ -711,9 +711,10 @@ FidesWriter::FidesWriter(MPI_Comm comm, const std::filesystem::path& filename, } //----------------------------------------------------------------------------- FidesWriter::FidesWriter(MPI_Comm comm, const std::filesystem::path& filename, - const ADIOS2Writer::U& u, const bool reuse_mesh) + const ADIOS2Writer::U& u, + const MeshReusePolicy mesh_reuse_policy) : ADIOS2Writer(comm, filename, "Fides function writer", u), - _reuse_mesh(reuse_mesh) + _mesh_reuse_policy(mesh_reuse_policy) { if (u.empty()) throw std::runtime_error("FidesWriter fem::Function list is empty"); @@ -788,15 +789,14 @@ void FidesWriter::write(double t) adios2::Variable var_step = define_variable(*_io, "step"); _engine->Put(var_step, t); - if (_reuse_mesh == false or first_write == true) + if (auto v = _io->InquireVariable("connectivity"); + _mesh_reuse_policy == MeshReusePolicy::DoNotReuse or not v) { fides_write_mesh(*_io, *_engine, *_mesh); } for (auto& v : _u) std::visit([&](const auto& u) { fides_write_data(*_io, *_engine, *u); }, v); - first_write = false; - _engine->EndStep(); } //----------------------------------------------------------------------------- diff --git a/cpp/dolfinx/io/ADIOS2Writers.h b/cpp/dolfinx/io/ADIOS2Writers.h index 41e5ce4c023..53c0cf6b891 100644 --- a/cpp/dolfinx/io/ADIOS2Writers.h +++ b/cpp/dolfinx/io/ADIOS2Writers.h @@ -111,6 +111,13 @@ class ADIOS2Writer class FidesWriter : public ADIOS2Writer { public: + /// Mesh reuse policy + enum class MeshReusePolicy + { + DoNotReuse, + Reuse + }; + /// @brief Create Fides writer for a mesh /// @param[in] comm The MPI communicator to open the file on /// @param[in] filename Name of output file @@ -129,7 +136,8 @@ class FidesWriter : public ADIOS2Writer /// @param[in] reuse_mesh True to save the mesh only at the first /// write, false to save the mesh at each write FidesWriter(MPI_Comm comm, const std::filesystem::path& filename, - const ADIOS2Writer::U& u, const bool reuse_mesh = false); + const ADIOS2Writer::U& u, + const MeshReusePolicy mesh_reuse_policy = MeshReusePolicy::DoNotReuse); // Copy constructor FidesWriter(const FidesWriter&) = delete; @@ -153,9 +161,7 @@ class FidesWriter : public ADIOS2Writer private: /// @brief If true, the mesh is saved only at the first write and then reused, /// otherwise the mesh will be saved at each write - bool _reuse_mesh; - /// @brief Auxiliary flag - bool first_write = true; + MeshReusePolicy _mesh_reuse_policy; }; /// @brief Writer for meshes and functions using the ADIOS2 VTX format, see From 7cb8a2d314c4a5c8a96190c39a2ad2cd384139a3 Mon Sep 17 00:00:00 2001 From: Massimiliano Leoni Date: Wed, 21 Sep 2022 15:58:40 +0200 Subject: [PATCH 08/12] Explicitly create string --- cpp/dolfinx/io/ADIOS2Writers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/dolfinx/io/ADIOS2Writers.cpp b/cpp/dolfinx/io/ADIOS2Writers.cpp index f46edd676d1..3ba5fd83271 100644 --- a/cpp/dolfinx/io/ADIOS2Writers.cpp +++ b/cpp/dolfinx/io/ADIOS2Writers.cpp @@ -789,7 +789,7 @@ void FidesWriter::write(double t) adios2::Variable var_step = define_variable(*_io, "step"); _engine->Put(var_step, t); - if (auto v = _io->InquireVariable("connectivity"); + if (auto v = _io->InquireVariable(std::string("connectivity")); _mesh_reuse_policy == MeshReusePolicy::DoNotReuse or not v) { fides_write_mesh(*_io, *_engine, *_mesh); From 00c933ac4f6098c13df96e1d42fcc9a57edb0bd8 Mon Sep 17 00:00:00 2001 From: Massimiliano Leoni Date: Wed, 21 Sep 2022 16:24:30 +0200 Subject: [PATCH 09/12] I have no idea what I'm doing --- cpp/dolfinx/io/ADIOS2Writers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/dolfinx/io/ADIOS2Writers.cpp b/cpp/dolfinx/io/ADIOS2Writers.cpp index 3ba5fd83271..d184d92a938 100644 --- a/cpp/dolfinx/io/ADIOS2Writers.cpp +++ b/cpp/dolfinx/io/ADIOS2Writers.cpp @@ -789,7 +789,7 @@ void FidesWriter::write(double t) adios2::Variable var_step = define_variable(*_io, "step"); _engine->Put(var_step, t); - if (auto v = _io->InquireVariable(std::string("connectivity")); + if (auto v = _io->InquireVariable("connectivity"); _mesh_reuse_policy == MeshReusePolicy::DoNotReuse or not v) { fides_write_mesh(*_io, *_engine, *_mesh); From 015651099a9a18e5bcbeea6af92a64c8c7d64dc1 Mon Sep 17 00:00:00 2001 From: Massimiliano Leoni Date: Wed, 21 Sep 2022 16:35:14 +0200 Subject: [PATCH 10/12] Finally got it --- cpp/dolfinx/io/ADIOS2Writers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/dolfinx/io/ADIOS2Writers.cpp b/cpp/dolfinx/io/ADIOS2Writers.cpp index d184d92a938..7042491ea5e 100644 --- a/cpp/dolfinx/io/ADIOS2Writers.cpp +++ b/cpp/dolfinx/io/ADIOS2Writers.cpp @@ -789,7 +789,7 @@ void FidesWriter::write(double t) adios2::Variable var_step = define_variable(*_io, "step"); _engine->Put(var_step, t); - if (auto v = _io->InquireVariable("connectivity"); + if (auto v = _io->InquireVariable("connectivity"); _mesh_reuse_policy == MeshReusePolicy::DoNotReuse or not v) { fides_write_mesh(*_io, *_engine, *_mesh); From b347112d41cdbffc8266b73cbc633b029c40f015 Mon Sep 17 00:00:00 2001 From: Massimiliano Leoni Date: Wed, 21 Sep 2022 16:41:33 +0200 Subject: [PATCH 11/12] Fix doc --- cpp/dolfinx/io/ADIOS2Writers.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cpp/dolfinx/io/ADIOS2Writers.h b/cpp/dolfinx/io/ADIOS2Writers.h index 53c0cf6b891..fcf24a70371 100644 --- a/cpp/dolfinx/io/ADIOS2Writers.h +++ b/cpp/dolfinx/io/ADIOS2Writers.h @@ -133,8 +133,9 @@ class FidesWriter : public ADIOS2Writer /// @param[in] u List of functions. The functions must (1) share the /// same mesh (degree 1) and (2) be degree 1 Lagrange. @note All /// functions in `u` must share the same Mesh - /// @param[in] reuse_mesh True to save the mesh only at the first - /// write, false to save the mesh at each write + /// @param[in] mesh_reuse_policy MeshReusePolicy::Reuse to save the + /// mesh only at the first write, MeshReusePolicy::DoNotReuse to + /// save the mesh at each write FidesWriter(MPI_Comm comm, const std::filesystem::path& filename, const ADIOS2Writer::U& u, const MeshReusePolicy mesh_reuse_policy = MeshReusePolicy::DoNotReuse); From 01969eea89b4dfdd8214db9471e74e7821418c00 Mon Sep 17 00:00:00 2001 From: "Garth N. Wells" Date: Fri, 23 Sep 2022 15:32:05 +0100 Subject: [PATCH 12/12] Simplifications and add Python interface --- cpp/dolfinx/io/ADIOS2Writers.cpp | 10 +++--- cpp/dolfinx/io/ADIOS2Writers.h | 20 ++++++------ python/dolfinx/wrappers/io.cpp | 52 +++++++++++++++----------------- 3 files changed, 40 insertions(+), 42 deletions(-) diff --git a/cpp/dolfinx/io/ADIOS2Writers.cpp b/cpp/dolfinx/io/ADIOS2Writers.cpp index 7042491ea5e..8c55529adad 100644 --- a/cpp/dolfinx/io/ADIOS2Writers.cpp +++ b/cpp/dolfinx/io/ADIOS2Writers.cpp @@ -703,7 +703,7 @@ void ADIOS2Writer::close() FidesWriter::FidesWriter(MPI_Comm comm, const std::filesystem::path& filename, std::shared_ptr mesh) : ADIOS2Writer(comm, filename, "Fides mesh writer", mesh), - _mesh_reuse_policy(MeshReusePolicy::DoNotReuse) + _mesh_reuse_policy(MeshPolicy::update) { assert(_io); assert(mesh); @@ -711,10 +711,9 @@ FidesWriter::FidesWriter(MPI_Comm comm, const std::filesystem::path& filename, } //----------------------------------------------------------------------------- FidesWriter::FidesWriter(MPI_Comm comm, const std::filesystem::path& filename, - const ADIOS2Writer::U& u, - const MeshReusePolicy mesh_reuse_policy) + const ADIOS2Writer::U& u, MeshPolicy policy) : ADIOS2Writer(comm, filename, "Fides function writer", u), - _mesh_reuse_policy(mesh_reuse_policy) + _mesh_reuse_policy(policy) { if (u.empty()) throw std::runtime_error("FidesWriter fem::Function list is empty"); @@ -790,10 +789,11 @@ void FidesWriter::write(double t) _engine->Put(var_step, t); if (auto v = _io->InquireVariable("connectivity"); - _mesh_reuse_policy == MeshReusePolicy::DoNotReuse or not v) + !v or _mesh_reuse_policy == MeshPolicy::update) { fides_write_mesh(*_io, *_engine, *_mesh); } + for (auto& v : _u) std::visit([&](const auto& u) { fides_write_data(*_io, *_engine, *u); }, v); diff --git a/cpp/dolfinx/io/ADIOS2Writers.h b/cpp/dolfinx/io/ADIOS2Writers.h index fcf24a70371..929ffca4430 100644 --- a/cpp/dolfinx/io/ADIOS2Writers.h +++ b/cpp/dolfinx/io/ADIOS2Writers.h @@ -112,10 +112,11 @@ class FidesWriter : public ADIOS2Writer { public: /// Mesh reuse policy - enum class MeshReusePolicy + enum class MeshPolicy { - DoNotReuse, - Reuse + update, ///< Re-write the mesh to file upon every write of a fem::Function + reuse ///< Write the mesh to file only the first time a fem::Function is + ///< written to file }; /// @brief Create Fides writer for a mesh @@ -133,12 +134,12 @@ class FidesWriter : public ADIOS2Writer /// @param[in] u List of functions. The functions must (1) share the /// same mesh (degree 1) and (2) be degree 1 Lagrange. @note All /// functions in `u` must share the same Mesh - /// @param[in] mesh_reuse_policy MeshReusePolicy::Reuse to save the - /// mesh only at the first write, MeshReusePolicy::DoNotReuse to - /// save the mesh at each write + /// @param[in] mesh_policy Controls if the mesh is written to file at + /// the first time step only or is re-written (updated) at each time + /// step. FidesWriter(MPI_Comm comm, const std::filesystem::path& filename, const ADIOS2Writer::U& u, - const MeshReusePolicy mesh_reuse_policy = MeshReusePolicy::DoNotReuse); + const MeshPolicy mesh_policy = MeshPolicy::update); // Copy constructor FidesWriter(const FidesWriter&) = delete; @@ -160,9 +161,8 @@ class FidesWriter : public ADIOS2Writer void write(double t); private: - /// @brief If true, the mesh is saved only at the first write and then reused, - /// otherwise the mesh will be saved at each write - MeshReusePolicy _mesh_reuse_policy; + // Control whether the mesh is written to file once or at every time step + MeshPolicy _mesh_reuse_policy; }; /// @brief Writer for meshes and functions using the ADIOS2 VTX format, see diff --git a/python/dolfinx/wrappers/io.cpp b/python/dolfinx/wrappers/io.cpp index 1add7162357..60fc4430391 100644 --- a/python/dolfinx/wrappers/io.cpp +++ b/python/dolfinx/wrappers/io.cpp @@ -95,9 +95,8 @@ void io(py::module& m) xdmf_file .def(py::init( - [](const MPICommWrapper comm, - const std::filesystem::path& filename, - const std::string& file_mode, + [](MPICommWrapper comm, std::filesystem::path filename, + std::string file_mode, dolfinx::io::XDMFFile::Encoding encoding) { return std::make_unique( @@ -113,8 +112,7 @@ void io(py::module& m) py::arg("xpath") = "/Xdmf/Domain") .def( "read_topology_data", - [](dolfinx::io::XDMFFile& self, const std::string& name, - const std::string& xpath) + [](dolfinx::io::XDMFFile& self, std::string name, std::string xpath) { auto [cells, shape] = self.read_topology_data(name, xpath); return as_pyarray(std::move(cells), shape); @@ -122,8 +120,7 @@ void io(py::module& m) py::arg("name") = "mesh", py::arg("xpath") = "/Xdmf/Domain") .def( "read_geometry_data", - [](dolfinx::io::XDMFFile& self, const std::string& name, - const std::string& xpath) + [](dolfinx::io::XDMFFile& self, std::string name, std::string xpath) { auto [x, shape] = self.read_geometry_data(name, xpath); return as_pyarray(std::move(x), shape); @@ -161,9 +158,8 @@ void io(py::module& m) py::class_>( m, "VTKFile") .def(py::init( - [](const MPICommWrapper comm, - const std::filesystem::path& filename, - const std::string& mode) { + [](MPICommWrapper comm, std::filesystem::path filename, + std::string mode) { return std::make_unique(comm.get(), filename, mode); }), @@ -181,13 +177,17 @@ void io(py::module& m) #ifdef HAS_ADIOS2 // dolfinx::io::FidesWriter - std::string pyclass_name = std::string("FidesWriter"); py::class_>(m, pyclass_name.c_str(), - "FidesWriter object") + std::shared_ptr> + fides_writer(m, "FidesWriter", "FidesWriter object"); + + py::enum_(fides_writer, "MeshPolicy") + .value("update", dolfinx::io::FidesWriter::MeshPolicy::update) + .value("reuse", dolfinx::io::FidesWriter::MeshPolicy::reuse); + + fides_writer .def(py::init( - [](const MPICommWrapper comm, - const std::filesystem::path& filename, + [](MPICommWrapper comm, std::filesystem::path filename, std::shared_ptr mesh) { return std::make_unique( @@ -195,17 +195,18 @@ void io(py::module& m) }), py::arg("comm"), py::arg("filename"), py::arg("mesh")) .def(py::init( - [](const MPICommWrapper comm, - const std::filesystem::path& filename, + [](MPICommWrapper comm, std::filesystem::path filename, const std::vector>, std::shared_ptr>>>>& u) + std::complex>>>>& u, + dolfinx::io::FidesWriter::MeshPolicy policy) { - return std::make_unique(comm.get(), - filename, u); + return std::make_unique( + comm.get(), filename, u, policy); }), - py::arg("comm"), py::arg("filename"), py::arg("u")) + py::arg("comm"), py::arg("filename"), py::arg("u"), + py::arg("policy") = dolfinx::io::FidesWriter::MeshPolicy::update) .def("close", [](dolfinx::io::FidesWriter& self) { self.close(); }) .def( "write", @@ -213,12 +214,10 @@ void io(py::module& m) py::arg("t")); // dolfinx::io::VTXWriter - pyclass_name = std::string("VTXWriter"); py::class_>( - m, pyclass_name.c_str(), "VTXWriter object") + m, "VTXWriter", "VTXWriter object") .def(py::init( - [](const MPICommWrapper comm, - const std::filesystem::path& filename, + [](MPICommWrapper comm, std::filesystem::path filename, std::shared_ptr mesh) { return std::make_unique( @@ -226,8 +225,7 @@ void io(py::module& m) }), py::arg("comm"), py::arg("filename"), py::arg("mesh")) .def(py::init( - [](const MPICommWrapper comm, - const std::filesystem::path& filename, + [](MPICommWrapper comm, std::filesystem::path filename, const std::vector>, std::shared_ptr