From 086a40beb80cb9f906b5887454819a22c5eb6d32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Simonis?= Date: Mon, 25 Nov 2024 10:10:34 +0100 Subject: [PATCH] Add API for runtime remeshing (#224) --- changelog-entries/224.md | 1 + cyprecice/Participant.pxd | 4 ++++ cyprecice/cyprecice.pyx | 36 ++++++++++++++++++++++++++++++++++++ test/Participant.cpp | 7 ++++++- test/test_bindings_module.py | 5 +++++ 5 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 changelog-entries/224.md diff --git a/changelog-entries/224.md b/changelog-entries/224.md new file mode 100644 index 00000000..088695ff --- /dev/null +++ b/changelog-entries/224.md @@ -0,0 +1 @@ +- Added API function `reset_mesh()` diff --git a/cyprecice/Participant.pxd b/cyprecice/Participant.pxd index ffe9783b..01614ce0 100644 --- a/cyprecice/Participant.pxd +++ b/cyprecice/Participant.pxd @@ -65,6 +65,10 @@ cdef extern from "precice/Participant.hpp" namespace "precice": void setMeshTetrahedra (const string& meshName, vector[int] vertices) + # remeshing + + void resetMesh (const string& meshName) + # data access void writeData (const string& meshName, const string& dataName, vector[int] vertices, vector[double] values) diff --git a/cyprecice/cyprecice.pyx b/cyprecice/cyprecice.pyx index 557e8f04..3349fead 100644 --- a/cyprecice/cyprecice.pyx +++ b/cyprecice/cyprecice.pyx @@ -710,6 +710,42 @@ cdef class Participant: self.thisptr.setMeshTetrahedra (convert(mesh_name), cpp_vertices) + # remeshing + + + def reset_mesh (self, mesh_name): + """ + Resets a mesh and allows setting it using set_mesh functions again. + + Parameters + ---------- + mesh_name : str + Name of the mesh to reset. + + Notes + ----- + This function is still experimental. + Please refer to the documentation on how to enable and use it. + + Previous calls: + advance() has been called + + Examples + -------- + Reset a mesh with 5 vertices to have 3 vertices. + + >>> positions = np.array([[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) + >>> mesh_name = "MeshOne" + >>> vertex_ids = participant.set_mesh_vertices(mesh_name, positions) + >>> # later in the coupling loop + >>> if remeshing_required(): + >>> participant.reset_mesh(mesh_name) + >>> positions = np.array([[1, 1], [3, 3], [5, 5]]) + >>> vertex_ids = participant.set_mesh_vertices(mesh_name, positions) + """ + + self.thisptr.resetMesh (convert(mesh_name)) + # data access def write_data (self, mesh_name, data_name, vertex_ids, values): diff --git a/test/Participant.cpp b/test/Participant.cpp index 8a36f2af..74107e9c 100644 --- a/test/Participant.cpp +++ b/test/Participant.cpp @@ -237,6 +237,11 @@ void Participant::setMeshTetrahedra precice::span vertices) {} +void Participant::resetMesh +( + precice::string_view meshName) +{} + void Participant:: writeData ( precice::string_view meshName, @@ -320,4 +325,4 @@ std::string getVersionInformation() return fake_version; } -} // namespace precice \ No newline at end of file +} // namespace precice diff --git a/test/test_bindings_module.py b/test/test_bindings_module.py index a34c3983..1f081f67 100644 --- a/test/test_bindings_module.py +++ b/test/test_bindings_module.py @@ -43,6 +43,11 @@ def test_requires_mesh_connectivity_for(self): fake_mesh_name = "FakeMesh" self.assertEqual(fake_bool, participant.requires_mesh_connectivity_for(fake_mesh_name)) + def test_reset_mesh(self): + participant = precice.Participant("test", "dummy.xml", 0, 1) + fake_mesh_name = "FakeMesh" + participant.reset_mesh(fake_mesh_name) + def test_set_mesh_vertices(self): participant = precice.Participant("test", "dummy.xml", 0, 1) fake_mesh_name = "FakeMesh" # compare to test/SolverInterface.cpp, fake_mesh_name