capytaine.bem.solver module¶
Solver for the BEM problem.
problem = RadiationProblem(...)
result = BEMSolver(engine=..., method=...).solve(problem)
- class capytaine.bem.solver.BEMSolver(*, green_function=None, engine=None, method='indirect')[source]¶
Bases:
objectSolver for linear potential flow problems.
- Parameters:
engine (MatrixEngine, optional) – Object handling the building of matrices and the resolution of linear systems with these matrices. (default:
BasicMatrixEngine)method (string, optional) – select boundary integral equation used to solve the problems. Accepted values: “indirect” (as in e.g. Nemoh), “direct” (as in e.g. WAMIT) Default value: “indirect”
green_function (AbstractGreenFunction, optional) – For convenience and backward compatibility, the Green function can be set here if the engine is the default one. This argument is just passed to the default engine at initialization.
- Variables:
timer (Timer) – Storing the time spent on each subtasks of the resolution
exportable_settings (dict) – Settings of the solver that can be saved to reinit the same solver later.
- compute_free_surface_elevation(points, result)[source]¶
Compute the value of the free surface elevation at given points for a previously solved potential flow problem.
- Parameters:
points (array of shape (2,) or (N, 2), or 2-ple of arrays returned by meshgrid, or MeshLike object) – Coordinates of the point(s) at which the free surface elevation should be computed
result (LinearPotentialFlowResult) – The return of the BEM solver
- Returns:
The value of the free surface elevation at the points
- Return type:
complex-valued array of shape (1,) or (N,) or (nx, ny, nz) or (mesh.nb_faces,) depending of the kind of input
- Raises:
Exception – if the
LinearPotentialFlowResultobject given as input does not contain the source distribution.:
- compute_potential(points, result)[source]¶
Compute the value of the potential at given points for a previously solved potential flow problem.
- Parameters:
points (array of shape (3,) or (N, 3), or 3-ple of arrays returned by meshgrid, or MeshLike object) – Coordinates of the point(s) at which the potential should be computed
result (LinearPotentialFlowResult) – The return of the BEM solver
- Returns:
The value of the potential at the points
- Return type:
complex-valued array of shape (1,) or (N,) or (nx, ny, nz) or (mesh.nb_faces,) depending of the kind of input
- Raises:
Exception – if the
LinearPotentialFlowResultobject given as input does not contain the source distribution.:
- compute_pressure(points, result)[source]¶
Compute the value of the pressure at given points for a previously solved potential flow problem.
- Parameters:
points (array of shape (3,) or (N, 3), or 3-ple of arrays returned by meshgrid, or MeshLike object) – Coordinates of the point(s) at which the pressure should be computed
result (LinearPotentialFlowResult) – The return of the BEM solver
- Returns:
The value of the pressure at the points
- Return type:
complex-valued array of shape (1,) or (N,) or (nx, ny, nz) or (mesh.nb_faces,) depending of the kind of input
- Raises:
Exception – if the
LinearPotentialFlowResultobject given as input does not contain the source distribution.:
- compute_velocity(points, result)[source]¶
Compute the value of the velocity vector at given points for a previously solved potential flow problem.
- Parameters:
points (array of shape (3,) or (N, 3), or 3-ple of arrays returned by meshgrid, or MeshLike object) – Coordinates of the point(s) at which the velocity should be computed
result (LinearPotentialFlowResult) – The return of the BEM solver
- Returns:
The value of the velocity at the points
- Return type:
complex-valued array of shape (3,) or (N,, 3) or (nx, ny, nz, 3) or (mesh.nb_faces, 3) depending of the kind of input
- Raises:
Exception – if the
LinearPotentialFlowResultobject given as input does not contain the source distribution.:
- fill_dataset(dataset, bodies, *, method=None, n_jobs=1, n_threads=None, _check_wavelength=True, progress_bar=None, **kwargs)[source]¶
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 Multibody or list of FloatingBody or list of Multibody) – The body or bodies involved in the problems They should all have different names.
method (string, optional) – select boundary integral equation used to solve the problems. It is recommended to set the method more globally when initializing the solver. If provided here, the value in argument of fill_dataset overrides the global one.
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.n_threads (int, optional) – the number of threads used to solve each problem. The total number of used CPU will be n_jobs×n_threads. By default: use as much as possible. Requires the optional dependency
threadpoolctlifn_jobs==1. Also controlled by the environment variablesOMP_NUM_THREADSandMKL_NUM_THREADS.progress_bar (bool, optional) – Display a progress bar while solving. If no value is provided to this method directly, check whether the environment variable CAPYTAINE_PROGRESS_BAR is defined and otherwise default to True.
_check_wavelength (bool, optional (default: True)) – If True, the frequencies are compared to the mesh resolution and the estimated first irregular frequency to warn the user.
- Return type:
xarray Dataset
- get_free_surface_elevation(result, free_surface, keep_details=False)[source]¶
Compute the elevation of the free surface on a mesh for a previously solved problem.
The newer method
compute_free_surface_elevationshould be preferred in the future.- Parameters:
result (LinearPotentialFlowResult) – the return of the solver
free_surface (FreeSurface) – a meshed free surface
keep_details (bool, optional) – if True, keep the free surface elevation in the LinearPotentialFlowResult (default:False)
- Returns:
the free surface elevation on each faces of the meshed free surface
- Return type:
array of shape (free_surface.nb_faces,)
- Raises:
Exception – if the
Resultobject given as input does not contain the source distribution.:
- get_potential_on_mesh(result, mesh, chunk_size=50)[source]¶
Compute the potential on a mesh for the potential field of a previously solved problem. Since the interaction matrix does not need to be computed in full to compute the matrix-vector product, only a few lines are evaluated at a time to reduce the memory cost of the operation.
The newer method
compute_potentialshould be preferred in the future.- Parameters:
result (LinearPotentialFlowResult) – the return of the BEM solver
mesh (MeshLike) – a mesh
chunk_size (int, optional) – Number of lines to compute in the matrix. (legacy, should be passed as an engine setting instead).
- Returns:
potential on the faces of the mesh
- Return type:
array of shape (mesh.nb_faces,)
- Raises:
Exception – if the
Resultobject given as input does not contain the source distribution.:
- solve_all(problems, *, method=None, n_jobs=1, n_threads=None, progress_bar=None, _check_wavelength=True, _display_errors=True, **kwargs)[source]¶
Solve several problems. Optional keyword arguments are passed to BEMSolver.solve.
- Parameters:
problems (list of LinearPotentialFlowProblem) – several problems to be solved
method (string, optional) – select boundary integral equation used to solve the problems. It is recommended to set the method more globally when initializing the solver. If provided here, the value in argument of solve_all overrides the global one.
n_jobs (int, optional (default: 1)) – the number of jobs to run in parallel using the optional dependency
joblibBy defaults: do not use joblib and solve sequentially.n_threads (int, optional) – the number of threads used to solve each problem. The total number of used CPU will be n_jobs×n_threads. By default: use as much as possible. Requires the optional dependency
threadpoolctlifn_jobs==1. Also controlled by the environment variablesOMP_NUM_THREADSandMKL_NUM_THREADS.progress_bar (bool, optional) – Display a progress bar while solving. If no value is provided to this method directly, check whether the environment variable CAPYTAINE_PROGRESS_BAR is defined and otherwise default to True.
_check_wavelength (bool, optional (default: True)) – If True, the frequencies are compared to the mesh resolution and the estimated first irregular frequency to warn the user.
- Returns:
the solved problems
- Return type:
list of LinearPotentialFlowResult