Exemple #1
0
    def evaluate_column_modal_response_amplitudes(self):
        """

        """
        bem_solver = cpt.BEMSolver()
        problems = [
            cpt.RadiationProblem(sea_bottom=self.water_depth,
                                 body=self.column_mesh,
                                 radiating_dof=dof,
                                 omega=omega) for dof in self.column_mesh.dofs
            for omega in self.wave_frequencies
        ]
        problems += [
            cpt.DiffractionProblem(sea_bottom=self.water_depth,
                                   body=self.column_mesh,
                                   wave_direction=self.wave_direction,
                                   omega=omega)
            for omega in self.wave_frequencies
        ]
        results = [bem_solver.solve(problem) for problem in problems]
        result_data = cpt.assemble_dataset(results)
        modal_response_amplitude_data = cpt.post_pro.rao(
            result_data, wave_direction=self.wave_direction)

        self.result_data = result_data
        self.modal_response_amplitude_data = modal_response_amplitude_data
Exemple #2
0
    def prepare_problems(self):
        if MPI:
            n_cores = MPI.COMM_WORLD.Get_size()
            max_cores = min(n_cores, self.max_cores)
            rank = MPI.COMM_WORLD.Get_rank()
        else:
            n_cores = 1
            max_cores = 1
            rank = 0

        if rank == 0:
            problems = []
            if self.radiation:
                if self.zero_frequency:
                    problems += [cpt.RadiationProblem(
                            body=self._cpt_hydrobody, free_surface=0.0, sea_bottom=-np.infty,
                            omega=0.0, rho=self.water_rho, g=self.grav, radiating_dof=dof
                        )
                        for dof in self._cpt_hydrobody.dofs
                    ]
                problems += [cpt.RadiationProblem(
                        body=self._cpt_hydrobody, free_surface=0.0, sea_bottom=-self.water_depth,
                        omega=omega, rho=self.water_rho, g=self.grav, radiating_dof=dof
                    )
                    for dof in self._cpt_hydrobody.dofs
                    for omega in self.omega_range
                ]
                if self.inf_frequency:
                    problems += [cpt.RadiationProblem(
                            body=self._cpt_hydrobody, free_surface=0.0, sea_bottom=-np.infty,
                            omega=np.infty, rho=self.water_rho, g=self.grav, radiating_dof=dof
                        )
                        for dof in self._cpt_hydrobody.dofs
                    ]
            if self.diffraction:
                problems += [cpt.DiffractionProblem(
                        body=self._cpt_hydrobody, free_surface=0.0, sea_bottom=-self.water_depth,
                        omega=omega, rho=self.water_rho, g=self.grav, wave_direction=wave_dir
                    )
                    for omega in self.omega_range
                    for wave_dir in self.wave_dir_range
                ]

            problems = sorted(problems)
            problists = list(self.__split_list_chunks(problems, max_cores))
            if len(problists) < n_cores:
                for _ in range(0, n_cores - len(problists)):
                    problists.append([]) # unused threads
        else:
            problems = []
            problists = []

        if MPI:
            MPI.COMM_WORLD.barrier()
            problems = MPI.COMM_WORLD.scatter(problists, root=0)
        
        self._problems = problems
def evaluate_buoy_forces(buoy_object):
    # Set up radiation and diffraction problems
    problems = [cpt.RadiationProblem(body=buoy_object, radiating_dof=degree_of_freedom, omega=omega)
                for omega in omega_range]
    problems += [cpt.DiffractionProblem(omega=omega, body=buoy_object, wave_direction=wave_direction)
                 for omega in omega_range]

    # Solve each matrix problem
    solver = cpt.BEMSolver(engine=cpt.HierarchicalToeplitzMatrixEngine())
    results = [solver.solve(pb) for pb in sorted(problems)]

    return cpt.assemble_dataset(results)
