drbx 2.0.0.dev0__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.
- drbx/__init__.py +20 -0
- drbx/__main__.py +5 -0
- drbx/cli.py +586 -0
- drbx/config/__init__.py +20 -0
- drbx/config/boutinp.py +556 -0
- drbx/config/model.py +34 -0
- drbx/config/normalization.py +66 -0
- drbx/data/atomic_rates/__init__.py +1 -0
- drbx/data/atomic_rates/iz_AMJUEL_H.x_2.1.5.json +213 -0
- drbx/data/atomic_rates/iz_AMJUEL_H.x_2.3.9a.json +213 -0
- drbx/data/atomic_rates/rec_AMJUEL_H.x_2.1.8.json +213 -0
- drbx/data/atomic_rates/rec_AMJUEL_H.x_2.3.13a.json +213 -0
- drbx/geometry/__init__.py +207 -0
- drbx/geometry/embedding.py +56 -0
- drbx/geometry/essos_import.py +1385 -0
- drbx/geometry/fci_geometry.py +4622 -0
- drbx/geometry/fci_maps.py +85 -0
- drbx/geometry/island_divertor.py +291 -0
- drbx/geometry/metric_tensor.py +99 -0
- drbx/geometry/open_slab.py +150 -0
- drbx/geometry/rotating_ellipse.py +253 -0
- drbx/geometry/shifted_torus.py +225 -0
- drbx/geometry/stellarator.py +287 -0
- drbx/geometry/vmec_extender_import.py +499 -0
- drbx/geometry/vmec_jax_import.py +306 -0
- drbx/linear/__init__.py +37 -0
- drbx/linear/dispersion.py +138 -0
- drbx/linear/eigen.py +91 -0
- drbx/native/__init__.py +224 -0
- drbx/native/array_backend.py +64 -0
- drbx/native/deck_runner.py +779 -0
- drbx/native/electromagnetic.py +250 -0
- drbx/native/expression.py +173 -0
- drbx/native/fci.py +295 -0
- drbx/native/fci_2_field_rhs.py +182 -0
- drbx/native/fci_4_field_rhs.py +1267 -0
- drbx/native/fci_boundaries.py +2494 -0
- drbx/native/fci_differentiable_case.py +304 -0
- drbx/native/fci_drb_EB_rhs.py +1243 -0
- drbx/native/fci_drb_rhs.py +190 -0
- drbx/native/fci_halo.py +1575 -0
- drbx/native/fci_helpers.py +350 -0
- drbx/native/fci_model.py +294 -0
- drbx/native/fci_neutral.py +139 -0
- drbx/native/fci_operators.py +4081 -0
- drbx/native/fci_sharding.py +597 -0
- drbx/native/fci_sheath_recycling.py +206 -0
- drbx/native/fci_time_integrator.py +96 -0
- drbx/native/fci_vorticity.py +198 -0
- drbx/native/fluid_1d.py +330 -0
- drbx/native/hasegawa_wakatani.py +196 -0
- drbx/native/limiters.py +57 -0
- drbx/native/mesh.py +238 -0
- drbx/native/metrics.py +234 -0
- drbx/native/neutrals/__init__.py +58 -0
- drbx/native/neutrals/atomic_rates.py +134 -0
- drbx/native/neutrals/detachment_sol_model.py +221 -0
- drbx/native/neutrals/reactions.py +164 -0
- drbx/native/neutrals/recycling_sol_model.py +197 -0
- drbx/native/sol_flux_tube.py +133 -0
- drbx/native/stellarator_turbulence.py +343 -0
- drbx/native/transport.py +134 -0
- drbx/native/units.py +32 -0
- drbx/native/vorticity.py +252 -0
- drbx/runtime/__init__.py +53 -0
- drbx/runtime/artifacts.py +161 -0
- drbx/runtime/memory.py +144 -0
- drbx/runtime/output.py +374 -0
- drbx/runtime/paths.py +9 -0
- drbx/runtime/performance.py +161 -0
- drbx/runtime/run_config.py +184 -0
- drbx/runtime/scheduler.py +99 -0
- drbx/runtime/state.py +40 -0
- drbx/validation/__init__.py +424 -0
- drbx/validation/autodiff_diffusion.py +329 -0
- drbx/validation/autodiff_diffusion_uncertainty.py +235 -0
- drbx/validation/diverted_tokamak_movie.py +558 -0
- drbx/validation/essos_fieldline_import_campaign.py +181 -0
- drbx/validation/essos_imported_artifact_audit.py +535 -0
- drbx/validation/essos_imported_drb_movie_campaign.py +2826 -0
- drbx/validation/essos_imported_fci_campaign.py +5241 -0
- drbx/validation/essos_imported_pytree_campaign.py +406 -0
- drbx/validation/essos_vmec_closed_field_campaign.py +314 -0
- drbx/validation/essos_vmec_closed_field_transient_campaign.py +629 -0
- drbx/validation/essos_vmec_fieldline_surface_campaign.py +620 -0
- drbx/validation/fluid_1d_mms_convergence.py +250 -0
- drbx/validation/geometry_lineouts.py +136 -0
- drbx/validation/geometry_slices.py +178 -0
- drbx/validation/publication_plotting.py +91 -0
- drbx/validation/stellarator_drb_pytree_campaign.py +621 -0
- drbx/validation/stellarator_fci_geometry_campaign.py +200 -0
- drbx/validation/stellarator_fci_operator_campaign.py +304 -0
- drbx/validation/stellarator_fci_suite_campaign.py +264 -0
- drbx/validation/stellarator_metric_mms_campaign.py +289 -0
- drbx/validation/stellarator_neutral_physics_campaign.py +255 -0
- drbx/validation/stellarator_sheath_recycling_campaign.py +331 -0
- drbx/validation/stellarator_sol_showcase.py +628 -0
- drbx/validation/stellarator_vorticity_campaign.py +304 -0
- drbx/validation/vmec_extender_edge_field_campaign.py +260 -0
- drbx/validation/vmec_extender_sol_smoke_campaign.py +365 -0
- drbx-2.0.0.dev0.dist-info/METADATA +380 -0
- drbx-2.0.0.dev0.dist-info/RECORD +106 -0
- drbx-2.0.0.dev0.dist-info/WHEEL +5 -0
- drbx-2.0.0.dev0.dist-info/entry_points.txt +2 -0
- drbx-2.0.0.dev0.dist-info/licenses/LICENSE +21 -0
- drbx-2.0.0.dev0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from matplotlib import pyplot as plt
|
|
8
|
+
import numpy as np
|
|
9
|
+
|
|
10
|
+
from ..geometry import (
|
|
11
|
+
EssosFieldLineBundle,
|
|
12
|
+
resolve_essos_landreman_qa_json,
|
|
13
|
+
save_essos_field_line_bundle_npz,
|
|
14
|
+
trace_essos_coil_field_lines,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass(frozen=True)
|
|
19
|
+
class EssosFieldLineImportArtifacts:
|
|
20
|
+
report_json_path: Path
|
|
21
|
+
arrays_npz_path: Path
|
|
22
|
+
plot_png_path: Path
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def create_essos_fieldline_import_package(
|
|
26
|
+
*,
|
|
27
|
+
output_root: str | Path,
|
|
28
|
+
coil_json_path: str | Path | None = None,
|
|
29
|
+
case_label: str = "essos_landreman_paul_qa_fieldline_import",
|
|
30
|
+
r_min: float = 1.21,
|
|
31
|
+
r_max: float = 1.40,
|
|
32
|
+
n_field_lines: int = 8,
|
|
33
|
+
maxtime: float = 1000.0,
|
|
34
|
+
times_to_trace: int = 6000,
|
|
35
|
+
trace_tolerance: float = 1.0e-8,
|
|
36
|
+
) -> EssosFieldLineImportArtifacts:
|
|
37
|
+
"""Export ESSOS-produced fields and field lines into a `drbx` artifact."""
|
|
38
|
+
|
|
39
|
+
root = Path(output_root)
|
|
40
|
+
data_dir = root / "data"
|
|
41
|
+
images_dir = root / "images"
|
|
42
|
+
data_dir.mkdir(parents=True, exist_ok=True)
|
|
43
|
+
images_dir.mkdir(parents=True, exist_ok=True)
|
|
44
|
+
|
|
45
|
+
resolved_coil_json = resolve_essos_landreman_qa_json(coil_json_path)
|
|
46
|
+
bundle = trace_essos_coil_field_lines(
|
|
47
|
+
coil_json_path=resolved_coil_json,
|
|
48
|
+
r_min=r_min,
|
|
49
|
+
r_max=r_max,
|
|
50
|
+
n_field_lines=n_field_lines,
|
|
51
|
+
maxtime=maxtime,
|
|
52
|
+
times_to_trace=times_to_trace,
|
|
53
|
+
trace_tolerance=trace_tolerance,
|
|
54
|
+
)
|
|
55
|
+
report = build_essos_fieldline_import_report(bundle)
|
|
56
|
+
report_json_path = data_dir / f"{case_label}.json"
|
|
57
|
+
report_json_path.write_text(json.dumps(report, indent=2, sort_keys=True), encoding="utf-8")
|
|
58
|
+
arrays_npz_path = save_essos_field_line_bundle_npz(bundle, data_dir / f"{case_label}.npz")
|
|
59
|
+
plot_png_path = save_essos_fieldline_import_plot(bundle, images_dir / f"{case_label}.png")
|
|
60
|
+
return EssosFieldLineImportArtifacts(
|
|
61
|
+
report_json_path=report_json_path,
|
|
62
|
+
arrays_npz_path=arrays_npz_path,
|
|
63
|
+
plot_png_path=plot_png_path,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def build_essos_fieldline_import_report(bundle: EssosFieldLineBundle) -> dict[str, object]:
|
|
68
|
+
"""Build a sanitized report for an ESSOS field-line import bundle."""
|
|
69
|
+
|
|
70
|
+
b_norm = np.linalg.norm(bundle.field_sample_b_xyz, axis=1)
|
|
71
|
+
radius = np.sqrt(bundle.trajectories_xyz[:, :, 0] ** 2 + bundle.trajectories_xyz[:, :, 1] ** 2)
|
|
72
|
+
radial_span = np.ptp(radius, axis=1)
|
|
73
|
+
z_span = np.ptp(bundle.trajectories_xyz[:, :, 2], axis=1)
|
|
74
|
+
report: dict[str, object] = {
|
|
75
|
+
"case": "essos_landreman_paul_qa_fieldline_import",
|
|
76
|
+
"source": "ESSOS external field and field-line import",
|
|
77
|
+
"metadata": bundle.metadata,
|
|
78
|
+
"n_field_lines": bundle.n_field_lines,
|
|
79
|
+
"n_times": bundle.n_times,
|
|
80
|
+
"poincare_point_count": bundle.poincare_point_count,
|
|
81
|
+
"field_sample_count": int(bundle.field_sample_xyz.shape[0]),
|
|
82
|
+
"coil_count": int(bundle.coil_gamma_xyz.shape[0]),
|
|
83
|
+
"coil_segments": int(bundle.coil_gamma_xyz.shape[1]),
|
|
84
|
+
"field_magnitude_min": float(np.min(b_norm)),
|
|
85
|
+
"field_magnitude_mean": float(np.mean(b_norm)),
|
|
86
|
+
"field_magnitude_max": float(np.max(b_norm)),
|
|
87
|
+
"radial_span_mean": float(np.mean(radial_span)),
|
|
88
|
+
"radial_span_max": float(np.max(radial_span)),
|
|
89
|
+
"vertical_span_mean": float(np.mean(z_span)),
|
|
90
|
+
"vertical_span_max": float(np.max(z_span)),
|
|
91
|
+
}
|
|
92
|
+
report["passed"] = bool(
|
|
93
|
+
bundle.n_field_lines > 0
|
|
94
|
+
and bundle.n_times > 10
|
|
95
|
+
and bundle.poincare_point_count > 0
|
|
96
|
+
and np.all(np.isfinite(bundle.trajectories_xyz))
|
|
97
|
+
and np.all(np.isfinite(bundle.field_sample_b_xyz))
|
|
98
|
+
and float(np.max(b_norm)) > float(np.min(b_norm)) > 0.0
|
|
99
|
+
)
|
|
100
|
+
return report
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def save_essos_fieldline_import_plot(bundle: EssosFieldLineBundle, path: str | Path) -> Path:
|
|
104
|
+
"""Save a QA plot of ESSOS-imported coils, field lines, field samples, and Poincare data."""
|
|
105
|
+
|
|
106
|
+
resolved = Path(path)
|
|
107
|
+
resolved.parent.mkdir(parents=True, exist_ok=True)
|
|
108
|
+
fig = plt.figure(figsize=(13.0, 5.6), constrained_layout=True)
|
|
109
|
+
ax3d = fig.add_subplot(1, 2, 1, projection="3d")
|
|
110
|
+
axp = fig.add_subplot(1, 2, 2)
|
|
111
|
+
|
|
112
|
+
for coil in bundle.coil_gamma_xyz:
|
|
113
|
+
ax3d.plot(coil[:, 0], coil[:, 1], coil[:, 2], color="0.50", alpha=0.20, lw=0.6)
|
|
114
|
+
colors = plt.cm.viridis(np.linspace(0.08, 0.92, bundle.n_field_lines))
|
|
115
|
+
stride = max(1, bundle.n_times // 1500)
|
|
116
|
+
for index, trajectory in enumerate(bundle.trajectories_xyz):
|
|
117
|
+
ax3d.plot(
|
|
118
|
+
trajectory[::stride, 0],
|
|
119
|
+
trajectory[::stride, 1],
|
|
120
|
+
trajectory[::stride, 2],
|
|
121
|
+
color=colors[index],
|
|
122
|
+
lw=0.8,
|
|
123
|
+
alpha=0.88,
|
|
124
|
+
)
|
|
125
|
+
ax3d.scatter(
|
|
126
|
+
bundle.initial_xyz[:, 0],
|
|
127
|
+
bundle.initial_xyz[:, 1],
|
|
128
|
+
bundle.initial_xyz[:, 2],
|
|
129
|
+
s=18.0,
|
|
130
|
+
color="black",
|
|
131
|
+
depthshade=False,
|
|
132
|
+
label="field-line seeds",
|
|
133
|
+
)
|
|
134
|
+
ax3d.set_xlabel("X")
|
|
135
|
+
ax3d.set_ylabel("Y")
|
|
136
|
+
ax3d.set_zlabel("Z")
|
|
137
|
+
ax3d.set_title("ESSOS-exported coil field lines")
|
|
138
|
+
ax3d.legend(frameon=False, loc="upper left")
|
|
139
|
+
_set_equal_3d(ax3d, bundle.trajectories_xyz.reshape((-1, 3)))
|
|
140
|
+
|
|
141
|
+
if bundle.poincare_point_count:
|
|
142
|
+
scatter = axp.scatter(
|
|
143
|
+
bundle.poincare_r,
|
|
144
|
+
bundle.poincare_z,
|
|
145
|
+
c=bundle.poincare_line_index,
|
|
146
|
+
cmap="viridis",
|
|
147
|
+
s=2.5,
|
|
148
|
+
alpha=0.78,
|
|
149
|
+
linewidths=0.0,
|
|
150
|
+
)
|
|
151
|
+
colorbar = fig.colorbar(scatter, ax=axp, fraction=0.045, pad=0.03)
|
|
152
|
+
colorbar.set_label("field-line seed")
|
|
153
|
+
axp.scatter(
|
|
154
|
+
np.sqrt(bundle.initial_xyz[:, 0] ** 2 + bundle.initial_xyz[:, 1] ** 2),
|
|
155
|
+
bundle.initial_xyz[:, 2],
|
|
156
|
+
s=18.0,
|
|
157
|
+
color="black",
|
|
158
|
+
label="seeds",
|
|
159
|
+
zorder=3,
|
|
160
|
+
)
|
|
161
|
+
axp.set_xlabel("R")
|
|
162
|
+
axp.set_ylabel("Z")
|
|
163
|
+
axp.set_aspect("equal", adjustable="box")
|
|
164
|
+
axp.grid(alpha=0.28)
|
|
165
|
+
axp.set_title("ESSOS Poincare sections imported into drbx")
|
|
166
|
+
axp.legend(frameon=False, loc="upper right")
|
|
167
|
+
|
|
168
|
+
fig.suptitle("External ESSOS field-line import for DRBX geometry/FCI workflows", fontsize=13)
|
|
169
|
+
fig.savefig(resolved, dpi=190)
|
|
170
|
+
plt.close(fig)
|
|
171
|
+
return resolved
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _set_equal_3d(axis: plt.Axes, points: np.ndarray) -> None:
|
|
175
|
+
center = np.mean(points, axis=0)
|
|
176
|
+
span = float(np.max(np.ptp(points, axis=0)))
|
|
177
|
+
span = max(span, 1.0e-12)
|
|
178
|
+
half = 0.5 * span
|
|
179
|
+
axis.set_xlim(center[0] - half, center[0] + half)
|
|
180
|
+
axis.set_ylim(center[1] - half, center[1] + half)
|
|
181
|
+
axis.set_zlim(center[2] - half, center[2] + half)
|