capytaine 2.1__cp312-cp312-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. capytaine/__about__.py +16 -0
  2. capytaine/__init__.py +48 -0
  3. capytaine/bem/__init__.py +0 -0
  4. capytaine/bem/airy_waves.py +106 -0
  5. capytaine/bem/engines.py +441 -0
  6. capytaine/bem/problems_and_results.py +540 -0
  7. capytaine/bem/solver.py +463 -0
  8. capytaine/bodies/__init__.py +4 -0
  9. capytaine/bodies/bodies.py +1084 -0
  10. capytaine/bodies/dofs.py +19 -0
  11. capytaine/bodies/predefined/__init__.py +6 -0
  12. capytaine/bodies/predefined/cylinders.py +151 -0
  13. capytaine/bodies/predefined/rectangles.py +109 -0
  14. capytaine/bodies/predefined/spheres.py +70 -0
  15. capytaine/green_functions/__init__.py +2 -0
  16. capytaine/green_functions/abstract_green_function.py +12 -0
  17. capytaine/green_functions/delhommeau.py +380 -0
  18. capytaine/green_functions/libs/Delhommeau_float32.cp312-win_amd64.dll.a +0 -0
  19. capytaine/green_functions/libs/Delhommeau_float32.cp312-win_amd64.pyd +0 -0
  20. capytaine/green_functions/libs/Delhommeau_float64.cp312-win_amd64.dll.a +0 -0
  21. capytaine/green_functions/libs/Delhommeau_float64.cp312-win_amd64.pyd +0 -0
  22. capytaine/green_functions/libs/XieDelhommeau_float32.cp312-win_amd64.dll.a +0 -0
  23. capytaine/green_functions/libs/XieDelhommeau_float32.cp312-win_amd64.pyd +0 -0
  24. capytaine/green_functions/libs/XieDelhommeau_float64.cp312-win_amd64.dll.a +0 -0
  25. capytaine/green_functions/libs/XieDelhommeau_float64.cp312-win_amd64.pyd +0 -0
  26. capytaine/green_functions/libs/__init__.py +0 -0
  27. capytaine/io/__init__.py +0 -0
  28. capytaine/io/bemio.py +141 -0
  29. capytaine/io/legacy.py +328 -0
  30. capytaine/io/mesh_loaders.py +1061 -0
  31. capytaine/io/mesh_writers.py +692 -0
  32. capytaine/io/meshio.py +35 -0
  33. capytaine/io/xarray.py +514 -0
  34. capytaine/matrices/__init__.py +16 -0
  35. capytaine/matrices/block.py +590 -0
  36. capytaine/matrices/block_toeplitz.py +325 -0
  37. capytaine/matrices/builders.py +89 -0
  38. capytaine/matrices/linear_solvers.py +233 -0
  39. capytaine/matrices/low_rank.py +393 -0
  40. capytaine/meshes/__init__.py +6 -0
  41. capytaine/meshes/clipper.py +464 -0
  42. capytaine/meshes/collections.py +313 -0
  43. capytaine/meshes/geometry.py +409 -0
  44. capytaine/meshes/meshes.py +746 -0
  45. capytaine/meshes/predefined/__init__.py +6 -0
  46. capytaine/meshes/predefined/cylinders.py +314 -0
  47. capytaine/meshes/predefined/rectangles.py +261 -0
  48. capytaine/meshes/predefined/spheres.py +62 -0
  49. capytaine/meshes/properties.py +199 -0
  50. capytaine/meshes/quadratures.py +80 -0
  51. capytaine/meshes/quality.py +448 -0
  52. capytaine/meshes/surface_integrals.py +63 -0
  53. capytaine/meshes/symmetric.py +383 -0
  54. capytaine/post_pro/__init__.py +6 -0
  55. capytaine/post_pro/free_surfaces.py +88 -0
  56. capytaine/post_pro/impedance.py +92 -0
  57. capytaine/post_pro/kochin.py +54 -0
  58. capytaine/post_pro/rao.py +60 -0
  59. capytaine/tools/__init__.py +0 -0
  60. capytaine/tools/cache_on_disk.py +24 -0
  61. capytaine/tools/deprecation_handling.py +18 -0
  62. capytaine/tools/lists_of_points.py +52 -0
  63. capytaine/tools/lru_cache.py +49 -0
  64. capytaine/tools/optional_imports.py +27 -0
  65. capytaine/tools/prony_decomposition.py +94 -0
  66. capytaine/tools/symbolic_multiplication.py +104 -0
  67. capytaine/ui/__init__.py +0 -0
  68. capytaine/ui/cli.py +28 -0
  69. capytaine/ui/rich.py +5 -0
  70. capytaine/ui/vtk/__init__.py +3 -0
  71. capytaine/ui/vtk/animation.py +329 -0
  72. capytaine/ui/vtk/body_viewer.py +26 -0
  73. capytaine/ui/vtk/helpers.py +82 -0
  74. capytaine/ui/vtk/mesh_viewer.py +461 -0
  75. capytaine-2.1.dist-info/DELVEWHEEL +2 -0
  76. capytaine-2.1.dist-info/LICENSE +674 -0
  77. capytaine-2.1.dist-info/METADATA +756 -0
  78. capytaine-2.1.dist-info/RECORD +85 -0
  79. capytaine-2.1.dist-info/WHEEL +4 -0
  80. capytaine-2.1.dist-info/entry_points.txt +3 -0
  81. capytaine.libs/libgcc_s_seh-1.dll +0 -0
  82. capytaine.libs/libgfortran-5.dll +0 -0
  83. capytaine.libs/libgomp-1.dll +0 -0
  84. capytaine.libs/libquadmath-0.dll +0 -0
  85. capytaine.libs/libwinpthread-1.dll +0 -0
