torax.geometry package

Submodules

torax.geometry.circular_geometry module

Classes for representing a circular geometry.

torax.geometry.circular_geometry.build_circular_geometry(n_rho, elongation_LCFS, Rmaj, Rmin, B0, hires_fac)[source]

Constructs a circular Geometry instance used for testing only.

Parameters:
  • n_rho (int) – Radial grid points (num cells)

  • elongation_LCFS (float) – Elongation at last closed flux surface.

  • Rmaj (float) – major radius (R) in meters

  • Rmin (float) – minor radius (a) in meters

  • B0 (float) – Toroidal magnetic field on axis [T]

  • hires_fac (int) – Grid refinement factor for poloidal flux <–> plasma current calculations.

Return type:

Geometry

Returns:

A Geometry instance.

torax.geometry.geometry module

Classes for representing the problem geometry.

class torax.geometry.geometry.Geometry(geometry_type, torax_mesh, Phi, Phi_face, Rmaj, Rmin, B0, volume, volume_face, area, area_face, vpr, vpr_face, spr, spr_face, delta_face, elongation, elongation_face, g0, g0_face, g1, g1_face, g2, g2_face, g3, g3_face, g2g3_over_rhon, g2g3_over_rhon_face, g2g3_over_rhon_hires, F, F_face, F_hires, Rin, Rin_face, Rout, Rout_face, spr_hires, rho_hires_norm, rho_hires, Phibdot, _z_magnetic_axis)[source]

Bases: Mapping

Describes the magnetic geometry.

Most users should default to using the StandardGeometry class, whether the source of their geometry comes from CHEASE, MEQ, EQDSK, etc.

Properties work for both 1D radial arrays and 2D stacked arrays where the leading dimension is time.

geometry_type

Type of geometry model used. See GeometryType for options.

torax_mesh

Grid1D object representing the radial mesh used by TORAX.

Phi

Toroidal magnetic flux at each radial grid point [\(\mathrm{Wb}\)].

Phi_face

Toroidal magnetic flux at each radial face [\(\mathrm{Wb}\)].

Rmaj

Tokamak major radius (geometric center) [\(\mathrm{m}\)].

Rmin

Tokamak minor radius [\(\mathrm{m}\)].

B0

Vacuum toroidal magnetic field on axis [\(\mathrm{T}\)].

volume

Plasma volume enclosed by each flux surface on cell grid [\(\mathrm{m}^3\)].

volume_face

Plasma volume enclosed by each flux surface on face grid [\(\mathrm{m}^3\)].

area

Poloidal cross-sectional area of each flux surface on cell grid [\(\mathrm{m}^2\)].

area_face

Poloidal cross-sectional area of each flux surface on face grid [\(\mathrm{m}^2\)].

vpr

Derivative of plasma volume enclosed by each flux surface with respect to the normalized toroidal flux coordinate rho_norm on cell grid [\(\mathrm{m}^3\)].

vpr_face

Derivative of plasma volume enclosed by each flux surface with respect to the normalized toroidal flux coordinate rho_face_norm, on face grid [\(\mathrm{m}^3\)].

spr

Derivative of plasma surface area enclosed by each flux surface, with respect to the normalized toroidal flux coordinate rho_norm on cell grid [\(\mathrm{m}^2\)]. Equal to vpr / (\(2 \pi\) Rmaj).

spr_face

Derivative of plasma surface area enclosed by each flux surface, with respect to the normalized toroidal flux coordinate rho_face_norm on face grid [\(\mathrm{m}^2\)]. Equal to vpr_face / (\(2 \pi\) Rmaj).

spr_hires

Derivative of plasma surface area enclosed by each flux surface on a higher resolution grid, with respect to the normalized toroidal flux coordinate rho_norm. [\(\mathrm{m}^2\)].

rho_hires

Toroidal flux coordinate on a higher resolution grid [\(\mathrm{m}\)].

rho_hires_norm

Normalized toroidal flux coordinate on a higher resolution grid [dimensionless].

g0

Flux surface averaged radial derivative of the plasma volume: \(\langle \nabla V \rangle\) on cell grid [\(\mathrm{m}^2\)].

