def test_rotation_axis(): body = cpt.RectangularParallelepiped(resolution=(4, 4, 4), center=(0, 0, -1), name="body") body.add_translation_dof(name="Sway") body.add_rotation_dof(axis=cpt.Axis(point=(0, 0, 0), vector=(0, 0, 1)), name="Yaw") l = 2.0 body.add_rotation_dof(axis=cpt.Axis(point=(l, 0, 0), vector=(0, 0, 1)), name="other_rotation") assert np.allclose(body.dofs['other_rotation'], (body.dofs['Yaw'] - l * body.dofs['Sway'])) problems = [ cpt.RadiationProblem(body=body, radiating_dof=dof, omega=1.0) for dof in body.dofs ] solver = cpt.Nemoh() results = solver.solve_all(problems, keep_details=True) dataset = cpt.assemble_dataset(results) sources = {result.radiating_dof: result.sources for result in results} assert np.allclose(sources['other_rotation'], sources['Yaw'] - l * sources['Sway'], atol=1e-4) potential = {result.radiating_dof: result.potential for result in results} assert np.allclose(potential['other_rotation'], potential['Yaw'] - l * potential['Sway'], atol=1e-4) A_m = dataset['added_mass'].sel(radiating_dof="other_rotation", influenced_dof="other_rotation").data A = dataset['added_mass'].sel(radiating_dof=["Yaw", "Sway"], influenced_dof=["Yaw", "Sway"]).data P = np.array([1, -l]) assert np.isclose(A_m, P.T @ A @ P)
def test_sum_of_dofs(): body1 = cpt.Sphere(radius=1.0, ntheta=3, nphi=12, center=(0, 0, -3), name="body1") body1.add_translation_dof(name="Heave") body2 = cpt.Sphere(radius=1.0, ntheta=3, nphi=8, center=(5, 3, -1.5), name="body2") body2.add_translation_dof(name="Heave") both = body1 + body2 both.add_translation_dof(name="Heave") problems = [ cpt.RadiationProblem(body=both, radiating_dof=dof, omega=1.0) for dof in both.dofs ] solver = cpt.Nemoh() results = solver.solve_all(problems) dataset = cpt.assemble_dataset(results) both_added_mass = dataset['added_mass'].sel(radiating_dof="Heave", influenced_dof="Heave").data body1_added_mass = dataset['added_mass'].sel( radiating_dof="body1__Heave", influenced_dof="body1__Heave").data body2_added_mass = dataset['added_mass'].sel( radiating_dof="body2__Heave", influenced_dof="body2__Heave").data assert np.allclose(both_added_mass, body1_added_mass + body2_added_mass, rtol=1e-2)
# Generate the mesh of a sphere full_sphere = cpt.Sphere( radius=3, center=(0, 0, 0), # Size and positions ntheta=20, nphi=20, # Fineness of the mesh ) full_sphere.add_translation_dof(name="Heave") # Keep only the immersed part of the mesh sphere = full_sphere.keep_immersed_part(inplace=False) sphere.add_translation_dof(name="Heave") # Set up and solve problem solver = cpt.Nemoh(use_symmetries=False) diffraction_problem = cpt.DiffractionProblem(body=sphere, wave_direction=0.0, omega=2.0) diffraction_result = solver.solve(diffraction_problem) radiation_problem = cpt.RadiationProblem(body=sphere, radiating_dof="Heave", omega=2.0) radiation_result = solver.solve(radiation_problem) # Define a mesh of the free surface and compute the free surface elevation free_surface = cpt.FreeSurface(x_range=(-50, 50), y_range=(-50, 50), nx=150,
[(0, 0, 1) for face in sphere.mesh.faces] ) # Bulging of the sphere, # that is a deformation vector normal to the body at all faces. # We can simply point to the normal vectors of the mesh for that. sphere.dofs["Bulge"] = sphere.mesh.faces_normals # Shearing of the sphere in the x direction. # The deformation vector on a face is computed from the position of the face. sphere.dofs["x-shear"] = np.array( [(np.cos(np.pi*z/2), 0, 0) for x, y, z in sphere.mesh.faces_centers] ) # SOLVE DIFFRACTION PROBLEMS solver = cpt.Nemoh() # Solve the problem for β=0 (incoming wave in the x direction). problem_1 = cpt.DiffractionProblem(body=sphere, wave_direction=0, omega=1.0) result_1 = solver.solve(problem_1) # Solve the problem for β=π/2 (incoming wave in the y direction). problem_2 = cpt.DiffractionProblem(body=sphere, wave_direction=np.pi/2, omega=1.0) result_2 = solver.solve(problem_2) # Print the generalized diffraction forces # for the three dofs we defined # for both values of the wave_direction β. for result in [result_1, result_2]: print(f"Angle: {result.wave_direction:.2f}") for dof in sphere.dofs:
#!/usr/bin/env python import capytaine as cpt # Generate the mesh of a cylinder cylinder = cpt.HorizontalCylinder( length=10.0, radius=1.0, # Dimensions center=(0, 0, -2), # Position nr=1, nx=8, ntheta=6, # Fineness of the mesh ) # Use Nemoh to compute the influence matrices solver = cpt.Nemoh(hierarchical_matrices=False) S, K = solver.build_matrices(cylinder.mesh, cylinder.mesh, wavenumber=1.0) # Plot the absolute value of the matrix V # import matplotlib.pyplot as plt plt.imshow(abs(S)) plt.colorbar() plt.title("$|S|$") plt.tight_layout() plt.show()
import logging from pathlib import Path import numpy as np from numpy import pi import capytaine as cpt from capytaine.ui.vtk import Animation logging.basicConfig(level=logging.INFO, format='%(levelname)-8s: %(message)s') bem_solver = cpt.Nemoh(linear_solver="gmres") def generate_boat() -> cpt.FloatingBody: boat = cpt.FloatingBody.from_file("boat_200.mar", file_format="mar", name="pirate ship") boat.rotate_z(pi) boat.add_all_rigid_body_dofs() boat.keep_immersed_part() # The computation of the RAO requires the values of the inertia matrix and the hydrostatic stiffness matrix. # They need to be computed independently. boat.mass = boat.add_dofs_labels_to_matrix([[1e4, 0, 0, 0, 0, 0], [0, 1e4, 0, 0, 0, 0], [0, 0, 1e4, 0, 0, 0], [0, 0, 0, 1e7, 0, 2e5], [0, 0, 0, 0, 4e7, 0], [0, 0, 0, 2e5, 0, 5e7]]) boat.hydrostatic_stiffness = boat.add_dofs_labels_to_matrix(