capytaine / capytaine

Python BEM solver for linear potential flow, based on Nemoh.
https://capytaine.github.io
GNU General Public License v3.0
157 stars 75 forks source link

Handling Center of Mass and Buoyancy Point in Multibody Analysis Using Capytaine and WEC-Sim #600

Open mech2809 opened 23 hours ago

mech2809 commented 23 hours ago

When performing a multibody analysis (BEM) in Capytaine, the output file does not include the center of mass for each body. Instead, it assumes the center of the body to be at the origin (0, 0, 0) for all bodies. Similarly, do I need to specify the buoyancy point for each body in Capytaine, or is this something that should be added later in WEC-Sim?

Could you also provide an example code for this setup?

mancellin commented 14 hours ago

The support for center of mass and hydrostatics in multiple-body cases is a bit lacking in Capytaine currently (see also #188).

Indeed, the center of mass is not stored in the output dataset. Yet the hydrodynamical data might have been computed with another center than (0, 0, 0). You should either transmit the information to WEC-SIM yourself or use the legacy.export_hydrostatics function.

The center of buoyancy can be computed by Capytaine but it is not necessary for hydrodynamics. There is not automatic way to pass it from Capytaine to WEC-SIM at the moment.

Below is a code sample based on the Quickstart example from the documentation. It runs, but I did not check the soundness of the results, nor the import from WEC-SIM.

import numpy as np
import xarray as xr
import capytaine as cpt

body_1 = cpt.FloatingBody(
            mesh=cpt.mesh_sphere(center=(0, 0, 0)),
            dofs=cpt.rigid_body_dofs(rotation_center=(0, 0, 0)),
            center_of_mass=(0, 0, 0),
        )
body_1.inertia_matrix = body_1.compute_rigid_body_inertia()
body_1.hydrostatic_stiffness = body_1.immersed_part().compute_hydrostatic_stiffness()

body_2 = cpt.FloatingBody(
            mesh=cpt.mesh_sphere(center=(2, 0, 0)),
            dofs=cpt.rigid_body_dofs(rotation_center=(2, 0, 0)),
            center_of_mass=(2, 0, 0),
        )
body_2.inertia_matrix = body_2.compute_rigid_body_inertia()
body_2.hydrostatic_stiffness = body_2.immersed_part().compute_hydrostatic_stiffness()

all_bodies = body_1 + body_2
all_bodies = all_bodies.immersed_part()

# Set up paramaters
test_matrix = xr.Dataset({
        "omega": np.linspace(0.1, 2.0, 20),
        "wave_direction": np.linspace(0, np.pi, 3),
        "radiating_dof": list(all_bodies.dofs),
        "water_depth": [np.inf],
        "rho": [1025],
        })

solver = cpt.BEMSolver()
dataset = solver.fill_dataset(test_matrix, all_bodies)

from capytaine.io.xarray import separate_complex_values
separate_complex_values(dataset).to_netcdf("dataset.nc",
                                           encoding={'radiating_dof': {'dtype': 'U'},
                                                     'influenced_dof': {'dtype': 'U'}})

from capytaine.io.legacy import export_hydrostatics
export_hydrostatics("hydrostatics/", [body_1, body_2])