Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 0 additions & 64 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1469,58 +1469,6 @@ transport model.
Width of HWHM Gaussian smoothing kernel operating on transport model outputs.
If using the ``QLKNN_7_11`` transport model, the default is set to 0.1.

``smooth_everywhere`` (bool [default = False])
Smooth across entire radial domain regardless of inner and outer patches.

``apply_inner_patch`` (**time-varying-scalar** [default = False])
If ``True``, set a patch for inner core transport coefficients below
``rho_inner``. Typically used as an ad-hoc measure for MHD (e.g. sawteeth) or
EM (e.g. KBM) transport in the inner-core. If using a
`CombinedTransportModel`, ensure that the inner patch is only set on the
global model rather than its component models to avoid conflicts.

``D_e_inner`` (**time-varying-scalar** [default = 0.2])
Particle diffusivity value for inner transport patch.

``V_e_inner`` (**time-varying-scalar** [default = 0.0])
Particle convection value for inner transport patch.

``chi_i_inner`` (**time-varying-scalar** [default = 1.0])
Ion heat conduction value for inner transport patch.

``chi_e_inner`` (**time-varying-scalar** [default = 1.0])
Electron heat conduction value for inner transport patch.

``rho_inner`` (**time-varying-scalar** [default = 0.3])
:math:`\hat{\rho}` below which inner patch is applied.
Note that ``rho_inner`` and ``rho_outer`` must have the same interpolation
mode to simplify the validation test ``rho_inner < rho_outer`` at all times.

``apply_outer_patch`` (**time-varying-scalar** [default = False])
If ``True``, set a patch for outer core transport coefficients above
``rho_outer``. Useful for the L-mode near-edge region where models like
QLKNN10D are not applicable. Only used if ``set_pedestal==False``.
If using a `CombinedTransportModel`, ensure that the outer patch is
only set on the global model rather than its component models to avoid
conflicts.

``D_e_outer`` (**time-varying-scalar** [default = 0.2])
Particle diffusivity value for outer transport patch.

``V_e_outer`` (**time-varying-scalar** [default = 0.0])
Particle convection value for outer transport patch.

``chi_i_outer`` (**time-varying-scalar** [default = 1.0])
Ion heat conduction value for outer transport patch.

``chi_e_outer`` (**time-varying-scalar** [default = 1.0])
Electron heat conduction value for outer transport patch.

``rho_outer`` (**time-varying-scalar** [default = 0.9])
:math:`\hat{\rho}` above which outer patch is applied.
Note that ``rho_inner`` and ``rho_outer`` must have the same interpolation
mode to simplify the validation test ``rho_inner < rho_outer`` at all times.

