torax.sources package

Subpackages

Submodules

torax.sources.base module

Base model for source pydantic configs.

class torax.sources.base.SourceModelBase(**data)[source]

Bases: BaseModelFrozen, ABC

Base model holding parameters common to all source models.

Subclasses should define the model_function_name attribute as a Literal string. This string should match the name of the function that calculates the source profile. This is used as an identifier for the model function in the source config for Pydantic to “discriminate” against. This should be given a unique value for each source model function implementation.

mode

Defines how the source values are computed (from a model, from a file, etc.)

is_explicit

Defines whether this is an explicit or implicit source. Explicit sources are calculated based on the simulation state at the beginning of a time step, or do not have any dependence on state. Implicit sources depend on updated states as our iterative solvers evolve the state through the course of a time step. NOTE: Not all source types can be implicit or explicit. For example, file-based sources are always explicit. If an incorrect combination of source type and is_explicit is passed in, an error will be thrown when running the simulation.

prescribed_values

Tuple of prescribed values for the source, one for each affected core profile. Used only when the source is fully prescribed (i.e. source.mode == Mode.PRESCRIBED). The default here is a vector of all zeros along for all rho and time, and the output vector is along the cell grid.

Parameters:

data (Any)

abstract build_dynamic_params(t)[source]

Builds dynamic runtime parameters for the source.

Parameters:

t (Union[Array, ndarray, bool, number, float, int])

Return type:

DynamicRuntimeParams

abstract build_source()[source]

Builds a source object from the model config.

Return type:

Source

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

abstract property model_func: SourceProfileFunction

Returns the model function for the source.

torax.sources.bootstrap_current_source module

bootstrap current source profile.

class torax.sources.bootstrap_current_source.BootstrapCurrentSource(*, model_func=None)[source]

Bases: Source

Bootstrap current density source profile.

Unlike other sources within TORAX, the BootstrapCurrentSource provides more than just the bootstrap current. It uses a neoclassical physics model to also determine the neoclassical conductivity. Outputs are as follows:

  • sigmaneo: neoclassical conductivity

  • bootstrap current (on cell and face grids)

  • total integrated bootstrap current

Parameters:

model_func (Optional[SourceProfileFunction])

property affected_core_profiles: tuple[AffectedCoreProfile, ...]

Returns the core profiles affected by this source.

get_value(static_runtime_params_slice, dynamic_runtime_params_slice, geo, core_profiles, calculated_source_profiles)[source]

Returns the cell grid profile for this source during one time step.

Parameters:
  • static_runtime_params_slice (StaticRuntimeParamsSlice) – Static runtime parameters.

  • dynamic_runtime_params_slice (DynamicRuntimeParamsSlice) – Slice of the general TORAX config that can be used as input for this time step.

  • geo (Geometry) – Geometry of the torus.

  • core_profiles (CoreProfiles) – Core plasma profiles. May be the profiles at the start of the time step or a “live” set of core profiles being actively updated depending on whether this source is explicit or implicit. Explicit sources get the core profiles at the start of the time step, implicit sources get the “live” profiles that is updated through the course of the time step as the solver converges.

  • calculated_source_profiles (SourceProfiles | None) – The source profiles which have already been calculated for this time step if they exist. This is used to avoid recalculating profiles that are used as inputs to other sources. These profiles will only exist for Source instances that are implicit. i.e. explicit sources cannot depend on other calculated source profiles. In addition, different source types will have different availability of specific calculated_source_profiles since the calculation order matters. See source_profile_builders.py for more details.

Return type:

tuple[Union[Array, ndarray, bool, number], ...]

Returns:

A tuple of arrays of shape (cell grid length,) with one array per affected core profile.

property source_name: str

Returns the name of the source.

class torax.sources.bootstrap_current_source.BootstrapCurrentSourceConfig(**data)[source]

Bases: SourceModelBase

Bootstrap current density source profile.

bootstrap_mult

Multiplication factor for bootstrap current.

Parameters:

data (Any)

build_dynamic_params(t)[source]

Builds dynamic runtime parameters for the source.

Parameters:

t (Union[Array, ndarray, bool, number, float, int])

Return type:

DynamicRuntimeParams

build_source()[source]

Builds a source object from the model config.

Return type:

BootstrapCurrentSource

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_func()[source]

Returns the model function for the source.

class torax.sources.bootstrap_current_source.DynamicRuntimeParams(prescribed_values, bootstrap_mult)[source]

Bases: DynamicRuntimeParams, Mapping

