Exemplo n.º 1
0
def test_low_rank_matrices():
    radius = 1.0
    resolution = 2
    perimeter = 2 * np.pi * radius
    buoy = Sphere(radius=radius,
                  center=(0.0, 0.0, 0.0),
                  ntheta=int(perimeter * resolution / 2),
                  nphi=int(perimeter * resolution),
                  clip_free_surface=True,
                  clever=False,
                  name=f"buoy")
    buoy.add_translation_dof(name="Heave")
    two_distant_buoys = FloatingBody.join_bodies(buoy, buoy.translated_x(20))
    two_distant_buoys.mesh._meshes[1].name = "other_buoy_mesh"

    S, V = solver_with_sym.build_matrices(two_distant_buoys.mesh,
                                          two_distant_buoys.mesh)
    assert isinstance(S.all_blocks[0, 1], LowRankMatrix)
    assert isinstance(S.all_blocks[1, 0], LowRankMatrix)
    # S.plot_shape()

    problem = RadiationProblem(body=two_distant_buoys,
                               omega=1.0,
                               radiating_dof="buoy__Heave")
    result = solver_with_sym.solve(problem)
    result2 = solver_without_sym.solve(problem)

    assert np.isclose(result.added_masses['buoy__Heave'],
                      result2.added_masses['buoy__Heave'],
                      atol=10.0)
    assert np.isclose(result.radiation_dampings['buoy__Heave'],
                      result2.radiation_dampings['buoy__Heave'],
                      atol=10.0)
Exemplo n.º 2
0
def test_floating_sphere_finite_depth():
    """Compare with Nemoh 2.0 for some cases of a heaving sphere at the free surface in finite depth."""
    sphere = Sphere(radius=1.0, ntheta=3, nphi=12, clip_free_surface=True)
    sphere.add_translation_dof(direction=(0, 0, 1), name="Heave")

    # omega = 1, radiation
    problem = RadiationProblem(body=sphere, omega=1.0, radiating_dof="Heave", sea_bottom=-10.0)
    result = solver.solve(problem, keep_details=True)
    assert np.isclose(result.added_masses["Heave"],       1740.6, atol=1e-3*sphere.volume*problem.rho)
    assert np.isclose(result.radiation_dampings["Heave"], 380.46, atol=1e-3*sphere.volume*problem.rho)

    kochin = compute_kochin(result, np.linspace(0, np.pi, 3))
    assert np.allclose(kochin, np.roll(kochin, 1))  # The far field is the same in all directions.
    assert np.isclose(kochin[0], -0.2267+3.49e-3j, rtol=1e-3)

    # omega = 1, diffraction
    problem = DiffractionProblem(body=sphere, omega=1.0, wave_direction=0.0, sea_bottom=-10.0)
    result = solver.solve(problem)
    assert np.isclose(result.forces["Heave"], 1749.4 * np.exp(-2.922j), rtol=1e-3)

    # omega = 2, radiation
    problem = RadiationProblem(body=sphere, omega=2.0, radiating_dof="Heave", sea_bottom=-10.0)
    result = solver.solve(problem)
    assert np.isclose(result.added_masses["Heave"],       1375.0, atol=1e-3*sphere.volume*problem.rho)
    assert np.isclose(result.radiation_dampings["Heave"], 1418.0, atol=1e-3*sphere.volume*problem.rho)

    # omega = 2, diffraction
    problem = DiffractionProblem(body=sphere, omega=2.0, wave_direction=0.0, sea_bottom=-10.0)
    result = solver.solve(problem)
    assert np.isclose(result.forces["Heave"], 5872.8 * np.exp(-2.627j), rtol=1e-3)
Exemplo n.º 3
0
def test_alien_sphere():
    """Compare with Nemoh 2.0 for some cases of a heaving sphere at the free surface in infinite depth
    for a non-usual gravity and density."""
    sphere = Sphere(radius=1.0, ntheta=3, nphi=12, clip_free_surface=True)
    sphere.add_translation_dof(direction=(0, 0, 1), name="Heave")
    sphere.add_translation_dof(direction=(1, 0, 0), name="Surge")

    # radiation
    problem = RadiationProblem(body=sphere,
                               rho=450.0,
                               g=1.625,
                               omega=1.0,
                               radiating_dof="Heave")
    result = solver.solve(problem)
    assert np.isclose(result.added_masses["Heave"],
                      515,
                      atol=1e-3 * sphere.volume * problem.rho)
    assert np.isclose(result.radiation_dampings["Heave"],
                      309,
                      atol=1e-3 * sphere.volume * problem.rho)

    # diffraction
    problem = DiffractionProblem(body=sphere,
                                 rho=450.0,
                                 g=1.625,
                                 omega=1.0,
                                 sea_bottom=-np.infty)
    result = solver.solve(problem)
    assert np.isclose(result.forces["Heave"],
                      548.5 * np.exp(-2.521j),
                      rtol=1e-2)
