diff --git a/cpp/dolfinx/io/ADIOS2Writers.cpp b/cpp/dolfinx/io/ADIOS2Writers.cpp index 016a8270a1f..ec231fc4796 100644 --- a/cpp/dolfinx/io/ADIOS2Writers.cpp +++ b/cpp/dolfinx/io/ADIOS2Writers.cpp @@ -716,7 +716,8 @@ void ADIOS2Writer::close() //----------------------------------------------------------------------------- FidesWriter::FidesWriter(MPI_Comm comm, const std::filesystem::path& filename, std::shared_ptr mesh) - : ADIOS2Writer(comm, filename, "Fides mesh writer", mesh) + : ADIOS2Writer(comm, filename, "Fides mesh writer", mesh), + _mesh_reuse_policy(MeshPolicy::update) { assert(_io); assert(mesh); @@ -724,8 +725,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, MeshPolicy policy) + : ADIOS2Writer(comm, filename, "Fides function writer", u), + _mesh_reuse_policy(policy) { if (u.empty()) throw std::runtime_error("FidesWriter fem::Function list is empty"); @@ -800,7 +802,12 @@ 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 (auto v = _io->InquireVariable("connectivity"); + !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 f00d5ed8d09..8528c422fdc 100644 --- a/cpp/dolfinx/io/ADIOS2Writers.h +++ b/cpp/dolfinx/io/ADIOS2Writers.h @@ -112,9 +112,17 @@ class ADIOS2Writer class FidesWriter : public ADIOS2Writer { public: - /// @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. + /// Mesh reuse policy + enum class MeshPolicy + { + 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 + /// @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. /// @note The mesh geometry can be updated between write steps but the /// topology should not be changed between write steps. @@ -127,8 +135,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_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 ADIOS2Writer::U& u, + const MeshPolicy mesh_policy = MeshPolicy::update); // Copy constructor FidesWriter(const FidesWriter&) = delete; @@ -148,6 +160,10 @@ class FidesWriter : public ADIOS2Writer /// @brief Write data with a given time /// @param[in] t The time step void write(double t); + +private: + // 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, diff --git a/python/dolfinx/wrappers/io.cpp b/python/dolfinx/wrappers/io.cpp index 9afd201a200..971bd22710d 100644 --- a/python/dolfinx/wrappers/io.cpp +++ b/python/dolfinx/wrappers/io.cpp @@ -177,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( @@ -191,20 +195,21 @@ 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>, std::shared_ptr< const dolfinx::fem::Function>>, 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", @@ -212,12 +217,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( @@ -225,8 +228,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>,