``fast_ion_stabilization`` (**time-varying-scalar** [default = False])
If ``True``, apply a fast ion stabilization correction to the :math:`R/L_{Ti}`
input of quasilinear transport models (QLKNN, TGLFNN, QuaLiKiz). The fast ion
Expand Down Expand Up @@ -3003,18 +2951,6 @@ CHEASE geometry), is shown below. The configuration file is also available in
},
'transport': {
'model_name': 'qlknn',
'apply_inner_patch': True,
'D_e_inner': 0.25,
'V_e_inner': 0.0,
'chi_i_inner': 1.5,
'chi_e_inner': 1.5,
'rho_inner': 0.3,
'apply_outer_patch': True,
'D_e_outer': 0.1,
'V_e_outer': 0.0,
'chi_i_outer': 2.0,
'chi_e_outer': 2.0,
'rho_outer': 0.9,
'chi_min': 0.05,
'chi_max': 100,
'D_e_min': 0.05,
Expand Down
2 changes: 1 addition & 1 deletion torax/_src/config/runtime_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class RuntimeParams:
profile_conditions: profile_conditions.RuntimeParams
solver: solver_params.RuntimeParams
sources: Mapping[str, sources_params.RuntimeParams]
transport: transport_model_params.RuntimeParams
transport: transport_model_params.CombinedRuntimeParams
time_step_calculator: time_step_calculator_runtime_params.RuntimeParams


Expand Down
4 changes: 2 additions & 2 deletions torax/_src/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from torax._src.pedestal_model import pedestal_model as pedestal_model_lib
from torax._src.sources import source_models as source_models_lib
from torax._src.time_step_calculator.time_step_calculator import TimeStepCalculator
from torax._src.transport_model import transport_model as transport_model_lib
from torax._src.transport_model import combined as combined_lib


@dataclasses.dataclass(frozen=True, eq=False)
Expand All @@ -36,7 +36,7 @@ class Models(static_dataclass.StaticDataclass):
"""

source_models: source_models_lib.SourceModels
transport_model: transport_model_lib.TransportModel
transport_model: combined_lib.CombinedTransportModel
pedestal_model: pedestal_model_lib.PedestalModel
neoclassical_models: neoclassical_models_lib.NeoclassicalModels
mhd_models: mhd_model_lib.MHDModels
Expand Down
91 changes: 48 additions & 43 deletions torax/_src/transport_model/combined.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
A class for combining transport models.
"""

# pylint: disable=invalid-name

import dataclasses
from typing import Callable, Sequence, Tuple
import chex
from typing import Callable, Sequence
import jax
import jax.numpy as jnp
from torax._src import array_typing
from torax._src import constants
from torax._src import jax_utils
from torax._src import state
from torax._src import static_dataclass
from torax._src.config import runtime_params as runtime_params_lib
from torax._src.geometry import geometry
from torax._src.pedestal_model import pedestal_model_output as pedestal_model_output_lib
Expand All @@ -37,27 +38,8 @@
MIN_SMOOTHING_WIDTH = 1e-5


@chex.dataclass
class SmoothingZoneParams:
rho_min: array_typing.FloatScalar
rho_max: array_typing.FloatScalar
smoothing_width: array_typing.FloatScalar


@jax.tree_util.register_dataclass
@dataclasses.dataclass(frozen=True)
class RuntimeParams(transport_runtime_params_lib.RuntimeParams):
"""Runtime parameters for the CombinedTransportModel."""

transport_model_params: Tuple[transport_runtime_params_lib.RuntimeParams, ...]
pedestal_transport_model_params: Tuple[
transport_runtime_params_lib.RuntimeParams, ...
]
smoothing_zones: Tuple[SmoothingZoneParams, ...]


@dataclasses.dataclass(frozen=True, eq=False)
class CombinedTransportModel(transport_model_lib.TransportModel):
class CombinedTransportModel(static_dataclass.StaticDataclass):
"""Combines coefficients from a tuple of transport models."""

transport_models: tuple[transport_model_lib.TransportModel, ...]
Expand All @@ -82,23 +64,12 @@ def __call__(
core_profiles,
pedestal_model_output,
)

# In contrast to the base TransportModel, we do not apply domain restriction
# or output masking (enabled/disabled channels) as these are handled at the
# component model level in call_implementation here.

# Apply min/max clipping
transport_coeffs = self._apply_clipping(
transport_runtime_params,
transport_coeffs,
)

# In contrast to the base TransportModel, we do not apply patches, as these
# should be handled by instantiating constant component models instead.
# However, the rho_inner and rho_outer arguments are currently required
# in the case where the inner/outer region are to be excluded from
# smoothing.

transport_coeffs = self._smooth_coeffs(
runtime_params,
geo,
Expand All @@ -110,7 +81,7 @@ def __call__(

def call_implementation(
self,
transport_runtime_params: transport_runtime_params_lib.RuntimeParams,
transport_runtime_params: transport_runtime_params_lib.CombinedRuntimeParams,
runtime_params: runtime_params_lib.RuntimeParams,
geo: geometry.Geometry,
core_profiles: state.CoreProfiles,
Expand All @@ -120,7 +91,8 @@ def call_implementation(

Args:
transport_runtime_params: Input runtime parameters for this transport
model. Can change without triggering a JAX recompilation.
model (expected to be an instance of CombinedRuntimeParams at runtime).
Can change without triggering a JAX recompilation.
runtime_params: Runtime parameters for the simulation at the current time.
geo: Geometry of the torus at the current time.
core_profiles: Core plasma profiles.
Expand All @@ -129,9 +101,6 @@ def call_implementation(
Returns:
coeffs: The transport coefficients
"""
# Required for pytype
assert isinstance(transport_runtime_params, RuntimeParams)

core_coeffs = self._combine(
self.transport_models,
transport_runtime_params.transport_model_params,
Expand Down Expand Up @@ -255,6 +224,41 @@ def _combine(

return transport_model_lib.TurbulentTransport(**accumulators)

def _apply_clipping(
self,
transport_runtime_params: transport_runtime_params_lib.CombinedRuntimeParams,
transport_coeffs: transport_model_lib.TurbulentTransport,
) -> transport_model_lib.TurbulentTransport:
"""Applies min/max clipping to transport coefficients for PDE stability."""
chi_face_ion = jnp.clip(
transport_coeffs.chi_face_ion,
transport_runtime_params.chi_min,
transport_runtime_params.chi_max,
)
chi_face_el = jnp.clip(
transport_coeffs.chi_face_el,
transport_runtime_params.chi_min,
transport_runtime_params.chi_max,
)
d_face_el = jnp.clip(
transport_coeffs.d_face_el,
transport_runtime_params.D_e_min,
transport_runtime_params.D_e_max,
)
v_face_el = jnp.clip(
transport_coeffs.v_face_el,
transport_runtime_params.V_e_min,
transport_runtime_params.V_e_max,
)

return dataclasses.replace(
transport_coeffs,
chi_face_ion=chi_face_ion,
chi_face_el=chi_face_el,
d_face_el=d_face_el,
v_face_el=v_face_el,
)

def _smooth_coeffs(
self,
runtime_params: runtime_params_lib.RuntimeParams,
Expand All @@ -263,7 +267,6 @@ def _smooth_coeffs(
pedestal_model_output: pedestal_model_output_lib.PedestalModelOutput,
) -> transport_model_lib.TurbulentTransport:
"""Gaussian smoothing of turbulent transport coefficients."""
assert isinstance(runtime_params.transport, RuntimeParams)
smoothing_matrix = _build_smoothing_matrix(
runtime_params.transport,
runtime_params,
Expand All @@ -280,7 +283,7 @@ def smooth_single_coeff(coeff):
lambda: jnp.dot(smoothing_matrix, coeff),
)

return jax.tree_util.tree_map(smooth_single_coeff, transport_coeffs)
return jax.tree.map(smooth_single_coeff, transport_coeffs)


def _add_optional(
Expand All @@ -305,14 +308,16 @@ def _pedestal_domain_mask(


def _build_smoothing_matrix(
transport_runtime_params: RuntimeParams,
transport_runtime_params: (
transport_runtime_params_lib.CombinedRuntimeParams
),
runtime_params: runtime_params_lib.RuntimeParams,
geo: geometry.Geometry,
pedestal_model_output: pedestal_model_output_lib.PedestalModelOutput,
) -> jax.Array:
"""Builds a smoothing matrix for the combined transport model."""
# To reduce the range of the convolution, weights under lower_cutoff are
# clipped to zero
# clipped to zero.
lower_cutoff = 0.01
# used for eps, small number to avoid divisions by zero for sigma = 0
consts = constants.CONSTANTS
Expand Down
Loading
Loading