Skip to content

Commit

Permalink
Fix error message for non-neutrally-buoyant not-single-rigid-body case (
Browse files Browse the repository at this point in the history
  • Loading branch information
mancellin authored Oct 23, 2023
1 parent 8f29582 commit 27351c0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions capytaine/bodies/bodies.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,10 @@ def each_hydrostatic_stiffness(self, influenced_dof_name, radiating_dof_name, *,
else:
norm_hs_stiff = 0.0
else:
if self.mass is not None and np.isclose(self.mass, self.disp_mass(rho), rtol=1e-4):
if self.mass is not None and not np.isclose(self.mass, self.disp_mass(rho=rho), rtol=1e-4):
raise NotImplementedError(
f"Trying to compute the hydrostatic stiffness for dofs {radiating_dof_name} and {influenced_dof_name}"
f"of body {self.name}, which is not neutrally buoyant (mass={self.mass}, disp_mass={self.disp_mass(rho)}.\n"
f"of body {self.name}, which is not neutrally buoyant (mass={self.mass}, disp_mass={self.disp_mass(rho=rho)}).\n"
f"This case has not been implemented in Capytaine. You need either a single rigid body or a neutrally buoyant body."
)

Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Bug fixes

* Fix :meth:`~capytaine.bem.solver.BEMSolver.compute_pressure` that was broken and a relevant test. (:pull:`394`)

* Fix error message when computing hydrostatic stiffness of non-neutrally-buoyant body that is not a single rigid body. (:issue:`413` and :pull:`414`)

Internals
~~~~~~~~~

Expand Down
12 changes: 12 additions & 0 deletions pytest/test_hydrostatics.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,18 @@ def test_center_of_mass_joined_bodies_with_missing_mass():
b = cpt.FloatingBody(mass=300, center_of_mass=(1, 0, 0))
assert (a + b).center_of_mass is None

def test_not_single_rigid_and_non_neutrally_buoyant_body():
m = cpt.mesh_sphere()
a = cpt.FloatingBody(
mesh=m, mass=100, center_of_mass=(0, 0, 0),
dofs=cpt.rigid_body_dofs(rotation_center=(0, 0, 0)),
)
b = cpt.FloatingBody(
mesh=m.translated_x(2.0), mass=300, center_of_mass=(2, 0, 0),
dofs=cpt.rigid_body_dofs(rotation_center=(2, 0, 0)),
)
with pytest.raises(NotImplementedError):
(a + b).compute_hydrostatic_stiffness()

def test_non_neutrally_buoyant_stiffness():
body = cpt.VerticalCylinder(radius=1.0, length=2.0, center=(0.0, 0.0, 0.0), nx=40, ntheta=40, nr=20)
Expand Down

0 comments on commit 27351c0

Please sign in to comment.