g0_face

Flux surface averaged \(\langle \nabla V \rangle\) on the faces [\(\mathrm{m}^2\)].

g1

Flux surface averaged \(\langle (\nabla V)^2 \rangle\) on cell grid [\(\mathrm{m}^4\)].

g1_face

Flux surface averaged \(\langle (\nabla V)^2 \rangle\) on the faces [\(\mathrm{m}^4\)].

g2

Flux surface averaged \(\langle (\nabla V)^2 / R^2 \rangle\) on cell grid [\(\mathrm{m}^2\)], where R is the major radius along the flux surface being averaged.

g2_face

Flux surface averaged \(\langle (\nabla V)^2 / R^2 \rangle\) on the faces [\(\mathrm{m}^2\)].

g3

Flux surface averaged \(\langle 1 / R^2 \rangle\) on cell grid [\(\mathrm{m}^{-2}\)].

g3_face

Flux surface averaged \(\langle 1 / R^2 \rangle\) on the faces [\(\mathrm{m}^{-2}\)].

g2g3_over_rhon

Ratio of g2g3 to the normalized toroidal flux coordinate rho_norm on cell grid [dimensionless].

g2g3_over_rhon_face

Ratio of g2g3 to the normalized toroidal flux coordinate rho_norm on face grid [dimensionless].

g2g3_over_rhon_hires

Ratio of g2g3 to the normalized toroidal flux coordinate rho_norm on a higher resolution grid [dimensionless].

F

Toroidal field flux function, \(F \equiv RB_\phi\) on cell grid, where \(R\) is major radius, and \(B_\phi\) is the toroidal magnetic field [\(\mathrm{T m}\)].

F_face

Toroidal field flux function, \(F \equiv RB_\phi\) on face grid [\(\mathrm{T m}\)].

F_hires

Toroidal field flux function, \(F \equiv RB_\phi\) on the high resolution grid [\(\mathrm{T m}\)].

Rin

Radius of the flux surface at the inboard side at midplane [\(\mathrm{m}\)] on cell grid. Inboard side is defined as the minimum radial extent of the flux surface.

Rin_face

Radius of the flux surface at the inboard side at midplane [\(\mathrm{m}\)] on face grid.

Rout

Radius of the flux surface at the outboard side at midplane [\(\mathrm{m}\)] on cell grid. Outboard side is defined as the maximum radial extent of the flux surface.

Rout_face

Radius of the flux surface at the outboard side at midplane [\(\mathrm{m}\)] on face grid.

delta_face

Average of upper and lower triangularity of each flux surface at the faces [dimensionless]. Upper triangularity is defined as (Rmaj_local - R_upper) / Rmin_local, where Rmaj_local = (Rout+Rin)/2, Rmin_local = (Rout-Rin)/2, and R_upper is the radial location of the upper extent of the flux surface. Lower triangularity is defined as (Rmaj_local - R_lower) / Rmin_local, where R_lower is the radial location of the lower extent of the flux surface.

elongation

Plasma elongation profile on cell grid [dimensionless]. Elongation is defined as (Z_upper - Z_lower) / (2.0 * Rmin_local), where Z_upper and Z_lower are the Z coordinates of the upper and lower extent of the flux surface.

elongation_face

Plasma elongation profile on face grid [dimensionless].

Phibdot

Time derivative of the toroidal magnetic flux [\(\mathrm{Wb/s}\)]. Calculated across a time interval using Phi from the Geometry objects at time t and t + dt. See torax.orchestration.step_function for more details.

_z_magnetic_axis

Vertical position of the magnetic axis [\(\mathrm{m}\)].

Parameters:
property Phib: Array | ndarray | bool | number

Toroidal flux at boundary (LCFS) \(\mathrm{Wb}\).

property drho: Array | ndarray | bool | number

Grid size for rho [m].

property drho_norm: Array | ndarray | bool | number

Grid size for rho_norm [dimensionless].

property g0_over_vpr_face: Array

g0_face/vpr_face [\(m^{-1}\)], equal to 1/rho_b on-axis.

