Skip to content

Commit 23d0c01

Browse files
hamelphiTorax team
authored andcommitted
Introduce thermal ion and impurity densities.
This change adds `n_i_thermal` and `n_impurity_thermal` properties to the state, which represent the main ion and impurity densities after subtracting the contributions from fast ions. The calculation of `pressure_thermal_i` is updated to use these new thermal densities. New variables are also added to the output tools skip list. PiperOrigin-RevId: 878655712
1 parent f848996 commit 23d0c01

File tree

6 files changed

+70
-7
lines changed

6 files changed

+70
-7
lines changed

torax/_src/output_tools/output.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ def _save_core_profiles(
574574
"charge_state_info_face",
575575
"impurity_density_scaling",
576576
"fast_ions",
577+
"n_impurity_thermal",
577578
):
578579
continue
579580

torax/_src/physics/formulas.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,20 @@ def calc_pprime(
6969
psi = core_profiles.psi.face_value()
7070
n_e = core_profiles.n_e.face_value()
7171
n_i = core_profiles.n_i.face_value()
72-
n_impurity = core_profiles.n_impurity.face_value()
72+
n_impurity_thermal = core_profiles.n_impurity_thermal.face_value()
7373
T_i = core_profiles.T_i.face_value()
7474
T_e = core_profiles.T_e.face_value()
7575
dne_drhon = core_profiles.n_e.face_grad()
7676
dni_drhon = core_profiles.n_i.face_grad()
77-
dnimp_drhon = core_profiles.n_impurity.face_grad()
77+
dnimp_drhon = core_profiles.n_impurity_thermal.face_grad()
7878
dti_drhon = core_profiles.T_i.face_grad()
7979
dte_drhon = core_profiles.T_e.face_grad()
8080
dpsi_drhon = core_profiles.psi.face_grad()
8181

8282
dptot_drhon = constants.CONSTANTS.keV_to_J * (
8383
n_e * dte_drhon
8484
+ n_i * dti_drhon
85-
+ n_impurity * dti_drhon
85+
+ n_impurity_thermal * dti_drhon
8686
+ dne_drhon * T_e
8787
+ dni_drhon * T_i
8888
+ dnimp_drhon * T_i

torax/_src/state.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,19 +172,45 @@ def pressure_thermal_e(self) -> cell_variable.CellVariable:
172172
right_face_grad_constraint=None,
173173
)
174174

175+
@functools.cached_property
176+
def n_impurity_thermal(self) -> cell_variable.CellVariable:
177+
"""True thermal impurity density without fast ions [m^-3].
178+
179+
TODO(b/868852029): This assumes fast ions subtracted from thermal impurities
180+
are originally from thermal species. This needs to be updated when we
181+
introduce other sources of fast ions that do not deplete thermal species
182+
(e.g. fusion).
183+
"""
184+
n_impurity_thermal_value = self.n_impurity.value
185+
n_impurity_thermal_right = self.n_impurity.right_face_constraint
186+
for fast_ion in self.fast_ions:
187+
if fast_ion.species in self.impurity_fractions:
188+
n_impurity_thermal_value -= fast_ion.n.value
189+
if (
190+
n_impurity_thermal_right is not None
191+
and fast_ion.n.right_face_constraint is not None
192+
):
193+
n_impurity_thermal_right -= fast_ion.n.right_face_constraint
194+
return cell_variable.CellVariable(
195+
value=n_impurity_thermal_value,
196+
face_centers=self.n_impurity.face_centers,
197+
right_face_constraint=n_impurity_thermal_right,
198+
right_face_grad_constraint=None,
199+
)
200+
175201
@functools.cached_property
176202
def pressure_thermal_i(self) -> cell_variable.CellVariable:
177203
"""Ion thermal pressure [Pa]."""
178204
return cell_variable.CellVariable(
179205
value=self.T_i.value
180206
* constants.CONSTANTS.keV_to_J
181-
* (self.n_i.value + self.n_impurity.value),
207+
* (self.n_i.value + self.n_impurity_thermal.value),
182208
face_centers=self.n_i.face_centers,
183209
right_face_constraint=self.T_i.right_face_constraint
184210
* constants.CONSTANTS.keV_to_J
185211
* (
186212
self.n_i.right_face_constraint
187-
+ self.n_impurity.right_face_constraint
213+
+ self.n_impurity_thermal.right_face_constraint
188214
),
189215
right_face_grad_constraint=None,
190216
)

torax/_src/tests/state_test.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from torax._src.core_profiles.plasma_composition import plasma_composition
3030
from torax._src.geometry import circular_geometry
3131
from torax._src.orchestration import run_simulation
32+
from torax._src.physics import fast_ions as fast_ions_lib
3233
from torax._src.test_utils import core_profile_helpers
3334
from torax._src.test_utils import default_configs
3435
from torax._src.torax_pydantic import model_config
@@ -356,6 +357,40 @@ def test_pressure_thermal_total(self):
356357
8.75e20 * constants.CONSTANTS.keV_to_J,
357358
)
358359

