def test_floating_sphere_finite_freq(): sphere = generate_sphere(radius=1.0, ntheta=6, nphi=12, clip_free_surface=True) sphere.dofs["Heave"] = sphere.faces_normals @ (0, 0, 1) solver = Nemoh() problem = RadiationProblem(body=sphere, omega=1.0, sea_bottom=-np.infty) mass, damping = solver.solve(problem, keep_details=True) assert np.isclose(mass, 1819.6, atol=1e-3 * sphere.volume * problem.rho) assert np.isclose(damping, 379.39, atol=1e-3 * sphere.volume * problem.rho) free_surface = generate_free_surface(width=125, length=125, nw=5, nl=5) eta = solver.get_free_surface(problem, free_surface, dof="Heave") 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) problem = DiffractionProblem(body=sphere, omega=1.0, sea_bottom=-np.infty) force = Nemoh().solve(problem) assert np.isclose(force, 1834.9 * np.exp(-2.933j) * -1j, rtol=1e-3)
def profile_capytaine(body, omega_range, result_dir, **problem_kwargs): if not os.path.isdir(result_dir): os.makedirs(result_dir) os.environ["MKL_NUM_THREADS"] = "1" if logging.root: del logging.root.handlers[:] logging.basicConfig( filename=f"{result_dir}/capytaine.log", level=logging.DEBUG, format="%(levelname)s:\t%(message)s" ) pr = cProfile.Profile() pr.enable() #==Start profiler== problems = [RadiationProblem(body=body, omega=omega, **problem_kwargs) for omega in omega_range] solver = Nemoh() results = [solver.solve(pb) for pb in problems] pr.disable() #================= results = np.asarray(results) np.savetxt(f'{result_dir}/results.csv', results) s = io.StringIO() sortby = 'time' ps = pstats.Stats(pr, stream=s).sort_stats(sortby) ps.print_stats() profiler_results = s.getvalue() with open(f'{result_dir}/profile.log', 'w') as log: log.write(profiler_results) os.environ["MKL_NUM_THREADS"] = "4" return float(profiler_results.split('\n')[0].split('in')[1].strip('seconds\n'))
# Set up logging logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s:\t%(message)s", datefmt="%H:%M:%S") # Initialize mesh and solver sphere = generate_clever_sphere(radius=5, ntheta=40, nphi=40, z0=-1.0, clip_free_surface=True) solver = Nemoh() # Solve diffraction problem problem = DiffractionProblem(body=sphere, angle=0.0, omega=2.0) results = solver.solve(problem, keep_details=True) # Compute free surface elevation fs_mesh = generate_free_surface(width=100.0, length=100.0, nw=100, nl=100) fs = solver.get_free_surface(problem, fs_mesh) # Add incoming waves fs = fs + 1j * problem.omega / problem.g * problem.Airy_wave_potential( fs_mesh.faces_centers) # Plot free surface elevation X = fs_mesh.faces_centers[:, 0].reshape(100, 100) Y = fs_mesh.faces_centers[:, 1].reshape(100, 100) fs = fs.reshape(100, 100) scale = np.abs(fs).max()
# buoy = generate_axi_symmetric_body( # profile=[[0, 0, -5], [1, 0, -4], [1.5, 0, -3], [2.0, 0, -2], [1.3, 0, -1], [0, 0, -0.5]] # ) buoy = generate_axi_symmetric_body(shape, z_range=np.linspace(-5.0, 0.0, 20), nphi=20) # buoy.show() buoy.dofs["Heave"] = buoy.faces_normals @ (0, 0, 1) solver = Nemoh() omega_range = np.linspace(0.1, 5.0, 40) problems = [ RadiationProblem(body=buoy, rho=rho, omega=omega) for omega in omega_range ] results = [solver.solve(pb) for pb in problems] results = np.array(results) plt.figure() plt.plot(omega_range, results[:, 0, 0, 0] / (rho * buoy.volume), label="Added mass") plt.plot(omega_range, results[:, 1, 0, 0] / (rho * buoy.volume), label="Added damping") plt.legend() plt.show()