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,190 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
import jax
|
|
6
|
+
import jax.numpy as jnp
|
|
7
|
+
|
|
8
|
+
from ..geometry import FciMaps, MetricTensor3D
|
|
9
|
+
from .fci import conservative_perp_diffusion_xz, logical_exb_bracket_xz
|
|
10
|
+
from .fci_neutral import compute_fci_neutral_reaction_diffusion
|
|
11
|
+
from .fci_sheath_recycling import fci_sheath_recycling_field_rhs
|
|
12
|
+
from .fci_vorticity import solve_fci_vorticity_potential_cg
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@jax.tree_util.register_pytree_node_class
|
|
16
|
+
@dataclass(frozen=True)
|
|
17
|
+
class FciDrbState:
|
|
18
|
+
ion_density: jax.Array
|
|
19
|
+
electron_density: jax.Array
|
|
20
|
+
neutral_density: jax.Array
|
|
21
|
+
ion_pressure: jax.Array
|
|
22
|
+
electron_pressure: jax.Array
|
|
23
|
+
neutral_pressure: jax.Array
|
|
24
|
+
ion_momentum: jax.Array
|
|
25
|
+
neutral_momentum: jax.Array
|
|
26
|
+
vorticity: jax.Array
|
|
27
|
+
|
|
28
|
+
def tree_flatten(self):
|
|
29
|
+
return (
|
|
30
|
+
(
|
|
31
|
+
self.ion_density,
|
|
32
|
+
self.electron_density,
|
|
33
|
+
self.neutral_density,
|
|
34
|
+
self.ion_pressure,
|
|
35
|
+
self.electron_pressure,
|
|
36
|
+
self.neutral_pressure,
|
|
37
|
+
self.ion_momentum,
|
|
38
|
+
self.neutral_momentum,
|
|
39
|
+
self.vorticity,
|
|
40
|
+
),
|
|
41
|
+
None,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
@classmethod
|
|
45
|
+
def tree_unflatten(cls, _aux_data, children):
|
|
46
|
+
return cls(*children)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@dataclass(frozen=True)
|
|
50
|
+
class FciDrbRhsParameters:
|
|
51
|
+
recycling_fraction: float = 0.98
|
|
52
|
+
recycled_neutral_energy: float = 0.03
|
|
53
|
+
vorticity_diffusivity: float = 2.0e-4
|
|
54
|
+
potential_boussinesq: bool = True
|
|
55
|
+
plasma_exb_advection_strength: float = 0.0
|
|
56
|
+
potential_iterations: int = 40
|
|
57
|
+
potential_regularization: float = 1.0e-9
|
|
58
|
+
potential_preconditioner: str | None = None
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@dataclass(frozen=True)
|
|
62
|
+
class FciDrbRhsResult:
|
|
63
|
+
rhs: FciDrbState
|
|
64
|
+
potential: jax.Array
|
|
65
|
+
potential_residual_l2: jax.Array
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def compute_fci_drb_rhs(
|
|
69
|
+
state: FciDrbState,
|
|
70
|
+
*,
|
|
71
|
+
maps: FciMaps,
|
|
72
|
+
metric: MetricTensor3D,
|
|
73
|
+
parameters: FciDrbRhsParameters = FciDrbRhsParameters(),
|
|
74
|
+
) -> FciDrbRhsResult:
|
|
75
|
+
"""Assemble the first transformable non-axisymmetric DRB component RHS."""
|
|
76
|
+
|
|
77
|
+
fields = {
|
|
78
|
+
"Ni": state.ion_density,
|
|
79
|
+
"Ne": state.electron_density,
|
|
80
|
+
"Nn": state.neutral_density,
|
|
81
|
+
"Pi": state.ion_pressure,
|
|
82
|
+
"Pe": state.electron_pressure,
|
|
83
|
+
"Pn": state.neutral_pressure,
|
|
84
|
+
}
|
|
85
|
+
sheath = fci_sheath_recycling_field_rhs(
|
|
86
|
+
fields,
|
|
87
|
+
maps,
|
|
88
|
+
recycling_fraction=parameters.recycling_fraction,
|
|
89
|
+
recycled_neutral_energy=parameters.recycled_neutral_energy,
|
|
90
|
+
)
|
|
91
|
+
neutral = compute_fci_neutral_reaction_diffusion(
|
|
92
|
+
neutral_density=state.neutral_density,
|
|
93
|
+
neutral_pressure=state.neutral_pressure,
|
|
94
|
+
neutral_momentum=state.neutral_momentum,
|
|
95
|
+
ion_density=state.ion_density,
|
|
96
|
+
ion_pressure=state.ion_pressure,
|
|
97
|
+
ion_momentum=state.ion_momentum,
|
|
98
|
+
electron_density=state.electron_density,
|
|
99
|
+
electron_pressure=state.electron_pressure,
|
|
100
|
+
maps=maps,
|
|
101
|
+
metric=metric,
|
|
102
|
+
)
|
|
103
|
+
potential_solve = solve_fci_vorticity_potential_cg(
|
|
104
|
+
state.vorticity,
|
|
105
|
+
state.ion_density,
|
|
106
|
+
metric,
|
|
107
|
+
iterations=parameters.potential_iterations,
|
|
108
|
+
boussinesq=parameters.potential_boussinesq,
|
|
109
|
+
regularization=parameters.potential_regularization,
|
|
110
|
+
preconditioner=parameters.potential_preconditioner,
|
|
111
|
+
)
|
|
112
|
+
vorticity_rhs = conservative_perp_diffusion_xz(
|
|
113
|
+
state.vorticity,
|
|
114
|
+
jnp.ones_like(state.vorticity, dtype=jnp.float64) * parameters.vorticity_diffusivity,
|
|
115
|
+
metric,
|
|
116
|
+
)
|
|
117
|
+
plasma_exb = _plasma_exb_advection_terms(
|
|
118
|
+
state,
|
|
119
|
+
potential_solve.potential,
|
|
120
|
+
metric,
|
|
121
|
+
strength=parameters.plasma_exb_advection_strength,
|
|
122
|
+
)
|
|
123
|
+
rhs = FciDrbState(
|
|
124
|
+
ion_density=sheath.get("Ni", 0.0) + neutral.ion_density_source + plasma_exb.ion_density,
|
|
125
|
+
electron_density=sheath.get("Ne", 0.0) + neutral.electron_density_source + plasma_exb.electron_density,
|
|
126
|
+
neutral_density=sheath.get("Nn", 0.0) + neutral.neutral_density_source,
|
|
127
|
+
ion_pressure=sheath.get("Pi", 0.0) + neutral.ion_pressure_source + plasma_exb.ion_pressure,
|
|
128
|
+
electron_pressure=sheath.get("Pe", 0.0) + neutral.electron_pressure_source + plasma_exb.electron_pressure,
|
|
129
|
+
neutral_pressure=sheath.get("Pn", 0.0) + neutral.neutral_pressure_source,
|
|
130
|
+
ion_momentum=neutral.ion_momentum_source + plasma_exb.ion_momentum,
|
|
131
|
+
neutral_momentum=neutral.neutral_momentum_source,
|
|
132
|
+
vorticity=vorticity_rhs + plasma_exb.vorticity,
|
|
133
|
+
)
|
|
134
|
+
return FciDrbRhsResult(
|
|
135
|
+
rhs=rhs,
|
|
136
|
+
potential=potential_solve.potential,
|
|
137
|
+
potential_residual_l2=potential_solve.residual_l2,
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _plasma_exb_advection_terms(
|
|
142
|
+
state: FciDrbState,
|
|
143
|
+
potential: jax.Array,
|
|
144
|
+
metric: MetricTensor3D,
|
|
145
|
+
*,
|
|
146
|
+
strength: float,
|
|
147
|
+
) -> FciDrbState:
|
|
148
|
+
"""Return compact ExB advection terms driven by the solved potential.
|
|
149
|
+
|
|
150
|
+
The compact FCI DRB lane treats ExB advection as a plasma perpendicular
|
|
151
|
+
drift, so it acts on charged-fluid density, pressure, parallel momentum,
|
|
152
|
+
and vorticity. Neutral gas density, pressure, and momentum remain governed
|
|
153
|
+
by the neutral reaction/diffusion closures rather than by ExB drift.
|
|
154
|
+
"""
|
|
155
|
+
|
|
156
|
+
coefficient = float(strength)
|
|
157
|
+
zero = jnp.zeros_like(state.neutral_density, dtype=jnp.float64)
|
|
158
|
+
if coefficient == 0.0:
|
|
159
|
+
return FciDrbState(
|
|
160
|
+
ion_density=jnp.zeros_like(state.ion_density, dtype=jnp.float64),
|
|
161
|
+
electron_density=jnp.zeros_like(state.electron_density, dtype=jnp.float64),
|
|
162
|
+
neutral_density=zero,
|
|
163
|
+
ion_pressure=jnp.zeros_like(state.ion_pressure, dtype=jnp.float64),
|
|
164
|
+
electron_pressure=jnp.zeros_like(state.electron_pressure, dtype=jnp.float64),
|
|
165
|
+
neutral_pressure=jnp.zeros_like(state.neutral_pressure, dtype=jnp.float64),
|
|
166
|
+
ion_momentum=jnp.zeros_like(state.ion_momentum, dtype=jnp.float64),
|
|
167
|
+
neutral_momentum=jnp.zeros_like(state.neutral_momentum, dtype=jnp.float64),
|
|
168
|
+
vorticity=jnp.zeros_like(state.vorticity, dtype=jnp.float64),
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
def advect(field: jax.Array) -> jax.Array:
|
|
172
|
+
return -coefficient * logical_exb_bracket_xz(
|
|
173
|
+
potential,
|
|
174
|
+
field,
|
|
175
|
+
metric,
|
|
176
|
+
periodic_x=False,
|
|
177
|
+
periodic_z=True,
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
return FciDrbState(
|
|
181
|
+
ion_density=advect(state.ion_density),
|
|
182
|
+
electron_density=advect(state.electron_density),
|
|
183
|
+
neutral_density=zero,
|
|
184
|
+
ion_pressure=advect(state.ion_pressure),
|
|
185
|
+
electron_pressure=advect(state.electron_pressure),
|
|
186
|
+
neutral_pressure=jnp.zeros_like(state.neutral_pressure, dtype=jnp.float64),
|
|
187
|
+
ion_momentum=advect(state.ion_momentum),
|
|
188
|
+
neutral_momentum=jnp.zeros_like(state.neutral_momentum, dtype=jnp.float64),
|
|
189
|
+
vorticity=advect(state.vorticity),
|
|
190
|
+
)
|