Skip to content

Commit

Permalink
Add API for runtime remeshing (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsimonis authored Nov 25, 2024
1 parent b6b9ee5 commit 086a40b
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog-entries/224.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Added API function `reset_mesh()`
4 changes: 4 additions & 0 deletions cyprecice/Participant.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 36 additions & 0 deletions cyprecice/cyprecice.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 6 additions & 1 deletion test/Participant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ void Participant::setMeshTetrahedra
precice::span<const precice::VertexID> vertices)
{}

void Participant::resetMesh
(
precice::string_view meshName)
{}

void Participant:: writeData
(
precice::string_view meshName,
Expand Down Expand Up @@ -320,4 +325,4 @@ std::string getVersionInformation()
return fake_version;
}

} // namespace precice
} // namespace precice
5 changes: 5 additions & 0 deletions test/test_bindings_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 086a40b

Please sign in to comment.