capytaine.bodies.bodies module

Floating bodies to be used in radiation-diffraction problems.

class capytaine.bodies.bodies.FloatingBody(mesh=None, dofs=None, mass=None, center_of_mass=None, name=None)[source]

Bases: ClippableMixin, Abstract3DObject

A floating body described as a mesh and some degrees of freedom.

The mesh structure is stored as a Mesh from capytaine.mesh.mesh or a CollectionOfMeshes from capytaine.mesh.meshes_collection.

The degrees of freedom (dofs) are stored as a dict associating a name to a complex-valued array of shape (nb_faces, 3). To each face of the body (as indexed in the mesh) corresponds a complex-valued 3d vector, which defines the displacement of the center of the face in frequency domain.

Parameters:
  • mesh (Mesh or CollectionOfMeshes, optional) – the mesh describing the geometry of the floating body. If none is given, a empty one is created.

  • dofs (dict, optional) – the degrees of freedom of the body. If none is given, a empty dictionary is initialized.

  • mass (float or None, optional) – the mass of the body in kilograms. Required only for some hydrostatics computation. If None, the mass is implicitly assumed to be the mass of displaced water.

  • center_of_mass (3-element array, optional) – the position of the center of mass. Required only for some hydrostatics computation.

  • name (str, optional) – a name for the body. If none is given, the one of the mesh is used.

add_all_rigid_body_dofs() None[source]

Add the six degrees of freedom of rigid bodies (in place).

add_dofs_labels_to_matrix(matrix)[source]

Helper function turning a bare matrix into a matrix labelled by the name of the dofs of the body, to be used for instance for the computation of RAO.

add_dofs_labels_to_vector(vector)[source]

Helper function turning a bare vector into a vector labelled by the name of the dofs of the body, to be used for instance for the computation of RAO.

add_rotation_dof(axis=None, name=None, amplitude=1.0) None[source]

Add a new rotation dof (in place). If no axis is given, the code tries to infer it from the name.

Parameters:
  • axis (Axis, optional) – the axis of the rotation

  • name (str, optional) – a name for the degree of freedom

  • amplitude (float, optional) – amplitude of the dof (default: 1.0)

add_translation_dof(direction=None, name=None, amplitude=1.0) None[source]

Add a new translation dof (in place). If no direction is given, the code tries to infer it from the name.

Parameters:
  • direction (array of shape (3,), optional) – the direction of the translation

  • name (str, optional) – a name for the degree of freedom

  • amplitude (float, optional) – amplitude of the dof (default: 1.0 m/s)

animate(motion, *args, **kwargs)[source]

Display a motion as a 3D animation.

Parameters:

motion (dict or pd.Series or str) – A dict or series mapping the name of the dofs to its amplitude. If a single string is passed, it is assumed to be the name of a dof and this dof with a unit amplitude will be displayed.

assemble_arbitrary_array(locations: ndarray)[source]
assemble_regular_array(distance, nb_bodies)[source]

Create an regular array of identical bodies.

Parameters:
  • distance (float) – Center-to-center distance between objects in the array

  • nb_bodies (couple of ints) – Number of objects in the x and y directions.

Return type:

FloatingBody

property center_of_buoyancy

Returns center of buoyancy of the FloatingBody.

clip(*args, inplace=True, name=None, **kwargs)
cluster_bodies(*, name=None)[source]

Builds a hierarchical clustering from a group of bodies

Parameters:
  • bodies (list) – a list of bodies

  • name (str, optional) – a name for the new body

Returns:

Array built from the provided bodies

Return type:

FloatingBody

static combine_dofs(bodies) dict[source]

Combine the degrees of freedom of several bodies.

compute_hydrostatic_stiffness(*, divergence=None, rho=1000.0, g=9.81)[source]

Compute hydrostatic stiffness matrix for all DOFs of the body.

\(C_{ij} = \rho g\iint_S (\hat{n} \cdot V_j) (w_i + z D_i) dS\)

where \(\hat{n}\) is surface normal,

\(V_i = u_i \hat{n}_x + v_i \hat{n}_y + w_i \hat{n}_z\) is DOF vector and

\(D_i = \nabla \cdot V_i\) is the divergence of the DOF.

Parameters:
  • divergence (dict mapping a dof name to an array of shape (nb_faces) or) – xarray.DataArray of shape (nb_dofs × nb_faces), optional Divergence of the DOFs, by default None

  • rho (float, optional) – Water density, by default 1000.0

  • g (float, optional) – Gravity acceleration, by default 9.81

Returns:

Matrix of hydrostatic stiffness

Return type:

xr.DataArray

Note

This function computes the hydrostatic stiffness assuming \(D_{i} = 0\). If \(D_i \neq 0\), input the divergence interpolated to face centers.

General integral equations are used for the rigid body modes and Neumann (1994) method is used for flexible modes.

References

Newman, John Nicholas. “Wave effects on deformable bodies.”Applied ocean research” 16.1 (1994): 47-59. http://resolver.tudelft.nl/uuid:0adff84c-43c7-43aa-8cd8-d4c44240bed8

