Esempio 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)
Esempio n. 2
0
def test_two_vertical_cylinders():
    distance = 5

    buoy = VerticalCylinder(length=3,
                            radius=0.5,
                            center=(-distance / 2, -1, 0),
                            nx=8,
                            nr=3,
                            ntheta=8)
    buoy.mesh = buoy.mesh.merged()
    buoy.mesh = buoy.mesh.keep_immersed_part()
    buoy.add_translation_dof(name="Sway")

    two_buoys = FloatingBody.join_bodies(buoy, buoy.translated_x(distance))
    two_buoys.mesh = buoy.mesh.symmetrized(
        yOz_Plane)  # Use a ReflectionSymmetry as mesh...

    problems = [
        RadiationProblem(body=two_buoys, omega=1.0, radiating_dof=dof)
        for dof in two_buoys.dofs
    ]

    results = assemble_dataset(solver_without_sym.solve_all(problems))
    # Check that the resulting matrix is symmetric
    assert np.isclose(results['added_mass'].data[0, 0, 0],
                      results['added_mass'].data[0, 1, 1])
    assert np.isclose(results['added_mass'].data[0, 1, 0],
                      results['added_mass'].data[0, 0, 1])
    assert np.isclose(results['radiation_damping'].data[0, 0, 0],
                      results['radiation_damping'].data[0, 1, 1])
    assert np.isclose(results['radiation_damping'].data[0, 1, 0],
                      results['radiation_damping'].data[0, 0, 1])

    results_with_sym = assemble_dataset(solver_with_sym.solve_all(problems))
    assert np.allclose(results['added_mass'].data,
                       results_with_sym['added_mass'].data)
    assert np.allclose(results['radiation_damping'].data,
                       results_with_sym['radiation_damping'].data)