Skip to content

Commit

Permalink
Always heal mesh on initialization of a FloatingBody (#83)
Browse files Browse the repository at this point in the history
* Define heal_mesh for collections of meshes.
* Always heal mesh when initializing a FloatingBody.
* Do not try to correct normals on CollectionOfMeshes
Because, you can't assume that each individual piece of mesh is closed (in general).
  • Loading branch information
mancellin committed Jul 28, 2021
1 parent e1573c4 commit 6b8dc62
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
6 changes: 5 additions & 1 deletion capytaine/bodies/bodies.py
Expand Up @@ -62,7 +62,11 @@ def __init__(self, mesh=None, dofs=None, name=None):
self.dofs = dofs
self.name = name

LOG.info(f"New floating body: {self.name}.")
if self.mesh.nb_vertices == 0 or self.mesh.nb_faces == 0:
LOG.warning(f"New floating body (with empty mesh!): {self.name}.")
else:
self.mesh.heal_mesh()
LOG.info(f"New floating body: {self.name}.")

@staticmethod
def from_file(filename: str, file_format=None, name=None) -> 'FloatingBody':
Expand Down
5 changes: 5 additions & 0 deletions capytaine/meshes/collections.py
Expand Up @@ -97,6 +97,11 @@ def copy(self, name=None):
new_mesh.name = name
return new_mesh

@inplace_transformation
def heal_mesh(self, closed_mesh=False):
for mesh in self:
mesh.heal_mesh(closed_mesh=closed_mesh)

##############
# Properties #
##############
Expand Down
5 changes: 3 additions & 2 deletions capytaine/meshes/meshes.py
Expand Up @@ -724,7 +724,7 @@ def remove_degenerated_faces(self, **kwargs):
return remove_degenerated_faces(self, **kwargs)

@inplace_transformation
def heal_mesh(self):
def heal_mesh(self, closed_mesh=True):
"""Heals the mesh for different tests available.
It applies:
Expand All @@ -739,7 +739,8 @@ def heal_mesh(self):
self.remove_degenerated_faces()
self.merge_duplicates()
self.heal_triangles()
self.heal_normals()
if closed_mesh:
self.heal_normals()
return self

#################
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.rst
Expand Up @@ -7,6 +7,11 @@ New in next version
---------------------------------

* Add method :code:`FloatingBody.assemble_arbitrary_array` to make an array of bodies with arbitrary layout.

* The mesh are always "healed" when a new :code:`FloatingBody` is initialised
(i.e. unused vertices are removed, degenerate triangles are removed, etc.).
See for instance `issue #46 <https://github.com/mancellin/capytaine/issues/46>`_.

* Add example in cookbook for computing hydrostatics and mass properties
* Use pytest skipif to skip tests if optional dependecies are not installed
* Break out impedance from RAO to separate function (see #61`<https://github.com/mancellin/capytaine/issues/61>`_ and (see #63`<https://github.com/mancellin/capytaine/pull/63>`_)
Expand Down
2 changes: 1 addition & 1 deletion pytest/test_bem_problems_and_results.py
Expand Up @@ -157,7 +157,7 @@ def test_import_cal_file():
assert problem.depth == np.infty
assert isinstance(problem.body, FloatingBody)
assert problem.body.nb_dofs == 6
assert problem.body.mesh.nb_vertices == 351
assert problem.body.mesh.nb_vertices == 299 # Duplicate vertices are removed during import.
assert problem.body.mesh.nb_faces == 280
assert problem.omega in np.linspace(0.1, 2.0, 41)
if isinstance(problem, DiffractionProblem):
Expand Down

0 comments on commit 6b8dc62

Please sign in to comment.