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.
Files changed (106) hide show
  1. drbx/__init__.py +20 -0
  2. drbx/__main__.py +5 -0
  3. drbx/cli.py +586 -0
  4. drbx/config/__init__.py +20 -0
  5. drbx/config/boutinp.py +556 -0
  6. drbx/config/model.py +34 -0
  7. drbx/config/normalization.py +66 -0
  8. drbx/data/atomic_rates/__init__.py +1 -0
  9. drbx/data/atomic_rates/iz_AMJUEL_H.x_2.1.5.json +213 -0
  10. drbx/data/atomic_rates/iz_AMJUEL_H.x_2.3.9a.json +213 -0
  11. drbx/data/atomic_rates/rec_AMJUEL_H.x_2.1.8.json +213 -0
  12. drbx/data/atomic_rates/rec_AMJUEL_H.x_2.3.13a.json +213 -0
  13. drbx/geometry/__init__.py +207 -0
  14. drbx/geometry/embedding.py +56 -0
  15. drbx/geometry/essos_import.py +1385 -0
  16. drbx/geometry/fci_geometry.py +4622 -0
  17. drbx/geometry/fci_maps.py +85 -0
  18. drbx/geometry/island_divertor.py +291 -0
  19. drbx/geometry/metric_tensor.py +99 -0
  20. drbx/geometry/open_slab.py +150 -0
  21. drbx/geometry/rotating_ellipse.py +253 -0
  22. drbx/geometry/shifted_torus.py +225 -0
  23. drbx/geometry/stellarator.py +287 -0
  24. drbx/geometry/vmec_extender_import.py +499 -0
  25. drbx/geometry/vmec_jax_import.py +306 -0
  26. drbx/linear/__init__.py +37 -0
  27. drbx/linear/dispersion.py +138 -0
  28. drbx/linear/eigen.py +91 -0
  29. drbx/native/__init__.py +224 -0
  30. drbx/native/array_backend.py +64 -0
  31. drbx/native/deck_runner.py +779 -0
  32. drbx/native/electromagnetic.py +250 -0
  33. drbx/native/expression.py +173 -0
  34. drbx/native/fci.py +295 -0
  35. drbx/native/fci_2_field_rhs.py +182 -0
  36. drbx/native/fci_4_field_rhs.py +1267 -0
  37. drbx/native/fci_boundaries.py +2494 -0
  38. drbx/native/fci_differentiable_case.py +304 -0
  39. drbx/native/fci_drb_EB_rhs.py +1243 -0
  40. drbx/native/fci_drb_rhs.py +190 -0
  41. drbx/native/fci_halo.py +1575 -0
  42. drbx/native/fci_helpers.py +350 -0
  43. drbx/native/fci_model.py +294 -0
  44. drbx/native/fci_neutral.py +139 -0
  45. drbx/native/fci_operators.py +4081 -0
  46. drbx/native/fci_sharding.py +597 -0
  47. drbx/native/fci_sheath_recycling.py +206 -0
  48. drbx/native/fci_time_integrator.py +96 -0
  49. drbx/native/fci_vorticity.py +198 -0
  50. drbx/native/fluid_1d.py +330 -0
  51. drbx/native/hasegawa_wakatani.py +196 -0
  52. drbx/native/limiters.py +57 -0
  53. drbx/native/mesh.py +238 -0
  54. drbx/native/metrics.py +234 -0
  55. drbx/native/neutrals/__init__.py +58 -0
  56. drbx/native/neutrals/atomic_rates.py +134 -0
  57. drbx/native/neutrals/detachment_sol_model.py +221 -0
  58. drbx/native/neutrals/reactions.py +164 -0
  59. drbx/native/neutrals/recycling_sol_model.py +197 -0
  60. drbx/native/sol_flux_tube.py +133 -0
  61. drbx/native/stellarator_turbulence.py +343 -0
  62. drbx/native/transport.py +134 -0
  63. drbx/native/units.py +32 -0
  64. drbx/native/vorticity.py +252 -0
  65. drbx/runtime/__init__.py +53 -0
  66. drbx/runtime/artifacts.py +161 -0
  67. drbx/runtime/memory.py +144 -0
  68. drbx/runtime/output.py +374 -0
  69. drbx/runtime/paths.py +9 -0
  70. drbx/runtime/performance.py +161 -0
  71. drbx/runtime/run_config.py +184 -0
  72. drbx/runtime/scheduler.py +99 -0
  73. drbx/runtime/state.py +40 -0
  74. drbx/validation/__init__.py +424 -0
  75. drbx/validation/autodiff_diffusion.py +329 -0
  76. drbx/validation/autodiff_diffusion_uncertainty.py +235 -0
  77. drbx/validation/diverted_tokamak_movie.py +558 -0
  78. drbx/validation/essos_fieldline_import_campaign.py +181 -0
  79. drbx/validation/essos_imported_artifact_audit.py +535 -0
  80. drbx/validation/essos_imported_drb_movie_campaign.py +2826 -0
  81. drbx/validation/essos_imported_fci_campaign.py +5241 -0
  82. drbx/validation/essos_imported_pytree_campaign.py +406 -0
  83. drbx/validation/essos_vmec_closed_field_campaign.py +314 -0
  84. drbx/validation/essos_vmec_closed_field_transient_campaign.py +629 -0
  85. drbx/validation/essos_vmec_fieldline_surface_campaign.py +620 -0
  86. drbx/validation/fluid_1d_mms_convergence.py +250 -0
  87. drbx/validation/geometry_lineouts.py +136 -0
  88. drbx/validation/geometry_slices.py +178 -0
  89. drbx/validation/publication_plotting.py +91 -0
  90. drbx/validation/stellarator_drb_pytree_campaign.py +621 -0
  91. drbx/validation/stellarator_fci_geometry_campaign.py +200 -0
  92. drbx/validation/stellarator_fci_operator_campaign.py +304 -0
  93. drbx/validation/stellarator_fci_suite_campaign.py +264 -0
  94. drbx/validation/stellarator_metric_mms_campaign.py +289 -0
  95. drbx/validation/stellarator_neutral_physics_campaign.py +255 -0
  96. drbx/validation/stellarator_sheath_recycling_campaign.py +331 -0
  97. drbx/validation/stellarator_sol_showcase.py +628 -0
  98. drbx/validation/stellarator_vorticity_campaign.py +304 -0
  99. drbx/validation/vmec_extender_edge_field_campaign.py +260 -0
  100. drbx/validation/vmec_extender_sol_smoke_campaign.py +365 -0
  101. drbx-2.0.0.dev0.dist-info/METADATA +380 -0
  102. drbx-2.0.0.dev0.dist-info/RECORD +106 -0
  103. drbx-2.0.0.dev0.dist-info/WHEEL +5 -0
  104. drbx-2.0.0.dev0.dist-info/entry_points.txt +2 -0
  105. drbx-2.0.0.dev0.dist-info/licenses/LICENSE +21 -0
  106. 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
+ )