360+
def test_thermal_densities_with_fast_ions(self):
361+
geo = circular_geometry.CircularConfig(n_rho=10).build_geometry()
362+
base_core_profiles = core_profile_helpers.make_zero_core_profiles(geo)
363+
364+
fast_ion_he3 = fast_ions_lib.FastIon(
365+
species='He3',
366+
source='ICRH',
367+
n=core_profile_helpers.make_constant_core_profile(geo, 0.05e20),
368+
T=core_profile_helpers.make_constant_core_profile(geo, 100.0),
369+
)
370+
371+
core_profiles = dataclasses.replace(
372+
base_core_profiles,
373+
T_i=core_profile_helpers.make_constant_core_profile(geo, 1.0),
374+
T_e=core_profile_helpers.make_constant_core_profile(geo, 2.0),
375+
n_e=core_profile_helpers.make_constant_core_profile(geo, 3.0e20),
376+
n_i=core_profile_helpers.make_constant_core_profile(geo, 2.5e20),
377+
n_impurity=core_profile_helpers.make_constant_core_profile(
378+
geo, 0.25e20
379+
),
380+
fast_ions=(fast_ion_he3,),
381+
main_ion_fractions={'D': 1.0},
382+
impurity_fractions={'He3': jnp.ones(10)},
383+
)
384+
385+
np.testing.assert_allclose(
386+
core_profiles.n_impurity_thermal.value,
387+
0.20e20,
388+
)
389+
np.testing.assert_allclose(
390+
core_profiles.pressure_thermal_i.value,
391+
2.7e20 * constants.CONSTANTS.keV_to_J,
392+
)
393+
359394
def test_cached_properties_with_jit(self):
360395
"""Tests cached properties behave correctly within a jitted function."""
361396

torax/_src/transport_model/quasilinear_transport_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def from_profiles(
6060
"lref_over_lte": core_profiles.T_e,
6161
"lref_over_lne": core_profiles.n_e,
6262
"lref_over_lni0": core_profiles.n_i,
63-
"lref_over_lni1": core_profiles.n_impurity,
63+
"lref_over_lni1": core_profiles.n_impurity_thermal,
6464
}.items():
6565
gradients[name] = calculate_normalized_logarithmic_gradient(
6666
var=profile,
@@ -167,7 +167,7 @@ def calculate_alpha(
167167
normalized_logarithmic_gradients.lref_over_lti
168168
+ normalized_logarithmic_gradients.lref_over_lni0
169169
)
170-
+ core_profiles.n_impurity.face_value()
170+
+ core_profiles.n_impurity_thermal.face_value()
171171
* core_profiles.T_i.face_value()
172172
* (
173173
normalized_logarithmic_gradients.lref_over_lti

torax/_src/transport_model/tests/quasilinear_transport_model_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ def _get_cell_variable(value):
204204
n_impurity=_get_cell_variable(1.0e20),
205205
fast_ions=(),
206206
pressure_fast_i=_get_cell_variable(0.0),
207+
n_impurity_thermal=_get_cell_variable(1.0e20),
207208
)
208209

209210
normalized_logarithmic_gradients = (

0 commit comments

Comments
 (0)