Exemplo n.º 4
0
def test_two_distant_spheres_in_finite_depth():
    radius = 0.5
    resolution = 4
    perimeter = 2 * np.pi * radius
    buoy = Sphere(radius=radius,
                  center=(0.0, 0.0, 0.0),
                  ntheta=int(perimeter * resolution / 2),
                  nphi=int(perimeter * resolution),
                  clip_free_surface=True,
                  clever=False,
                  name="buoy")
    other_buoy = buoy.translated_x(20, name="other_buoy")
    both_buoys = buoy.join_bodies(other_buoy)
    both_buoys.add_translation_dof(name="Surge")
    problem = RadiationProblem(body=both_buoys,
                               radiating_dof="Surge",
                               sea_bottom=-10,
                               omega=7.0)
    result = solver.solve(problem)

    total_volume = 2 * 4 / 3 * np.pi * radius**3
    assert np.isclose(result.added_masses['Surge'],
                      124.0,
                      atol=1e-3 * total_volume * problem.rho)
    assert np.isclose(result.radiation_dampings['Surge'],
                      913.3,
                      atol=1e-3 * total_volume * problem.rho)
Exemplo n.º 5
0
def test_sphere_clipping():
    s1 = Sphere(ntheta=4, nphi=4, axial_symmetry=False, clip_free_surface=True)
    s2 = Sphere(ntheta=8,
                nphi=4,
                axial_symmetry=False,
                clip_free_surface=False).keep_immersed_part()
    assert s1.mesh.nb_faces == s2.mesh.nb_faces
    assert s1.mesh.nb_vertices == s2.mesh.nb_vertices
Exemplo n.º 6
0
def test_LinearPotentialFlowProblem():
    # Without a body
    pb = LinearPotentialFlowProblem(omega=1.0)
    assert pb.omega == 1.0
    assert pb.period == 2 * np.pi
    assert pb.wavenumber == 1.0 / 9.81
    assert pb.wavelength == 9.81 * 2 * np.pi

    assert LinearPotentialFlowProblem(free_surface=np.infty,
                                      sea_bottom=-np.infty).depth == np.infty
    assert LinearPotentialFlowProblem(free_surface=0.0,
                                      sea_bottom=-np.infty).depth == np.infty

    pb = LinearPotentialFlowProblem(free_surface=0.0,
                                    sea_bottom=-1.0,
                                    omega=1.0)
    assert pb.depth == 1.0
    assert np.isclose(pb.omega**2,
                      pb.g * pb.wavenumber * np.tanh(pb.wavenumber * pb.depth))
    assert pb.dimensionless_wavenumber == pb.wavenumber * 1.0

    with pytest.raises(NotImplementedError):
        LinearPotentialFlowProblem(free_surface=2.0)

    with pytest.raises(NotImplementedError):
        LinearPotentialFlowProblem(free_surface=np.infty, sea_bottom=0.0)

    with pytest.raises(ValueError):
        LinearPotentialFlowProblem(free_surface=0.0, sea_bottom=1.0)

    with pytest.raises(TypeError):
        LinearPotentialFlowProblem(wave_direction=1.0)

    with pytest.raises(TypeError):
        LinearPotentialFlowProblem(radiating_dof="Heave")

    with pytest.raises(ValueError):
        LinearPotentialFlowProblem(body=FloatingBody(mesh=Mesh([], [])))

    # With a body
    sphere = Sphere(center=(0, 0, -2.0))
    sphere.add_translation_dof(direction=(0, 0, 1), name="Heave")
    pb = LinearPotentialFlowProblem(body=sphere, omega=1.0)
    pb.boundary_condition = sphere.mesh.faces_normals @ (1, 1, 1)
    assert list(pb.influenced_dofs.keys()) == ['Heave']

    pb2 = LinearPotentialFlowProblem(body=sphere, omega=2.0)
    pb2.boundary_condition = sphere.mesh.faces_normals @ (1, 1, 1)
    assert pb < pb2

    # Test transformation to result class
    res = pb.make_results_container()
    assert isinstance(res, LinearPotentialFlowResult)
    assert res.problem is pb
    assert res.omega == pb.omega
    assert res.period == pb.period
    assert res.body is pb.body