Exemple #4
0
def make_database(body, omegas, wave_directions):
    # SOLVE BEM PROBLEMS
    problems = []
    for wave_direction in wave_directions:
        for omega in omegas:
            problems += [cpt.RadiationProblem(omega=omega, body=body, radiating_dof=dof) for dof in body.dofs]
            problems += [cpt.DiffractionProblem(omega=omega, body=body, wave_direction=wave_direction)]
    results = [bem_solver.solve(problem) for problem in problems]
    *radiation_results, diffraction_result = results
    dataset = cpt.assemble_dataset(results)

    dataset['diffraction_result'] = diffraction_result

    return dataset
Exemple #5
0
def simulation(lc, ship, weights, tanks, mesh, omegas):
    body = generate_boat(lc, ship, weights, tanks, mesh)

    problems = []
    for omega in omegas:
        for dof in body.dofs:
            problems.append(cpt.RadiationProblem(omega=omega,
                                                 body=body,
                                                 radiating_dof=dof))
        for d in DIRS:
            problems.append(cpt.DiffractionProblem(omega=omega,
                                                   body=body,
                                                   wave_direction=d))
    return problems
Exemple #6
0
def setup_animation(body, fs, omega, wave_amplitude,
                    wave_direction) -> Animation:
    # SOLVE BEM PROBLEMS
    problems = [
        cpt.RadiationProblem(omega=omega, body=body, radiating_dof=dof)
        for dof in body.dofs
    ]
    problems += [
        cpt.DiffractionProblem(omega=omega,
                               body=body,
                               wave_direction=wave_direction)
    ]
    results = [bem_solver.solve(problem) for problem in problems]
    *radiation_results, diffraction_result = results
    dataset = cpt.assemble_dataset(results)

    # COMPUTE RAO
    dataset['RAO'] = cpt.post_pro.rao(dataset, wave_direction=wave_direction)

    # Compute the motion of each face of the mesh for the animation
    rao_faces_motion = sum(
        dataset['RAO'].sel(omega=omega, radiating_dof=dof).data *
        body.full_body.dofs[dof] for dof in body.dofs)

    # COMPUTE FREE SURFACE ELEVATION
    # Compute the diffracted wave pattern
    diffraction_elevation = bem_solver.get_free_surface_elevation(
        diffraction_result, fs)
    incoming_waves_elevation = fs.incoming_waves(diffraction_result)

    # Compute the wave pattern radiated by the RAO
    radiation_elevations_per_dof = {
        res.radiating_dof: bem_solver.get_free_surface_elevation(res, fs)
        for res in radiation_results
    }
    rao_radiation_elevation = sum(
        dataset['RAO'].sel(omega=omega, radiating_dof=dof).data *
        radiation_elevations_per_dof[dof] for dof in body.dofs)

    # SET UP ANIMATION
    animation = Animation(loop_duration=2 * pi / omega)
    animation.add_body(body.full_body,
                       faces_motion=wave_amplitude * rao_faces_motion)
    animation.add_free_surface(
        fs,
        wave_amplitude * (incoming_waves_elevation + diffraction_elevation +
                          rao_radiation_elevation))
    return animation
def test_showmatplotlib_with_colors(tmp_path):
    cylinder = cpt.HorizontalCylinder(
        length=5.0, radius=1.0, center=(0, 0, -2), nr=5, nx=20, ntheta=20,
    )

    problem = cpt.DiffractionProblem(body=cylinder, wave_direction=0.0, omega=1.0)
    solver = cpt.BEMSolver()
    results = solver.solve(problem)

    cylinder.show_matplotlib(saveas=tmp_path / "showmpl.png")

    fig = plt.figure()
    ax = fig.add_subplot(111,projection='3d')
    import matplotlib.cm as cm
    colormap = cm.get_cmap('cividis')
    cylinder.show_matplotlib(color_field=np.abs(results.potential),
                             ax=ax, cbar_label=r'$\phi (m^2/s)$')
    ax.set_title('Potential distribution')
    plt.savefig(tmp_path / "showmpl_with_color_field.png")