property g1_over_vpr: Array | ndarray | bool | number

g1/vpr [\(\mathrm{m}\)].

property g1_over_vpr2: Array | ndarray | bool | number

g1/vpr**2 [\(\mathrm{m}^{-2}\)].

property g1_over_vpr2_face: Array

g1_face/vpr_face**2 [\(m^{-2}\)], equal to 1/rho_b**2 on-axis.

property g1_over_vpr_face: Array

g1_face/vpr_face [\(\mathrm{m}\)]. Zero on-axis.

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
property q_correction_factor: Array | ndarray | bool | number | float | int

Ad-hoc fix for non-physical circular geometry model.

Set such that q(r=a) = 3 for standard ITER parameters.

property rho: Array | ndarray | bool | number

Toroidal flux coordinate on cell grid \(\mathrm{m}\).

The toroidal flux coordinate is defined as \(\rho=\sqrt{\frac{\Phi}{\pi B_0}}\), where \(\Phi\) is the toroidal flux enclosed by the flux surface, and \(B_0\) the magnetic field on the magnetic axis.

property rho_b: Array | ndarray | bool | number

Toroidal flux coordinate [m] at boundary (LCFS).

property rho_face: Array | ndarray | bool | number

Toroidal flux coordinate on face grid \(\mathrm{m}\).

property rho_face_norm: Array | ndarray | bool | number

Normalized toroidal flux coordinate on face grid [dimensionless].

property rho_norm: Array | ndarray | bool | number

Normalized toroidal flux coordinate on cell grid [dimensionless].

property rmid: Array | ndarray | bool | number

Midplane radius of the plasma [m], defined as (Rout-Rin)/2.

property rmid_face: Array | ndarray | bool | number

Midplane radius of the plasma on the face grid [m].

values() an object providing a view on D's values
z_magnetic_axis()[source]

z position of magnetic axis [m].

Return type:

Union[Array, ndarray, bool, number, float, int]

class torax.geometry.geometry.GeometryType(value)[source]

Bases: IntEnum

Integer enum for geometry type.

This type can be used within JAX expressions to access the geometry type without having to call isinstance.

torax.geometry.geometry.face_to_cell(face)[source]

Infers cell values corresponding to a vector of face values.

Simply a linear interpolation between face values.

Parameters:

face (Union[Array, ndarray, bool, number]) – An array containing face values.

Returns:

An array containing cell values.

Return type:

cell

torax.geometry.geometry.stack_geometries(geometries)[source]

Batch together a sequence of geometries.

Parameters:

geometries (Sequence[Geometry]) – A sequence of geometries to stack. The geometries must have the same mesh, geometry type.

Return type:

Geometry

Returns:

A Geometry object, where each array attribute has an additional leading axis (e.g. for the time dimension) compared to each Geometry in the input sequence.

torax.geometry.geometry.update_geometries_with_Phibdot(*, dt, geo_t, geo_t_plus_dt)[source]

Update Phibdot in the geometry dataclasses used in the time interval.

Phibdot is used in calc_coeffs to calcuate terms related to time-dependent geometry. It should be set to be the same for geo_t and geo_t_plus_dt for each given time interval. This means that geo_t_plus_dt.Phibdot will not necessarily be the same as the geo_t.Phibdot at the next time step.

Parameters:
  • dt (Union[Array, ndarray, bool, number, float, int]) – Time step duration.

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

  • geo_t_plus_dt (Geometry) – The geometry of the torus during the next time step of the simulation.

Returns:

  • The geometry of the torus during this time step of the simulation.

  • The geometry of the torus during the next time step of the simulation.

Return type:

Tuple containing

torax.geometry.geometry_loader module

File I/O for loading geometry files.

class torax.geometry.geometry_loader.GeometrySource(value)[source]

Bases: Enum

Integer enum for geometry source.

torax.geometry.geometry_loader.load_geo_data(geometry_dir, geometry_file, geometry_source)[source]

Loads the data from a CHEASE file into a dictionary.

Parameters:
Return type:

dict[str, ndarray]

torax.geometry.geometry_provider module