Exemplo n.º 7
0
def test_floating_sphere_finite_freq():
    """Compare with Nemoh 2.0 for some cases of a heaving sphere at the free surface in infinite depth."""
    sphere = Sphere(radius=1.0, ntheta=3, nphi=12, clip_free_surface=True)
    sphere.add_translation_dof(direction=(0, 0, 1), name="Heave")

    # omega = 1, radiation
    problem = RadiationProblem(body=sphere, omega=1.0, sea_bottom=-np.infty)
    result = solver.solve(problem, keep_details=True)
    assert np.isclose(result.added_masses["Heave"],       1819.6, atol=1e-3*sphere.volume*problem.rho)
    assert np.isclose(result.radiation_dampings["Heave"], 379.39, atol=1e-3*sphere.volume*problem.rho)

    # omega = 1, free surface
    free_surface = FreeSurface(x_range=(-62.5, 62.5), nx=5, y_range=(-62.5, 62.5), ny=5)
    eta = solver.get_free_surface_elevation(result, free_surface)
    ref = np.array(
            [[-0.4340802E-02-0.4742809E-03j, -0.7986111E-03+0.4840984E-02j, 0.2214827E-02+0.4700642E-02j, -0.7986111E-03+0.4840984E-02j, -0.4340803E-02-0.4742807E-03j],
             [-0.7986111E-03+0.4840984E-02j, 0.5733187E-02-0.2179381E-02j, 0.9460892E-03-0.7079404E-02j, 0.5733186E-02-0.2179381E-02j, -0.7986110E-03+0.4840984E-02j],
             [0.2214827E-02+0.4700643E-02j, 0.9460892E-03-0.7079403E-02j, -0.1381670E-01+0.6039315E-01j, 0.9460892E-03-0.7079405E-02j, 0.2214827E-02+0.4700643E-02j],
             [-0.7986111E-03+0.4840984E-02j, 0.5733186E-02-0.2179381E-02j, 0.9460891E-03-0.7079404E-02j, 0.5733187E-02-0.2179380E-02j, -0.7986113E-03+0.4840984E-02j],
             [-0.4340803E-02-0.4742807E-03j, -0.7986111E-03+0.4840984E-02j, 0.2214827E-02+0.4700643E-02j, -0.7986113E-03+0.4840983E-02j, -0.4340803E-02-0.4742809E-03j]]
        )
    assert np.allclose(eta.reshape((5, 5)), ref, rtol=1e-4)

    # omega = 1, diffraction
    problem = DiffractionProblem(body=sphere, omega=1.0, sea_bottom=-np.infty)
    result = solver.solve(problem, keep_details=True)
    assert np.isclose(result.forces["Heave"], 1834.9 * np.exp(-2.933j), rtol=1e-3)

    # omega = 1, Kochin function of diffraction problem

    kochin = compute_kochin(result, np.linspace(0, np.pi, 10))

    ref_kochin = np.array([
        0.20229*np.exp(-1.5872j), 0.20369*np.exp(-1.5871j),
        0.20767*np.exp(-1.5868j), 0.21382*np.exp(-1.5863j),
        0.22132*np.exp(-1.5857j), 0.22931*np.exp(-1.5852j),
        0.23680*np.exp(-1.5847j), 0.24291*np.exp(-1.5843j),
        0.24688*np.exp(-1.5841j), 0.24825*np.exp(-1.5840j),
        ])

    assert np.allclose(kochin, ref_kochin, rtol=1e-3)

    # omega = 2, radiation
    problem = RadiationProblem(body=sphere, omega=2.0, sea_bottom=-np.infty)
    result = solver.solve(problem)
    assert np.isclose(result.added_masses["Heave"],       1369.3, atol=1e-3*sphere.volume*problem.rho)
    assert np.isclose(result.radiation_dampings["Heave"], 1425.6, atol=1e-3*sphere.volume*problem.rho)

    # omega = 2, diffraction
    problem = DiffractionProblem(body=sphere, omega=2.0, sea_bottom=-np.infty)
    result = solver.solve(problem)
    assert np.isclose(result.forces["Heave"], 5846.6 * np.exp(-2.623j), rtol=1e-3)
