def call_cptdriver(rank): hprobs = hydro_problems() if rank == 0: halfbody = cpt.FloatingBody.from_file('cptdriver_example.gdf', file_format='wamit') fullbody = cpt.FloatingBody(cpt.ReflectionSymmetricMesh( halfbody.mesh, cpt.xOz_Plane), name='symmetric_body') fullbody.add_all_rigid_body_dofs() hprobs.max_cores = 4 hprobs.body = fullbody hprobs.omega_range = np.array([0.1, 0.2, 0.5, 1.0, 2.0, 5.0]) hprobs.wave_dir_range = np.array([0.0, 15.0, 45.0, 90.0, 180.0 ]) / 180 * np.pi hprobs.water_depth = 100.0 hprobs.water_rho = 1025.0 hprobs.grav = 9.80665 hprobs.zero_frequency = True hprobs.inf_frequency = True hprobs.radiation = True hprobs.diffraction = True # evaluate hydro_problems for all ranks (definitions of rank 0 object will be used) hprobs.prepare_problems() hprobs.solve_hydrodynamics() hprobs.solve_hydrostatics() if rank == 0: print('\nSolution obtained.') return hprobs else: return []
def make_mesh(points_array): # Close the bottom of the points bottom = np.array(points_array[0]) bottom_spacing = np.linspace(0, bottom[0], mesh_bottom_cells) bottom_pts = np.asarray([[bottom_spacing[i], 0, bottom[2]] for i in range(mesh_bottom_cells - 1)]) mesh_shape = np.concatenate((bottom_pts, points_array), axis=0) # Make mesh and add the vertical degree of freedom buoy = cpt.FloatingBody( cpt.AxialSymmetricMesh.from_profile(profile=mesh_shape, nphi=mesh_resolution)) buoy.add_translation_dof(name=degree_of_freedom) # Calculate the mass and stiffness parameters volume = buoy.mesh.volume mass = volume * 1000 radius = points_array[-1][0] stiffness = np.pi * 1000 * 9.81 * radius**2 #approximate_resonance_radial_frequency = np.sqrt(stiffness / mass) #if verbose: # print('\tMass = {}'.format(mass)) # print('\tStiffness = {}'.format(stiffness)) # print('\tApproximate resonance radial frequency = {} rad/s'.format(approximate_resonance_radial_frequency)) return mesh_shape, buoy, mass, stiffness
def generate_boat(lc, ship, weights, tanks, mesh): M, kHS, draft, trim = equilibrium_data(lc, ship, weights, tanks) boat = cpt.FloatingBody(mesh=freecad_mesh_to_captain(mesh, draft, trim), name=lc.Name) boat.add_all_rigid_body_dofs() boat.keep_immersed_part() boat.mass = boat.add_dofs_labels_to_matrix(M) boat.hydrostatic_stiffness = boat.add_dofs_labels_to_matrix(kHS) return boat
def make_mesh(points_array): # Close the bottom of the mesh bottom = np.array(points_array[0]) bottom_spacing = np.linspace(0, bottom[0], mesh_bottom_cells) bottom_pts = np.asarray([[bottom_spacing[i], 0, bottom[2]] for i in range(mesh_bottom_cells - 1)]) mesh_shape = np.concatenate((bottom_pts, points_array), axis=0) # Make mesh and add the vertical degree of freedom buoy = cpt.FloatingBody( cpt.AxialSymmetricMesh.from_profile(profile=mesh_shape, nphi=mesh_resolution)) buoy.add_translation_dof(name=degree_of_freedom) # Calculate the mass and stiffness parameters volume = buoy.mesh.volume mass = volume * 1000 radius = points_array[-1][0] stiffness = np.pi * 1000 * 9.81 * radius**2 return mesh_shape, buoy, mass, stiffness
#!/usr/bin/env python import numpy as np import capytaine as cpt # Load a mesh original_mesh = cpt.Sphere(axial_symmetry=False).mesh # METHOD 1 # Get the indices of the panels such that the center is in the half-space y > 0. indices_of_some_faces = np.where(original_mesh.faces_centers[:, 1] > 0)[0] half_mesh = original_mesh.extract_faces(indices_of_some_faces) # METHOD 2 # Clip the mesh half_mesh = original_mesh.clip(plane=cpt.xOz_Plane) # Define a new body by reflecting the half mesh across the xOz plane. body = cpt.FloatingBody(cpt.ReflectionSymmetricMesh(half_mesh, cpt.xOz_Plane), name="symmetric_body") # Display the body with VTK. body.show()
import logging import numpy as np import capytaine as cpt import capytaine.io.xarray logging.basicConfig(level=logging.INFO, format="%(levelname)s:\t%(message)s") # Profile of the axisymmetric body def shape(z): return 0.1 * (-(z + 1)**2 + 16) # Generate the mesh and display it with VTK. buoy = cpt.FloatingBody( cpt.AxialSymmetricMesh.from_profile(shape, z_range=np.linspace(-5, 0, 30), nphi=40)) buoy.add_translation_dof(name="Heave") buoy.show() # Set up problems omega_range = np.linspace(0.1, 5.0, 60) problems = [ cpt.RadiationProblem(body=buoy, radiating_dof='Heave', omega=omega) for omega in omega_range ] # Solve the problems solver = cpt.Nemoh() results = [solver.solve(pb) for pb in sorted(problems)] dataset = capytaine.io.xarray.assemble_dataset(results)
def set_hydrobody(self, hydrobody): self._hydrobody = hydrobody self._cpt_hydrobody = cpt.FloatingBody(mesh=hydrobody.Mesh)