コード例 #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
コード例 #2
0
ファイル: test_io.py プロジェクト: mancellin/capytaine
def test_dataset_from_bemio():
    bemio = pytest.importorskip("bemio.io.wamit",
                                reason="Bemio not installed, test skipped.")
    current_file_path = os.path.dirname(os.path.abspath(__file__))
    out_file = os.path.join(current_file_path, "Bemio_verification_cases",
                            "sphere.out")
    bemio_data = bemio.read(out_file)

    new_dataset = cpt.assemble_dataset(bemio_data)
    assert (np.moveaxis(bemio_data.body[0].am.all, 2, 0) * bemio_data.body[0].rho == \
        new_dataset['added_mass'].values).all()
コード例 #3
0
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)
コード例 #4
0
ファイル: capytaine_to_nc.py プロジェクト: oceanum/mafredo
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
コード例 #5
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
コード例 #6
0
ファイル: Tools.py プロジェクト: FreeCAD/freecad.ship
def solve_sim(sims, omegas):
    """Solve for all the directions of a single period
    """
    bem_solver = cpt.BEMSolver()
    i_sim = 0
    for j, omega in enumerate(omegas):
        radiation = [
            bem_solver.solve(sims[i_sim + i]) for i in range(len(DOFS))]
        i_sim += len(DOFS)
        for i, d in enumerate(DIRS):
            results = radiation[:]
            results.append(bem_solver.solve(sims[i_sim]))
            i_sim += 1
            dataset = cpt.assemble_dataset(results)
            yield i, j, cpt.post_pro.rao(dataset, wave_direction=d)
    """
コード例 #7
0
def test_xarray_dataset_with_more_data():
    # Store some mesh data when several bodies in dataset
    bodies = [
        cpt.Sphere(radius=1, ntheta=3, nphi=3, name="sphere_1"),
        cpt.Sphere(radius=2, ntheta=5, nphi=3, name="sphere_2"),
        cpt.Sphere(radius=3, ntheta=7, nphi=3, name="sphere_3"),
    ]
    for body in bodies:
        body.keep_immersed_part()
        body.add_translation_dof(name="Heave")

    problems = [cpt.RadiationProblem(body=b, radiating_dof="Heave", omega=1.0) for b in bodies]
    results = cpt.BEMSolver().solve_all(problems)

    ds = cpt.assemble_dataset(results, mesh=True)
    assert 'nb_faces' in ds.coords
    assert set(ds.coords['nb_faces'].values) == set([b.mesh.nb_faces for b in bodies])
コード例 #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
コード例 #9
0
def test_rotation_axis():
    body = cpt.RectangularParallelepiped(resolution=(4, 4, 4),
                                         center=(0, 0, -1),
                                         name="body")
    body.add_translation_dof(name="Sway")
    body.add_rotation_dof(axis=cpt.Axis(point=(0, 0, 0), vector=(0, 0, 1)),
                          name="Yaw")

    l = 2.0
    body.add_rotation_dof(axis=cpt.Axis(point=(l, 0, 0), vector=(0, 0, 1)),
                          name="other_rotation")

    assert np.allclose(body.dofs['other_rotation'],
                       (body.dofs['Yaw'] - l * body.dofs['Sway']))

    problems = [
        cpt.RadiationProblem(body=body, radiating_dof=dof, omega=1.0)
        for dof in body.dofs
    ]
    solver = cpt.Nemoh()
    results = solver.solve_all(problems, keep_details=True)
    dataset = cpt.assemble_dataset(results)

    sources = {result.radiating_dof: result.sources for result in results}
    assert np.allclose(sources['other_rotation'],
                       sources['Yaw'] - l * sources['Sway'],
                       atol=1e-4)

    potential = {result.radiating_dof: result.potential for result in results}
    assert np.allclose(potential['other_rotation'],
                       potential['Yaw'] - l * potential['Sway'],
                       atol=1e-4)

    A_m = dataset['added_mass'].sel(radiating_dof="other_rotation",
                                    influenced_dof="other_rotation").data
    A = dataset['added_mass'].sel(radiating_dof=["Yaw", "Sway"],
                                  influenced_dof=["Yaw", "Sway"]).data
    P = np.array([1, -l])
    assert np.isclose(A_m, P.T @ A @ P)
コード例 #10
0
    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
コード例 #11
0
def test_sum_of_dofs():
    body1 = cpt.Sphere(radius=1.0,
                       ntheta=3,
                       nphi=12,
                       center=(0, 0, -3),
                       name="body1")
    body1.add_translation_dof(name="Heave")

    body2 = cpt.Sphere(radius=1.0,
                       ntheta=3,
                       nphi=8,
                       center=(5, 3, -1.5),
                       name="body2")
    body2.add_translation_dof(name="Heave")

    both = body1 + body2
    both.add_translation_dof(name="Heave")

    problems = [
        cpt.RadiationProblem(body=both, radiating_dof=dof, omega=1.0)
        for dof in both.dofs
    ]
    solver = cpt.Nemoh()
    results = solver.solve_all(problems)
    dataset = cpt.assemble_dataset(results)

    both_added_mass = dataset['added_mass'].sel(radiating_dof="Heave",
                                                influenced_dof="Heave").data
    body1_added_mass = dataset['added_mass'].sel(
        radiating_dof="body1__Heave", influenced_dof="body1__Heave").data
    body2_added_mass = dataset['added_mass'].sel(
        radiating_dof="body2__Heave", influenced_dof="body2__Heave").data

    assert np.allclose(both_added_mass,
                       body1_added_mass + body2_added_mass,
                       rtol=1e-2)
コード例 #12
0
ファイル: demo.py プロジェクト: yuyihsiang/WEC-Sim
                           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)

###############################################################################
# ** Alternate method to 2-5
#    Create a dataset of parameters.
#    'fill_dataset()' automatically creates problems and solves them.
#    This method is easy and clean, but has less control on the problem details
test_matrix = xr.Dataset(
    coords={
        'omega': freq,
        'wave_direction': directions,
        'radiating_dof': list(body.dofs),
        'water_depth': [np.infty],
    })
dataset = solver.fill_dataset(test_matrix, [body], hydrostatics=False)
###############################################################################
コード例 #13
0
# 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)))
plt.xlabel('omega')
plt.ylabel('RAO ' + dof)
plt.show()