GeometryProvider interface and implementations.

NOTE: Time dependent providers currently live in geometry.py and match the protocol defined here.

class torax.geometry.geometry_provider.ConstantGeometryProvider(geo)[source]

Bases: GeometryProvider

Returns the same Geometry for all calls.

Parameters:

geo (Geometry)

property torax_mesh: Grid1D

Returns the mesh used by Torax, this is consistent across time.

class torax.geometry.geometry_provider.GeometryProvider(*args, **kwargs)[source]

Bases: Protocol

Returns the geometry to use during one time step of the simulation.

A GeometryProvider is any callable (class or function) which takes the time of a time step and returns the Geometry for that time step. See SimulationStepFn for how this callable is used.

This class is a typing.Protocol, meaning it defines an interface, but any function asking for a GeometryProvider as an argument can accept any function or class that implements this API without specifically extending this class.

For instance, the following is an equivalent implementation of the ConstantGeometryProvider without actually creating a class, and equally valid.

geo = circular_geometry.build_circular_geometry(...)
constant_geo_provider = lamdba t: geo

def func_expecting_geo_provider(gp: GeometryProvider):
  ... # do something with the provider.

func_expecting_geo_provider(constant_geo_provider)  # this works.

NOTE: In order to maintain consistency between the DynamicRuntimeParamsSlice and the geometry, sim.get_consistent_dynamic_runtime_params_slice_and_geometry should be used to get a Geometry and a corresponding DynamicRuntimeParamsSlice.

property torax_mesh: Grid1D

Returns the mesh used by Torax, this is consistent across time.

class torax.geometry.geometry_provider.TimeDependentGeometryProvider(geometry_type, torax_mesh, drho_norm, Phi, Phi_face, Rmaj, Rmin, B0, volume, volume_face, area, area_face, vpr, vpr_face, spr, spr_face, delta_face, elongation, elongation_face, g0, g0_face, g1, g1_face, g2, g2_face, g3, g3_face, g2g3_over_rhon, g2g3_over_rhon_face, g2g3_over_rhon_hires, F, F_face, F_hires, Rin, Rin_face, Rout, Rout_face, spr_hires, rho_hires_norm, rho_hires, _z_magnetic_axis)[source]

Bases: Mapping

A geometry provider which holds values to interpolate based on time.

Parameters:
classmethod create_provider(geometries)[source]

Creates a GeometryProvider from a mapping of times to geometries.

Parameters:

geometries (Mapping[float, Geometry])

Return type:

Self

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.geometry.pydantic_model module

Pydantic model for geometry.

class torax.geometry.pydantic_model.CheaseConfig(**data)[source]

Bases: BaseModelFrozen

Pydantic model for the CHEASE geometry.

geometry_type

Always set to ‘chease’.

n_rho

Number of radial grid points.

hires_fac

Only used when the initial condition psi is from plasma current. Sets up a higher resolution mesh with nrho_hires = nrho * hi_res_fac, used for j to psi conversions.

geometry_dir

Optionally overrides the TORAX_GEOMETRY_DIR environment variable.

Ip_from_parameters

Toggles whether total plasma current is read from the configuration file, or from the geometry file. If True, then the psi calculated from the geometry file is scaled to match the desired I_p.

Rmaj

Major radius (R) in meters.

Rmin

Minor radius (a) in meters.

B0

Vacuum toroidal magnetic field on axis [T].

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].

class torax.geometry.pydantic_model.CircularConfig(**data)[source]

Bases: BaseModelFrozen

Pydantic model for the circular geometry config.

geometry_type

Always set to ‘circular’.

n_rho

Number of radial grid points.

hires_fac

Only used when the initial condition psi is from plasma current. Sets up a higher resolution mesh with nrho_hires = nrho * hi_res_fac, used for j to psi conversions.

Rmaj

Major radius (R) in meters.

Rmin

Minor radius (a) in meters.

B0

Vacuum toroidal magnetic field on axis [T].

elongation_LCFS

Sets the plasma elongation used for volume, area and q-profile corrections.

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].

class torax.geometry.pydantic_model.EQDSKConfig(**data)[source]

