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, clever=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)
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) S_again, K_again = solver.build_matrices(sphere.mesh, sphere.mesh, **params_1) assert S is not S_again assert K is not K_again # Cache solver = Nemoh(matrix_cache_size=1) S, K = solver.build_matrices(sphere.mesh, sphere.mesh, **params_1) S_again, K_again = solver.build_matrices(sphere.mesh, sphere.mesh, **params_1) _, _ = solver.build_matrices(sphere.mesh, sphere.mesh, **params_2) S_once_more, K_once_more = solver.build_matrices(sphere.mesh, sphere.mesh, **params_1) assert S is S_again assert S is not S_once_more assert K is K_again assert K is not K_once_more