bluemira.equilibria.fem_fixed_boundary.utilities ================================================ .. py:module:: bluemira.equilibria.fem_fixed_boundary.utilities .. autoapi-nested-parse:: Module to support the fem_fixed_boundary implementation Functions --------- .. autoapisummary:: bluemira.equilibria.fem_fixed_boundary.utilities.plot_scalar_field bluemira.equilibria.fem_fixed_boundary.utilities.plot_profile bluemira.equilibria.fem_fixed_boundary.utilities.get_tricontours bluemira.equilibria.fem_fixed_boundary.utilities.find_flux_surface bluemira.equilibria.fem_fixed_boundary.utilities.get_mesh_boundary bluemira.equilibria.fem_fixed_boundary.utilities.get_flux_surfaces_from_mesh bluemira.equilibria.fem_fixed_boundary.utilities.calculate_plasma_shape_params bluemira.equilibria.fem_fixed_boundary.utilities.find_magnetic_axis bluemira.equilibria.fem_fixed_boundary.utilities._interpolate_profile bluemira.equilibria.fem_fixed_boundary.utilities.refine_mesh bluemira.equilibria.fem_fixed_boundary.utilities.create_mesh Module Contents --------------- .. py:function:: plot_scalar_field(x: numpy.ndarray, y: numpy.ndarray, data: numpy.ndarray, levels: int = 20, ax: matplotlib.pyplot.Axes | None = None, *, contour: bool = True, tofill: bool = True, **kwargs) -> tuple[matplotlib.pyplot.Axes, matplotlib.pyplot.Axes | None, matplotlib.pyplot.Axes | None] Plot a scalar field :param x: x coordinate array :param z: z coordinate array :param data: value array :param levels: Number of contour levels to plot :param axis: axis onto which to plot :param contour: Whether or not to plot contour lines :param tofill: Whether or not to plot filled contours :rtype: Matplotlib axis on which the plot ocurred .. py:function:: plot_profile(x: numpy.ndarray, prof: numpy.ndarray, var_name: str, var_unit: str, ax: matplotlib.pyplot.Axes | None = None, *, show: bool = True) Plot profile .. py:function:: get_tricontours(x: numpy.ndarray, z: numpy.ndarray, array: numpy.ndarray, value: float | collections.abc.Iterable) -> list[numpy.ndarray | None] Get the contours of a value in a triangular set of points. :param x: The x value array :param z: The z value array :param array: The value array :param value: The value of the desired contour in the array :returns: * *The points of the value contour in the array. If no contour is found* * *for a value, None is returned* .. py:function:: find_flux_surface(psi_norm_func: collections.abc.Callable[[numpy.ndarray], float], psi_norm: float, mesh: dolfinx.mesh.Mesh | None = None, n_points: int = 100) -> numpy.ndarray Find a flux surface in the psi_norm function precisely by normalised psi value. :param psi_norm_func: Function to calculate normalised psi :param psi_norm: Normalised psi value for which to find the flux surface :param mesh: Mesh object to use to estimate the flux surface If None, reasonable guesses are used. :param n_points: Number of points along the flux surface :rtype: x, z coordinates of the flux surface .. rubric:: Notes Since it is not possible anymore to extrapolate dolfinx function data outside the mesh domain, this procedure fails when psi_norm is almost 1 (i.e. points are near to the boundary). Not sure how to solve this problem. Moreover, this procedure seems to be slow now. .. py:function:: get_mesh_boundary(mesh: dolfinx.mesh.Mesh) -> tuple[numpy.ndarray, numpy.ndarray] Retrieve the boundary of the mesh, as an ordered set of coordinates. :param mesh: Mesh for which to retrieve the exterior boundary :returns: * *xbdry* -- x coordinates of the boundary * *zbdry* -- z coordinates of the boundary .. py:function:: get_flux_surfaces_from_mesh(mesh: dolfinx.mesh.Mesh, psi_norm_func: collections.abc.Callable[[float, float], float], x_1d: numpy.ndarray | None = None, nx: int | None = None, ny_fs_min: int = 40) -> tuple[numpy.ndarray, list[bluemira.equilibria.flux_surfaces.ClosedFluxSurface]] Get a list of flux surfaces from a mesh and normalised psi callable. :param mesh: Mesh for which to extract the flux surfaces :param psi_norm_func: Callable for psi_norm on the mesh :param x_1d: Array of 1-D normalised psi_values [0..1]. If None, nx will define a linearly spaced vector. :param nx: Number of points to linearly space along [0..1]. If x_1d is defined, not used. :param ny_fs_min: Minimum number of points in a flux surface retrieved from mesh. Below this, flux surfaces will be discarded. :returns: * *x_1d* -- The 1-D normalised psi_values for which flux surfaces could be retrieved. * *flux_surfaces* -- The list of closed flux surfaces :raises ValueError: nx or x_1d must be provided .. rubric:: Notes x_1d is returned, as it is not always possible to return a flux surface for small values of normalised psi. Some flux surfaces near the axis can have few points and be relatively distorted, causing convergence issues. Make sure to change the cut-off when changing the mesh discretisation. .. py:function:: calculate_plasma_shape_params(psi_norm_func: collections.abc.Callable[[numpy.ndarray], numpy.ndarray], mesh: dolfinx.mesh.Mesh, psi_norm: float, *, plot: bool = False) -> tuple[float, float, float] Calculate the plasma parameters (r_geo, kappa, delta) for a given magnetic isoflux from the mesh. :param psi_norm_func: Function to calculate normalised psi :param mesh: Mesh object to use to estimate extrema prior to optimisation :param psi_norm: Normalised psi value for which to calculate the shape parameters :param plot: Whether or not to plot :returns: * *r_geo* -- Geometric major radius of the flux surface at psi_norm * *kappa* -- Elongation of the flux surface at psi_norm * *delta* -- Triangularity of the flux surface at psi_norm .. py:function:: find_magnetic_axis(psi_func: collections.abc.Callable[[numpy.ndarray], float], mesh: dolfinx.mesh.Mesh | None = None) -> numpy.ndarray Find the magnetic axis in the poloidal flux map. :param psi_func: Function to return psi at a given point :param mesh: Mesh object to use to estimate magnetic axis prior to optimisation If None, a reasonable guess is made. :rtype: Position vector (2) of the magnetic axis [m] .. py:function:: _interpolate_profile(x: numpy.ndarray, profile_data: numpy.ndarray) -> collections.abc.Callable[[numpy.ndarray], numpy.ndarray] Interpolate profile data .. py:function:: refine_mesh(mesh: dolfinx.mesh.Mesh, refine_point: collections.abc.Iterable[float], distance: float, num_levels: int = 1) -> dolfinx.mesh.Mesh Refine the mesh around a reference point. :param mesh: Mesh to refine :param refine_point: Point at which to refine the mesh :param distance: Refinement distance from the point :param num_levels: Number of refinement levels :returns: Refined mesh .. py:function:: create_mesh(plasma: bluemira.base.components.PhysicalComponent, directory: str | os.PathLike, mesh_name_msh: str, gdim: int | tuple = (0, 2), comm=MPI.COMM_WORLD, rank: int = 0) -> dolfinx.mesh.Mesh Create mesh :returns: Mesh object