From 159003658c965ce72cf8b1e41a2b0679f247edf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Simonis?= Date: Tue, 23 Apr 2024 14:53:52 +0200 Subject: [PATCH 1/5] Add API for runtime remeshing. --- cyprecice/Participant.pxd | 4 ++++ cyprecice/cyprecice.pyx | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) 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..6b5c3f66 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() been called + + Examples + -------- + Set mesh vertices for a 2D problem with 5 mesh 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): From 49c9cc68ba79378bd892e3fae54e500be09ea9fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Simonis?= Date: Mon, 4 Nov 2024 17:43:35 +0100 Subject: [PATCH 2/5] Add changelog --- changelog-entries/224.md | 1 + 1 file changed, 1 insertion(+) 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()` From 36bbd5babd9b5783b1ab47075e2092938e54ce52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Simonis?= Date: Tue, 5 Nov 2024 09:51:05 +0100 Subject: [PATCH 3/5] Add resetMesh to mock --- test/Participant.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 From 64a49afcbf9b32395e52d50bfa6564bde6b7341b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Simonis?= Date: Fri, 22 Nov 2024 16:14:30 +0100 Subject: [PATCH 4/5] Fix wording Co-authored-by: Benjamin Uekermann Co-authored-by: Ishaan Desai --- cyprecice/cyprecice.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cyprecice/cyprecice.pyx b/cyprecice/cyprecice.pyx index 6b5c3f66..3349fead 100644 --- a/cyprecice/cyprecice.pyx +++ b/cyprecice/cyprecice.pyx @@ -728,11 +728,11 @@ cdef class Participant: Please refer to the documentation on how to enable and use it. Previous calls: - advance() been called + advance() has been called Examples -------- - Set mesh vertices for a 2D problem with 5 mesh vertices. + 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" From 841c57f7e13d261139ed6bee84c5b558fa25a663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Simonis?= Date: Fri, 22 Nov 2024 16:16:21 +0100 Subject: [PATCH 5/5] Add mock test for reset_mesh --- test/test_bindings_module.py | 5 +++++ 1 file changed, 5 insertions(+) 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