def test_fill_dataset(): body = HorizontalCylinder(radius=1, center=(0, 0, -2)) body.add_all_rigid_body_dofs() test_matrix = xr.Dataset(coords={'omega': [1.0, 2.0, 3.0], 'wave_direction': [0, np.pi/2], 'radiating_dof': ['Heave']}) dataset = solver.fill_dataset(test_matrix, [body]) assert dataset['added_mass'].data.shape == (3, 1, 6) assert dataset['Froude_Krylov_force'].data.shape == (3, 2, 6)
def test_mincing(): body = HorizontalCylinder(length=10, radius=0.5, clever=False) body = body.minced((4, 1, 1)) assert len(body.mesh) == 2 assert np.all(body.mesh[0].faces_centers[:, 0] < 0) assert isinstance(body.mesh[0][0], Mesh) body = body.minced((1, 2, 2)) assert isinstance(body.mesh[0][0][0][0], Mesh)
def test_multibody(): """Compare with Nemoh 2.0 for two bodies.""" sphere = Sphere(radius=1.0, ntheta=5, nphi=20) sphere.translate_z(-2.0) sphere.add_translation_dof(direction=(1, 0, 0), name="Surge") sphere.add_translation_dof(direction=(0, 0, 1), name="Heave") cylinder = HorizontalCylinder(length=5.0, radius=1.0, nx=10, nr=1, ntheta=10) cylinder.translate([+1.5, 3.0, -3.0]) cylinder.add_translation_dof(direction=(1, 0, 0), name="Surge") cylinder.add_translation_dof(direction=(0, 0, 1), name="Heave") both = cylinder + sphere total_volume = cylinder.volume + sphere.volume # both.show() problems = [ RadiationProblem(body=both, radiating_dof=dof, omega=1.0) for dof in both.dofs ] problems += [DiffractionProblem(body=both, wave_direction=0.0, omega=1.0)] results = [solver.solve(problem) for problem in problems] data = assemble_dataset(results) data_from_nemoh_2 = np.array([ [ 3961.86548, 50.0367661, -3.32347107, 6.36901855E-02, 172.704819, 19.2018471, -5.67303181, -2.98873377 ], [ -3.08301544, 5.72392941E-02, 14522.1689, 271.796814, 128.413834, 6.03351116, 427.167358, 64.1587067 ], [ 161.125534, 17.8332844, 126.392113, 5.88006783, 2242.47412, 7.17850924, 1.29002571, 0.393169671 ], [ -5.02560759, -2.75930357, 419.927460, 63.3179016, 1.23501396, 0.416424811, 2341.57593, 15.8266096 ], ]) dofs_names = list(both.dofs.keys()) assert np.allclose(data['added_mass'].sel( omega=1.0, radiating_dof=dofs_names, influenced_dof=dofs_names).values, data_from_nemoh_2[:, ::2], atol=1e-3 * total_volume * problems[0].rho) assert np.allclose(data['radiation_damping'].sel( omega=1.0, radiating_dof=dofs_names, influenced_dof=dofs_names).values, data_from_nemoh_2[:, 1::2], atol=1e-3 * total_volume * problems[0].rho)
def test_dof_name_inference(): body = HorizontalCylinder() body.add_translation_dof(direction=(1, 0, 0), name="Surge_1") for dofname in ['Surge', 'SURGE', 'surge']: body.add_translation_dof(name=dofname) assert np.allclose(body.dofs[dofname], body.dofs['Surge_1']) body.add_rotation_dof(name="Pitch") body.add_rotation_dof(name="yaw") body.dofs.clear() body.add_all_rigid_body_dofs()
def test_horizontal_cylinder(depth): cylinder = HorizontalCylinder(length=10.0, radius=1.0, reflection_symmetry=False, translation_symmetry=False, nr=2, ntheta=10, nx=10) assert isinstance(cylinder.mesh, Mesh) cylinder.translate_z(-3.0) cylinder.add_translation_dof(direction=(0, 0, 1), name="Heave") problem = RadiationProblem(body=cylinder, omega=1.0, sea_bottom=-depth) result1 = solver_with_sym.solve(problem) trans_cylinder = HorizontalCylinder(length=10.0, radius=1.0, reflection_symmetry=False, translation_symmetry=True, nr=2, ntheta=10, nx=10) assert isinstance(trans_cylinder.mesh, CollectionOfMeshes) assert isinstance(trans_cylinder.mesh[0], TranslationalSymmetricMesh) trans_cylinder.translate_z(-3.0) trans_cylinder.add_translation_dof(direction=(0, 0, 1), name="Heave") problem = RadiationProblem(body=trans_cylinder, omega=1.0, sea_bottom=-depth) result2 = solver_with_sym.solve(problem) # S, V = solver_with_sym.build_matrices(trans_cylinder.mesh, trans_cylinder.mesh) # S.plot_shape() assert np.isclose(result1.added_masses["Heave"], result2.added_masses["Heave"], atol=1e-4*cylinder.volume*problem.rho) assert np.isclose(result1.radiation_dampings["Heave"], result2.radiation_dampings["Heave"], atol=1e-4*cylinder.volume*problem.rho)
def test_cylinder(): HorizontalCylinder() VerticalCylinder()