Exemplo n.º 8
0
def sphere_fb():
    sphere = Sphere(radius=r, ntheta=3, nphi=12, clip_free_surface=True)
    sphere.add_all_rigid_body_dofs()

    sphere.inertia_matrix = sphere.add_dofs_labels_to_matrix(M)
    sphere.hydrostatic_stiffness = sphere.add_dofs_labels_to_matrix(kHS)

    return sphere
Exemplo n.º 9
0
def test_clipping_of_dofs(z_center, collection_of_meshes):
    """Check that clipping a body with a dof is the same as clipping the body ant then adding the dof."""
    full_sphere = Sphere(center=(0, 0, z_center), name="sphere", clever=collection_of_meshes, clip_free_surface=False)
    axis = Axis(point=(1, 0, 0), vector=(1, 0, 0))

    full_sphere.add_rotation_dof(axis, name="test_dof")
    clipped_sphere = full_sphere.keep_immersed_part(free_surface=0.0, sea_bottom=-np.infty, inplace=False)

    other_clipped_sphere = FloatingBody(mesh=clipped_sphere.mesh, name="other_sphere")
    other_clipped_sphere.add_rotation_dof(axis, name="test_dof")

    if clipped_sphere.mesh.nb_faces > 0:
        assert np.allclose(clipped_sphere.dofs['test_dof'], other_clipped_sphere.dofs['test_dof'])
    else:
        assert len(clipped_sphere.dofs['test_dof']) == 0
Exemplo n.º 10
0
def test_Froude_Krylov():
    from capytaine.bem.airy_waves import froude_krylov_force
    from capytaine.bodies.predefined.spheres import Sphere
    from capytaine.bem.problems_and_results import DiffractionProblem

    sphere = Sphere(radius=1.0, ntheta=3, nphi=12, clever=True, clip_free_surface=True)
    sphere.add_translation_dof(direction=(0, 0, 1), name="Heave")

    problem = DiffractionProblem(body=sphere, omega=1.0, sea_bottom=-np.infty)
    assert np.isclose(froude_krylov_force(problem)['Heave'], 27596, rtol=1e-3)

    problem = DiffractionProblem(body=sphere, omega=2.0, sea_bottom=-np.infty)
    assert np.isclose(froude_krylov_force(problem)['Heave'], 22491, rtol=1e-3)

    problem = DiffractionProblem(body=sphere, omega=1.0, sea_bottom=-10.0)
    assert np.isclose(froude_krylov_force(problem)['Heave'], 27610, rtol=1e-3)
Exemplo n.º 11
0
def test_diffraction_problem():
    assert DiffractionProblem().body is None

    sphere = Sphere(radius=1.0, ntheta=20, nphi=40)
    sphere.add_translation_dof(direction=(0, 0, 1), name="Heave")

    pb = DiffractionProblem(body=sphere, wave_direction=1.0)
    assert len(pb.boundary_condition) == sphere.mesh.nb_faces

    with pytest.raises(TypeError):
        DiffractionProblem(boundary_conditions=[0, 0, 0])

    assert "DiffractionProblem" in str(DiffractionProblem(g=10, rho=1025, free_surface=np.infty))

    res = pb.make_results_container()
    assert isinstance(res, DiffractionResult)
Exemplo n.º 12
0
def test_assemble_dataset():
    body = Sphere(center=(0, 0, -4), name="sphere")
    body.add_translation_dof(name="Heave")

    pb_1 = DiffractionProblem(body=body, wave_direction=1.0, omega=1.0)
    res_1 = solver.solve(pb_1)
    ds1 = assemble_dataset([res_1])
    assert "Froude_Krylov_force" in ds1

    pb_2 = RadiationProblem(body=body, radiating_dof="Heave", omega=1.0)
    res_2 = solver.solve(pb_2)
    ds2 = assemble_dataset([res_2])
    assert "added_mass" in ds2

    ds12 = assemble_dataset([res_1, res_2])
    assert "Froude_Krylov_force" in ds12
    assert "added_mass" in ds12
