bluemira.equilibria.fem_fixed_boundary.fem_magnetostatic_2D
Bluemira module for the solution of a 2D magnetostatic problem with cylindrical symmetry and toroidal current source using fenics FEM solver
Classes
Simple minimal dataclass for a fixed boundary equilibrium. |
|
A 2D fem Grad Shafranov solver. The solver is thought as support for the fem fixed |
Functions
|
|
|
Module Contents
- class bluemira.equilibria.fem_fixed_boundary.fem_magnetostatic_2D.FixedBoundaryEquilibrium
Simple minimal dataclass for a fixed boundary equilibrium.
- mesh: dolfinx.mesh.Mesh
- psi: collections.abc.Callable[[numpy.typing.ArrayLike], float | numpy.typing.NDArray[numpy.float64]]
- p_prime: numpy.ndarray
- ff_prime: numpy.ndarray
- R_0: float
- B_0: float
- I_p: float
- plot(ax=None, *, show: bool = False, show_mesh: bool = False) matplotlib.pyplot.Axes
Plot the fixed boundary FE equilibrium.
- Parameters:
ax – The matplotlib axes object to plot on. If None, a new one is created.
show_mesh (bool) – Whether or not to show the mesh on the plot.
show (bool)
- Returns:
The matplotlib axes object
- Return type:
ax
- class bluemira.equilibria.fem_fixed_boundary.fem_magnetostatic_2D.FemGradShafranovFixedBoundary(p_prime: collections.abc.Callable[[float], float] | None = None, ff_prime: collections.abc.Callable[[float], float] | None = None, mesh: dolfinx.mesh.Mesh | str | None = None, I_p: float | None = None, R_0: float | None = None, B_0: float | None = None, p_order: int = 2, maxiter: int = 10, iter_err_max: float = 1e-05, relaxation: float = 0.0)
Bases:
bluemira.magnetostatics.finite_element_2d.FemMagnetostatic2dA 2D fem Grad Shafranov solver. The solver is thought as support for the fem fixed boundary module.
- Parameters:
p_prime (collections.abc.Callable[[float], float] | None) – p’ flux function. If callable, then used directly (50 points saved in file). If None, these must be specified later on, but before the solve.
ff_prime (collections.abc.Callable[[float], float] | None) – FF’ flux function. If callable, then used directly (50 points saved in file). If None, these must be specified later on, but before the solve.
mesh (dolfinx.mesh.Mesh | str | None) – Mesh to use when solving the problem. If None, must be specified later on, but before the solve.
I_p (float | None) – Plasma current [A]. If None, the plasma current is calculated, otherwise the source term is scaled to match the plasma current.
B_0 (float | None) – Toroidal field at R_0 [T]. Used when saving to file.
R_0 (float | None) – Major radius [m]. Used when saving to file.
p_order (int) – Order of the approximating polynomial basis functions
maxiter (int) – Maximum number of iterations
iter_err_max (float) – Convergence criterion value
relaxation (float) – Relaxation factor for the Picard iteration procedure
- _g_func = None
- _psi_ax = None
- _psi_b = None
- _grad_psi = None
- _pprime = None
- _ffprime = None
- _mesh_area = None
- _curr_target = None
- _R_0 = None
- _B_0 = None
- iter_err_max = 1e-05
- maxiter = 10
- relaxation = 0.0
- k = 1
- property psi_ax: float
Poloidal flux on the magnetic axis
- Return type:
float
- property psi_b: float
Poloidal flux on the boundary
- Return type:
float
- grad_psi(point: numpy.ndarray) numpy.ndarray
Calculate the gradients of psi at a point
- Parameters:
point (numpy.ndarray)
- Return type:
numpy.ndarray
- property psi_norm_2d: collections.abc.Callable[[numpy.ndarray], numpy.ndarray]
Normalised flux function in 2-D
- Return type:
collections.abc.Callable[[numpy.ndarray], numpy.ndarray]
- set_mesh(mesh: dolfinx.mesh.Mesh | str)
Set the mesh for the solver
- Parameters:
mesh (dolfinx.mesh.Mesh | str) – Filename of the xml file with the mesh definition or a dolfin mesh
- _create_g_func(pprime: collections.abc.Callable[[numpy.typing.ArrayLike], float | numpy.typing.NDArray[numpy.float64]] | float, ffprime: collections.abc.Callable[[numpy.typing.ArrayLike], float | numpy.typing.NDArray[numpy.float64]] | float, curr_target: float | None = None) collections.abc.Callable[[numpy.ndarray], float]
Return the density current function given pprime and ffprime.
- Parameters:
pprime (collections.abc.Callable[[numpy.typing.ArrayLike], float | numpy.typing.NDArray[numpy.float64]] | float) – pprime as function of psi_norm (1-D function)
ffprime (collections.abc.Callable[[numpy.typing.ArrayLike], float | numpy.typing.NDArray[numpy.float64]] | float) – ffprime as function of psi_norm (1-D function)
curr_target (float | None) – Target current (also used to initialise the solution in case self.psi is still 0 and pprime and ffprime are, then, not defined) [A]
- Return type:
Source current callable to solve the magnetostatic problem
- define_g()
Return the density current DOLFIN function given pprime and ffprime.
- set_profiles(p_prime: collections.abc.Callable[[float], float], ff_prime: collections.abc.Callable[[float], float], I_p: float | None = None, B_0: float | None = None, R_0: float | None = None)
Set the profies for the FEM G-S solver.
- Parameters:
p_prime (collections.abc.Callable[[float], float]) – pprime as function of psi_norm (1-D function)
ff_prime (collections.abc.Callable[[float], float]) – ffprime as function of psi_norm (1-D function)
I_p (float | None) – Target current (also used to initialise the solution in case self.psi is still 0 and pprime and ffprime are, then, not defined). If None, plasma current is calculated and not constrained
B_0 (float | None) – Toroidal field at R_0 [T]. Used when saving to file.
R_0 (float | None) – Major radius [m]. Used when saving to file.
- Raises:
TypeError – p_prime and ff_prime must be functions
- _calculate_curr_tot() float
Calculate the total current into the domain
- Return type:
float
- _update_curr()
- _reset_psi_cache()
Reset cached psi-axis and psi-boundary properties.
- _check_all_inputs_ready_error()
- solve(*, plot: bool = False, debug: bool = False, gif: bool = False, figname: str | None = None, autoclose_plot: bool = True) FixedBoundaryEquilibrium
Solve the G-S problem.
- Parameters:
plot (bool) – Whether or not to plot
debug (bool) – Whether or not to display debug information
gif (bool) – Whether or not to produce a GIF
figname (str | None) – The name of the figure. If None, a suitable default is used.
autoclose_plot (bool)
- Return type:
FixedBoundaryEquilibrium object corresponding to the solve
- _equilibrium()
- Returns:
Equilibrium data object
- static _setup_plot(*, debug: bool) tuple[matplotlib.figure.Figure, numpy.ndarray, list]
- Parameters:
debug (bool)
- Return type:
tuple[matplotlib.figure.Figure, numpy.ndarray, list]
- _plot_current_iteration(ax, cax, i_iter: int, points: collections.abc.Iterable, prev: numpy.ndarray, diff: numpy.ndarray, *, debug: bool = False)
- Parameters:
i_iter (int)
points (collections.abc.Iterable)
prev (numpy.ndarray)
diff (numpy.ndarray)
debug (bool)
- bluemira.equilibria.fem_fixed_boundary.fem_magnetostatic_2D._plot_array(ax, points: numpy.ndarray, array: numpy.ndarray, title: str, cmap: str, levels: numpy.ndarray | None = None)
- Parameters:
points (numpy.ndarray)
array (numpy.ndarray)
title (str)
cmap (str)
levels (numpy.ndarray | None)
- bluemira.equilibria.fem_fixed_boundary.fem_magnetostatic_2D._add_colorbar(cm, cax, title)