Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reusing mesh when saving to Fides #2314

Merged
merged 39 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
95ba335
Allow to reuse mesh
Aug 8, 2022
c9366e6
Update doc
Aug 8, 2022
4ca7a32
Merge branch 'main' into mleoni/fides-reuse-mesh
massimiliano-leoni Aug 22, 2022
af85afb
Merge branch 'main' into mleoni/fides-reuse-mesh
massimiliano-leoni Aug 23, 2022
cb7e308
Merge branch 'main' into mleoni/fides-reuse-mesh
massimiliano-leoni Sep 6, 2022
0ea5890
Merge branch 'main' into mleoni/fides-reuse-mesh
jorgensd Sep 8, 2022
c0dffa4
Merge branch 'main' into mleoni/fides-reuse-mesh
garth-wells Sep 9, 2022
a7c50c6
Merge branch 'main' into mleoni/fides-reuse-mesh
massimiliano-leoni Sep 12, 2022
909e1d2
Decide on mesh reuse policy at construction time
massimiliano-leoni Sep 13, 2022
bf76ed7
More sensible behaviour
massimiliano-leoni Sep 13, 2022
e9fe150
Merge branch 'main' into mleoni/fides-reuse-mesh
massimiliano-leoni Sep 13, 2022
8e92560
Fix doc
massimiliano-leoni Sep 13, 2022
a09b1e4
Merge branch 'mleoni/fides-reuse-mesh' of github.com:massimiliano-leo…
massimiliano-leoni Sep 13, 2022
d02240c
Merge branch 'main' into mleoni/fides-reuse-mesh
massimiliano-leoni Sep 14, 2022
c247935
Merge branch 'main' into mleoni/fides-reuse-mesh
massimiliano-leoni Sep 19, 2022
fed7611
Fixing subtle bug
massimiliano-leoni Sep 20, 2022
fe6ed2e
Merge branch 'mleoni/fides-reuse-mesh' of github.com:massimiliano-leo…
massimiliano-leoni Sep 20, 2022
036a09b
Merge branch 'main' into mleoni/fides-reuse-mesh
massimiliano-leoni Sep 21, 2022
f09b235
Removing unnecessary bool flag and introducing enum
massimiliano-leoni Sep 21, 2022
7cb8a2d
Explicitly create string
massimiliano-leoni Sep 21, 2022
00c933a
I have no idea what I'm doing
massimiliano-leoni Sep 21, 2022
0156510
Finally got it
massimiliano-leoni Sep 21, 2022
b347112
Fix doc
massimiliano-leoni Sep 21, 2022
3e83b80
Merge remote-tracking branch 'origin/main' into mleoni/fides-reuse-mesh
garth-wells Sep 23, 2022
01969ee
Simplifications and add Python interface
garth-wells Sep 23, 2022
e1ba6c2
Merge branch 'main' into mleoni/fides-reuse-mesh
massimiliano-leoni Sep 29, 2022
f955e57
Merge branch 'main' into mleoni/fides-reuse-mesh
massimiliano-leoni Sep 29, 2022
ca15b85
Merge branch 'main' into mleoni/fides-reuse-mesh
massimiliano-leoni Oct 8, 2022
b843fdf
Merge branch 'main' into mleoni/fides-reuse-mesh
massimiliano-leoni Oct 11, 2022
1609adc
Merge branch 'main' into mleoni/fides-reuse-mesh
massimiliano-leoni Oct 11, 2022
db77adb
Merge branch 'main' into mleoni/fides-reuse-mesh
massimiliano-leoni Oct 11, 2022
5b3f1a2
Merge branch 'main' into mleoni/fides-reuse-mesh
massimiliano-leoni Oct 11, 2022
785f601
Merge branch 'main' into mleoni/fides-reuse-mesh
massimiliano-leoni Oct 17, 2022
270301c
Merge branch 'FEniCS:main' into mleoni/fides-reuse-mesh
massimiliano-leoni Oct 18, 2022
644f3a5
Merge branch 'main' into mleoni/fides-reuse-mesh
garth-wells Nov 7, 2022
505cc0a
Merge branch 'main' into mleoni/fides-reuse-mesh
massimiliano-leoni Nov 8, 2022
732e163
Merge branch 'main' into mleoni/fides-reuse-mesh
massimiliano-leoni Nov 14, 2022
964bef4
Merge branch 'main' into mleoni/fides-reuse-mesh
massimiliano-leoni Nov 14, 2022
54c0c63
Merge branch 'main' into mleoni/fides-reuse-mesh
garth-wells Nov 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions cpp/dolfinx/io/ADIOS2Writers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,16 +716,18 @@ void ADIOS2Writer::close()
//-----------------------------------------------------------------------------
FidesWriter::FidesWriter(MPI_Comm comm, const std::filesystem::path& filename,
std::shared_ptr<const mesh::Mesh> mesh)
: ADIOS2Writer(comm, filename, "Fides mesh writer", mesh)
: ADIOS2Writer(comm, filename, "Fides mesh writer", mesh),
_mesh_reuse_policy(MeshPolicy::update)
{
assert(_io);
assert(mesh);
fides_initialize_mesh_attributes(*_io, *mesh);
}
//-----------------------------------------------------------------------------
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");
Expand Down Expand Up @@ -800,7 +802,12 @@ void FidesWriter::write(double t)
adios2::Variable<double> var_step = define_variable<double>(*_io, "step");
_engine->Put<double>(var_step, t);