compute_hydrostatics(*, rho=1000.0, g=9.81, divergence=None)[source]

Compute hydrostatics of the FloatingBody.

Parameters:
  • rho (float, optional) – Density of Water. The default is 1000.

  • g (float, optional) – Gravity acceleration. The default is 9.81.

  • divergence (np.ndarray, optional) – Divergence of the DOFs.

Returns:

hydrostatics – All hydrostatics values of the FloatingBody.

Return type:

dict

compute_rigid_body_inertia(*, rho=1000, output_type='body_dofs')[source]

Inertia Mass matrix of the body for 6 rigid DOFs.

Parameters:
  • rho (float, optional) – Density of water, by default 1000.0

  • output_type ({“body_dofs”, “rigid_dofs”, “all_dofs”}) – Type of DOFs for mass mat output, by default “body_dofs”.

Returns:

Inertia matrix

Return type:

xarray.DataArray

Raises:

ValueError – If output_type is not in {“body_dofs”, “rigid_dofs”, “all_dofs”}.

copy(name=None) FloatingBody[source]

Return a deep copy of the body.

Parameters:

name (str, optional) – a name for the new copy

disp_mass(*, rho=1000)[source]
dof_normals(dof)[source]

Returns dot product of the surface face normals and DOF

each_hydrostatic_stiffness(influenced_dof_name, radiating_dof_name, *, influenced_dof_div=0.0, rho=1000.0, g=9.81)[source]

Return the hydrostatic stiffness for a pair of DOFs.

\(C_{ij} = \rho g\iint_S (\hat{n} \cdot V_j) (w_i + z D_i) dS\)

where \(\hat{n}\) is surface normal,

\(V_i = u_i \hat{n}_x + v_i \hat{n}_y + w_i \hat{n}_z\) is DOF vector and

\(D_i = \nabla \cdot V_i\) is the divergence of the DOF.

Parameters:
  • influenced_dof_name (str) – Name of influenced DOF vector of the FloatingBody

  • radiating_dof_name (str) – Name of radiating DOF vector of the FloatingBody

  • influenced_dof_div (np.ndarray (Face_count), optional) – Influenced DOF divergence of the FloatingBody, by default 0.0.

  • rho (float, optional) – water density, by default 1000.0

  • g (float, optional) – Gravity acceleration, by default 9.81

Returns:

hs_ij – hydrostatic_stiffness of ith DOF and jth DOF.

Return type:

xarray.variable

Note

This function computes the hydrostatic stiffness assuming \(D_{i} = 0\). If \(D_i \neq 0\), input the divergence interpolated to face centers.

General integral equations are used for the rigid body modes and Neumann (1994) method is used for flexible modes.

References

Newman, John Nicholas. “Wave effects on deformable bodies.”Applied ocean research” 16.1 (1994): 47-59. http://resolver.tudelft.nl/uuid:0adff84c-43c7-43aa-8cd8-d4c44240bed8

extract_faces(id_faces_to_extract, return_index=False)[source]

Create a new FloatingBody by extracting some faces from the mesh. The dofs evolve accordingly.

static from_file(filename: str, file_format=None, name=None) FloatingBody[source]

Create a FloatingBody from a mesh file using meshmagick.

static from_meshio(mesh, name=None) FloatingBody[source]

Create a FloatingBody from a meshio mesh object.

integrate_pressure(pressure)[source]
join_bodies(*, name=None) FloatingBody[source]
keep_only_dofs(*args, inplace=True, name=None, **kwargs)
property longitudinal_metacentric_height

Returns longitudinal metacentric height of the mesh.

property longitudinal_metacentric_radius

Returns longitudinal metacentric radius of the mesh.

minced(nb_slices=(8, 8, 4))[source]

Experimental method decomposing the mesh as a hierarchical structure.

Parameters:

nb_slices (Tuple[int, int, int]) – The number of slices in each of the x, y and z directions. Only powers of 2 are supported at the moment.

Return type:

FloatingBody

property minimal_computable_wavelength

For accuracy of the resolution, wavelength should not be smaller than this value.

mirror(*args, inplace=True, name=None, **kwargs)
property nb_dofs: int

Number of degrees of freedom.

rotate(*args, inplace=True, name=None, **kwargs)
show(**kwargs)[source]
show_matplotlib(*args, **kwargs)[source]
sliced_by_plane(plane)[source]
surface_integral(data, **kwargs)[source]

Returns integral of given data along wet surface area.

translate(*args, inplace=True, name=None, **kwargs)
property transversal_metacentric_height

Returns transversal metacentric height of the mesh.

property transversal_metacentric_radius

Returns transversal metacentric radius of the mesh.

property volume

Returns volume of the FloatingBody.

property volumes

Returns volumes using x, y, z components of the FloatingBody.

property waterplane_area

Returns water plane area of the FloatingBody.

property waterplane_center

Returns water plane center of the FloatingBody.

Note: Returns None if the FloatingBody is full submerged.

waterplane_integral(data, **kwargs)[source]

Returns integral of given data along water plane area.

property wet_surface_area

Returns wet surface area.