Exemplo n.º 13
0
def test_immersed_sphere():
    """Compare with Nemoh 2.0 for a sphere in infinite fluid.

    The test is ran for two degrees of freedom; due to the symmetries of the problem, the results should be the same.
    They are actually slightly different due to the meshing of the sphere.
    """
    sphere = Sphere(radius=1.0, ntheta=10, nphi=40, clip_free_surface=False)
    sphere.add_translation_dof(direction=(1, 0, 0), name="Surge")
    sphere.add_translation_dof(direction=(0, 0, 1), name="Heave")

    problem = RadiationProblem(body=sphere,
                               radiating_dof="Heave",
                               free_surface=np.infty,
                               sea_bottom=-np.infty)
    result = solver.solve(problem)
    assert np.isclose(result.added_masses["Heave"],
                      2187,
                      atol=1e-3 * sphere.volume * problem.rho)
    assert np.isclose(result.added_masses["Surge"],
                      0.0,
                      atol=1e-3 * sphere.volume * problem.rho)
    assert np.isclose(result.radiation_dampings["Heave"],
                      0.0,
                      atol=1e-3 * sphere.volume * problem.rho)
    assert np.isclose(result.radiation_dampings["Surge"],
                      0.0,
                      atol=1e-3 * sphere.volume * problem.rho)

    problem = RadiationProblem(body=sphere,
                               radiating_dof="Surge",
                               free_surface=np.infty,
                               sea_bottom=-np.infty)
    result = solver.solve(problem)
    assert np.isclose(result.added_masses["Surge"],
                      2194,
                      atol=1e-3 * sphere.volume * problem.rho)
    assert np.isclose(result.added_masses["Heave"],
                      0.0,
                      atol=1e-3 * sphere.volume * problem.rho)
    assert np.isclose(result.radiation_dampings["Surge"],
                      0.0,
                      atol=1e-3 * sphere.volume * problem.rho)
    assert np.isclose(result.radiation_dampings["Heave"],
                      0.0,
                      atol=1e-3 * sphere.volume * problem.rho)
Exemplo n.º 14
0
def test_build_matrix_of_rankine_and_reflected_rankine():
    gf = Delhommeau()
    sphere = Sphere(radius=1.0, ntheta=2, nphi=3, clip_free_surface=True)

    S, V = gf.evaluate(sphere.mesh, sphere.mesh, 0.0, -np.infty, 0.0)
    S_ref = np.array([[
        -0.15413386, -0.21852682, -0.06509213, -0.16718431, -0.06509213,
        -0.16718431
    ],
                      [
                          -0.05898834, -0.39245688, -0.04606661, -0.18264734,
                          -0.04606661, -0.18264734
                      ],
                      [
                          -0.06509213, -0.16718431, -0.15413386, -0.21852682,
                          -0.06509213, -0.16718431
                      ],
                      [
                          -0.04606661, -0.18264734, -0.05898834, -0.39245688,
                          -0.04606661, -0.18264734
                      ],
                      [
                          -0.06509213, -0.16718431, -0.06509213, -0.16718431,
                          -0.15413386, -0.21852682
                      ],
                      [
                          -0.04606661, -0.18264734, -0.04606661, -0.18264734,
                          -0.05898834, -0.39245688
                      ]])
    assert np.allclose(S, S_ref)

    S, V = gf.evaluate(sphere.mesh, sphere.mesh, 0.0, -np.infty, np.infty)
    S_ref = np.array([[
        -0.12666269, -0.07804937, -0.03845837, -0.03993999, -0.03845837,
        -0.03993999
    ],
                      [
                          -0.02106031, -0.16464793, -0.01169102, -0.02315146,
                          -0.01169102, -0.02315146
                      ],
                      [
                          -0.03845837, -0.03993999, -0.12666269, -0.07804937,
                          -0.03845837, -0.03993999
                      ],
                      [
                          -0.01169102, -0.02315146, -0.02106031, -0.16464793,
                          -0.01169102, -0.02315146
                      ],
                      [
                          -0.03845837, -0.03993999, -0.03845837, -0.03993999,
                          -0.12666269, -0.07804937
                      ],
                      [
                          -0.01169102, -0.02315146, -0.01169102, -0.02315146,
                          -0.02106031, -0.16464793
                      ]])
    assert np.allclose(S, S_ref)