@@ -0,0 +1,463 @@
1
+ # Copyright (C) 2017-2019 Matthieu Ancellin
2
+ # See LICENSE file at <https://github.com/mancellin/capytaine>
3
+ """Solver for the BEM problem.
4
+
5
+ .. code-block:: python
6
+
7
+ problem = RadiationProblem(...)
8
+ result = BEMSolver(green_functions=..., engine=...).solve(problem)
9
+
10
+ """
11
+
12
+ import logging
13
+
14
+ import numpy as np
15
+
16
+ from datetime import datetime
17
+
18
+ from rich.progress import track
19
+
20
+ from capytaine.bem.problems_and_results import LinearPotentialFlowProblem
21
+ from capytaine.green_functions.delhommeau import Delhommeau
22
+ from capytaine.bem.engines import BasicMatrixEngine
23
+ from capytaine.io.xarray import problems_from_dataset, assemble_dataset, kochin_data_array
24
+ from capytaine.tools.optional_imports import silently_import_optional_dependency
25
+ from capytaine.tools.lists_of_points import _normalize_points, _normalize_free_surface_points
26
+ from capytaine.tools.symbolic_multiplication import supporting_symbolic_multiplication
27
+
28
+ LOG = logging.getLogger(__name__)
29
+
30
+ class BEMSolver:
31
+ """
32
+ Solver for linear potential flow problems.
33
+
34
+ Parameters
35
+ ----------
36
+ green_function: AbstractGreenFunction, optional
37
+ Object handling the computation of the Green function.
38
+ (default: :class:`~capytaine.green_function.delhommeau.Delhommeau`)
39
+ engine: MatrixEngine, optional
40
+ Object handling the building of matrices and the resolution of linear systems with these matrices.
41
+ (default: :class:`~capytaine.bem.engines.BasicMatrixEngine`)
42
+
43
+ Attributes
44
+ ----------
45
+ exportable_settings : dict
46
+ Settings of the solver that can be saved to reinit the same solver later.
47
+ """
48
+
49
+ def __init__(self, *, green_function=None, engine=None):
50
+ self.green_function = Delhommeau() if green_function is None else green_function
51
+ self.engine = BasicMatrixEngine() if engine is None else engine
52
+
53
+ try:
54
+ self.exportable_settings = {
55
+ **self.green_function.exportable_settings,
56
+ **self.engine.exportable_settings
57
+ }
58
+ except AttributeError:
59
+ pass
60
+
61
+ def __str__(self):
62
+ return f"BEMSolver(engine={self.engine}, green_function={self.green_function})"
63
+
64
+ def __repr__(self):
65
+ return self.__str__()
66
+
67
+ def _repr_pretty_(self, p, cycle):
68
+ p.text(self.__str__())
69
+
70
+ @classmethod
71
+ def from_exported_settings(settings):
72
+ raise NotImplementedError
73
+
74
+ def solve(self, problem, method='indirect', keep_details=True, _check_wavelength=True):
75
+ """Solve the linear potential flow problem.
76
+
77
+ Parameters
78
+ ----------
79
+ problem: LinearPotentialFlowProblem
80
+ the problem to be solved
81
+ method: string, optional
82
+ select boundary integral approach indirect (i.e.Nemoh)/direct (i.e.WAMIT) (default: indirect)
83
+ keep_details: bool, optional
84
+ if True, store the sources and the potential on the floating body in the output object
85
+ (default: True)
86
+ _check_wavelength: bool, optional
87
+ if True, check the mesh resolution with respect to the wavelength
88
+
89
+ Returns
90
+ -------
91
+ LinearPotentialFlowResult
92
+ an object storing the problem data and its results
93
+ """
94
+ LOG.info("Solve %s.", problem)
95
+
96
+ if _check_wavelength: self._check_wavelength([problem])
97
+
98
+ if problem.forward_speed != 0.0:
99
+ omega, wavenumber = problem.encounter_omega, problem.encounter_wavenumber
100
+ else:
101
+ omega, wavenumber = problem.omega, problem.wavenumber
102
+
103
+ linear_solver = supporting_symbolic_multiplication(self.engine.linear_solver)
104
+ if (method == 'direct'):
105
+ if problem.forward_speed != 0.0:
106
+ raise NotImplementedError("Direct solver is not able to solve problems with forward speed.")
107
+
108
+ S, D = self.engine.build_matrices(
109
+ problem.body.mesh, problem.body.mesh,
110
+ problem.free_surface, problem.water_depth, wavenumber,
111
+ self.green_function, adjoint_double_layer=False
112
+ )
113
+
114
+ potential = linear_solver(D, S @ problem.boundary_condition)
115
+ pressure = 1j * omega * problem.rho * potential
116
+ sources = None
117
+ else:
118
+ S, K = self.engine.build_matrices(
119
+ problem.body.mesh, problem.body.mesh,
120
+ problem.free_surface, problem.water_depth, wavenumber,
121
+ self.green_function, adjoint_double_layer=True
122
+ )
123
+
124
+ sources = linear_solver(K, problem.boundary_condition)
125
+ potential = S @ sources
126
+ pressure = 1j * omega * problem.rho * potential
127
+ if problem.forward_speed != 0.0:
128
+ result = problem.make_results_container(sources=sources)
129
+ # Temporary result object to compute the ∇Φ term
130
+ nabla_phi = self._compute_potential_gradient(problem.body.mesh, result)
131
+ pressure += problem.rho * problem.forward_speed * nabla_phi[:, 0]
132
+
133
+ forces = problem.body.integrate_pressure(pressure)
134
+
135
+ if not keep_details:
136
+ result = problem.make_results_container(forces)
137
+ else:
138
+ result = problem.make_results_container(forces, sources, potential, pressure)
139
+
140
+ LOG.debug("Done!")
141
+
142
+ return result
143
+
144
+ def solve_all(self, problems, *, method='indirect', n_jobs=1, progress_bar=True, _check_wavelength=True, **kwargs):
145
+ """Solve several problems.
146
+ Optional keyword arguments are passed to `BEMSolver.solve`.
147
+
148
+ Parameters
149
+ ----------
150
+ problems: list of LinearPotentialFlowProblem
151
+ several problems to be solved
152
+ method: string, optional
153
+ select boundary integral approach indirect (i.e.Nemoh)/direct (i.e.WAMIT) (default: indirect)
154
+ n_jobs: int, optional (default: 1)
155
+ the number of jobs to run in parallel using the optional dependency `joblib`
156
+ By defaults: do not use joblib and solve sequentially.
157
+ progress_bar: bool, optional (default: True)
158
+ Display a progress bar while solving
159
+
160
+ Returns
161
+ -------
162
+ list of LinearPotentialFlowResult
163
+ the solved problems
164
+ """
165
+ if _check_wavelength: self._check_wavelength(problems)
166
+
167
+ if n_jobs == 1: # force sequential resolution
168
+ problems = sorted(problems)
169
+ if progress_bar:
170
+ problems = track(problems, total=len(problems), description="Solving BEM problems")
171
+ return [self.solve(pb, method=method, _check_wavelength=False, **kwargs) for pb in problems]
172
+ else:
173
+ joblib = silently_import_optional_dependency("joblib")
174
+ if joblib is None:
175
+ raise ImportError(f"Setting the `n_jobs` argument to {n_jobs} requires the missing optional dependency 'joblib'.")
176
+ groups_of_problems = LinearPotentialFlowProblem._group_for_parallel_resolution(problems)
177
+ parallel = joblib.Parallel(return_as="generator", n_jobs=n_jobs)
178
+ groups_of_results = parallel(joblib.delayed(self.solve_all)(grp, method=method, n_jobs=1, progress_bar=False, _check_wavelength=False, **kwargs) for grp in groups_of_problems)
179
+ if progress_bar:
180
+ groups_of_results = track(groups_of_results,
181
+ total=len(groups_of_problems),
182
+ description=f"Solving BEM problems with {n_jobs} threads:")
183
+ results = [res for grp in groups_of_results for res in grp] # flatten the nested list
184
+ return results
185
+
186
+ @staticmethod
187
+ def _check_wavelength(problems):
188
+ """Display a warning if some of the problems have a mesh resolution
189
+ that might not be sufficient for the given wavelength."""
190
+ risky_problems = [pb for pb in problems
191
+ if pb.wavelength < pb.body.minimal_computable_wavelength]
192
+ nb_risky_problems = len(risky_problems)
193
+ if nb_risky_problems == 1:
194
+ pb = risky_problems[0]
195
+ freq_type = risky_problems[0].provided_freq_type
196
+ freq = pb.__getattribute__(freq_type)
197
+ LOG.warning(f"Mesh resolution for {pb}:\n"
198
+ f"The resolution of the mesh of the body {pb.body.__short_str__()} might "
199
+ f"be insufficient for {freq_type}={freq}.\n"
200
+ "This warning appears because the largest panel of this mesh "
201
+ f"has radius {pb.body.mesh.faces_radiuses.max():.3f} > wavelength/8."
202
+ )
203
+ elif nb_risky_problems > 1:
204
+ freq_type = risky_problems[0].provided_freq_type
205
+ freqs = np.array([float(pb.__getattribute__(freq_type)) for pb in risky_problems])
206
+ LOG.warning(f"Mesh resolution for {nb_risky_problems} problems:\n"
207
+ "The resolution of the mesh might be insufficient "
208
+ f"for {freq_type} ranging from {freqs.min():.3f} to {freqs.max():.3f}.\n"
209
+ "This warning appears when the largest panel of this mesh "
210
+ "has radius > wavelength/8."
211
+ )
212
+
213
+ def fill_dataset(self, dataset, bodies, *, method='indirect', n_jobs=1, **kwargs):
214
+ """Solve a set of problems defined by the coordinates of an xarray dataset.
215
+
216
+ Parameters
217
+ ----------
218
+ dataset : xarray Dataset
219
+ dataset containing the problems parameters: frequency, radiating_dof, water_depth, ...
220
+ bodies : FloatingBody or list of FloatingBody
221
+ The body or bodies involved in the problems
222
+ They should all have different names.
223
+ method: string, optional
224
+ select boundary integral approach indirect (i.e.Nemoh)/direct (i.e.WAMIT) (default: indirect)
225
+ n_jobs: int, optional (default: 1)
226
+ the number of jobs to run in parallel using the optional dependency `joblib`
227
+ By defaults: do not use joblib and solve sequentially.
228
+ progress_bar: bool, optional (default: True)
229
+ Display a progress bar while solving
230
+
231
+ Returns
232
+ -------
233
+ xarray Dataset
234
+ """
235
+ attrs = {'start_of_computation': datetime.now().isoformat(),
236
+ **self.exportable_settings}
237
+ problems = problems_from_dataset(dataset, bodies)
238
+ if 'theta' in dataset.coords:
239
+ results = self.solve_all(problems, keep_details=True, method=method, n_jobs=n_jobs)
240
+ kochin = kochin_data_array(results, dataset.coords['theta'])
241
+ dataset = assemble_dataset(results, attrs=attrs, **kwargs)
242
+ dataset.update(kochin)
243
+ else:
244
+ results = self.solve_all(problems, keep_details=False, method=method, n_jobs=n_jobs)
245
+ dataset = assemble_dataset(results, attrs=attrs, **kwargs)
246
+ return dataset
247
+
248
+
249
+ def compute_potential(self, points, result):
250
+ """Compute the value of the potential at given points for a previously solved potential flow problem.
251
+
252
+ Parameters
253
+ ----------
254
+ points: array of shape (3,) or (N, 3), or 3-ple of arrays returned by meshgrid, or cpt.Mesh or cpt.CollectionOfMeshes object
255
+ Coordinates of the point(s) at which the potential should be computed
256
+ result: LinearPotentialFlowResult
257
+ The return of the BEM solver
258
+
259
+ Returns
260
+ -------
261
+ complex-valued array of shape (1,) or (N,) or (nx, ny, nz) or (mesh.nb_faces,) depending of the kind of input
262
+ The value of the potential at the points
263
+
264
+ Raises
265
+ ------
266
+ Exception: if the :code:`LinearPotentialFlowResult` object given as input does not contain the source distribution.
267
+ """
268
+ points, output_shape = _normalize_points(points, keep_mesh=True)
269
+ if result.sources is None:
270
+ raise Exception(f"""The values of the sources of {result} cannot been found.
271
+ They probably have not been stored by the solver because the option keep_details=True have not been set or the direct method has been used.
272
+ Please re-run the resolution with the indirect method and keep_details=True.""")
273
+
274
+ S, _ = self.green_function.evaluate(points, result.body.mesh, result.free_surface, result.water_depth, result.encounter_wavenumber)
275
+ potential = S @ result.sources # Sum the contributions of all panels in the mesh
276
+ return potential.reshape(output_shape)
277
+
278
+ def _compute_potential_gradient(self, points, result):
279
+ points, output_shape = _normalize_points(points, keep_mesh=True)
280
+
281
+ if result.sources is None:
282
+ raise Exception(f"""The values of the sources of {result} cannot been found.
283
+ They probably have not been stored by the solver because the option keep_details=True have not been set.
284
+ Please re-run the resolution with this option.""")
285
+
286
+ _, gradG = self.green_function.evaluate(points, result.body.mesh, result.free_surface, result.water_depth, result.encounter_wavenumber,
287
+ early_dot_product=False)
288
+ velocities = np.einsum('ijk,j->ik', gradG, result.sources) # Sum the contributions of all panels in the mesh
289
+ return velocities.reshape((*output_shape, 3))
290
+
291
+ def compute_velocity(self, points, result):
292
+ """Compute the value of the velocity vector at given points for a previously solved potential flow problem.
293
+
294
+ Parameters
295
+ ----------
296
+ points: array of shape (3,) or (N, 3), or 3-ple of arrays returned by meshgrid, or cpt.Mesh or cpt.CollectionOfMeshes object
297
+ Coordinates of the point(s) at which the velocity should be computed
298
+ result: LinearPotentialFlowResult
299
+ The return of the BEM solver
300
+
301
+ Returns
302
+ -------
303
+ 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
304
+ The value of the velocity at the points
305
+
306
+ Raises
307
+ ------
308
+ Exception: if the :code:`LinearPotentialFlowResult` object given as input does not contain the source distribution.
309
+ """
310
+ nabla_phi = self._compute_potential_gradient(points, result)
311
+ if result.forward_speed != 0.0:
312
+ nabla_phi[..., 0] -= result.forward_speed
313
+ return nabla_phi
314
+
315
+ def compute_pressure(self, points, result):
316
+ """Compute the value of the pressure at given points for a previously solved potential flow problem.
317
+
318
+ Parameters
319
+ ----------
320
+ points: array of shape (3,) or (N, 3), or 3-ple of arrays returned by meshgrid, or cpt.Mesh or cpt.CollectionOfMeshes object
321
+ Coordinates of the point(s) at which the pressure should be computed
322
+ result: LinearPotentialFlowResult
323
+ The return of the BEM solver
324
+
325
+ Returns
326
+ -------
327
+ complex-valued array of shape (1,) or (N,) or (nx, ny, nz) or (mesh.nb_faces,) depending of the kind of input
328
+ The value of the pressure at the points
329
+
330
+ Raises
331
+ ------
332
+ Exception: if the :code:`LinearPotentialFlowResult` object given as input does not contain the source distribution.
333
+ """
334
+ if result.forward_speed != 0:
335
+ pressure = 1j * result.encounter_omega * result.rho * self.compute_potential(points, result)
336
+ nabla_phi = self._compute_potential_gradient(points, result)
337
+ pressure += result.rho * result.forward_speed * nabla_phi[..., 0]
338
+ else:
339
+ pressure = 1j * result.omega * result.rho * self.compute_potential(points, result)
340
+ return pressure
341
+
342
+
343
+ def compute_free_surface_elevation(self, points, result):
344
+ """Compute the value of the free surface elevation at given points for a previously solved potential flow problem.
345
+
346
+ Parameters
347
+ ----------
348
+ points: array of shape (2,) or (N, 2), or 2-ple of arrays returned by meshgrid, or cpt.Mesh or cpt.CollectionOfMeshes object
349
+ Coordinates of the point(s) at which the free surface elevation should be computed
350
+ result: LinearPotentialFlowResult
351
+ The return of the BEM solver
352
+
353
+ Returns
354
+ -------
355
+ complex-valued array of shape (1,) or (N,) or (nx, ny, nz) or (mesh.nb_faces,) depending of the kind of input
356
+ The value of the free surface elevation at the points
357
+
358
+ Raises
359
+ ------
360
+ Exception: if the :code:`LinearPotentialFlowResult` object given as input does not contain the source distribution.
361
+ """
362
+ points, output_shape = _normalize_free_surface_points(points, keep_mesh=True)
363
+
364
+ if result.forward_speed != 0:
365
+ fs_elevation = -1/result.g * (-1j*result.encounter_omega) * self.compute_potential(points, result)
366
+ nabla_phi = self._compute_potential_gradient(points, result)
367
+ fs_elevation += -1/result.g * result.forward_speed * nabla_phi[..., 0]
368
+ else:
369
+ fs_elevation = -1/result.g * (-1j*result.omega) * self.compute_potential(points, result)
370
+
371
+ return fs_elevation.reshape(output_shape)
372
+
373
+
374
+ ## Legacy
375
+
376
+ def get_potential_on_mesh(self, result, mesh, chunk_size=50):
377
+ """Compute the potential on a mesh for the potential field of a previously solved problem.
378
+ Since the interaction matrix does not need to be computed in full to compute the matrix-vector product,
379
+ only a few lines are evaluated at a time to reduce the memory cost of the operation.
380
+
381
+ The newer method :code:`compute_potential` should be preferred in the future.
382
+
383
+ Parameters
384
+ ----------
385
+ result : LinearPotentialFlowResult
386
+ the return of the BEM solver
387
+ mesh : Mesh or CollectionOfMeshes
388
+ a mesh
389
+ chunk_size: int, optional
390
+ Number of lines to compute in the matrix.
391
+ (legacy, should be passed as an engine setting instead).
392
+
393
+ Returns
394
+ -------
395
+ array of shape (mesh.nb_faces,)
396
+ potential on the faces of the mesh
397
+
398
+ Raises
399
+ ------
400
+ Exception: if the :code:`Result` object given as input does not contain the source distribution.
401
+ """
402
+ LOG.info(f"Compute potential on {mesh.name} for {result}.")
403
+
404
+ if result.sources is None:
405
+ raise Exception(f"""The values of the sources of {result} cannot been found.
406
+ They probably have not been stored by the solver because the option keep_details=True have not been set or the direct method has been used.
407
+ Please re-run the resolution with the indirect method and keep_details=True.""")
408
+
409
+ if chunk_size > mesh.nb_faces:
410
+ S = self.engine.build_S_matrix(
411
+ mesh,
412
+ result.body.mesh,
413
+ result.free_surface, result.water_depth, result.wavenumber,
414
+ self.green_function
415
+ )
416
+ phi = S @ result.sources
417
+
418
+ else:
419
+ phi = np.empty((mesh.nb_faces,), dtype=np.complex128)
420
+ for i in range(0, mesh.nb_faces, chunk_size):
421
+ faces_to_extract = list(range(i, min(i+chunk_size, mesh.nb_faces)))
422
+ S = self.engine.build_S_matrix(
423
+ mesh.extract_faces(faces_to_extract),
424
+ result.body.mesh,
425
+ result.free_surface, result.water_depth, result.wavenumber,
426
+ self.green_function
427
+ )
428
+ phi[i:i+chunk_size] = S @ result.sources
429
+
430
+ LOG.debug(f"Done computing potential on {mesh.name} for {result}.")
431
+
432
+ return phi
433
+
434
+ def get_free_surface_elevation(self, result, free_surface, keep_details=False):
435
+ """Compute the elevation of the free surface on a mesh for a previously solved problem.
436
+
437
+ The newer method :code:`compute_free_surface_elevation` should be preferred in the future.
438
+
439
+ Parameters
440
+ ----------
441
+ result : LinearPotentialFlowResult
442
+ the return of the solver
443
+ free_surface : FreeSurface
444
+ a meshed free surface
445
+ keep_details : bool, optional
446
+ if True, keep the free surface elevation in the LinearPotentialFlowResult (default:False)
447
+
448
+ Returns
449
+ -------
450
+ array of shape (free_surface.nb_faces,)
451
+ the free surface elevation on each faces of the meshed free surface
452
+
453
+ Raises
454
+ ------
455
+ Exception: if the :code:`Result` object given as input does not contain the source distribution.
456
+ """
457
+ if result.forward_speed != 0.0:
458
+ raise NotImplementedError("For free surface elevation with forward speed, please use the `compute_free_surface_elevation` method.")
459
+
460
+ fs_elevation = 1j*result.omega/result.g * self.get_potential_on_mesh(result, free_surface.mesh)
461
+ if keep_details:
462
+ result.fs_elevation[free_surface] = fs_elevation
463
+ return fs_elevation
@@ -0,0 +1,4 @@
1
+ # Copyright (C) 2017-2019 Matthieu Ancellin
2
+ # See LICENSE file at <https://github.com/mancellin/capytaine>
3
+
4
+ from capytaine.bodies.bodies import FloatingBody