Base classes#
Base classes for MHD equilibria.
- class struphy.fields_background.base.FluidEquilibrium[source]#
Bases:
objectAbstract base class for callable fluid equilibria on arbitrary domains.
This class provides a unified interface for representing fluid equilibrium states, including velocity, pressure, and number density fields. It supports coordinate transformations between logical (reference) and physical domains through the Domain object, enabling computations on mapped domains.
- Variables:
params (dict) – Dictionary of parameters passed to the class initialization. Automatically strips ‘self’ and ‘__class__’ entries.
domain (Domain) – Domain object that characterizes the mapping from the logical cube [0, 1]^3 to the physical domain. Enables coordinate transformations and differential form conversions (0-forms, 1-forms, 2-forms, 3-forms).
Requirements (Implementation)
---------------------------
pairs (Child classes must provide at least one method from each of these)
Velocity (*)
Pressure (*)
Density (* Number)
Quantities (Derived)
------------------
fields (The class automatically provides derived fields computed from the basic)
Temperature (*)
velocity (* Thermal)
density (* Entropy)
Forms (Differential)
-------------------
as (Vector fields (velocity) are available)
uv (*)
u1 (*)
u2 (*)
u_cart (*)
(densities) (Scalar fields are available as 0-forms (point values) and 3-forms)
p3 (* p0,)
n3 (* n0,)
t3 (* t0,)
q3 (* q0,)
Notes
The class uses abstract methods to enforce implementation in child classes. Subclasses should override coordinate-appropriate base methods (CartesianFluidEquilibrium or LogicalFluidEquilibrium) to simplify implementation.
- property params: dict#
Parameters passed to __init__() of the class in equils.py, as dictionary.
- property domain#
Domain object that characterizes the mapping from the logical to the physical domain.
- property is_default#
- uv(*etas, squeeze_out=False)[source]#
Contra-variant components of velocity on logical cube [0, 1]^3.
- u_cart(*etas, squeeze_out=False)[source]#
Cartesian components of velocity evaluated on logical cube [0, 1]^3. Returns also (x,y,z).
- s0_monoatomic(*etas, squeeze_out=False)[source]#
0-form entropy density on logical cube [0, 1]^3. Hard coded assumption : gamma = 5/3 (monoatomic perfect gaz)
- s3_monoatomic(*etas, squeeze_out=False)[source]#
3-form entropy density on logical cube [0, 1]^3. Hard coded assumption : gamma = 5/3 (monoatomic perfect gaz)
- s0_diatomic(*etas, squeeze_out=False)[source]#
0-form entropy density on logical cube [0, 1]^3. Hard coded assumption : gamma = 7/5 (diatomic perfect gaz)
- s3_diatomic(*etas, squeeze_out=False)[source]#
3-form entropy density on logical cube [0, 1]^3. Hard coded assumption : gamma = 5/3 (monoatomic perfect gaz)
- classmethod from_dict(dct: dict | None) FluidEquilibrium[source]#
- classmethod get_equil_by_name(equil_name: str) type[FluidEquilibrium][source]#
- class struphy.fields_background.base.CartesianFluidEquilibrium[source]#
Bases:
FluidEquilibriumSpecialization for equilibria defined in Cartesian coordinates.
Child classes must implement the abstract methods
u_xyz,p_xyz, andn_xyz, which return velocity, pressure, and number density in Cartesian physical space (x, y, z). The base class automatically handles coordinate transformations and differential form conversions.- abstract u_xyz(x, y, z)[source]#
Cartesian velocity in physical space. Must return the components as a tuple.
- property domain#
Domain object that characterizes the mapping from the logical to the physical domain.
- class struphy.fields_background.base.LogicalFluidEquilibrium[source]#
Bases:
FluidEquilibriumSpecialization for equilibria defined on the logical cube [0, 1]^3.
Child classes must implement the abstract methods
uv,p0, andn0, which return contravariant velocity, 0-form pressure, and 0-form number density on the logical reference domain. Useful for direct implementation when physical coordinates are obtained via coordinate transformation through the domain mapping.- abstract uv(*etas, squeeze_out=False)[source]#
Contra-variant (vector field) velocity on logical cube [0, 1]^3. Must return the components as a tuple.
- property domain#
Domain object that characterizes the mapping from the logical to the physical domain.
- class struphy.fields_background.base.NumericalFluidEquilibrium[source]#
Bases:
LogicalFluidEquilibriumSpecialization for equilibria with numerically computed domain mappings.
Child classes must provide a
numerical_domainproperty that returns a Domain object representing the mapping from the logical cube [0, 1]^3 to the physical domain. This class overrides the domain property to use the numerically computed mapping.- abstract property numerical_domain#
Numerically computed mapping from the logical cube [0, 1]^3 to the physical domain in the form of a
Domainobject.
- property domain#
Domain object that characterizes the mapping from the logical to the physical domain.
- class struphy.fields_background.base.FluidEquilibriumWithB[source]#
Bases:
FluidEquilibriumExtension of FluidEquilibrium with magnetic field and its gradient.
Child classes must implement either Cartesian (
b_xyz,gradB_xyz) or logical (bv,gradB1) methods for magnetic field and its gradient. Provides methods for 1-form and 2-form transformations of the magnetic field.- property domain#
Domain object that characterizes the mapping from the logical to the physical domain.
- bv(*etas, squeeze_out=False)[source]#
Contra-variant components of magnetic field on logical cube [0, 1]^3.
- b_cart(*etas, squeeze_out=False)[source]#
Cartesian components of magnetic field evaluated on logical cube [0, 1]^3. Returns also (x,y,z).
- unit_b1(*etas, squeeze_out=False)[source]#
Unit vector components of magnetic field (1-form) on logical cube [0, 1]^3.
- unit_b2(*etas, squeeze_out=False)[source]#
Unit vector components of magnetic field (2-form) on logical cube [0, 1]^3.
- unit_bv(*etas, squeeze_out=False)[source]#
Unit vector components of magnetic field (contra-variant) on logical cube [0, 1]^3.
- unit_b_cart(*etas, squeeze_out=False)[source]#
Unit vector Cartesian components of magnetic field evaluated on logical cube [0, 1]^3. Returns also (x,y,z).
- gradB1(*etas, squeeze_out=False)[source]#
1-form components of gradient of magnetic field strength evaluated on logical cube [0, 1]^3. Returns also (x,y,z).
- gradB2(*etas, squeeze_out=False)[source]#
2-form components of gradient of magnetic field strength evaluated on logical cube [0, 1]^3. Returns also (x,y,z).
- gradBv(*etas, squeeze_out=False)[source]#
Contra-variant components of gradient of magnetic field strength evaluated on logical cube [0, 1]^3. Returns also (x,y,z).
- gradB_cart(*etas, squeeze_out=False)[source]#
Cartesian components of gradient of magnetic field strength evaluated on logical cube [0, 1]^3. Returns also (x,y,z).
- a1(*etas, squeeze_out=False)[source]#
1-form components of vector potential on logical cube [0, 1]^3.
- a2(*etas, squeeze_out=False)[source]#
2-form components of vector potential on logical cube [0, 1]^3.
- av(*etas, squeeze_out=False)[source]#
Contra-variant components of vector potneital on logical cube [0, 1]^3.
- absB0(*etas, squeeze_out=False)[source]#
0-form absolute value of magnetic field on logical cube [0, 1]^3.
- class struphy.fields_background.base.CartesianFluidEquilibriumWithB[source]#
Bases:
CartesianFluidEquilibriumSpecialization for fluid equilibria with magnetic field in Cartesian coordinates.
Child classes must implement the abstract methods
b_xyzandgradB_xyz, which return magnetic field and its gradient strength in Cartesian physical space.- abstract b_xyz(x, y, z)[source]#
Cartesian magnetic field in physical space. Must return the components as a tuple.
- abstract gradB_xyz(x, y, z)[source]#
Cartesian gradient of magnetic field strength in physical space. Must return the components as a tuple.
- property domain#
Domain object that characterizes the mapping from the logical to the physical domain.
- class struphy.fields_background.base.LogicalFluidEquilibriumWithB[source]#
Bases:
LogicalFluidEquilibriumSpecialization for fluid equilibria with magnetic field on the logical cube [0, 1]^3.
Child classes must implement the abstract methods
bv(contravariant magnetic field) andgradB1(1-form gradient of magnetic field strength) on the logical domain.- abstract bv(*etas, squeeze_out=False)[source]#
Contra-variant (vector field) magnetic field on logical cube [0, 1]^3. Must return the components as a tuple.
- abstract gradB1(*etas, squeeze_out=False)[source]#
Co-variant (1-from) gradient of magnetic field strength on logical cube [0, 1]^3. Must return the components as a tuple.
- property domain#
Domain object that characterizes the mapping from the logical to the physical domain.
- class struphy.fields_background.base.NumericalFluidEquilibriumWithB[source]#
Bases:
LogicalFluidEquilibriumWithBSpecialization for fluid equilibria with magnetic field and numerically computed domain mappings.
Child classes must provide a
numerical_domainproperty that returns a Domain object. This class overrides the domain property to use the numerically computed mapping.- abstract property numerical_domain#
Numerically computed mapping from the logical cube [0, 1]^3 to the physical domain in the form of a
Domainobject.
- property domain#
Domain object that characterizes the mapping from the logical to the physical domain.
- class struphy.fields_background.base.MHDequilibrium[source]#
Bases:
FluidEquilibriumWithBExtension of FluidEquilibriumWithB with current density field.
Child classes must implement either Cartesian (
j_xyz) or logical (jv) methods for current density. The velocity field is derived from current density as j/n, overriding the base FluidEquilibrium. Provides methods for 1-form and 2-form transformations of the current density.- property domain#
Domain object that characterizes the mapping from the logical to the physical domain.
- jv(*etas, squeeze_out=False)[source]#
Contra-variant components of current on logical cube [0, 1]^3.
- j_cart(*etas, squeeze_out=False)[source]#
Cartesian components of current evaluated on logical cube [0, 1]^3. Returns also (x,y,z).
- u1(*etas, squeeze_out=False)[source]#
1-form components of mean velocity evaluated on logical cube [0, 1]^3. Returns also (x,y,z).
- u2(*etas, squeeze_out=False)[source]#
2-form components of mean velocity evaluated on logical cube [0, 1]^3. Returns also (x,y,z).
- uv(*etas, squeeze_out=False)[source]#
Contra-variant components of mean velocity evaluated on logical cube [0, 1]^3. Returns also (x,y,z).
- u_cart(*etas, squeeze_out=False)[source]#
Cartesian components of mean velocity evaluated on logical cube [0, 1]^3. Returns also (x,y,z).
- curl_unit_b1(*etas, squeeze_out=False)[source]#
1-form components of curl of unit magnetic field evaluated on logical cube [0, 1]^3. Returns also (x,y,z).
- curl_unit_b2(*etas, squeeze_out=False)[source]#
2-form components of curl of unit magnetic field evaluated on logical cube [0, 1]^3. Returns also (x,y,z).
- curl_unit_bv(*etas, squeeze_out=False)[source]#
Contra-variant components of curl of unit magnetic field evaluated on logical cube [0, 1]^3. Returns also (x,y,z).
- curl_unit_b_cart(*etas, squeeze_out=False)[source]#
Cartesian components of curl of unit magnetic field evaluated on logical cube [0, 1]^3. Returns also (x,y,z).
- curl_unit_b_dot_b0(*etas, squeeze_out=False)[source]#
0-form of \((\nabla \times \mathbf b_0) \times \mathbf b_0\) evaluated on logical cube [0, 1]^3.
- show(n1=16, n2=33, n3=21, n_planes=5)[source]#
Generate vtk files of equilibirum and do some 2d plots with matplotlib.
- Parameters:
n1 (int) – Evaluation points of mapping in each direcion.
n2 (int) – Evaluation points of mapping in each direcion.
n3 (int) – Evaluation points of mapping in each direcion.
n_planes (int) – Number of planes to show perpendicular to eta3.
- class struphy.fields_background.base.CartesianMHDequilibrium[source]#
Bases:
MHDequilibriumSpecialization for MHD equilibria in Cartesian coordinates.
Child classes must implement the abstract methods
b_xyz,j_xyz,p_xyz,n_xyz, andgradB_xyzin Cartesian physical space.- abstract b_xyz(x, y, z)[source]#
Cartesian magnetic field in physical space. Must return the components as a tuple.
- abstract j_xyz(x, y, z)[source]#
Cartesian current (curl of magnetic field) in physical space. Must return the components as a tuple.
- abstract gradB_xyz(x, y, z)[source]#
Cartesian gradient of magnetic field strength in physical space. Must return the components as a tuple.
- property domain#
Domain object that characterizes the mapping from the logical to the physical domain.
- class struphy.fields_background.base.AxisymmMHDequilibrium[source]#
Bases:
CartesianMHDequilibriumBase class for ideal axisymmetric MHD equilibria based on a poloidal flux function \(\psi(R, Z)\) and a toroidal field function \(g_{tor}(R, Z)\) in a cylindrical coordinate system \((R, \phi, Z)\).
The magnetic field and current density are then given by
\[\mathbf B = \nabla \psi \times \nabla \phi + g_{tor} \nabla \phi\,,\qquad \mathbf j = \nabla \times \mathbf B\,.\]The pressure and density profiles need to be implemented by child classes.
- abstract psi(R, Z, dR=0, dZ=0)[source]#
Poloidal flux function per radian. First AND second derivatives dR=0,1,2 and dZ=0,1,2 must be implemented.
- abstract g_tor(R, Z, dR=0, dZ=0)[source]#
Toroidal field function. First derivatives dR=0,1 and dZ=0,1 must be implemented.
- abstract property psi_range#
Psi on-axis and at plasma boundary returned as list [psi_axis, psi_boundary].
- abstract property psi_axis_RZ#
Location of magnetic axis in R-Z-coordinates returned as list [psi_axis_R, psi_axis_Z].
- b_xyz(x, y, z)[source]#
Cartesian B-field components calculated as BR = -(dpsi/dZ)/R, BPhi = g_tor/R, BZ = (dpsi/dR)/R.
- gradB_xyz(x, y, z)[source]#
Cartesian gradient |B| components calculated as grad(sqrt(BR**2 + BPhi**2 + BZ**2)).
- property domain#
Domain object that characterizes the mapping from the logical to the physical domain.
- class struphy.fields_background.base.LogicalMHDequilibrium[source]#
Bases:
MHDequilibriumSpecialization for MHD equilibria on the logical cube [0, 1]^3.
Child classes must implement the abstract methods
bv,jv,p0,n0, andgradB1on the logical reference domain.- abstract bv(*etas, squeeze_out=False)[source]#
Contra-variant (vector field) magnetic field on logical cube [0, 1]^3. Must return the components as a tuple.
- abstract jv(*etas, squeeze_out=False)[source]#
Contra-variant (vector field) current density (=curl B) on logical cube [0, 1]^3. Must return the components as a tuple.
- abstract p0(*etas, squeeze_out=False)[source]#
0-form pressure on logical cube [0, 1]^3. Must return the components as a tuple.
- abstract gradB1(*etas, squeeze_out=False)[source]#
1-form gradient of magnetic field strength strength on logical cube [0, 1]^3. Must return the components as a tuple.
- property domain#
Domain object that characterizes the mapping from the logical to the physical domain.
- class struphy.fields_background.base.NumericalMHDequilibrium[source]#
Bases:
LogicalMHDequilibriumSpecialization for MHD equilibria with numerically computed domain mappings.
Child classes must provide a
numerical_domainproperty that returns a Domain object. This class overrides the domain property to use the numerically computed mapping.