Exemplo n.º 15
0
def test_problems_from_dataset():
    body = Sphere(center=(0, 0, -4), name="sphere")
    body.add_translation_dof(name="Heave")

    dset = xr.Dataset(
        coords={
            'omega': [0.5, 1.0, 1.5],
            'radiating_dof': ["Heave"],
            'body_name': ["sphere"],
            'wave_direction': [0.0],
            'water_depth': [np.infty]
        })

    problems = problems_from_dataset(dset, [body])
    assert RadiationProblem(body=body, omega=0.5,
                            radiating_dof="Heave") in problems
    assert len(problems) == 6
    assert len([
        problem for problem in problems
        if isinstance(problem, DiffractionProblem)
    ]) == 3

    dset = xr.Dataset(coords={
        'omega': [0.5, 1.0, 1.5],
        'wave_direction': [0.0],
        'body_name': ["cube"]
    })
    with pytest.raises(AssertionError):
        problems_from_dataset(dset, [body])

    shifted_body = body.translated_y(5.0, name="shifted_sphere")
    dset = xr.Dataset(
        coords={
            'omega': [0.5, 1.0, 1.5],
            'radiating_dof': ["Heave"],
            'wave_direction': [0.0]
        })
    problems = problems_from_dataset(dset, [body, shifted_body])
    assert RadiationProblem(body=body, omega=0.5,
                            radiating_dof="Heave") in problems
    assert RadiationProblem(body=shifted_body,
                            omega=0.5,
                            radiating_dof="Heave") in problems
    assert len(problems) == 12
Exemplo n.º 16
0
def test_wave_direction_radians_warning(caplog):
    sphere = Sphere(radius=1.0, ntheta=20, nphi=40)
    sphere.keep_immersed_part()
    sphere.add_all_rigid_body_dofs()
    with caplog.at_level(logging.WARNING):
        DiffractionProblem(body=sphere, omega=1.0, wave_direction=180)
    assert 'in radians and not in degrees' in caplog.text
Exemplo n.º 17
0
def fb_array():
    
    sphere = Sphere(
                    radius=r,            # Dimension
                    center=(0, 0, 0),    # Position
                    nphi=4, ntheta=10,   # Fineness of the mesh
    )
    my_axis = Axis((0, 1, 0), 
                   point=(0,0,0))
    sphere.add_rotation_dof(axis=my_axis)
    sphere.keep_immersed_part()
    
    return sphere.assemble_arbitrary_array(locations)
Exemplo n.º 18
0
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_floating_sphere(depth, omega):
    """Comparison of the added mass and radiation damping
    for a heaving sphere described using several symmetries
    in finite and infinite depth.
    """
    reso = 2

    full_sphere = Sphere(radius=1.0, ntheta=reso, nphi=4*reso, axial_symmetry=False, clip_free_surface=True)
    full_sphere.add_translation_dof(direction=(0, 0, 1), name="Heave")
    problem = RadiationProblem(body=full_sphere, omega=omega, sea_bottom=-depth)
    result1 = solver_with_sym.solve(problem)

    half_sphere_mesh = full_sphere.mesh.extract_faces(
        np.where(full_sphere.mesh.faces_centers[:, 1] > 0)[0],
        name="half_sphere_mesh")
    two_halves_sphere = FloatingBody(ReflectionSymmetricMesh(half_sphere_mesh, xOz_Plane))
    two_halves_sphere.add_translation_dof(direction=(0, 0, 1), name="Heave")
    problem = RadiationProblem(body=two_halves_sphere, omega=omega, sea_bottom=-depth)
    result2 = solver_with_sym.solve(problem)

    quarter_sphere_mesh = half_sphere_mesh.extract_faces(
        np.where(half_sphere_mesh.faces_centers[:, 0] > 0)[0],
        name="quarter_sphere_mesh")
    four_quarter_sphere = FloatingBody(ReflectionSymmetricMesh(ReflectionSymmetricMesh(quarter_sphere_mesh, yOz_Plane), xOz_Plane))
    assert 'None' not in four_quarter_sphere.mesh.tree_view()
    four_quarter_sphere.add_translation_dof(direction=(0, 0, 1), name="Heave")
    problem = RadiationProblem(body=four_quarter_sphere, omega=omega, sea_bottom=-depth)
    result3 = solver_with_sym.solve(problem)

    clever_sphere = Sphere(radius=1.0, ntheta=reso, nphi=4*reso, axial_symmetry=True, clip_free_surface=True)
    clever_sphere.add_translation_dof(direction=(0, 0, 1), name="Heave")
    problem = RadiationProblem(body=clever_sphere, omega=omega, sea_bottom=-depth)
    result4 = solver_with_sym.solve(problem)

    # (quarter_sphere + half_sphere + full_sphere + clever_sphere).show()

    volume = 4/3*np.pi
    assert np.isclose(result1.added_masses["Heave"], result2.added_masses["Heave"], atol=1e-4*volume*problem.rho)
    assert np.isclose(result1.added_masses["Heave"], result3.added_masses["Heave"], atol=1e-4*volume*problem.rho)
    assert np.isclose(result1.added_masses["Heave"], result4.added_masses["Heave"], atol=1e-4*volume*problem.rho)
    assert np.isclose(result1.radiation_dampings["Heave"], result2.radiation_dampings["Heave"], atol=1e-4*volume*problem.rho)
    assert np.isclose(result1.radiation_dampings["Heave"], result3.radiation_dampings["Heave"], atol=1e-4*volume*problem.rho)
    assert np.isclose(result1.radiation_dampings["Heave"], result4.radiation_dampings["Heave"], atol=1e-4*volume*problem.rho)