fides_write_mesh(*_io, *_engine, *_mesh);
if (auto v = _io->InquireVariable<std::int64_t>("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);

Expand Down
24 changes: 20 additions & 4 deletions cpp/dolfinx/io/ADIOS2Writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -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,
Expand Down
36 changes: 19 additions & 17 deletions python/dolfinx/wrappers/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,56 +177,58 @@ void io(py::module& m)

#ifdef HAS_ADIOS2
// dolfinx::io::FidesWriter
std::string pyclass_name = std::string("FidesWriter");
py::class_<dolfinx::io::FidesWriter,
std::shared_ptr<dolfinx::io::FidesWriter>>(m, pyclass_name.c_str(),
"FidesWriter object")
std::shared_ptr<dolfinx::io::FidesWriter>>
fides_writer(m, "FidesWriter", "FidesWriter object");

py::enum_<dolfinx::io::FidesWriter::MeshPolicy>(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<const dolfinx::mesh::Mesh> mesh)
{
return std::make_unique<dolfinx::io::FidesWriter>(
comm.get(), filename, mesh);
}),
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::variant<
std::shared_ptr<const dolfinx::fem::Function<float>>,
std::shared_ptr<const dolfinx::fem::Function<double>>,
std::shared_ptr<
const dolfinx::fem::Function<std::complex<float>>>,
std::shared_ptr<const dolfinx::fem::Function<
std::complex<double>>>>>& u)
std::complex<double>>>>>& u,
dolfinx::io::FidesWriter::MeshPolicy policy)
{
return std::make_unique<dolfinx::io::FidesWriter>(comm.get(),
filename, u);
return std::make_unique<dolfinx::io::FidesWriter>(
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",
[](dolfinx::io::FidesWriter& self, double t) { self.write(t); },
py::arg("t"));

// dolfinx::io::VTXWriter
pyclass_name = std::string("VTXWriter");
py::class_<dolfinx::io::VTXWriter, std::shared_ptr<dolfinx::io::VTXWriter>>(
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<const dolfinx::mesh::Mesh> mesh)
{
return std::make_unique<dolfinx::io::VTXWriter>(
comm.get(), filename, mesh);
}),
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::variant<
std::shared_ptr<const dolfinx::fem::Function<float>>,
std::shared_ptr<const dolfinx::fem::Function<double>>,
Expand Down