Bases: BaseModelFrozen

Pydantic model for the EQDSK geometry.

geometry_type

Always set to ‘eqdsk’.

n_rho

Number of radial grid points.

hires_fac

Only used when the initial condition psi is from plasma current. Sets up a higher resolution mesh with nrho_hires = nrho * hi_res_fac, used for j to psi conversions.

geometry_dir

Optionally overrides the TORAX_GEOMETRY_DIR environment variable.

Ip_from_parameters

Toggles whether total plasma current is read from the configuration file, or from the geometry file. If True, then the psi calculated from the geometry file is scaled to match the desired I_p.

n_surfaces

Number of surfaces for which flux surface averages are calculated.

last_surface_factor

Multiplication factor of the boundary poloidal flux, used for the contour defining geometry terms at the LCFS on the TORAX grid. Needed to avoid divergent integrations in diverted geometries.

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].

class torax.geometry.pydantic_model.FBTConfig(**data)[source]

Bases: BaseModelFrozen

Pydantic model for the FBT geometry.

geometry_type

Always set to ‘fbt’.

n_rho

Number of radial grid points.

hires_fac

Only used when the initial condition psi is from plasma current. Sets up a higher resolution mesh with nrho_hires = nrho * hi_res_fac, used for j to psi conversions.

geometry_dir

Optionally overrides the TORAX_GEOMETRY_DIR environment variable.

Ip_from_parameters

Toggles whether total plasma current is read from the configuration file, or from the geometry file. If True, then the psi calculated from the geometry file is scaled to match the desired I_p.

hires_fac

Sets up a higher resolution mesh with nrho_hires = nrho * hi_res_fac, used for j to psi conversions.

LY_object

Sets a single-slice FBT LY geometry file to be loaded, or alternatively a dict directly containing a single time slice of LY data.

LY_bundle_object

Sets the FBT LY bundle file to be loaded, corresponding to multiple time-slices, or alternatively a dict directly containing all time-slices of LY data.

LY_to_torax_times

Sets the TORAX simulation times corresponding to the individual slices in the FBT LY bundle file. If not provided, then the times are taken from the LY_bundle_file itself. The length of the array must match the number of slices in the bundle.

L_object

Sets the FBT L geometry file loaded, or alternatively a dict directly containing the L data.

Parameters:

data (Any)

build_fbt_geometry_provider_from_bundle()[source]

Builds a GeometryProvider from the input config.

Return type:

GeometryProvider

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].

class torax.geometry.pydantic_model.Geometry(**data)[source]

Bases: BaseModelFrozen

Pydantic model for a geometry.

This object can be constructed via Geometry.from_dict(config), where config is a dict described in https://torax.readthedocs.io/en/latest/configuration.html#geometry.

geometry_type

A geometry.GeometryType enum.

geometry_configs

Either a single GeometryConfig or a dict of GeometryConfig objects, where the keys are times in seconds.

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].

class torax.geometry.pydantic_model.GeometryConfig(**data)[source]

Bases: BaseModelFrozen

Pydantic model for a single geometry config.

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].

torax.geometry.standard_geometry module

Classes for representing a standard geometry.

This is a geometry object that is used for most geometries sources CHEASE, FBT, etc.

class torax.geometry.standard_geometry.StandardGeometry(geometry_type, torax_mesh, Phi, Phi_face, Rmaj, Rmin, B0, volume, volume_face, area, area_face, vpr, vpr_face, spr, spr_face, delta_face, elongation, elongation_face, g0, g0_face, g1, g1_face, g2, g2_face, g3, g3_face, g2g3_over_rhon, g2g3_over_rhon_face, g2g3_over_rhon_hires, F, F_face, F_hires, Rin, Rin_face, Rout, Rout_face, spr_hires, rho_hires_norm, rho_hires, Phibdot, _z_magnetic_axis, Ip_from_parameters, Ip_profile_face, psi, psi_from_Ip, psi_from_Ip_face, jtot, jtot_face, delta_upper_face, delta_lower_face)[source]

Bases: Geometry, Mapping