Exemplo n.º 20
0
def test_radiation_problem(caplog):
    sphere = Sphere(radius=1.0, ntheta=20, nphi=40, clip_free_surface=True)

    # with pytest.raises(ValueError):
    #     RadiationProblem(body=sphere)

    sphere.add_translation_dof(direction=(0, 0, 1), name="Heave")
    pb = RadiationProblem(body=sphere)
    assert len(pb.boundary_condition) == sphere.mesh.nb_faces

    sphere.add_translation_dof(direction=(1, 0, 0), name="Surge")
    pb2 = RadiationProblem(body=sphere, radiating_dof="Heave")
    assert np.all(pb.boundary_condition == pb2.boundary_condition)

    assert "RadiationProblem" in str(RadiationProblem(g=10, rho=1025, free_surface=np.infty))

    res = pb.make_results_container()
    assert isinstance(res, RadiationResult)
    assert 'forces' not in res.__dict__
    assert res.added_masses == {}
    assert res.radiation_dampings == {}
Exemplo n.º 21
0
def test_sphere_axisymmetric():
    sphere = Sphere(axial_symmetry=True)
    assert isinstance(sphere.mesh, AxialSymmetricMesh)
Exemplo n.º 22
0
def test_sphere_nb_panels_clipped():
    sphere = Sphere(ntheta=5, nphi=5, clip_free_surface=True)
    assert sphere.mesh.nb_faces == 25
Exemplo n.º 23
0
def test_sphere_not_axisymmetric():
    sphere = Sphere(axial_symmetry=False)
    assert isinstance(sphere.mesh, Mesh)
Exemplo n.º 24
0
def test_sphere_nb_panels_clipped_is_underwater():
    sphere = Sphere(ntheta=5, nphi=5, clip_free_surface=True)
    assert np.all(sphere.mesh.vertices[:, 2] <= 0.0)
Exemplo n.º 25
0
def test_wamit_convention():
    sphere = Sphere()
    pb1 = DiffractionProblem(body=sphere, convention="Nemoh")
    pb2 = DiffractionProblem(body=sphere, convention="WAMIT")
    assert np.allclose(pb1.boundary_condition, np.conjugate(pb2.boundary_condition))
Exemplo n.º 26
0
def test_bodies():
    body = Sphere(name="sphere", clever=False)
    assert str(body) == "sphere"
    repr(body)
    assert np.allclose(body.geometric_center, (0, 0, 0))
    body.add_translation_dof(name="Surge")
    body.add_translation_dof(name="Heave")

    # Extract faces
    body.extract_faces(np.where(body.mesh.faces_centers[:, 2] < 0)[0])

    # Clipping
    body.keep_immersed_part(inplace=False)

    # Mirror of the dofs
    mirrored = body.mirrored(Plane(point=(1, 0, 0), normal=(1, 0, 0)))
    assert np.allclose(mirrored.geometric_center, np.array([2, 0, 0]))
    assert np.allclose(body.dofs['Surge'], -mirrored.dofs['Surge'])

    # Rotation of the dofs
    sideways = body.rotated(Axis(point=(0, 0, 0), vector=(0, 1, 0)), np.pi/2)
    assert np.allclose(sideways.dofs['Heave'][0], np.array([1, 0, 0]))

    upside_down = body.rotated(Axis(point=(0, 0, 0), vector=(0, 1, 0)), np.pi)
    assert np.allclose(body.dofs['Heave'], -upside_down.dofs['Heave'])

    # Copy of the body
    copy_of_body = body.copy(name="copy_of_sphere")
    copy_of_body.translate_x(10.0)
    copy_of_body.add_translation_dof(name="Heave")

    # Join bodies
    both = body.join_bodies(copy_of_body)
    assert set(both.dofs) == {'sphere__Surge', 'copy_of_sphere__Surge', 'sphere__Heave', 'copy_of_sphere__Heave'}
