gvec.core.compute#
GVEC Postprocessing - Compute Functions
- gvec.core.compute.Evaluations(rho: Literal['int'] | int | float | DataArray | ndarray | Sequence | None = 'int', theta: Literal['int'] | int | float | DataArray | ndarray | Sequence | None = 'int', zeta: Literal['int'] | int | float | DataArray | ndarray | Sequence | None = 'int', state: State | None = None, nfp: int | None = None)#
- gvec.core.compute.EvaluationsBoozer(rho: Literal['int'] | int | float | DataArray | ndarray | Sequence, theta_B: int | float | DataArray | ndarray | Sequence, zeta_B: int | float | DataArray | ndarray | Sequence, state: State, radial_derivative: bool = True, epsilon_FD: float = 1e-08, **boozer_kwargs)#
Create an Evaluations dataset with a grid in Boozer coordinates.
This factory function generates a mesh in logical coordinates (rho, theta, zeta) based on a grid in Boozer coordinates. The grid has dimensions (“rad”, “pol”, “tor”), corresponding to the radial, poloidal, and toroidal directions.
If a 2D or 3D array for theta_B or zeta_B is passed, the corresponding coordinate for the poloidal/toroidal dimension needs to be set manually afterwards (e.g. ev[“alpha”] = (“pol”, values) and ev = ev.set_coords(“alpha”).set_xindex(“alpha”)).
- Parameters:
rho ("int" | int | float | 1D array (DataArray, ndarray, list)) – The specification of the radial, radius-like coordinate. “int” will use the integration points from the state object.
theta_B (int | float | 1D, 2D or 3D array (DataArray, ndarray, list)) – The specification of the poloidal, angle-like Boozer coordinate. 1D assumes dimension “pol”, 2D assumes (“pol”, “tor”), 3D assumes (“rad”, “pol”, “tor”).
zeta_B (int | float | 1D, 2D or 3D array (DataArray, ndarray, list)) – The specification of the toroidal, angle-like Boozer coordinate. 1D assumes dimension “tor”, 2D assumes (“pol”, “tor”), 3D assumes (“rad”, “pol”, “tor”).
state (State) – The gvec.State object to create the grid for. Used to perform the Boozer transform.
radial_derivative (bool, default True) – Whether to compute the radial derivatives of the LA and NU_B variables, at fixed GVEC angles \((\vartheta(\rho_i,\vartheta_{B,j},\zeta_{B,k}),\zeta(\rho_i,\vartheta_{B,j},\zeta_{B,k}))\). Computes boozer transform at additional radial points \(\rho-\epsilon\), and uses a first order Finite Difference for the derivatives.
epsilon_FD (float, optional) – The offset in rho used for the Finite Difference computation of the radial derivatives, default
1e-8.boozer_kwargs (dict, optional) – Additional keyword arguments to pass to the
get_boozermethod of thestateobject. These can be used to specify the Boozer transform parameters. For example the maximum mode number factorboozer_kwargs={"MNfactor": 3}.
- Return type:
xr.Dataset
- gvec.core.compute.EvaluationsBoozerCustom(rho, theta_B, zeta_B, state, **boozer_kwargs)#
Create a custom EvaluationsBoozer dataset with Boozer coordinates.
Deprecated since version v1.2.
- gvec.core.compute.EvaluationsPEST(rho: Literal['int'] | int | float | DataArray | ndarray | Sequence, theta_P: int | float | DataArray | ndarray | Sequence, zeta: int | float | DataArray | ndarray | Sequence, state: State)#
Create an Evaluations dataset with a grid in PEST coordinates.
PEST coordinates are straight-fieldline coordinates with both the radial and toroidal coordinate being identical to their logical coordinates, i.e. rho_P = rho and zeta_P = zeta. Note that for GVEC the toroidal coordinate is not necessarily the cylindrical angle.
This factory function generates a mesh in logical coordinates (rho, theta, zeta) based on a grid in PEST coordinates. The grid has dimensions (“rad”, “pol”, “tor”), corresponding to the radial, poloidal, and toroidal directions.
If a 2D or 3D array for theta_P or zeta is passed, the corresponding coordinate for the poloidal/toroidal dimension needs to be set manually afterwards (e.g. ev[“alpha”] = (“pol”, values) and ev = ev.set_coords(“alpha”).set_xindex(“alpha”)).
- Parameters:
rho ("int" | int | float | 1D array (DataArray, ndarray, list)) – The specification of the radial, radius-like coordinate. “int” will use the integration points from the state object.
theta_P (int | float | 1D, 2D or 3D array (DataArray, ndarray, list)) – The specification of the poloidal, angle-like PEST coordinate. 1D assumes dimension “pol”, 2D assumes (“pol”, “tor”), 3D assumes (“rad”, “pol”, “tor”).
zeta (int | float | 1D, 2D or 3D array (DataArray, ndarray, list)) – The specification of the toroidal, angle-like logical coordinate. 1D assumes dimension “tor”, 2D assumes (“pol”, “tor”), 3D assumes (“rad”, “pol”, “tor”).
state (State) – The gvec.State object to create the grid for. Used to perform the PEST transform.
- gvec.core.compute.compute(ev: Dataset, *quantities: str, state: State | None = None, registry: Mapping | None = None) Dataset#
Compute the target quantity and add it to the given evaluation dataset.
This method will recursively determine prerequisites, compute them and add them to the dataset as needed.
- Parameters:
ev (xr.Dataset) – The evaluation dataset with the target grid
(rad, pol, tor), coordinates(rho, theta, zeta)and possibly some precomputed quantities.*quantities (str) – One or more names of the quantities to compute. See the default table of available quantities or call
table_of_quantitiesto see all options.state (gvec.State | None, optional) – A gvec.State object that can be used by quantities which require it. Not necessary if the desired quantities only depend on already computed quantities.
registry (Mapping | None, optional) – The registry of computable quantites to use. Default: the
gvec.core.compute.QUANTITIESregistry used to evaluate a gvec.State object.
See also
evaluatecreate a new grid in logical coordinates and compute target quantities.
evaluate_sflcreate a new grid in straight-fieldline coordinates and compute target quantities.
gvec.core.state.State.evaluatethis function as a method of gvec.State.
- gvec.core.compute.ev2ft(ev, quiet=False)#
- gvec.core.compute.evaluate(state: State, *quantities: str, rho: Literal['int'] | int | float | DataArray | ndarray | Sequence | None = 'int', theta: Literal['int'] | int | float | DataArray | ndarray | Sequence | None = 'int', zeta: Literal['int'] | int | float | DataArray | ndarray | Sequence | None = 'int') Dataset#
Evaluate the specified quantities on a grid in logical coordinates (rho, theta, zeta). This function creates an xarray Dataset with a specified grid and evaluates the desired quantities and recursively determined prerequisites on that grid.
- Parameters:
state (State) – The gvec.State object to evaluate the quantities for.
*quantities (str) –
The names of (registered) quantities to evaluate, e.g.
"pos","B","mod_B".See the default table of available quantities or call
table_of_quantitiesto see all options.rho ("int" | int | float | 1D array | None, default: "int") –
The specification of the radial, radius-like coordinate (\(\rho\)), defined in the interval \([0, 1]\). It can be specified as:
The literal string
"int"to use the integration points from the state object.An integer number of points (e.g.
rho=10) to create a uniform grid (offset at the magnetic axis).A float value (e.g.
rho=0.5) to evaluate at a single point.A 1D array-like (list, numpy.ndarray) of values.
An xarray.DataArray containing at least the required dimension
radrespectively.Noneto omit this dimension and coordinate.
theta ("int" | int | float | 1D array | None, default: "int") –
The specification of the poloidal, angle-like coordinate (\(\vartheta\)), defined in the interval \([0, 2\pi)\). It can be specified as:
The literal string
"int"to use the integration points from the state object.An integer number of points (e.g.
theta=10) to create a uniform grid.A float value (e.g.
theta=0.5) to evaluate at a single point.A 1D array-like (list, numpy.ndarray) of values.
An xarray.DataArray containing at least the required dimension
polrespectively.Noneto omit this dimension and coordinate.
zeta ("int" | int | float | 1D array | None, default: "int") –
The specification of the toroidal, angle-like coordinate (\(\zeta\)), defined in the interval \([0, 2\pi)\). It can be specified as:
The literal string
"int"to use the integration points from the state object (distributed on a single field-period).An integer number of points (e.g.
zeta=10) to create a uniform grid (on a single field-period).A float value (e.g.
zeta=0.5) to evaluate at a single point.A 1D array-like (list, numpy.ndarray) of values.
An xarray.DataArray containing at least the required dimension
torrespectively.Noneto omit this dimension and coordinate.
- Returns:
An xarray Dataset containing the evaluated quantities and prerequisites on the specified grid.
The returned Dataset has dimensions
("rad", "pol", "tor")corresponding to the radial, poloidal, and toroidal directions, with respective coordinatesrho(rad),theta(pol), andzeta(tor).- Return type:
See also
gvec.core.compute.evaluatethis function as a standalone function.
gvec.core.state.State.evaluatethis function as a method of gvec.State.
gvec.core.compute.computecompute quantities and add them to an existing dataset.
gvec.core.compute.evaluate_sflevaluate quantities on a grid in straight-fieldline coordinates.
- gvec.core.compute.evaluate_sfl(state: State, *quantities: str, rho: int | float | DataArray | ndarray | Sequence | Literal['int'], theta: int | float | DataArray | ndarray | Sequence, zeta: int | float | DataArray | ndarray | Sequence, sfl: Literal['boozer', 'pest'], **boozer_kwargs) Dataset#
Evaluate the specified quantities on a grid in straight-fieldline coordinates (Boozer or PEST). This function creates an xarray Dataset with a specified grid and evaluates the desired quantities and recursively determined prerequisites on that grid.
- Parameters:
state (State) – The gvec.State object to evaluate the quantities for.
*quantities (str) –
The names of (registered) quantities to evaluate, e.g.
"pos","B","mod_B".See the default table of available quantities or call
table_of_quantitiesto see all options.rho ("int" | int | float | 1D array) –
The specification of the radial, radius-like coordinate (\(\rho\)), defined in the interval \([0, 1]\). It can be specified as:
The literal string
"int"to use the integration points from the state object.An integer number of points (e.g.
rho=10) to create a uniform grid.A float value (e.g.
rho=0.5) to evaluate at a single point.A 1D array-like (list, numpy.ndarray) of values.
An xarray.DataArray containing at least the dimension
rad.
theta (int | float | 1D, 2D or 3D array) –
The specification of the poloidal, angle-like coordinate (\(\vartheta\), \(\vartheta_P\) or \(\vartheta_B\)), defined in the interval \([0, 2\pi)\). It can be specified as:
An integer number of points (e.g.
theta=10) to create a uniform grid.A float value (e.g.
theta=0.5) to evaluate at a single point.A 1D array-like (list, numpy.ndarray) of values.
A 2D array-like with assumed dimensions (pol, tor).
A 3D array-like with assumed dimensions (rad, pol, tor).
An xarray.DataArray containing at least the dimension
pol.
zeta (int | float | 1D, 2D or 3D array) –
The specification of the toroidal, angle-like coordinate (\(\zeta\) or \(\zeta_B\)), defined in the interval \([0, 2\pi)\). For equidistant grids, the grid will only cover one field period (i.e. \([0, 2\pi/N_{FP})\)). It can be specified as:
An integer number of points (e.g.
zeta=10) to create a uniform grid (on a single field-period).A float value (e.g.
zeta=0.5) to evaluate at a single point.A 1D array-like (list, numpy.ndarray) of values.
A 2D array-like with assumed dimensions (pol, tor).
A 3D array-like with assumed dimensions (rad, pol, tor).
An xarray.DataArray containing at least the dimension
tor.
sfl ("boozer" | "pest") – The type of straight-fieldline coordinates to use for the grid.
boozer_kwargs (optional) – Additional keyword arguments to pass to the
get_boozermethod of thestateobject. These can be used to specify the Boozer transform parameters. For example the maximum mode number factorboozer_kwargs={'MNfactor': 3}.
- Returns:
An xarray Dataset containing the evaluated quantities and prerequisites on the specified grid.
The returned Dataset has (at least) dimensions
("rad", "pol", "tor")corresponding to the radial, poloidal, and toroidal directions. With 1D or equidistant coordinates, the respective coordinates arerho(rad),theta_P(pol)ortheta_B(pol), andzeta(tor)orzeta_B(tor). The logical coordinates are then normal data variables of more dimensions in the dataset.- Return type:
See also
gvec.core.compute.evaluate_sflthis function as a standalone function.
gvec.core.state.State.evaluate_sflthis function as a method of gvec.State.
gvec.core.compute.computecompute quantities and add them to an existing dataset.
gvec.core.compute.evaluateevaluate quantities on a grid in logical coordinates.
- gvec.core.compute.fluxsurface_integral(quantity: DataArray)#
Compute the flux surface integral of the given quantity.
- gvec.core.compute.ft_autoremove(ft: Dataset, drop=False, **tol_kwargs)#
autoremove variables which are always close to zero (e.g. due to stellarator symmetry)
- gvec.core.compute.poloidal_integral(quantity: DataArray)#
Compute the poloidal (along theta) integral/average of the given quantity.
- gvec.core.compute.radial_integral(quantity: DataArray)#
Compute the radial integral/average of the given quantity.
- gvec.core.compute.register(quantities: None | str | Collection[str] = None, requirements: Collection[str] = (), integration: Collection[str] = (), attrs: Mapping = {}, registry: MutableMapping | None = None)#
Function decorator to register equilibrium quantities.
The quantity (compute function) is registered in the QUANTITIES dictionary. It contains:
a function pointer
the name of the computed quantities (used as key in QUANTITIES)
the names of required quantities (that should be computed before)
the names of the integration axes required for the computation
the attributes of the computed quantity (
long_name,symbol, etc.)
- gvec.core.compute.table_of_quantities(markdown: bool = False, registry: Mapping | None = None)#
Generate a table of computable quantities.
- Parameters:
markdown (bool, optional) – If True, return the table as a Ipython.Markdown object. Otherwise, return the table as a string.
registry (Mapping | None, optional) – The registry of computable quantites to use. Default: the
gvec.core.compute.QUANTITIESregistry used to evaluate a gvec.State object.
- Returns:
The table of quantities. If markdown is True, the table is returned as an instance of IPython.display.Markdown. Otherwise, the table is returned as a string.
- Return type:
str or IPython.display.Markdown
Notes
This method generates a table of quantities based on the attributes of the registered quantities. The table includes the label, long name, and symbol of each quantity.