Standard geometry object including additional useful attributes, like psi.

Most instances of Geometry should be of this type. This class extends the base Geometry class with attributes that are commonly computed from various equilibrium data sources (CHEASE, FBT, EQDSK, etc.).

Ip_from_parameters

Boolean indicating whether the total plasma current (Ip_tot) is determined by the config parameters (True) or read from the geometry file (False).

Ip_profile_face

Plasma current profile on the face grid [\(\mathrm{A}\)].

psi

1D poloidal flux profile on the cell grid [\(\mathrm{Wb}\)].

psi_from_Ip

Poloidal flux profile on the cell grid [\(\mathrm{Wb}\)], calculated from the plasma current profile in the geometry file.

psi_from_Ip_face

Poloidal flux profile on the face grid [Wb], calculated from the plasma current profile in the geometry file.

jtot

Total toroidal current density profile on the cell grid [\(\mathrm{A/m^2}\)].

jtot_face

Total toroidal current density profile on the face grid [\(\mathrm{A/m^2}\)].

delta_upper_face

Upper triangularity on the face grid [dimensionless]. See Geometry docstring for definition of delta_upper_face.

delta_lower_face

Lower triangularity on the face grid [dimensionless]. See Geometry docstring for definition of delta_lower_face.

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.geometry.standard_geometry.StandardGeometryIntermediates(geometry_type, Ip_from_parameters, Rmaj, Rmin, B, psi, Ip_profile, Phi, Rin, Rout, F, int_dl_over_Bp, flux_surf_avg_1_over_R2, flux_surf_avg_Bp2, flux_surf_avg_RBp, flux_surf_avg_R2Bp2, delta_upper_face, delta_lower_face, elongation, vpr, n_rho, hires_fac, z_magnetic_axis)[source]

Bases: object

Holds the intermediate values used to build a StandardGeometry.

In particular these are the values that are used when interpolating different geometries. These intermediates are typically extracted directly from equilibrium solver outputs (like CHEASE, FBT, or EQDSK) and then used to construct a StandardGeometry instance.

TODO(b/335204606): Specify the expected COCOS format. NOTE: Right now, TORAX does not have a specified COCOS format. Our team is working on adding this and updating documentation to make that clear. The CHEASE input data is still COCOS 2.

All inputs are 1D profiles vs normalized rho toroidal (rhon).

geometry_type

The type of geometry being represented (e.g., CHEASE, FBT, EQDSK).

Ip_from_parameters

If True, the Ip is taken from the parameters and the values in the Geometry are rescaled to match the new Ip.

Rmaj

major radius on the magnetic axis in [\(\mathrm{m}\)].

Rmin

minor radius (a) in [\(\mathrm{m}\)].

B

Toroidal magnetic field on axis [\(\mathrm{T}\)].

psi

Poloidal flux profile [\(\mathrm{Wb}\)].

Ip_profile

Plasma current profile [\(\mathrm{A}\)].

Phi

Toroidal flux profile [\(\mathrm{Wb}\)].

Rin

Radius of the flux surface at the inboard side at midplane [\(\mathrm{m}\)]. Inboard side is defined as the innermost radius.

Rout

Radius of the flux surface at the outboard side at midplane [\(\mathrm{m}\)]. Outboard side is defined as the outermost radius.

F

Toroidal field flux function (\(F = R B_{\phi}\)) [\(\mathrm{m T}\)].

int_dl_over_Bp

\(\oint dl/B_p\) (field-line contour integral on the flux surface) [\(\mathrm{m / T}\)], where \(B_p\) is the poloidal magnetic field.

flux_surf_avg_1_over_R2

Flux surface average of \(1/R^2\) [\(\mathrm{m^{-2}}\)].

flux_surf_avg_Bp2

Flux surface average of \(B_p^2\) [\(\mathrm{T^2}\)].

flux_surf_avg_RBp

Flux surface average of \(R B_p\) [\(\mathrm{m T}\)].

flux_surf_avg_R2Bp2

Flux surface average of \(R^2 B_p^2\) [\(\mathrm{m^2 T^2}\)].

delta_upper_face