Exemple #8
0
    def solve_tube_hydrodynamics(self):
        """

        """
        #print('\tSolving tube hydrodynamics.')

        solver = cpt.BEMSolver()
        problems = [
            cpt.RadiationProblem(omega=omega,
                                 body=self.tube,
                                 radiating_dof=dof,
                                 rho=self.rho,
                                 sea_bottom=self.water_depth)
            for dof in self.tube.dofs for omega in self.wave_frequencies
        ]
        problems += [
            cpt.DiffractionProblem(omega=omega,
                                   body=self.tube,
                                   wave_direction=self.wave_direction,
                                   rho=self.rho,
                                   sea_bottom=self.water_depth)
            for omega in self.wave_frequencies
        ]
        results = solver.solve_all(problems, keep_details=False)
        result_data = cpt.assemble_dataset(results)

        if self.save_results:
            from capytaine.io.xarray import separate_complex_values
            save_file_name = 'flexible_tube_results__rs_le_zs__{:.2f}_{:.1f}_{:.2f}__with_{}_cells.nc' \
                                .format(self.static_radius, self.length, self.submergence, self.tube.mesh.nb_faces)
            separate_complex_values(result_data).to_netcdf(
                save_file_name,
                encoding={
                    'radiating_dof': {
                        'dtype': 'U'
                    },
                    'influenced_dof': {
                        'dtype': 'U'
                    }
                })

        self.result_data = result_data
    def solve_beam_hydrodynamics(self, save_results):
        """

        """
        bem_solver = cpt.BEMSolver()
        problems = [
            cpt.RadiationProblem(sea_bottom=self.water_depth,
                                 body=self.beam_mesh,
                                 radiating_dof=dof,
                                 omega=omega) for dof in self.beam_mesh.dofs
            for omega in self.wave_frequencies
        ]
        problems += [
            cpt.DiffractionProblem(sea_bottom=self.water_depth,
                                   body=self.beam_mesh,
                                   wave_direction=self.wave_direction,
                                   omega=omega)
            for omega in self.wave_frequencies
        ]
        results = [bem_solver.solve(problem) for problem in problems]
        result_data = cpt.assemble_dataset(results)

        if save_results:
            from capytaine.io.xarray import separate_complex_values
            separate_complex_values(result_data).to_netcdf(
                'beam_hydrodynamics_results.nc',
                encoding={
                    'radiating_dof': {
                        'dtype': 'U'
                    },
                    'influenced_dof': {
                        'dtype': 'U'
                    }
                })

        return result_data
Exemple #10
0
# Bulging of the sphere,
# that is a deformation vector normal to the body at all faces.
# We can simply point to the normal vectors of the mesh for that.
sphere.dofs["Bulge"] = sphere.mesh.faces_normals

# Shearing of the sphere in the x direction.
# The deformation vector on a face is computed from the position of the face.
sphere.dofs["x-shear"] = np.array(
    [(np.cos(np.pi*z/2), 0, 0) for x, y, z in sphere.mesh.faces_centers]
)

# SOLVE DIFFRACTION PROBLEMS
solver = cpt.Nemoh()

# Solve the problem for β=0 (incoming wave in the x direction).
problem_1 = cpt.DiffractionProblem(body=sphere, wave_direction=0, omega=1.0)
result_1 = solver.solve(problem_1)

# Solve the problem for β=π/2 (incoming wave in the y direction).
problem_2 = cpt.DiffractionProblem(body=sphere, wave_direction=np.pi/2, omega=1.0)
result_2 = solver.solve(problem_2)

# Print the generalized diffraction forces
# for the three dofs we defined
# for both values of the wave_direction β.
for result in [result_1, result_2]:
    print(f"Angle: {result.wave_direction:.2f}")
    for dof in sphere.dofs:
        force = result.forces[dof]
        print(f"{dof}: {np.abs(force):.2f}·exp({np.angle(force):.2f}i) N")
    print()
