コード例 #1
0
    def generate_column(self):
        column = cpt.VerticalCylinder(length=self.height + 2,
                                      radius=self.radius,
                                      center=(0, 0, -self.height / 2),
                                      nx=50,
                                      ntheta=30,
                                      nr=8,
                                      clever=False)

        for k in range(self.mode_count):
            key_name = 'Flexure Mode ' + str(k)
            column.dofs[key_name] = np.array([
                self.cantilever_beam_flexure_mode_shape(x, y, z, mode_number=k)
                for x, y, z in column.mesh.faces_centers
            ])

        column.keep_immersed_part(sea_bottom=self.water_depth)

        column.mass = column.add_dofs_labels_to_matrix(self.mass_matrix())
        column.dissipation = column.add_dofs_labels_to_matrix(
            self.damping_matrix())
        column.hydrostatic_stiffness = column.add_dofs_labels_to_matrix(
            self.stiffness_matrix())

        self.column_mesh = column
コード例 #2
0
def test_non_neutrally_buoyant_inertia():
    body = cpt.VerticalCylinder(radius=1.0, length=1.0, center=(0.0, 0.0, -0.5), nx=20, ntheta=40, nr=20)
    body.add_all_rigid_body_dofs()
    body.keep_immersed_part()
    body.center_of_mass = (0.0, 0.0, -0.25)
    body.mass = body.volume * 500
    M = body.compute_rigid_body_inertia().values
    assert np.allclose(np.diag(M), np.array([1570, 1570, 1570, 936, 936, 801]), rtol=5e-2)
コード例 #3
0
def test_non_neutrally_buoyant_K55():
    body = cpt.VerticalCylinder(radius=1.0, length=1.0, center=(0.0, 0.0, -0.5), nx=20, ntheta=40, nr=20)
    body.add_all_rigid_body_dofs()
    body.keep_immersed_part()

    ref_data = pd.DataFrame([
        dict(body_density=1000, z_cog=-0.00, K55=-7.70e3),
        dict(body_density=1000, z_cog=-0.25, K55=5.0),
        dict(body_density=1000, z_cog=-0.50, K55=7.67e3),
        dict(body_density=500,  z_cog=-0.00, K55=-7.67e3),
        dict(body_density=500,  z_cog=-0.25, K55=-3.83e3),
        dict(body_density=500,  z_cog=-0.50, K55=5.0),
        ])
    ref_data['mass'] = body.volume * ref_data['body_density']

    rho_g = 1000*9.81
    for (i, case) in ref_data.iterrows():
        body.mass = case.mass
        body.center_of_mass = (0.0, 0.0, case.z_cog)
        K55 = body.compute_hydrostatic_stiffness().sel(influenced_dof="Pitch", radiating_dof="Pitch").values
        assert np.isclose(K55, case.K55, atol=rho_g*1e-2)
コード例 #4
0
def test_vertical_elastic_dof():

    bodies = [
        cpt.VerticalCylinder(
            length=10.0, radius=5.0,
            center=(0.0,0.0,0.0),
            nr=100, nx=100, ntheta=100,
        ),

        cpt.Sphere(
            radius=100,
            center=(0,0,0),
            nphi=50, ntheta=50,
        ),

        cpt.HorizontalCylinder(
            length=5.0, radius=1.0,
            center=(0,10,0),
            nr=20, nx=20, ntheta=10,
        )
    ]

    for body in bodies:
        body.center_of_mass = body.center_of_buoyancy
        body.keep_immersed_part()
        faces_centers = body.mesh.faces_centers
        body.dofs["elongate"] = np.zeros_like(faces_centers)
        body.dofs["elongate"][:,2] = faces_centers[:,2]

        divergence = np.ones(body.mesh.faces_centers.shape[0])

        density = 1000
        gravity = 9.80665
        capy_hs = body.each_hydrostatic_stiffness("elongate", "elongate",
                    influenced_dof_div=divergence, rho=density, g=gravity).values[0][0]

        analytical_hs = - (density * gravity * 4 * body.volume
                        * body.center_of_buoyancy[2])

        assert np.isclose(capy_hs, analytical_hs)
コード例 #5
0
def test_non_neutrally_buoyant_stiffness():
    body = cpt.VerticalCylinder(radius=1.0, length=1.0, center=(0.0, 0.0, -0.5), nx=20, ntheta=40, nr=20)
    body.add_all_rigid_body_dofs()
    body.keep_immersed_part()
    body.mass = 500 * body.volume
    body.center_of_mass = (0.0, 0.0, -0.25)

    K = body.compute_hydrostatic_stiffness()
    dofs = ["Heave", "Roll", "Pitch", "Yaw"]
    K = K.sel(influenced_dof=dofs, radiating_dof=dofs).values
    # K is now a 4x4 np.array in correct order

    rho_g = 1000*9.81
    K_ref = rho_g * np.array([
        [3.137, -0.382e-3, -0.613e-4, 0.0       ],
        [0.0,   -0.392,    -0.276e-4, -0.448e-4 ],
        [0.0,   0.0,       -0.392,    0.313e-3  ],
        [0.0,   0.0,       0.0,       0.0       ],
        ])  # Computed with WAMIT
    print(K)
    print(K_ref)
    assert np.allclose(K, K_ref, atol=rho_g*1e-2)