Upper triangularity [dimensionless]. See Geometry docstring for definition.

delta_lower_face

Lower triangularity [dimensionless]. See Geometry docstring for definition.

elongation

Plasma elongation profile [dimensionless]. See Geometry docstring for definition.

vpr

Profile of dVolume/d(rho_norm), where rho_norm is the normalized toroidal flux coordinate [\(\mathrm{m^3}\)].

n_rho

Radial grid points (number of cells).

hires_fac

Grid refinement factor for poloidal flux <–> plasma current calculations. Used to create a higher-resolution grid to improve accuracy when initializing psi from a plasma current profile.

z_magnetic_axis

z position of magnetic axis [\(\mathrm{m}\)].

Parameters:
classmethod from_chease(geometry_dir, geometry_file, Ip_from_parameters, n_rho, Rmaj, Rmin, B0, hires_fac)[source]

Constructs a StandardGeometryIntermediates from a CHEASE file.

Parameters:
  • geometry_dir (str | None) – Directory where to find the CHEASE file describing the magnetic geometry. If None, uses the environment variable TORAX_GEOMETRY_DIR if available. If that variable is not set and geometry_dir is not provided, then it defaults to another dir. See implementation.

  • geometry_file (str) – CHEASE file name.

  • Ip_from_parameters (bool) – If True, the Ip is taken from the parameters and the values in the Geometry are rescaled to match the new Ip.

  • n_rho (int) – Radial grid points (num cells)

  • Rmaj (float) – major radius (R) in meters. CHEASE geometries are normalized, so this is used as an unnormalization factor.

  • Rmin (float) – minor radius (a) in meters

  • B0 (float) – Toroidal magnetic field on axis [T].

  • hires_fac (int) – Grid refinement factor for poloidal flux <–> plasma current calculations.

Return type:

Self

Returns:

A StandardGeometry instance based on the input file. This can then be used to build a StandardGeometry by passing to build_standard_geometry.

classmethod from_eqdsk(geometry_dir, geometry_file, hires_fac, Ip_from_parameters, n_rho, n_surfaces, last_surface_factor)[source]

Constructs a StandardGeometryIntermediates from EQDSK.

This method constructs a StandardGeometryIntermediates object from an EQDSK file. It calculates flux surface averages based on the EQDSK geometry 2D psi mesh.

Parameters:
  • geometry_dir (str | None) – Directory where to find the EQDSK file describing the magnetic geometry. If None, uses the environment variable TORAX_GEOMETRY_DIR if available. If that variable is not set and geometry_dir is not provided, then it defaults to another dir. See implementation.

  • geometry_file (str) – EQDSK file name.

  • hires_fac (int) – Grid refinement factor for poloidal flux <–> plasma current calculations.

  • Ip_from_parameters (bool) – If True, then Ip is taken from the config and the values in the Geometry are rescaled.

  • n_rho (int) – Grid resolution used for all TORAX cell variables.

  • n_surfaces (int) – Number of surfaces for which flux surface averages are calculated.

  • last_surface_factor (float) – Multiplication factor of the boundary poloidal flux, used for the contour defining geometry terms at the LCFS on the TORAX grid. Needed to avoid divergent integrations in diverted geometries.

Return type:

Self

Returns:

A StandardGeometryIntermediates instance based on the input file. This can then be used to build a StandardGeometry by passing to build_standard_geometry.

classmethod from_fbt_bundle(geometry_dir, LY_bundle_object, L_object, LY_to_torax_times, Ip_from_parameters=True, n_rho=25, hires_fac=4)[source]

Returns StandardGeometryIntermediates from a bundled FBT LY file.

LY_bundle_object is an FBT data object containing a bundle of LY geometry slices at different times, packaged within a single object (as opposed to a sequence of standalone LY files). LY_to_torax_times is a 1D array of times, defining the times in the TORAX simulation corresponding to each slice in the LY bundle. All times in the LY bundle must be mapped to times in TORAX. The LY_bundle_object and L_object can either be file names for disk loading, or directly the data dicts.