Parameters:
  • prescribed_values (tuple[Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']], ...])

  • bootstrap_mult (float)

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
values() an object providing a view on D's values
torax.sources.bootstrap_current_source.calc_sauter_model(*, bootstrap_multiplier, nref, Zeff_face, Zi_face, ne, ni, temp_el, temp_ion, psi, q_face, geo)[source]

Calculates sigmaneo, j_bootstrap, and I_bootstrap.

Parameters:
Return type:

BootstrapCurrentProfile

torax.sources.bremsstrahlung_heat_sink module

Bremsstrahlung heat sink for electron heat equation..

class torax.sources.bremsstrahlung_heat_sink.BremsstrahlungHeatSink(*, model_func=<function bremsstrahlung_model_func>)[source]

Bases: Source

Brehmsstrahlung heat sink for electron heat equation.

Parameters:

model_func (SourceProfileFunction)

property affected_core_profiles: tuple[AffectedCoreProfile, ...]

Returns the core profiles affected by this source.

model_func(dynamic_runtime_params_slice, geo, source_name, core_profiles, unused_calculated_source_profiles)

Model function for the Bremsstrahlung heat sink.

Parameters:
Return type:

tuple[Union[Array, ndarray, bool, number], ...]

property source_name: str

Returns the name of the source.

class torax.sources.bremsstrahlung_heat_sink.BremsstrahlungHeatSinkConfig(**data)[source]

Bases: SourceModelBase

Bremsstrahlung heat sink for electron heat equation.

use_relativistic_correction

Whether to use relativistic correction.

Parameters:

data (Any)

build_dynamic_params(t)[source]

Builds dynamic runtime parameters for the source.

Parameters:

t (Union[Array, ndarray, bool, number, float, int])

Return type:

DynamicRuntimeParams

build_source()[source]

Builds a source object from the model config.

Return type:

BremsstrahlungHeatSink

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

property model_func: SourceProfileFunction

Returns the model function for the source.

class torax.sources.bremsstrahlung_heat_sink.DynamicRuntimeParams(prescribed_values, use_relativistic_correction)[source]

Bases: DynamicRuntimeParams, Mapping

Parameters:
  • prescribed_values (tuple[Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']], ...])

  • use_relativistic_correction (bool)

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
values() an object providing a view on D's values
torax.sources.bremsstrahlung_heat_sink.bremsstrahlung_model_func(unused_static_runtime_params_slice, dynamic_runtime_params_slice, geo, source_name, core_profiles, unused_calculated_source_profiles)[source]

Model function for the Bremsstrahlung heat sink.

Parameters:
Return type:

tuple[Union[Array, ndarray, bool, number], ...]

torax.sources.bremsstrahlung_heat_sink.calc_bremsstrahlung(core_profiles, geo, Zeff_face, nref, use_relativistic_correction=False)[source]

Calculate the Bremsstrahlung radiation power profile.

Uses the model from Wesson, John, and David J. Campbell. Tokamaks. Vol. 149. An optional correction for relativistic effects from Stott PPCF 2005 can be enabled with the flag “use_relativistic_correction”.

Parameters:
  • core_profiles (state.CoreProfiles) – core plasma profiles.

  • geo (geometry.Geometry) – geometry object.

  • Zeff_face (float) – effective charge number on face grid.

  • nref (float) – reference density.

  • use_relativistic_correction (bool, optional) – Set to true to include the relativistic correction from Stott. Defaults to False.

Returns:

total bremsstrahlung radiation power [MW] jax.Array: bremsstrahlung radiation power profile [W/m^3]

Return type:

jax.Array

torax.sources.cyclotron_radiation_heat_sink module

Cyclotron radiation heat sink for electron heat equation..

class torax.sources.cyclotron_radiation_heat_sink.CyclotronRadiationHeatSink(*, model_func=<function cyclotron_radiation_albajar>)[source]

Bases: Source

Cyclotron radiation heat sink for electron heat equation.

Parameters:

model_func (SourceProfileFunction)

property affected_core_profiles: tuple[AffectedCoreProfile, ...]

Returns the core profiles affected by this source.

model_func(dynamic_runtime_params_slice, geo, source_name, core_profiles, unused_calculated_source_profiles)

Calculates the cyclotron radiation heat sink contribution to the electron heat equation.

Total cyclotron radiation is from: F. Albajar et al 2001 Nucl. Fusion 41 665 https://doi.org/10.1088/0029-5515/41/6/301

Radial profile of the cyclotron radiation is from: J.F. Artaud et al 2018 Nucl. Fusion 58 105001 https://doi.org/10.1088/1741-4326/aad5b1

The alpha_n, alpha_T and beta_T parameters are calculated from best fits of the following electron density and temperature parameterization to the actual plasma data.

ne = ne(0)*(1 - rhonorm**2)**alpha_n Te = (Te(0)-Te(a))*(1 - rhonorm**beta_T)**alpha_T + Te(a)

Where we take a=0.9 in rhonorm space, and perform the best fit between 0<rhonorm<0.9, to avoid pedestal effects.

Parameters:
Return type:

tuple[Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']], ...]

Returns:

The cyclotron radiation heat sink contribution to the electron heat equation.

property source_name: str

Returns the name of the source.

class torax.sources.cyclotron_radiation_heat_sink.CyclotronRadiationHeatSinkConfig(**data)[source]

Bases: SourceModelBase

Cyclotron radiation heat sink for electron heat equation.

wall_reflection_coeff

The wall reflection coefficient is a machine-dependent dimensionless parameter corresponding to the fraction of cyclotron radiation reflected off the wall and back into the plasma where it is re-absorbed. The default value is a typical value.

beta_min

The minimum value of the beta parameter used in the parameterized function for the temperature fit.

beta_max

The maximum value of the beta parameter used in the parameterized function for the temperature fit.

beta_grid_size

The number of points to use in the grid search for the best fit of the temperature function.

Parameters:

data (Any)

build_dynamic_params(t)[source]

Builds dynamic runtime parameters for the source.

Parameters:

t (Union[Array, ndarray, bool, number, float, int])

Return type:

DynamicRuntimeParams

build_source()[source]

Builds a source object from the model config.

Return type:

CyclotronRadiationHeatSink

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

property model_func: SourceProfileFunction

Returns the model function for the source.

class torax.sources.cyclotron_radiation_heat_sink.DynamicRuntimeParams(prescribed_values, wall_reflection_coeff)[source]

Bases: DynamicRuntimeParams, Mapping

Parameters:
  • prescribed_values (tuple[Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']], ...])

  • wall_reflection_coeff (Union[Float[Array, ''], Float[ndarray, ''], number, float])

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
values() an object providing a view on D's values
class torax.sources.cyclotron_radiation_heat_sink.StaticRuntimeParams(mode, is_explicit, beta_min, beta_max, beta_grid_size)[source]

Bases: StaticRuntimeParams, Mapping

Parameters:
items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
values() an object providing a view on D's values
torax.sources.cyclotron_radiation_heat_sink.cyclotron_radiation_albajar(static_runtime_params_slice, dynamic_runtime_params_slice, geo, source_name, core_profiles, unused_calculated_source_profiles)[source]

Calculates the cyclotron radiation heat sink contribution to the electron heat equation.

Total cyclotron radiation is from: F. Albajar et al 2001 Nucl. Fusion 41 665 https://doi.org/10.1088/0029-5515/41/6/301

Radial profile of the cyclotron radiation is from: J.F. Artaud et al 2018 Nucl. Fusion 58 105001 https://doi.org/10.1088/1741-4326/aad5b1

The alpha_n, alpha_T and beta_T parameters are calculated from best fits of the following electron density and temperature parameterization to the actual plasma data.

ne = ne(0)*(1 - rhonorm**2)**alpha_n Te = (Te(0)-Te(a))*(1 - rhonorm**beta_T)**alpha_T + Te(a)

Where we take a=0.9 in rhonorm space, and perform the best fit between 0<rhonorm<0.9, to avoid pedestal effects.

Parameters:
Return type:

tuple[Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']], ...]

Returns:

The cyclotron radiation heat sink contribution to the electron heat equation.

torax.sources.electron_cyclotron_source module

Electron cyclotron heating (prescribed Gaussian) and current drive (Lin-Liu model).

class torax.sources.electron_cyclotron_source.DynamicRuntimeParams(prescribed_values, cd_efficiency, manual_ec_power_density, gaussian_ec_power_density_width, gaussian_ec_power_density_location, gaussian_ec_total_power)[source]

Bases: DynamicRuntimeParams, Mapping

Runtime parameters for the electron-cyclotron source for a given time and geometry.

Parameters:
  • prescribed_values (tuple[Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']], ...])

  • cd_efficiency (Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']])

  • manual_ec_power_density (Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']])

  • gaussian_ec_power_density_width (Union[Float[Array, ''], Float[ndarray, ''], number, float])

  • gaussian_ec_power_density_location (Union[Float[Array, ''], Float[ndarray, ''], number, float])

  • gaussian_ec_total_power (Union[Float[Array, ''], Float[ndarray, ''], number, float])

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
values() an object providing a view on D's values
class torax.sources.electron_cyclotron_source.ElectronCyclotronSource(*, model_func=<function calc_heating_and_current>)[source]

Bases: Source

Electron cyclotron source for the Te and Psi equations.

Parameters:

model_func (SourceProfileFunction)

property affected_core_profiles: tuple[AffectedCoreProfile, ...]

Returns the core profiles affected by this source.

model_func(dynamic_runtime_params_slice, geo, source_name, core_profiles, unused_calculated_source_profiles)

Model function for the electron-cyclotron source.

Based on Lin-Liu, Y. R., Chan, V. S., & Prater, R. (2003). See https://torax.readthedocs.io/en/latest/electron-cyclotron-derivation.html

Parameters:
Return type:

tuple[Union[Array, ndarray, bool, number], ...]

Returns:

2D array of electron cyclotron heating power density and current density.

property source_name: str

Returns the name of the source.

class torax.sources.electron_cyclotron_source.ElectronCyclotronSourceConfig(**data)[source]

Bases: SourceModelBase

Config for the electron-cyclotron source.

cd_efficiency

Local dimensionless current drive efficiency. Zeta from Lin-Liu, Chan, and Prater, 2003, eq 44

manual_ec_power_density

Manual EC power density profile on the rho grid

gaussian_ec_power_density_width

Gaussian EC power density profile width

gaussian_ec_power_density_location

Gaussian EC power density profile location

gaussian_ec_total_power

Gaussian EC total power

Parameters:

data (Any)

build_dynamic_params(t)[source]

Builds dynamic runtime parameters for the source.

Parameters:

t (Union[Array, ndarray, bool, number, float, int])

Return type:

DynamicRuntimeParams

build_source()[source]

Builds a source object from the model config.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

property model_func: SourceProfileFunction

Returns the model function for the source.

torax.sources.electron_cyclotron_source.calc_heating_and_current(unused_static_runtime_params_slice, dynamic_runtime_params_slice, geo, source_name, core_profiles, unused_calculated_source_profiles)[source]

Model function for the electron-cyclotron source.

Based on Lin-Liu, Y. R., Chan, V. S., & Prater, R. (2003). See https://torax.readthedocs.io/en/latest/electron-cyclotron-derivation.html

Parameters:
Return type:

tuple[Union[Array, ndarray, bool, number], ...]

Returns:

2D array of electron cyclotron heating power density and current density.

torax.sources.formulas module

Prescribed formulas for computing source profiles.

torax.sources.formulas.exponential_profile(geo, *, decay_start, width, total)[source]

Returns an exponential profile on the cell grid.

The profile is parameterized by (decay_start, width, total) like so:

profile = C * exp(-(decay_start - r) / width)

Where C is a calculated prefactor to ensure the volume integral of the profile equals total.

Parameters:
  • geo (Geometry) – Geometry constants of torus.

  • decay_start (float) – See description above. In normalized radial coordinate.

  • width (float) – See description above. In normalized radial coordinate.

  • total (float) – See description above.

Return type:

Array

Returns:

Exponential profile on the cell grid.

torax.sources.formulas.gaussian_profile(geo, *, center, width, total)[source]

Returns a gaussian profile on the cell grid.

The profile is parameterized by (center, width, total) like so:

profile = C * exp(-( (r - center)**2 / (2 * width**2) ))

Where C is a calculated prefactor to ensure the volume integral of the profile equals total.

Parameters:
  • geo (Geometry) – Geometry constants of torus.

  • center (float) – See description above. In normalized radial coordinate.

  • width (float) – See description above. In normalized radial coordinate.

  • total (float) – See description above.

Return type:

Array

Returns:

Gaussian profile on the cell grid.

torax.sources.fusion_heat_source module

Fusion heat source for both ion and electron heat equations.

class torax.sources.fusion_heat_source.FusionHeatSource(*, model_func=<function fusion_heat_model_func>)[source]

Bases: Source

Fusion heat source for both ion and electron heat.

Parameters:

model_func (SourceProfileFunction)

property affected_core_profiles: tuple[AffectedCoreProfile, ...]

Returns the core profiles affected by this source.

model_func(dynamic_runtime_params_slice, geo, unused_source_name, core_profiles, unused_calculated_source_profiles)

Model function for fusion heating.

Parameters:
Return type:

tuple[Union[Array, ndarray, bool, number], ...]

property source_name: str

Returns the name of the source.

class torax.sources.fusion_heat_source.FusionHeatSourceConfig(**data)[source]

Bases: SourceModelBase

Configuration for the FusionHeatSource.

Parameters:

data (Any)

build_dynamic_params(t)[source]

Builds dynamic runtime parameters for the source.

Parameters:

t (Union[Array, ndarray, bool, number, float, int])

Return type:

DynamicRuntimeParams

build_source()[source]

Builds a source object from the model config.

Return type:

FusionHeatSource

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

property model_func: SourceProfileFunction

Returns the model function for the source.

torax.sources.fusion_heat_source.calc_fusion(geo, core_profiles, static_runtime_params_slice, dynamic_runtime_params_slice)[source]

Computes DT fusion power with the Bosch-Hale parameterization NF 1992.

Parameters:
  • geo (Geometry) – Magnetic geometry.

  • core_profiles (CoreProfiles) – Core plasma profiles.

  • static_runtime_params_slice (StaticRuntimeParamsSlice) – Static runtime params, used to determine the existence of deuterium and tritium.

  • dynamic_runtime_params_slice (DynamicRuntimeParamsSlice) – Dynamic runtime params, used to extract nref and the D and T densities.

Returns:

total fusion power in MW, ion and electron

fusion power densities in W/m^3.

Return type:

Tuple of Ptot, Pfus_i, Pfus_e

torax.sources.fusion_heat_source.fusion_heat_model_func(static_runtime_params_slice, dynamic_runtime_params_slice, geo, unused_source_name, core_profiles, unused_calculated_source_profiles)[source]

Model function for fusion heating.

Parameters:
Return type:

tuple[Union[Array, ndarray, bool, number], ...]

torax.sources.gas_puff_source module

Gas puff source for the ne equation.

class torax.sources.gas_puff_source.DynamicGasPuffRuntimeParams(prescribed_values, puff_decay_length, S_puff_tot)[source]

Bases: DynamicRuntimeParams, Mapping

Parameters:
  • prescribed_values (tuple[Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']], ...])

  • puff_decay_length (Union[Float[Array, ''], Float[ndarray, ''], number, float])

  • S_puff_tot (Union[Float[Array, ''], Float[ndarray, ''], number, float])

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
values() an object providing a view on D's values
class torax.sources.gas_puff_source.GasPuffSource(*, model_func=<function calc_puff_source>)[source]

Bases: Source

Gas puff source for the ne equation.

Parameters:

model_func (SourceProfileFunction)

property affected_core_profiles: tuple[AffectedCoreProfile, ...]

Returns the core profiles affected by this source.

model_func(dynamic_runtime_params_slice, geo, source_name, unused_state, unused_calculated_source_profiles)

Calculates external source term for n from puffs.

Parameters:
Return type:

tuple[Union[Array, ndarray, bool, number], ...]

property source_name: str

Returns the name of the source.

class torax.sources.gas_puff_source.GasPuffSourceConfig(**data)[source]

Bases: SourceModelBase

Gas puff source for the ne equation.

source_name

Name of the source, hardcoded to ‘gas_puff_source’

puff_decay_length

exponential decay length of gas puff ionization [normalized radial coord]

S_puff_tot

total gas puff particles/s

Parameters:

data (Any)

build_dynamic_params(t)[source]

Builds dynamic runtime parameters for the source.

Parameters:

t (Union[Array, ndarray, bool, number, float, int])

Return type:

DynamicGasPuffRuntimeParams

build_source()[source]

Builds a source object from the model config.

Return type:

GasPuffSource

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

property model_func: SourceProfileFunction

Returns the model function for the source.

torax.sources.gas_puff_source.calc_puff_source(unused_static_runtime_params_slice, dynamic_runtime_params_slice, geo, source_name, unused_state, unused_calculated_source_profiles)[source]

Calculates external source term for n from puffs.

Parameters:
Return type:

tuple[Union[Array, ndarray, bool, number], ...]

torax.sources.generic_current_source module

External current source profile.

class torax.sources.generic_current_source.DynamicRuntimeParams(prescribed_values, Iext, fext, wext, rext, use_absolute_current)[source]

Bases: DynamicRuntimeParams, Mapping

Dynamic runtime parameters for the external current source.

Parameters:
items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
sanity_check()[source]

Checks that all parameters are valid.

values() an object providing a view on D's values
class torax.sources.generic_current_source.GenericCurrentSource(*, model_func=<function calculate_generic_current>)[source]

Bases: Source

A generic current density source profile.

Parameters:

model_func (SourceProfileFunction)

property affected_core_profiles: tuple[AffectedCoreProfile, ...]

Returns the core profiles affected by this source.

model_func(dynamic_runtime_params_slice, geo, source_name, unused_state, unused_calculated_source_profiles)

Calculates the external current density profiles on the cell grid.

Parameters:
Return type:

tuple[Union[Array, ndarray, bool, number], ...]

property source_name: str

Returns the name of the source.

class torax.sources.generic_current_source.GenericCurrentSourceConfig(**data)[source]

Bases: SourceModelBase

Configuration for the GenericCurrentSource.

Iext

total “external” current in MA. Used if use_absolute_current=True.

fext

total “external” current fraction. Used if use_absolute_current=False.

wext

width of “external” Gaussian current profile

rext

normalized radius of “external” Gaussian current profile

use_absolute_current

Toggles if external current is provided absolutely or as a fraction of Ip.

Parameters:

data (Any)

build_dynamic_params(t)[source]

Builds dynamic runtime parameters for the source.

Parameters:

t (Union[Array, ndarray, bool, number, float, int])

Return type:

DynamicRuntimeParams

build_source()[source]

Builds a source object from the model config.

Return type:

GenericCurrentSource

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

property model_func: SourceProfileFunction

Returns the model function for the source.

torax.sources.generic_current_source.calculate_generic_current(unused_static_runtime_params_slice, dynamic_runtime_params_slice, geo, source_name, unused_state, unused_calculated_source_profiles)[source]

Calculates the external current density profiles on the cell grid.

Parameters:
Return type:

tuple[Union[Array, ndarray, bool, number], ...]

torax.sources.generic_ion_el_heat_source module

Generic heat source for both ion and electron heat.

class torax.sources.generic_ion_el_heat_source.DynamicRuntimeParams(prescribed_values, w, rsource, Ptot, el_heat_fraction, absorption_fraction)[source]

Bases: DynamicRuntimeParams, Mapping

Parameters:
items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
values() an object providing a view on D's values
class torax.sources.generic_ion_el_heat_source.GenericIonElHeatSourceConfig(**data)[source]

Bases: SourceModelBase

Configuration for the GenericIonElHeatSource.

w

Gaussian width in normalized radial coordinate

rsource

Source Gaussian central location (in normalized r)

Ptot

Total heating: high default based on total ITER power including alphas

el_heat_fraction

Electron heating fraction

absorption_fraction

Fraction of absorbed power

Parameters:

data (Any)

build_dynamic_params(t)[source]

Builds dynamic runtime parameters for the source.

Parameters:

t (Union[Array, ndarray, bool, number, float, int])

Return type:

DynamicRuntimeParams

build_source()[source]

Builds a source object from the model config.

Return type:

GenericIonElectronHeatSource

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

property model_func: SourceProfileFunction

Returns the model function for the source.

class torax.sources.generic_ion_el_heat_source.GenericIonElectronHeatSource(*, model_func=<function default_formula>)[source]

Bases: Source

Generic heat source for both ion and electron heat.

Parameters:

model_func (SourceProfileFunction)

property affected_core_profiles: tuple[AffectedCoreProfile, ...]

Returns the core profiles affected by this source.

model_func(dynamic_runtime_params_slice, geo, source_name, unused_core_profiles, unused_calculated_source_profiles)

Returns the default formula-based ion/electron heat source profile.

Parameters:
Return type:

tuple[Union[Array, ndarray, bool, number], ...]

property source_name: str

Returns the name of the source.

torax.sources.generic_ion_el_heat_source.calc_generic_heat_source(geo, rsource, w, Ptot, el_heat_fraction, absorption_fraction)[source]

Computes ion/electron heat source terms.

Flexible prescribed heat source term.

Parameters:
  • geo (Geometry) – Geometry describing the torus.

  • rsource (float) – Source Gaussian central location

  • w (float) – Gaussian width

  • Ptot (float) – total heating

  • el_heat_fraction (float) – fraction of heating deposited on electrons

  • absorption_fraction (float) – fraction of absorbed power

Returns:

source term for ions. source_el: source term for electrons.

Return type:

source_ion

torax.sources.generic_ion_el_heat_source.default_formula(unused_static_runtime_params_slice, dynamic_runtime_params_slice, geo, source_name, unused_core_profiles, unused_calculated_source_profiles)[source]

Returns the default formula-based ion/electron heat source profile.

Parameters:
Return type:

tuple[Union[Array, ndarray, bool, number], ...]

torax.sources.generic_particle_source module

Generic particle source for the ne equation.

class torax.sources.generic_particle_source.DynamicParticleRuntimeParams(prescribed_values, particle_width, deposition_location, S_tot)[source]

Bases: DynamicRuntimeParams, Mapping

Parameters:
  • prescribed_values (tuple[Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']], ...])

  • particle_width (Union[Float[Array, ''], Float[ndarray, ''], number, float])

  • deposition_location (Union[Float[Array, ''], Float[ndarray, ''], number, float])

  • S_tot (Union[Float[Array, ''], Float[ndarray, ''], number, float])

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
values() an object providing a view on D's values
class torax.sources.generic_particle_source.GenericParticleSource(*, model_func=<function calc_generic_particle_source>)[source]

Bases: Source

Neutral-beam injection source for the ne equation.

Parameters:

model_func (SourceProfileFunction)

property affected_core_profiles: tuple[AffectedCoreProfile, ...]

Returns the core profiles affected by this source.

model_func(dynamic_runtime_params_slice, geo, source_name, unused_state, unused_calculated_source_profiles)

Calculates external source term for n from SBI.

Parameters:
Return type:

tuple[Union[Array, ndarray, bool, number], ...]

property source_name: str

Returns the name of the source.

class torax.sources.generic_particle_source.GenericParticleSourceConfig(**data)[source]

Bases: SourceModelBase

Generic particle source for the ne equation.

particle_width

particle source Gaussian width in normalized radial coord

deposition_location

particle source Gaussian center in normalized radial coord

S_tot

total particle source particles/s

mode

Defines how the source values are computed (from a model, from a file, etc.)

Parameters:

data (Any)

build_dynamic_params(t)[source]

Builds dynamic runtime parameters for the source.

Parameters:

t (Union[Array, ndarray, bool, number, float, int])

Return type:

DynamicParticleRuntimeParams

build_source()[source]

Builds a source object from the model config.

Return type:

GenericParticleSource

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

property model_func: SourceProfileFunction

Returns the model function for the source.

torax.sources.generic_particle_source.calc_generic_particle_source(unused_static_runtime_params_slice, dynamic_runtime_params_slice, geo, source_name, unused_state, unused_calculated_source_profiles)[source]

Calculates external source term for n from SBI.

Parameters:
Return type:

tuple[Union[Array, ndarray, bool, number], ...]

torax.sources.ion_cyclotron_source module

Surrogate model for ion-cyclotron resonance heating (ICRH) model.

class torax.sources.ion_cyclotron_source.DynamicRuntimeParams(prescribed_values, frequency, minority_concentration, Ptot, absorption_fraction, wall_inner, wall_outer)[source]

Bases: DynamicRuntimeParams, Mapping

Parameters:
items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
values() an object providing a view on D's values
class torax.sources.ion_cyclotron_source.IonCyclotronSource(*, model_func=None)[source]

Bases: Source

Ion cyclotron source with surrogate model.

Parameters:

model_func (Optional[SourceProfileFunction])

property affected_core_profiles: tuple[AffectedCoreProfile, ...]

Returns the core profiles affected by this source.

property source_name: str

Returns the name of the source.

class torax.sources.ion_cyclotron_source.IonCyclotronSourceConfig(**data)[source]

Bases: SourceModelBase

Configuration for the IonCyclotronSource.

wall_inner

Inner radial location of first wall at plasma midplane level [m].

wall_outer

Outer radial location of first wall at plasma midplane level [m].

frequency

ICRF wave frequency [Hz].

minority_concentration

He3 minority concentration relative to the electron density in %.

Ptot

Total heating power [W].

absorption_fraction

Fraction of absorbed power.

Parameters:

data (Any)

build_dynamic_params(t)[source]

Builds dynamic runtime parameters for the source.

Parameters:

t (Union[Array, ndarray, bool, number, float, int])

Return type:

DynamicRuntimeParams

build_source()[source]

Builds a source object from the model config.

Return type:

IonCyclotronSource

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

property model_func: SourceProfileFunction

Returns the model function for the source.

class torax.sources.ion_cyclotron_source.ToricNNInputs(frequency, volume_average_temperature, volume_average_density, minority_concentration, gap_inner, gap_outer, z0, temperature_peaking_factor, density_peaking_factor, B0)[source]

Bases: Mapping

Inputs to the ToricNN model.

Parameters:
items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
values() an object providing a view on D's values
class torax.sources.ion_cyclotron_source.ToricNNOutputs(power_deposition_He3, power_deposition_2T, power_deposition_e)[source]

Bases: Mapping

Outputs from the ToricNN model.

Parameters:
  • power_deposition_He3 (Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']])

  • power_deposition_2T (Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']])

  • power_deposition_e (Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']])

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
values() an object providing a view on D's values
class torax.sources.ion_cyclotron_source.ToricNNWrapper(path=None)[source]

Bases: object

Wrapper for the Toric NN model.

This wrapper is currently for a SPARC-specific ion cyclotron resosonanc heating scheme.

TODO(b/378072116): Make the wrapper more general to work with other ICRH schemes and surrogate models.

This wrapper is the main interface for interacting with the Toric NN model. for making predictions of heating power deposition profiles given ToricNNInputs.

The wrapper constructs 3 separate instances of the _ToricNN class, one for each simulated output (Helium-3, 2nd-harmonic tritium and electrons).

Parameters:

path (Optional[str])

torax.sources.ion_cyclotron_source.icrh_model_func(unused_static_runtime_params_slice, dynamic_runtime_params_slice, geo, source_name, core_profiles, unused_calculated_source_profiles, toric_nn)[source]

Compute ion/electron heat source terms.

Parameters:
Return type:

tuple[Union[Array, ndarray, bool, number], ...]

torax.sources.ohmic_heat_source module

Ohmic heat source.

class torax.sources.ohmic_heat_source.OhmicHeatSource(*, model_func=<function ohmic_model_func>)[source]

Bases: Source

Ohmic heat source for electron heat equation.

Pohm = jtor * psidot /(2*pi*Rmaj), related to electric power formula P = IV.

Parameters:

model_func (SourceProfileFunction)

property affected_core_profiles: tuple[AffectedCoreProfile, ...]

Returns the core profiles affected by this source.

model_func(dynamic_runtime_params_slice, geo, unused_source_name, core_profiles, calculated_source_profiles)

Returns the Ohmic source for electron heat equation.

Parameters:
Return type:

tuple[Union[Array, ndarray, bool, number], ...]

property source_name: str

Returns the name of the source.

class torax.sources.ohmic_heat_source.OhmicHeatSourceConfig(**data)[source]

Bases: SourceModelBase

Configuration for the OhmicHeatSource.

Parameters:

data (Any)

build_dynamic_params(t)[source]

Builds dynamic runtime parameters for the source.

Parameters:

t (Union[Array, ndarray, bool, number, float, int])

Return type:

DynamicRuntimeParams

build_source()[source]

Builds a source object from the model config.

Return type:

OhmicHeatSource

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

property model_func: SourceProfileFunction

Returns the model function for the source.

torax.sources.ohmic_heat_source.ohmic_model_func(unused_static_runtime_params_slice, dynamic_runtime_params_slice, geo, unused_source_name, core_profiles, calculated_source_profiles)[source]

Returns the Ohmic source for electron heat equation.

Parameters:
Return type:

tuple[Union[Array, ndarray, bool, number], ...]

torax.sources.pellet_source module

Pellet source for the ne equation.

class torax.sources.pellet_source.DynamicPelletRuntimeParams(prescribed_values, pellet_width, pellet_deposition_location, S_pellet_tot)[source]

Bases: DynamicRuntimeParams, Mapping

Parameters:
  • prescribed_values (tuple[Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']], ...])

  • pellet_width (Union[Float[Array, ''], Float[ndarray, ''], number, float])

  • pellet_deposition_location (Union[Float[Array, ''], Float[ndarray, ''], number, float])

  • S_pellet_tot (Union[Float[Array, ''], Float[ndarray, ''], number, float])

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
values() an object providing a view on D's values
class torax.sources.pellet_source.PelletSource(*, model_func=<function calc_pellet_source>)[source]

Bases: Source

Pellet source for the ne equation.

Parameters:

model_func (SourceProfileFunction)

property affected_core_profiles: tuple[AffectedCoreProfile, ...]

Returns the core profiles affected by this source.

model_func(dynamic_runtime_params_slice, geo, source_name, unused_state, unused_calculated_source_profiles)

Calculates external source term for n from pellets.

Parameters:
Return type:

tuple[Union[Array, ndarray, bool, number], ...]

property source_name: str

Returns the name of the source.

class torax.sources.pellet_source.PelletSourceConfig(**data)[source]

Bases: SourceModelBase

Pellet source for the ne equation.

pellet_width

Gaussian width of pellet deposition [normalized radial coord]

pellet_deposition_location

Gaussian center of pellet deposition [normalized radial coord]

S_pellet_tot

total pellet particles/s

mode

Defines how the source values are computed (from a model, from a file, etc.)

Parameters:

data (Any)

build_dynamic_params(t)[source]

Builds dynamic runtime parameters for the source.

Parameters:

t (Union[Array, ndarray, bool, number, float, int])

Return type:

DynamicPelletRuntimeParams

build_source()[source]

Builds a source object from the model config.

Return type:

PelletSource

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

property model_func: SourceProfileFunction

Returns the model function for the source.

torax.sources.pellet_source.calc_pellet_source(unused_static_runtime_params_slice, dynamic_runtime_params_slice, geo, source_name, unused_state, unused_calculated_source_profiles)[source]

Calculates external source term for n from pellets.

Parameters:
Return type:

tuple[Union[Array, ndarray, bool, number], ...]

torax.sources.pydantic_model module

Pydantic config for source models.

class torax.sources.pydantic_model.Sources(**data)[source]

Bases: BaseModelFrozen

Config for source models.

The from_dict method of constructing this class supports the config described in: https://torax.readthedocs.io/en/latest/configuration.html

Parameters:

data (Any)

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

validate_radiation_models()[source]

Validate that bremsstrahlung and Mavrin models are not both active at the same time.

This prevents double counting radiation losses.

Return type:

Self

Returns:

Self for method chaining.

Raises:

ValueError – If both bremsstrahlung and Mavrin models are active.

torax.sources.qei_source module

Collisional ion-electron heat source.

class torax.sources.qei_source.DynamicRuntimeParams(prescribed_values, Qei_mult)[source]

Bases: DynamicRuntimeParams, Mapping

Parameters:
  • prescribed_values (tuple[Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']], ...])

  • Qei_mult (float)

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
values() an object providing a view on D's values
class torax.sources.qei_source.QeiSource(*, model_func=None)[source]

Bases: Source

Collisional ion-electron heat source.

This is a special-case source because it can provide both implicit and explicit terms in our solver. See sim.py for how this is used.

Parameters:

model_func (Optional[SourceProfileFunction])

property affected_core_profiles: tuple[AffectedCoreProfile, ...]

Returns the core profiles affected by this source.

get_qei(static_runtime_params_slice, dynamic_runtime_params_slice, geo, core_profiles)[source]

Computes the value of the source.

Parameters:
Return type:

QeiInfo

get_value(static_runtime_params_slice, dynamic_runtime_params_slice, geo, core_profiles, calculated_source_profiles)[source]

Returns the cell grid profile for this source during one time step.

Parameters:
  • static_runtime_params_slice (StaticRuntimeParamsSlice) – Static runtime parameters.

  • dynamic_runtime_params_slice (DynamicRuntimeParamsSlice) – Slice of the general TORAX config that can be used as input for this time step.

  • geo (Geometry) – Geometry of the torus.

  • core_profiles (CoreProfiles) – Core plasma profiles. May be the profiles at the start of the time step or a “live” set of core profiles being actively updated depending on whether this source is explicit or implicit. Explicit sources get the core profiles at the start of the time step, implicit sources get the “live” profiles that is updated through the course of the time step as the solver converges.

  • calculated_source_profiles (SourceProfiles | None) – The source profiles which have already been calculated for this time step if they exist. This is used to avoid recalculating profiles that are used as inputs to other sources. These profiles will only exist for Source instances that are implicit. i.e. explicit sources cannot depend on other calculated source profiles. In addition, different source types will have different availability of specific calculated_source_profiles since the calculation order matters. See source_profile_builders.py for more details.

Return type:

tuple[Union[Array, ndarray, bool, number], ...]

Returns:

A tuple of arrays of shape (cell grid length,) with one array per affected core profile.

property source_name: str

Returns the name of the source.

class torax.sources.qei_source.QeiSourceConfig(**data)[source]

Bases: SourceModelBase

Configuration for the QeiSource.

Qei_mult

multiplier for ion-electron heat exchange term for sensitivity testing

Parameters:

data (Any)

build_dynamic_params(t)[source]

Builds dynamic runtime parameters for the source.

Parameters:

t (Union[Array, ndarray, bool, number, float, int])

Return type:

DynamicRuntimeParams

build_source()[source]

Builds a source object from the model config.

Return type:

QeiSource

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

property model_func: None

Returns the model function for the source.

torax.sources.runtime_params module

Configuration for all the sources/sinks modelled in Torax.

class torax.sources.runtime_params.DynamicRuntimeParams(prescribed_values)[source]

Bases: Mapping

Dynamic params for a single TORAX source.

These params can be changed without triggering a recompile. TORAX sources are stateless, so these params are their inputs to determine their output profiles.

Parameters:

prescribed_values (tuple[Union[Float[Array, 'rhon'], Float[ndarray, 'rhon']], ...])

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
values() an object providing a view on D's values
class torax.sources.runtime_params.Mode(value)[source]

Bases: Enum

Defines how to compute the source terms for this source/sink.

class torax.sources.runtime_params.StaticRuntimeParams(mode, is_explicit)[source]

Bases: Mapping

Static params for the sources.

Parameters:
items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
values() an object providing a view on D's values

torax.sources.source module

Module for a single source/sink term.

This module contains all the base classes for defining source terms. Other files in this folder use these classes to define specific types of sources/sinks.

See Source class docstring for more details on what a TORAX source is and how to use it.

class torax.sources.source.AffectedCoreProfile(value)[source]

Bases: IntEnum

Defines which part of the core profiles the source helps evolve.

The profiles of each source/sink are terms included in equations evolving different core profiles. This enum maps a source to those equations.

class torax.sources.source.Source(*, model_func=None)[source]

Bases: ABC

Base class for a single source/sink term.

Sources are used to compute source profiles (see source_profiles.py), which are in turn used to compute coeffs in sim.py.

SOURCE_NAME

The name of the source.

runtime_params

Input dataclass containing all the source-specific runtime parameters. At runtime, the parameters here are interpolated to a specific time t and then passed to the model_func, depending on the mode this source is running in.

affected_core_profiles

Core profiles affected by this source’s profile(s). This attribute defines which equations the source profiles are terms for. By default, the number of affected core profiles should equal the rank of the output shape returned by output_shape.

model_func

The function used when the the runtime type is set to “MODEL_BASED”. If not provided, then it defaults to returning zeros.

affected_core_profiles_ints

Derived property from the affected_core_profiles. Integer values of those enums.

Parameters:

model_func (Optional[SourceProfileFunction])

abstract property affected_core_profiles: tuple[AffectedCoreProfile, ...]

Returns the core profiles affected by this source.

get_value(static_runtime_params_slice, dynamic_runtime_params_slice, geo, core_profiles, calculated_source_profiles)[source]

Returns the cell grid profile for this source during one time step.

Parameters:
  • static_runtime_params_slice (StaticRuntimeParamsSlice) – Static runtime parameters.

  • dynamic_runtime_params_slice (DynamicRuntimeParamsSlice) – Slice of the general TORAX config that can be used as input for this time step.

  • geo (Geometry) – Geometry of the torus.

  • core_profiles (CoreProfiles) – Core plasma profiles. May be the profiles at the start of the time step or a “live” set of core profiles being actively updated depending on whether this source is explicit or implicit. Explicit sources get the core profiles at the start of the time step, implicit sources get the “live” profiles that is updated through the course of the time step as the solver converges.

  • calculated_source_profiles (SourceProfiles | None) – The source profiles which have already been calculated for this time step if they exist. This is used to avoid recalculating profiles that are used as inputs to other sources. These profiles will only exist for Source instances that are implicit. i.e. explicit sources cannot depend on other calculated source profiles. In addition, different source types will have different availability of specific calculated_source_profiles since the calculation order matters. See source_profile_builders.py for more details.

Return type:

tuple[Union[Array, ndarray, bool, number], ...]

Returns:

A tuple of arrays of shape (cell grid length,) with one array per affected core profile.

abstract property source_name: str

Returns the name of the source.

class torax.sources.source.SourceProfileFunction(*args, **kwargs)[source]

Bases: Protocol

Sources implement these functions to be able to provide source profiles.

torax.sources.source_models module

Functions for building source profiles in TORAX.

class torax.sources.source_models.SourceModels(sources)[source]

Bases: object

Source/sink models for the different equations being evolved in Torax.

Each source/sink (all called sources as the difference is only a sign change) can be explicit or implicit and signal to our solver on how to handle these terms. Their values are provided via model, file, prescribed function, etc. The specific approach used depends on how the source is initialized and what runtime configuration inputs are provided.

You can both override the default set of sources in TORAX as well as define new custom sources inline when constructing this object. The example below shows how to define a new custom electron-density source.

# Define an electron-density source with a time-dependent Gaussian profile.
gas_puff_source = register_source.get_registered_source('gas_puff_source')
gas_puff_source_builder = source_lib.make_source_builder(
    gas_puff_source.source_class,
    runtime_params_type=gas_puff_source.model_functions['calc_puff_source'].runtime_params_class,
    model_func=gas_puff_source.model_functions['calc_puff_source'].source_profile_function,
)
# Define the collection of sources here, which in this example only includes
# one source.
all_torax_sources = SourceModels(
    sources={'gas_puff_source': gas_puff_source_builder}
)

See runtime_params.py for more details on how to configure all the source/sink terms.

Parameters:

sources (Mapping[str, SourceModelBase])

property standard_sources: dict[str, Source]

Returns all sources that are not used in special cases.

Practically, this means this includes all sources other than j_bootstrap and qei_source.

torax.sources.source_profile_builders module

Functions for building source profiles in TORAX.

torax.sources.source_profile_builders.build_all_zero_profiles(geo)[source]

Returns a SourceProfiles object with all zero profiles.

Parameters:

geo (Geometry)

Return type:

SourceProfiles

torax.sources.source_profile_builders.build_source_profiles(static_runtime_params_slice, dynamic_runtime_params_slice, geo, core_profiles, source_models, explicit, explicit_source_profiles=None)[source]

Builds explicit profiles or the union of explicit and implicit profiles.

Parameters:
  • static_runtime_params_slice (StaticRuntimeParamsSlice) – Input config. Cannot change from time step to time step.

  • dynamic_runtime_params_slice (DynamicRuntimeParamsSlice) – Input config for this time step. Can change from time step to time step.

  • geo (Geometry) – Geometry of the torus.

  • core_profiles (CoreProfiles) – Core plasma profiles, either at the start of the time step (if explicit) or the live profiles being evolved during the time step (if implicit).

  • source_models (SourceModels) – Functions computing profiles for all TORAX sources/sinks.

  • explicit (bool) – If True, this function will only return profiles for explicit sources. If False, then the explicit_source_profiles argument must be provided and the returned profiles will be the union of the explicit profiles in explicit_source_profiles and the implicit profiles computed here. Note that for the special-case sources (bootstrap and qei), the explicit argument will be used to determine whether to return a profile or all zeros.

  • explicit_source_profiles (Optional[SourceProfiles]) – If explicit is False, this argument must be provided. It will be used to compute the union of the explicit profiles and the implicit profiles computed here.

Return type:

SourceProfiles

Returns:

SourceProfiles caclulated from the source models. If explicit is True, then only explicit profiles will be returned. If explicit is False, then the union of the explicit profiles in explicit_source_profiles and the implicit profiles computed here will be returned.

torax.sources.source_profile_builders.build_standard_source_profiles(*, calculated_source_profiles, static_runtime_params_slice, dynamic_runtime_params_slice, geo, core_profiles, source_models, explicit=True, calculate_anyway=False, psi_only=False)[source]

Updates calculated_source_profiles with standard source profiles.

Parameters:
torax.sources.source_profile_builders.get_initial_source_profiles(static_runtime_params_slice, dynamic_runtime_params_slice, geo, core_profiles, source_models)[source]

Returns the source profiles for the initial state in run_simulation().

Parameters:
  • static_runtime_params_slice (StaticRuntimeParamsSlice) – Runtime parameters which, when they change, trigger recompilations. They should not change within a single run of the sim.

  • dynamic_runtime_params_slice (DynamicRuntimeParamsSlice) – Runtime parameters which may change from time step to time step without triggering recompilations.

  • geo (Geometry) – The geometry of the torus during this time step of the simulation.

  • core_profiles (CoreProfiles) – Core profiles that may evolve throughout the course of a simulation. These values here are, of course, only the original states.

  • source_models (SourceModels) – Source models used to compute core source profiles.

Return type:

SourceProfiles

Returns:

Implicit and explicit SourceProfiles from source models based on the core profiles from the starting state.

torax.sources.source_profiles module

Source/sink profiles for all the sources in TORAX.

class torax.sources.source_profiles.BootstrapCurrentProfile(sigma, sigma_face, j_bootstrap, j_bootstrap_face, I_bootstrap)[source]

Bases: Mapping

Bootstrap current profile.

sigma

plasma conductivity with neoclassical corrections on cell grid.

sigma_face

plasma conductivity with neoclassical corrections on face grid.

j_bootstrap

Bootstrap current density (Amps / m^2)

j_bootstrap_face

Bootstrap current density (Amps / m^2) on face grid

I_bootstrap

Total bootstrap current. Used primarily for diagnostic purposes.

Parameters:
  • sigma (Array)

  • sigma_face (Array)

  • j_bootstrap (Array)

  • j_bootstrap_face (Array)

  • I_bootstrap (Array)

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
values() an object providing a view on D's values
class torax.sources.source_profiles.QeiInfo(qei_coef, implicit_ii, explicit_i, implicit_ee, explicit_e, implicit_ie, implicit_ei)[source]

Bases: Mapping

Represents the source values coming from a QeiSource.

Parameters:
  • qei_coef (Array)

  • implicit_ii (Array)

  • explicit_i (Array)

  • implicit_ee (Array)

  • explicit_e (Array)

  • implicit_ie (Array)

  • implicit_ei (Array)

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
values() an object providing a view on D's values
class torax.sources.source_profiles.SourceProfiles(j_bootstrap, qei, temp_el=<factory>, temp_ion=<factory>, ne=<factory>, psi=<factory>)[source]

Bases: Mapping

Collection of profiles for all sources in TORAX.

Most profiles are stored in the attributes relating to the core profile they affect, but special-case profiles j_bootstrap and qei are pulled out into their own attributes as these sources need to be treated differently (though they could still be set to zero using appropriate runtime params).

This dataclass is inspired by the IMAS core_sources IDS. It is not a 1:1 mapping to that schema, but it contains similar profiles as you’d expect in that IDS.

Parameters:
items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
classmethod merge(explicit_source_profiles, implicit_source_profiles)[source]

Returns a SourceProfiles that merges the input profiles.

Sources can either be explicit or implicit. The explicit_source_profiles contain the profiles for all source models that are set to explicit, and it contains profiles with all zeros for any implicit source. The opposite holds for the implicit_source_profiles.

This function adds the two dictionaries of profiles and returns a single SourceProfiles that includes both.

Parameters:
  • explicit_source_profiles (Self) – Profiles from explicit source models. This SourceProfiles dict will include keys for both the explicit and implicit sources, but only the explicit sources will have non-zero profiles. See source.py and runtime_params.py for more info on explicit vs. implicit.

  • implicit_source_profiles (Self) – Profiles from implicit source models. This SourceProfiles dict will include keys for both the explicit and implicit sources, but only the implicit sources will have non-zero profiles. See source.py and runtime_params.py for more info on explicit vs. implicit.

Return type:

Self

Returns:

A SourceProfiles with non-zero profiles for all sources, both explicit and implicit (assuming the source model outputted a non-zero profile).

values() an object providing a view on D's values

Module contents

Sources.

This module contains functionality related to setting up TORAX heat, particle, and current sources.