# Hydrostatics
kHS = block_diag(0, 0, hsd['stiffness_matrix'], 0)
body.hydrostatic_stiffness = body.add_dofs_labels_to_matrix(kHS)

# change omega values
omega = np.linspace(0.1, 2, 10)
wave_direction = 0.0
#body.keep_only_dofs(['Heave'])

problems = [
    cpt.RadiationProblem(omega=w, body=body, radiating_dof=dof)
    for dof in body.dofs for w in omega
]
problems += [
    cpt.DiffractionProblem(omega=w, body=body, wave_direction=wave_direction)
    for w in omega
]
results = [bem_solver.solve(problem) for problem in problems]
*radiation_results, diffraction_result = results
dataset = cpt.assemble_dataset(results)

# COMPUTE RAO
dataset['RAO'] = cpt.post_pro.rao(dataset, wave_direction=wave_direction)
# print(dataset['RAO'])
# print(dataset['RAO'].data)
#plt.plot(omega,dataset['RAO'].data)

#change dof to heave, pitch, surge
dof = "Heave"
plt.plot(omega, np.abs(dataset['RAO'].sel(radiating_dof=dof)))
Exemple #12
0
    cpt.AxialSymmetricMesh.from_profile(shape,
                                        z_range=np.linspace(-draft, 0, 30),
                                        nphi=40))
buoy.add_translation_dof(name="Heave")

if show_mesh:
    buoy.show()

# Set up radiation and diffraction problems
omega_range = np.linspace(0.3, 5.0, 60)
problems = [
    cpt.RadiationProblem(body=buoy, radiating_dof='Heave', omega=omega)
    for omega in omega_range
]
problems += [
    cpt.DiffractionProblem(omega=omega, body=buoy, wave_direction=0.0)
    for omega in omega_range
]

# Solve the problems using the axial symmetry
solver = cpt.BEMSolver(engine=cpt.HierarchicalToeplitzMatrixEngine()
                       )  # TODO: investigate why this engine is uses
results = [solver.solve(pb) for pb in sorted(problems)]
*radiation_results, diffraction_result = results
dataset = cpt.assemble_dataset(results)

# Assemble needed values for control algorithm
added_mass = dataset['added_mass'].sel(radiating_dof='Heave',
                                       influenced_dof='Heave')
radiation_damping = dataset['radiation_damping'].sel(radiating_dof='Heave',
                                                     influenced_dof='Heave')
Exemple #13
0
    radius=r,
    center=(0., 0., 0.),
    nx=10,
    nr=10,
    ntheta=50,
    clever=
    False,  # Do not use axial symmetry of the mesh (not really useful here)
)
body.keep_immersed_part()
body.add_translation_dof(name='Heave')

solver = cpt.BEMSolver()

# Define and solve the diffraction and radiation problems
diff_problem = cpt.DiffractionProblem(body=body,
                                      sea_bottom=-depth,
                                      omega=omega,
                                      wave_direction=0.)
rad_problem = cpt.RadiationProblem(body=body,
                                   sea_bottom=-depth,
                                   omega=omega,
                                   radiating_dof='Heave')

diff_solution = solver.solve(diff_problem)
rad_solution = solver.solve(rad_problem)

# Read mesh properties
faces_centers = body.mesh.faces_centers
faces_normals = body.mesh.faces_normals
faces_areas = body.mesh.faces_areas

from capytaine.bem.airy_waves import airy_waves_potential, airy_waves_velocity, froude_krylov_force
    radius=3,
    center=(0, 0, 0),  # Size and positions
    ntheta=20,
    nphi=20,  # Fineness of the mesh
)
full_sphere.add_translation_dof(name="Heave")