Parameters:
  • geometry_dir (str | None) – Directory where to find the FBT file describing the magnetic geometry. If None, uses the environment variable TORAX_GEOMETRY_DIR if available. If that variable is not set and geometry_dir is not provided, then it defaults to another dir. See load_geo_data implementation.

  • LY_bundle_object (str | Mapping[str, ndarray]) – Either file name for bundled LY data, e.g. as produced by liuqe meqlpack, or the data dict itself.

  • L_object (str | Mapping[str, ndarray]) – Either file name for L data. Assumed to be the same L data for all LY slices in the bundle, or the data dict itself.

  • LY_to_torax_times (ndarray | None) – User-provided times which map the times of the LY geometry slices to TORAX simulation times. A ValueError is raised if the number of array elements doesn’t match the length of the LY_bundle array data. If None, then times are taken from the LY_bundle_object itself.

  • Ip_from_parameters (bool) – If True, then Ip is taken from the config and the values in the Geometry are rescaled.

  • n_rho (int) – Grid resolution used for all TORAX cell variables.

  • hires_fac (int) – Grid refinement factor for poloidal flux <–> plasma current calculations.

Return type:

Mapping[float, Self]

Returns:

A mapping from user-provided (or inferred) times to StandardGeometryIntermediates instances based on the input slices. This can then be used to build a StandardGeometryProvider.

classmethod from_fbt_single_slice(geometry_dir, LY_object, L_object, Ip_from_parameters=True, n_rho=25, hires_fac=4)[source]

Returns StandardGeometryIntermediates from a single slice FBT LY file.

LY and L are FBT data files containing magnetic geometry information. The majority of the needed information is in the LY file. The L file is only needed to get the normalized poloidal flux coordinate, pQ.

This method is for cases when the LY file on disk corresponds to a single time slice. Either a single time slice or sequence of time slices can be provided in the geometry config.

Parameters:
  • geometry_dir (str | None) – Directory where to find the FBT file describing the magnetic geometry. If None, uses the environment variable TORAX_GEOMETRY_DIR if available. If that variable is not set and geometry_dir is not provided, then it defaults to another dir. See load_geo_data implementation.

  • LY_object (str | Mapping[str, ndarray]) – File name for LY data, or directly an LY single slice dict.

  • L_object (str | Mapping[str, ndarray]) – File name for L data, or directly an L dict.

  • Ip_from_parameters (bool) – If True, then Ip is taken from the config and the values in the Geometry are rescaled

  • n_rho (int) – Grid resolution used for all TORAX cell variables.

  • hires_fac (int) – Grid refinement factor for poloidal flux <–> plasma current calculations.

Return type:

Self

Returns:

A StandardGeometryIntermediates instance based on the input slice. This can then be used to build a StandardGeometry by passing to build_standard_geometry.

class torax.geometry.standard_geometry.StandardGeometryProvider(geometry_type, torax_mesh, drho_norm, Phi, Phi_face, Rmaj, Rmin, B0, volume, volume_face, area, area_face, vpr, vpr_face, spr, spr_face, delta_face, elongation, elongation_face, g0, g0_face, g1, g1_face, g2, g2_face, g3, g3_face, g2g3_over_rhon, g2g3_over_rhon_face, g2g3_over_rhon_hires, F, F_face, F_hires, Rin, Rin_face, Rout, Rout_face, spr_hires, rho_hires_norm, rho_hires, _z_magnetic_axis, Ip_from_parameters, Ip_profile_face, psi, psi_from_Ip, psi_from_Ip_face, jtot, jtot_face, delta_upper_face, delta_lower_face)[source]

Bases: TimeDependentGeometryProvider, Mapping

Values to be interpolated for a Standard Geometry.

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.geometry.standard_geometry.build_standard_geometry(intermediate)[source]

Build geometry object based on set of profiles from an EQ solution.

Parameters:

intermediate (StandardGeometryIntermediates) – A StandardGeometryIntermediates object that holds the intermediate values used to build a StandardGeometry for this timeslice. These can either be direct or interpolated values.

Return type:

StandardGeometry

Returns:

A StandardGeometry object.

Module contents

This package contains functionality related to geometry.