wavesimfem 0.5.0__py3-none-any.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.
wavesimfem/__init__.py ADDED
@@ -0,0 +1,214 @@
1
+ """WaveSimFEM: A GPU-accelerated finite element framework for acoustic and elastic wave propagation in layered media.
2
+
3
+ Public symbols are resolved lazily so that ``import wavesimfem`` (and
4
+ lightweight modules such as :mod:`wavesimfem.config`) do not pull in
5
+ DOLFINx, PETSc, or MPI until a FEM feature is actually used.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import importlib
11
+ from importlib.metadata import PackageNotFoundError, version
12
+ from typing import TYPE_CHECKING, Any
13
+
14
+ try:
15
+ __version__ = version("wavesimfem")
16
+ except PackageNotFoundError: # pragma: no cover - source tree without installation
17
+ __version__ = "0.0.0+unknown"
18
+
19
+ # Public name -> defining submodule
20
+ _EXPORTS: dict[str, str] = {
21
+ # acoustics
22
+ "AcousticProblem": "acoustics",
23
+ "AcousticSolveResult": "acoustics",
24
+ "build_acoustic_problem": "acoustics",
25
+ "run_acoustic_simulation": "acoustics",
26
+ "solve_acoustic": "acoustics",
27
+ # analysis
28
+ "plot_full_analysis": "analysis",
29
+ "plot_quick_overview": "analysis",
30
+ "bandpass_filter": "analysis",
31
+ # characterisation
32
+ "measure_packets": "characterisation",
33
+ "write_characterisation": "characterisation",
34
+ # config
35
+ "dump_config": "config",
36
+ "flatten_config": "config",
37
+ "generate_template_config": "config",
38
+ "load_config": "config",
39
+ "parse_and_resolve_config": "config",
40
+ "resolve_and_apply_config": "config",
41
+ # device
42
+ "DeviceInfo": "device",
43
+ "DeviceUnavailableError": "device",
44
+ "detect_available_devices": "device",
45
+ "select_device": "device",
46
+ # lamb
47
+ "separate_fundamentals": "lamb",
48
+ "write_lamb_report": "lamb",
49
+ # materials
50
+ "compute_rayleigh_speed": "materials",
51
+ "preflight_estimate": "materials",
52
+ "structure_from_config": "materials",
53
+ # numerics
54
+ "PetscRK4": "numerics",
55
+ "PointSensors": "numerics",
56
+ "RK4_STABILITY_RADIUS": "numerics",
57
+ "dispersion_spectrum": "numerics",
58
+ "operator_bound": "numerics",
59
+ "rk4_step": "numerics",
60
+ "time_grid": "numerics",
61
+ "validate_tensor": "numerics",
62
+ # parallel
63
+ "limit_threads_per_rank": "parallel",
64
+ # reporting
65
+ "set_verbosity": "reporting",
66
+ # sources
67
+ "SOURCE_TYPES": "sources",
68
+ "ricker": "sources",
69
+ "source_signal": "sources",
70
+ "tone_burst": "sources",
71
+ # structure_analysis
72
+ "reference_dispersion": "structure_analysis",
73
+ "structure_profile": "structure_analysis",
74
+ # units
75
+ "parse_quantity": "units",
76
+ # solvers
77
+ "run_simulation": "solvers",
78
+ "build_problem": "solvers",
79
+ "solve_explicit": "solvers",
80
+ "solve_implicit": "solvers",
81
+ # solvers_gpu
82
+ "build_sensor_interpolation_matrix": "solvers_gpu",
83
+ "integrate_explicit_rk4": "solvers_gpu",
84
+ "solve_explicit_rk4_device": "solvers_gpu",
85
+ # wave_reports
86
+ "write_structure_report": "wave_reports",
87
+ # wave_spectra
88
+ "phase_velocity_spectrum": "wave_spectra",
89
+ "polarization_spectrum": "wave_spectra",
90
+ }
91
+
92
+ __all__ = [
93
+ "RK4_STABILITY_RADIUS",
94
+ "SOURCE_TYPES",
95
+ "AcousticProblem",
96
+ "AcousticSolveResult",
97
+ "DeviceInfo",
98
+ "DeviceUnavailableError",
99
+ "PetscRK4",
100
+ "PointSensors",
101
+ "__version__",
102
+ "bandpass_filter",
103
+ "build_acoustic_problem",
104
+ "build_problem",
105
+ "build_sensor_interpolation_matrix",
106
+ "compute_rayleigh_speed",
107
+ "detect_available_devices",
108
+ "dispersion_spectrum",
109
+ "dump_config",
110
+ "flatten_config",
111
+ "generate_template_config",
112
+ "integrate_explicit_rk4",
113
+ "limit_threads_per_rank",
114
+ "load_config",
115
+ "measure_packets",
116
+ "operator_bound",
117
+ "parse_and_resolve_config",
118
+ "parse_quantity",
119
+ "phase_velocity_spectrum",
120
+ "plot_full_analysis",
121
+ "plot_quick_overview",
122
+ "polarization_spectrum",
123
+ "preflight_estimate",
124
+ "reference_dispersion",
125
+ "resolve_and_apply_config",
126
+ "ricker",
127
+ "rk4_step",
128
+ "run_acoustic_simulation",
129
+ "run_simulation",
130
+ "select_device",
131
+ "separate_fundamentals",
132
+ "set_verbosity",
133
+ "solve_acoustic",
134
+ "solve_explicit",
135
+ "solve_explicit_rk4_device",
136
+ "solve_implicit",
137
+ "source_signal",
138
+ "structure_from_config",
139
+ "structure_profile",
140
+ "time_grid",
141
+ "tone_burst",
142
+ "validate_tensor",
143
+ "write_characterisation",
144
+ "write_lamb_report",
145
+ "write_structure_report",
146
+ ]
147
+
148
+
149
+ def __getattr__(name: str) -> Any:
150
+ module_name = _EXPORTS.get(name)
151
+ if module_name is None:
152
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
153
+ value = getattr(importlib.import_module(f"{__name__}.{module_name}"), name)
154
+ globals()[name] = value # cache for subsequent lookups
155
+ return value
156
+
157
+
158
+ def __dir__() -> list[str]:
159
+ return sorted(set(globals()) | set(__all__))
160
+
161
+
162
+ if TYPE_CHECKING: # pragma: no cover - static analysers only
163
+ from wavesimfem.acoustics import (
164
+ AcousticProblem,
165
+ AcousticSolveResult,
166
+ build_acoustic_problem,
167
+ run_acoustic_simulation,
168
+ solve_acoustic,
169
+ )
170
+ from wavesimfem.analysis import bandpass_filter, plot_full_analysis, plot_quick_overview
171
+ from wavesimfem.characterisation import measure_packets, write_characterisation
172
+ from wavesimfem.config import (
173
+ dump_config,
174
+ flatten_config,
175
+ generate_template_config,
176
+ load_config,
177
+ parse_and_resolve_config,
178
+ resolve_and_apply_config,
179
+ )
180
+ from wavesimfem.device import (
181
+ DeviceInfo,
182
+ DeviceUnavailableError,
183
+ detect_available_devices,
184
+ select_device,
185
+ )
186
+ from wavesimfem.lamb import separate_fundamentals, write_lamb_report
187
+ from wavesimfem.materials import (
188
+ compute_rayleigh_speed,
189
+ preflight_estimate,
190
+ structure_from_config,
191
+ )
192
+ from wavesimfem.numerics import (
193
+ RK4_STABILITY_RADIUS,
194
+ PetscRK4,
195
+ PointSensors,
196
+ dispersion_spectrum,
197
+ operator_bound,
198
+ rk4_step,
199
+ time_grid,
200
+ validate_tensor,
201
+ )
202
+ from wavesimfem.parallel import limit_threads_per_rank
203
+ from wavesimfem.reporting import set_verbosity
204
+ from wavesimfem.solvers import build_problem, run_simulation, solve_explicit, solve_implicit
205
+ from wavesimfem.solvers_gpu import (
206
+ build_sensor_interpolation_matrix,
207
+ integrate_explicit_rk4,
208
+ solve_explicit_rk4_device,
209
+ )
210
+ from wavesimfem.sources import SOURCE_TYPES, ricker, source_signal, tone_burst
211
+ from wavesimfem.structure_analysis import reference_dispersion, structure_profile
212
+ from wavesimfem.units import parse_quantity
213
+ from wavesimfem.wave_reports import write_structure_report
214
+ from wavesimfem.wave_spectra import phase_velocity_spectrum, polarization_spectrum
wavesimfem/__main__.py ADDED
@@ -0,0 +1,8 @@
1
+ """Executable module entrypoint for `python -m wavesimfem`."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from wavesimfem._launcher import main
6
+
7
+ if __name__ == "__main__":
8
+ main()
@@ -0,0 +1,36 @@
1
+ """Console entry point that fixes the thread policy before heavy imports.
2
+
3
+ BLAS/OpenMP thread pools are sized when NumPy and PETSc load, so the
4
+ per-rank thread cap from :mod:`wavesimfem.parallel` must be applied
5
+ before :mod:`wavesimfem.cli` (which imports them) is imported.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import sys
11
+
12
+ _FEM_RUNTIME_MODULES = frozenset({"dolfinx", "mpi4py", "petsc4py", "ufl"})
13
+
14
+
15
+ def main() -> None:
16
+ """Apply the MPI thread policy, then run the ``wavesim`` CLI."""
17
+ from wavesimfem.parallel import apply_thread_policy
18
+
19
+ apply_thread_policy()
20
+
21
+ try:
22
+ from wavesimfem.cli import main as cli_main
23
+ except ModuleNotFoundError as exc:
24
+ missing = (exc.name or "").split(".", 1)[0]
25
+ if missing in _FEM_RUNTIME_MODULES:
26
+ print(
27
+ f"wavesim: error: missing FEM runtime dependency '{missing}'.\n"
28
+ "DOLFINx, PETSc, petsc4py, and mpi4py must be installed from conda-forge:\n"
29
+ " conda env create -f environment.yml && conda activate wavesim\n"
30
+ " pip install --no-deps -e .",
31
+ file=sys.stderr,
32
+ )
33
+ sys.exit(1)
34
+ raise
35
+
36
+ cli_main()