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