Exemplo n.º 1
0
def test_problems_from_dataset():
    body = Sphere(center=(0, 0, -4), name="sphere")
    body.add_translation_dof(name="Heave")

    dset = xr.Dataset(coords={'omega': [0.5, 1.0, 1.5],
                              'radiating_dof': ["Heave"],
                              'body_name': ["sphere"],
                              'wave_direction': [0.0],
                              'water_depth': [np.infty]})

    problems = problems_from_dataset(dset, [body])
    assert RadiationProblem(body=body, omega=0.5, radiating_dof="Heave") in problems
    assert len(problems) == 6
    assert len([problem for problem in problems if isinstance(problem, DiffractionProblem)]) == 3

    dset = xr.Dataset(coords={'omega': [0.5, 1.0, 1.5],
                              'wave_direction': [0.0],
                              'body_name': ["cube"]})
    with pytest.raises(AssertionError):
        problems_from_dataset(dset, [body])

    shifted_body = body.translated_y(5.0, name="shifted_sphere")
    dset = xr.Dataset(coords={'omega': [0.5, 1.0, 1.5],
                              'radiating_dof': ["Heave"],
                              'wave_direction': [0.0]})
    problems = problems_from_dataset(dset, [body, shifted_body])
    assert RadiationProblem(body=body, omega=0.5, radiating_dof="Heave") in problems
    assert RadiationProblem(body=shifted_body, omega=0.5, radiating_dof="Heave") in problems
    assert len(problems) == 12
Exemplo n.º 2
0
def test_incomplete_test_matrix():
    body = cpt.Sphere()
    test_matrix = xr.Dataset(coords={
        "omega": np.linspace(0, 1, 2),
    })
    with pytest.raises(ValueError):
        problems_from_dataset(test_matrix, body)
Exemplo n.º 3
0
    def fill_dataset(self, dataset, bodies, **kwargs):
        """Solve a set of problems defined by the coordinates of an xarray dataset.

        Parameters
        ----------
        dataset : xarray Dataset
            dataset containing the problems parameters: frequency, radiating_dof, water_depth, ...
        bodies : list of FloatingBody
            the bodies involved in the problems

        Returns
        -------
        xarray Dataset
        """
        attrs = {
            'start_of_computation': datetime.now().isoformat(),
            **self.exportable_settings
        }
        problems = problems_from_dataset(dataset, bodies)
        if 'theta' in dataset.coords:
            results = self.solve_all(problems, keep_details=True)
            kochin = kochin_data_array(results, dataset.coords['theta'])
            dataset = assemble_dataset(results, attrs=attrs, **kwargs)
            dataset['kochin'] = kochin
        else:
            results = self.solve_all(problems, keep_details=False)
            dataset = assemble_dataset(results, attrs=attrs, **kwargs)
        return dataset
Exemplo n.º 4
0
    def fill_dataset(self, dataset, bodies, *, n_jobs=1, **kwargs):
        """Solve a set of problems defined by the coordinates of an xarray dataset.

        Parameters
        ----------
        dataset : xarray Dataset
            dataset containing the problems parameters: frequency, radiating_dof, water_depth, ...
        bodies : FloatingBody or list of FloatingBody
            The body or bodies involved in the problems
            They should all have different names.
        n_jobs: int, optional (default: 1)
            the number of jobs to run in parallel using the optional dependency `joblib`
            By defaults: do not use joblib and solve sequentially.

        Returns
        -------
        xarray Dataset
        """
        attrs = {
            'start_of_computation': datetime.now().isoformat(),
            **self.exportable_settings
        }
        problems = problems_from_dataset(dataset, bodies)
        if 'theta' in dataset.coords:
            results = self.solve_all(problems,
                                     keep_details=True,
                                     n_jobs=n_jobs)
            kochin = kochin_data_array(results, dataset.coords['theta'])
            dataset = assemble_dataset(results, attrs=attrs, **kwargs)
            dataset.update(kochin)
        else:
            results = self.solve_all(problems,
                                     keep_details=False,
                                     n_jobs=n_jobs)
            dataset = assemble_dataset(results, attrs=attrs, **kwargs)
        return dataset