Exemplo n.º 27
0
def test_sphere_out_of_water():
    with pytest.raises(ValueError):
        sphere = Sphere(radius=1.0, center=(0, 0, 10), clip_free_surface=True)
Exemplo n.º 28
0
def test_sphere_geometric_center():
    sphere = Sphere(radius=2.0, center=(-2.0, 2.0, 1.0))
    assert np.allclose(sphere.geometric_center, np.array([-2.0, 2.0, 1.0]))
def test_array_of_spheres():
    radius = 1.0
    resolution = 2
    perimeter = 2*np.pi*radius
    buoy = Sphere(radius=radius, center=(0.0, 0.0, 0.0),
                  ntheta=int(perimeter*resolution/2), nphi=int(perimeter*resolution),
                  clip_free_surface=True, axial_symmetry=False, name=f"buoy")
    buoy.add_translation_dof(name="Surge")
    buoy.add_translation_dof(name="Sway")
    buoy.add_translation_dof(name="Heave")

    # Corner case
    dumb_array = buoy.assemble_regular_array(distance=5.0, nb_bodies=(1, 1))
    assert dumb_array.mesh == buoy.mesh

    # Main case
    array = buoy.assemble_regular_array(distance=4.0, nb_bodies=(3, 3))

    assert isinstance(array.mesh, TranslationalSymmetricMesh)
    assert isinstance(array.mesh[0], TranslationalSymmetricMesh)
    assert array.mesh[0][0] == buoy.mesh

    assert len(array.dofs) == 3*3*3
    assert "2_0__Heave" in array.dofs

    #
    array = buoy.assemble_regular_array(distance=4.0, nb_bodies=(3, 1))

    settings = dict(cache_rankine_matrices=False, matrix_cache_size=0)
    nemoh_without_sym = Nemoh(hierarchical_matrices=False, **settings)
    nemoh_with_sym = Nemoh(hierarchical_matrices=True, **settings)

    fullS, fullV = nemoh_without_sym.build_matrices(array.mesh, array.mesh, 0.0, -np.infty, 1.0)
    S, V = nemoh_with_sym.build_matrices(array.mesh, array.mesh, 0.0, -np.infty, 1.0)

    assert isinstance(S, cpt.matrices.block.BlockMatrix)
    assert np.allclose(S.full_matrix(), fullS)
    assert np.allclose(V.full_matrix(), fullV)

    problem = RadiationProblem(body=array, omega=1.0, radiating_dof="2_0__Heave", sea_bottom=-np.infty)

    result = nemoh_with_sym.solve(problem)
    result2 = nemoh_without_sym.solve(problem)

    assert np.isclose(result.added_masses['2_0__Heave'], result2.added_masses['2_0__Heave'], atol=15.0)
    assert np.isclose(result.radiation_dampings['2_0__Heave'], result2.radiation_dampings['2_0__Heave'], atol=15.0)
Exemplo n.º 30
0
import pytest

import numpy as np
import xarray as xr
from numpy import pi

from capytaine import __version__
from capytaine.bem.nemoh import Nemoh
from capytaine.bem.problems_and_results import RadiationProblem
from capytaine.bodies.predefined.spheres import Sphere

sphere = Sphere(radius=1.0, ntheta=2, nphi=3, clip_free_surface=True)
sphere.add_translation_dof(direction=(1, 0, 0), name="Surge")


def test_exportable_settings():
    assert Nemoh().exportable_settings() == Nemoh.defaults_settings
    assert 'ACA_distance' not in Nemoh(
        hierarchical_matrices=False).exportable_settings()
    assert 'cache_rankine_matrices' not in Nemoh(
        matrix_cache_size=0).exportable_settings()


def test_cache_matrices():
    """Test how the solver caches the interaction matrices."""
    params_1 = dict(free_surface=0.0, sea_bottom=-np.infty, wavenumber=1.0)
    params_2 = dict(free_surface=0.0, sea_bottom=-np.infty, wavenumber=2.0)

    # No cache
    solver = Nemoh(matrix_cache_size=0)
    S, K = solver.build_matrices(sphere.mesh, sphere.mesh, **params_1)