bluemira.equilibria.fem_fixed_boundary.utilities

Module to support the fem_fixed_boundary implementation

Functions

plot_scalar_field(→ tuple[matplotlib.pyplot.Axes, ...)

Plot a scalar field

plot_profile(x, prof, var_name, var_unit[, ax, show])

Plot profile

get_tricontours(→ list[numpy.ndarray | None])

Get the contours of a value in a triangular set of points.

find_flux_surface(→ numpy.ndarray)

Find a flux surface in the psi_norm function precisely by normalised psi value.

get_mesh_boundary(→ tuple[numpy.ndarray, numpy.ndarray])

Retrieve the boundary of the mesh, as an ordered set of coordinates.

get_flux_surfaces_from_mesh(→ tuple[numpy.ndarray, ...)

Get a list of flux surfaces from a mesh and normalised psi callable.

calculate_plasma_shape_params(→ tuple[float, float, float])

Calculate the plasma parameters (r_geo, kappa, delta) for a given magnetic

find_magnetic_axis(→ numpy.ndarray)

Find the magnetic axis in the poloidal flux map.

_interpolate_profile(...)

Interpolate profile data

refine_mesh(→ dolfinx.mesh.Mesh)

Refine the mesh around a reference point.

create_mesh([comm])

Create mesh

Module Contents

bluemira.equilibria.fem_fixed_boundary.utilities.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

Parameters:
  • x (numpy.ndarray) – x coordinate array

  • z – z coordinate array

  • data (numpy.ndarray) – value array

  • levels (int) – Number of contour levels to plot

  • axis – axis onto which to plot

  • contour (bool) – Whether or not to plot contour lines

  • tofill (bool) – Whether or not to plot filled contours

  • y (numpy.ndarray)

  • ax (matplotlib.pyplot.Axes | None)

Return type:

Matplotlib axis on which the plot ocurred

bluemira.equilibria.fem_fixed_boundary.utilities.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

Parameters:
  • x (numpy.ndarray)

  • prof (numpy.ndarray)

  • var_name (str)

  • var_unit (str)

  • ax (matplotlib.pyplot.Axes | None)

  • show (bool)

bluemira.equilibria.fem_fixed_boundary.utilities.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.

Parameters:
  • x (numpy.ndarray) – The x value array

  • z (numpy.ndarray) – The z value array

  • array (numpy.ndarray) – The value array

  • value (float | collections.abc.Iterable) – 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

Return type:

list[numpy.ndarray | None]

bluemira.equilibria.fem_fixed_boundary.utilities.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.

Parameters:
  • psi_norm_func (collections.abc.Callable[[numpy.ndarray], float]) – Function to calculate normalised psi

  • psi_norm (float) – Normalised psi value for which to find the flux surface

  • mesh (dolfinx.mesh.Mesh | None) – Mesh object to use to estimate the flux surface If None, reasonable guesses are used.

  • n_points (int) – Number of points along the flux surface

Return type:

x, z coordinates of the flux surface

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.

bluemira.equilibria.fem_fixed_boundary.utilities.get_mesh_boundary(mesh: dolfinx.mesh.Mesh) tuple[numpy.ndarray, numpy.ndarray]

Retrieve the boundary of the mesh, as an ordered set of coordinates.

Parameters:

mesh (dolfinx.mesh.Mesh) – Mesh for which to retrieve the exterior boundary

Returns:

  • xbdry – x coordinates of the boundary

  • zbdry – z coordinates of the boundary

Return type:

tuple[numpy.ndarray, numpy.ndarray]

bluemira.equilibria.fem_fixed_boundary.utilities.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.

Parameters:
  • mesh (dolfinx.mesh.Mesh) – Mesh for which to extract the flux surfaces

  • psi_norm_func (collections.abc.Callable[[float, float], float]) – Callable for psi_norm on the mesh

  • x_1d (numpy.ndarray | None) – Array of 1-D normalised psi_values [0..1]. If None, nx will define a linearly spaced vector.

  • nx (int | None) – Number of points to linearly space along [0..1]. If x_1d is defined, not used.

  • ny_fs_min (int) – 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

Return type:

tuple[numpy.ndarray, list[bluemira.equilibria.flux_surfaces.ClosedFluxSurface]]

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.

bluemira.equilibria.fem_fixed_boundary.utilities.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.

Parameters:
  • psi_norm_func (collections.abc.Callable[[numpy.ndarray], numpy.ndarray]) – Function to calculate normalised psi

  • mesh (dolfinx.mesh.Mesh) – Mesh object to use to estimate extrema prior to optimisation

  • psi_norm (float) – Normalised psi value for which to calculate the shape parameters

  • plot (bool) – 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

Return type:

tuple[float, float, float]

bluemira.equilibria.fem_fixed_boundary.utilities.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.

Parameters:
  • psi_func (collections.abc.Callable[[numpy.ndarray], float]) – Function to return psi at a given point

  • mesh (dolfinx.mesh.Mesh | None) – Mesh object to use to estimate magnetic axis prior to optimisation If None, a reasonable guess is made.

Return type:

Position vector (2) of the magnetic axis [m]

bluemira.equilibria.fem_fixed_boundary.utilities._interpolate_profile(x: numpy.ndarray, profile_data: numpy.ndarray) collections.abc.Callable[[numpy.ndarray], numpy.ndarray]

Interpolate profile data

Parameters:
  • x (numpy.ndarray)

  • profile_data (numpy.ndarray)

Return type:

collections.abc.Callable[[numpy.ndarray], numpy.ndarray]

bluemira.equilibria.fem_fixed_boundary.utilities.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.

Parameters:
  • mesh (dolfinx.mesh.Mesh) – Mesh to refine

  • refine_point (collections.abc.Iterable[float]) – Point at which to refine the mesh

  • distance (float) – Refinement distance from the point

  • num_levels (int) – Number of refinement levels

Returns:

Refined mesh

Return type:

dolfinx.mesh.Mesh

bluemira.equilibria.fem_fixed_boundary.utilities.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

Parameters:
Return type:

dolfinx.mesh.Mesh