1414
1515"""A transport model that uses a QLKNN model."""
1616import dataclasses
17+ import enum
1718import functools
1819import logging
1920import os
3738
3839
3940# pylint: disable=invalid-name
41+ class ShearSuppressionModel (enum .StrEnum ):
42+ """Shear suppression model for rotation effects on transport.
43+
44+ WALTZ_RULE: Simple model from Waltz et al., PoP 1998
45+ (https://doi.org/10.1063/1.872847): f_rot_rule = -alpha.
46+ VANDEPLASSCHE2020: Fitted rotation rule from Van de Plassche et al., PoP 2020
47+ (https://doi.org/10.1063/1.5134126). It was fitted for purely toroidal
48+ transport, so has both stabilizing (ExB shear) and destabilizing (parallel
49+ velocity shear) effects, with a geometry dependence setting the relative
50+ impact.
51+ """
52+
53+ WALTZ_RULE = 'waltz_rule'
54+ VANDEPLASSCHE2020 = 'vandeplassche2020'
55+
56+
4057@jax .tree_util .register_dataclass
4158@dataclasses .dataclass (frozen = True )
4259class RuntimeParams (qualikiz_based_transport_model .RuntimeParams ):
60+ """Runtime parameters for QLKNN transport model."""
4361 include_ITG : bool
4462 include_TEM : bool
4563 include_ETG : bool
4664 ITG_flux_ratio_correction : float
4765 ETG_correction_factor : float
4866 clip_inputs : bool
4967 clip_margin : float
68+ shear_suppression_model : ShearSuppressionModel = dataclasses .field (
69+ metadata = {'static' : True }
70+ )
71+ shear_suppression_alpha : float
5072 output_mode_contributions : bool = dataclasses .field (metadata = {'static' : True })
5173
5274
@@ -174,27 +196,27 @@ def clip_inputs(
174196 return feature_scan
175197
176198
177- def _calculate_rotation_rule_factor (
178- qualikiz_inputs : qualikiz_based_transport_model .QualikizInputs ,
179- ) -> jax .Array :
180- """Calculate the rotation scaling factor."""
181- # TODO(b/456456279): The rotation rule has been calibrated for QLKNN10D.
182- # We should validate if this formula makes sense for QLKNN_7_11.
183- return (
184- _C1 * qualikiz_inputs .q
185- + _C2 * qualikiz_inputs .smag
186- + _C3 / (_EPSILON_NN * qualikiz_inputs .x )
187- - _C4
188- )
189-
190-
191199def _maybe_apply_rotation_rule (
192200 model_output : base_qlknn_model .ModelOutput ,
193201 qualikiz_inputs : qualikiz_based_transport_model .QualikizInputs ,
194202 rotation_mode : qualikiz_based_transport_model .RotationMode ,
203+ shear_suppression_model : ShearSuppressionModel ,
204+ shear_suppression_alpha : float ,
195205 geo : geometry .Geometry ,
196206) -> base_qlknn_model .ModelOutput :
197- """Apply the rotation scaling factor to the model output (Victor rule)."""
207+ """Apply the rotation scaling factor to the model output.
208+
209+ Args:
210+ model_output: The raw model output from QLKNN.
211+ qualikiz_inputs: Prepared inputs for the quasilinear model.
212+ rotation_mode: Controls where the rotation rule is applied.
213+ shear_suppression_model: Which shear suppression model to use.
214+ shear_suppression_alpha: Alpha parameter for Waltz rule.
215+ geo: Geometry of the torus.
216+
217+ Returns:
218+ Model output with rotation scaling applied to ITG and TEM modes.
219+ """
198220 if rotation_mode == qualikiz_based_transport_model .RotationMode .OFF :
199221 # Rotation is disabled. Do not apply the rotation rule.
200222 return model_output
@@ -212,7 +234,21 @@ def _maybe_apply_rotation_rule(
212234 )
213235 gamma_E_GB = gamma_E_GB * scaling
214236
215- f_rot_rule = _calculate_rotation_rule_factor (qualikiz_inputs )
237+ if shear_suppression_model == ShearSuppressionModel .WALTZ_RULE :
238+ c1 , c2 , c3 , c4 = 0.0 , 0.0 , 0.0 , shear_suppression_alpha
239+ elif shear_suppression_model == ShearSuppressionModel .VANDEPLASSCHE2020 :
240+ c1 , c2 , c3 , c4 = _C1 , _C2 , _C3 , _C4
241+ else :
242+ raise ValueError (
243+ f'Unknown shear suppression model: { shear_suppression_model } '
244+ )
245+
246+ f_rot_rule = (
247+ c1 * qualikiz_inputs .q
248+ + c2 * qualikiz_inputs .smag
249+ + c3 / (_EPSILON_NN * qualikiz_inputs .x )
250+ - c4
251+ )
216252
217253 lower_bound = 1e-4
218254 gamma_max = jnp .maximum (model_output ['gamma_max' ].squeeze (), lower_bound )
@@ -347,6 +383,8 @@ def _combined(
347383 model_output ,
348384 qualikiz_inputs ,
349385 runtime_config_inputs .transport .rotation_mode ,
386+ runtime_config_inputs .transport .shear_suppression_model ,
387+ runtime_config_inputs .transport .shear_suppression_alpha ,
350388 geo ,
351389 )
352390
0 commit comments