# Keep only the immersed part of the mesh
sphere = full_sphere.keep_immersed_part(inplace=False)
sphere.add_translation_dof(name="Heave")

# Set up and solve problem
solver = cpt.BEMSolver()

diffraction_problem = cpt.DiffractionProblem(body=sphere,
                                             wave_direction=0.0,
                                             omega=2.0)
diffraction_result = solver.solve(diffraction_problem)

radiation_problem = cpt.RadiationProblem(body=sphere,
                                         radiating_dof="Heave",
                                         omega=2.0)
radiation_result = solver.solve(radiation_problem)

# Define a mesh of the free surface and compute the free surface elevation
free_surface = cpt.FreeSurface(x_range=(-50, 50),
                               y_range=(-50, 50),
                               nx=150,
                               ny=150)
diffraction_elevation_at_faces = solver.get_free_surface_elevation(
    diffraction_result, free_surface)
Exemple #15
0
                                  radius=1.0,
                                  center=(1.5, 3.0, -3.0),
                                  nx=20,
                                  nr=3,
                                  ntheta=20,
                                  name="cylinder")
cylinder.add_translation_dof(name="Surge")
cylinder.add_translation_dof(name="Heave")

# Combine the three individual bodies into a single body.
all_bodies = cylinder + sphere + other_sphere

print("Merged body name:", all_bodies.name)
print("Merged body dofs:", list(all_bodies.dofs.keys()))

# The merged body can be used to define the problems in the usual way
problems = [
    cpt.RadiationProblem(body=all_bodies, radiating_dof=dof, omega=1.0)
    for dof in all_bodies.dofs
]
problems += [
    cpt.DiffractionProblem(body=all_bodies, wave_direction=0.0, omega=1.0)
]

# Solves the problem
solver = cpt.Nemoh()
results = solver.solve_all(problems)
data = cpt.assemble_dataset(results)

print(data)
Exemple #16
0
# 2. Define a list of problems to be solved. Can be radiation problems or
#    diffraction problems. (
#    Uses python 'list comprehension' to easily loop through all dofs / freq
problems = [
    cpt.RadiationProblem(body=body,
                         radiating_dof=dof,
                         omega=w,
                         sea_bottom=-np.infty,
                         g=9.81,
                         rho=1000.0) for dof in body.dofs for w in freq
]
problems += [
    cpt.DiffractionProblem(body=body,
                           omega=w,
                           wave_direction=heading,
                           sea_bottom=-np.infty,
                           g=9.81,
                           rho=1000.0) for w in freq for heading in directions
]

# 3. Define the BEM solver to be used.
solver = cpt.BEMSolver()

# 4. Loop through the problems and solve each
results = [
    solver.solve(problem, keep_details=True) for problem in sorted(problems)
]

# 5. Create a dataset using the list of results and any hydrostatics output
capyData = cpt.assemble_dataset(results, hydrostatics=False)
Exemple #17
0
directions = np.linspace(0,90,2)


# 2. Define a list of problems to be solved. Can be radiation problems or 
#    diffraction problems. (
#    Uses python 'list comprehension' to easily loop through all dofs / freq
problems = [cpt.RadiationProblem(body=body,
                              radiating_dof=dof,
                              omega=w,
                              sea_bottom=-np.infty,
                              g=9.81,
                              rho=1000.0)
                              for dof in body.dofs for w in freq]
problems += [cpt.DiffractionProblem(body=body,
                                omega=w,
                                wave_direction=heading,
                                sea_bottom=-np.infty,
                                g=9.81,
                                rho=1000.0)
                                for w in freq for heading in directions]

# 3. Define the BEM solver to be used. 
solver = cpt.BEMSolver()

# 4. Loop through the problems and solve each
results = [solver.solve(problem, keep_details=True) for problem in sorted(problems)]

# 5. Create a dataset using the list of results and any hydrostatics output
capyData = cpt.assemble_dataset(results, hydrostatics=False)


###############################################################################