コード例 #6
0
def test_all_hydrostatics():
    density = 1000
    gravity = 9.80665

    sphere = cpt.Sphere(
        radius=10.0,
        center=(0,0,-1),
        nphi=100, ntheta=50,
    )
    horizontal_cylinder = cpt.HorizontalCylinder(
        length=10.0, radius=5.0,
        center=(0,10,-1),
        nr=100, nx=100, ntheta=10,
    )
    vertical_cylinder = cpt.VerticalCylinder(
        length=10.0, radius=5.0,
        center=(10,0,0),
        nr=200, nx=200, ntheta=10,
    )
    body = sphere + horizontal_cylinder + vertical_cylinder
    body.add_all_rigid_body_dofs()
    body.center_of_mass = body.center_of_buoyancy

    capy_hsdb = body.compute_hydrostatics(rho=density, g=gravity)

    stiff_compare_dofs = ["Heave", "Roll", "Pitch"]
    capy_hsdb["stiffness_matrix"] = capy_hsdb["hydrostatic_stiffness"].sel(
        influenced_dof=stiff_compare_dofs, radiating_dof=stiff_compare_dofs
        ).values

    mass_compare_dofs = ["Roll", "Pitch", "Yaw"]
    capy_hsdb["inertia_matrix"] = capy_hsdb["inertia_matrix"].sel(
        influenced_dof=mass_compare_dofs, radiating_dof=mass_compare_dofs
        ).values


    # =============================================================================
    # Meshmagick
    # =============================================================================
    case_dir = Path(__file__).parent / "Hydrostatics_cases"
    # case_dir.mkdir(parents=True, exist_ok=True)
    # import meshmagick.mesh as mmm
    # import meshmagick.hydrostatics as mmhs
    # body_mesh = mmm.Mesh(body.mesh.vertices, body.mesh.faces, name=body.mesh.name)
    # mm_hsdb = mmhs.compute_hydrostatics(body_mesh, body.center_of_mass, density, gravity)
    # mm_hsdb["inertia_matrix"] = body_mesh.eval_plain_mesh_inertias(
    # rho_medium=density).inertia_matrix
    # mm_hsdb["mesh"] = ""
    # with open(f'{case_dir}/sphere__hor_cyl__ver_cyl.pkl.json', 'w') as convert_file:
    #     mm_hsdb_json = {key:(value.tolist() if type(value)==np.ndarray else value)
    #                         for key, value in mm_hsdb.items() }
    #     convert_file.write(json.dumps(mm_hsdb_json))

    with open(f'{case_dir}/sphere__hor_cyl__ver_cyl.pkl.json', 'r',
              encoding="UTF-8") as f:
        mm_hsdb = json.load(f)

    # =============================================================================
    # Testing
    # =============================================================================

    for var in capy_hsdb.keys():
        if var in mm_hsdb.keys():
            # if not np.isclose(capy_hsdb[var], mm_hsdb[var],
            #                   rtol=1e-2, atol=1e-3).all():
            #     print(f"{var}:")
            #     print(f"    Capytaine  - {capy_hsdb[var]}")
            #     print(f"    Meshmagick - {mm_hsdb[var]}")
            assert np.isclose(capy_hsdb[var], mm_hsdb[var],
                              rtol=1e-2, atol=1e-3).all()
コード例 #7
0
ファイル: kochin.py プロジェクト: MRE-Code-Hub/Capytaine
import numpy as np
from numpy import pi
import xarray as xr
import matplotlib.pyplot as plt

import capytaine as cpt

logging.basicConfig(level=logging.INFO)

# SET UP THE MESH
buoy = cpt.VerticalCylinder(
    radius=1.0,
    length=3.0,
    center=(0, 0, -1.0),
    nx=15,
    ntheta=15,
    nr=3,
    clever=True,
)
buoy.keep_immersed_part()
buoy.add_translation_dof(name="Surge")

# SOLVE THE BEM PROBLEMS AND COMPUTE THE KOCHIN FUNCTIONS
theta_range = np.linspace(0, 2 * pi, 40)
omega_range = np.linspace(1.0, 5.0, 3)

test_matrix = xr.Dataset(coords={
    'omega': omega_range,
    'theta': theta_range,
    'radiating_dof': ["Surge"],
コード例 #8
0
ファイル: haskind.py プロジェクト: mancellin/capytaine
import numpy as np
import capytaine as cpt

r = 1.
draft = 0.5
depth = 10.
omega = 1.
rho = 1000

# Define geometry and heave degree of freedom
body = cpt.VerticalCylinder(
    length=2 * draft,
    radius=r,
    center=(0., 0., 0.),
    nx=10,
    nr=10,
    ntheta=50,
    clever=
    False,  # Do not use axial symmetry of the mesh (not really useful here)
)
body.keep_immersed_part()
body.add_translation_dof(name='Heave')

solver = cpt.BEMSolver()

# Define and solve the diffraction and radiation problems
diff_problem = cpt.DiffractionProblem(body=body,
                                      sea_bottom=-depth,
                                      omega=omega,
                                      wave_direction=0.)
rad_problem = cpt.RadiationProblem(body=body,