Mesh¶
2D FEM mesh tools and solvers for basic physics on them.
This module contains classes and functions for creating and manipulating 2D meshes. Currently, we exclusively support simply connected geometries that carry current. The LondonSolver class implements the simulation of superconducting current flow in these meshes using the London equations.
For plotting functions, we refer to the Meshplotting module
- class sottools.mesh.SingleBodyMesh¶
Bases:
ABCBase class for FEM meshes that consist of a single body.
- class sottools.mesh.SimplyConnectedCurrentMesh(vertices, segments, segment_markers, max_area=0.1, min_angle=30.0, verbose=False, refine_distance=None)¶
Bases:
SingleBodyMesh2D FEM mesh for simply connected current-carrying geometries.
A 2D FEM mesh catered to simply connected (hole-free) geometries that carry current, and therefore have well-defined sources and sinks.
Pre-defines basis functions, gradients and matrices such that FEM problems and calculations can easily be set up.
- Parameters:
vertices (list[list[float]]) – List of 2D coordinates. These are the outer points of the geometry.
segments (list[list[int]]) – List of vertex index pairs defining which vertices are connected.
segment_markers (list[int]) – List of the same length as segments. Each entry defines the boundary type of that segment. The left and right sides are called .DIRICHLET_LEFT and .DIRICHLET_RIGHT. The inlet and outlet are called .NEUMANN_IN and .NEUMANN_OUT.
max_area (float) – Maximum area of a single mesh cell, enforced in the triangulation. Defaults to 0.1
min_angle (float) – Minimum angle of a single mesh cell, enforced in the triangulation. Defaults to 30.0 degrees.
verbose (bool) – If true, debug messages are printed to console. Defaults to False.
refine_distance (float or None) – If not none, the outer boundary gets subdivided until the smallest boundary segement has length refine_distance. Essential if a fine meshing at the edge, e.g. for London problems, is desired.
- class BoundaryMarker(*values)¶
Bases:
IntEnumThe various types a boundary segment can have.
- INTERIOR = 0¶
- DIRICHLET_LEFT = 1¶
- DIRICHLET_RIGHT = 2¶
- NEUMANN_IN = 3¶
- NEUMANN_OUT = 4¶
- field_curl(field)¶
Calculate the curl of a field defined on the vertices.
Represents the operation v = nabla x (f zhat), where the field f is a scalar field defined on the vertices. This is exactly how streamfunctions are related to sheet current densities in 2D.
- Parameters:
field (np.ndarray) – Field defined on the vertices of the mesh. Shape (N_v,).
- Returns:
Kx (np.ndarray) – x-component of the curl of the field, defined on the cell centers. Shape (N_t,).
Ky (np.ndarray) – y-component of the curl of the field, defined on the cell centers. Shape (N_t,).
- Return type:
- property triangles: ndarray¶
Triangulation of the mesh.
Returns a (N_t,3) array containing the vertex indices of a triangle.
- property areas: ndarray¶
Areas of the triangles in the mesh.
Returns a (N_t,) array containing the areas of the triangles.
- property centers: ndarray¶
Centers of the triangles in the mesh.
Returns a (N_t,2) array containing the coordinates of the triangle centers.
- property neighbors: ndarray¶
Neighbor relationships between triangles.
Returns a (N_t,3) array containing the triangle indices of the neighbors of a triangle.
- property boundary_vertices: ndarray¶
Vertices on the boundary of the mesh.
Returns a (N_b,2) array containing the coordinates of the boundary vertices.
- property boundary_segments: ndarray¶
Boundary segments of the mesh.
Returns a (N_s, 2) array of vertex index pairs defining boundary edges.
- property shapegradients: ndarray¶
Gradients of the basis functions.
Returns a (N_t,3,2) array containing the gradients of the P1 linear basis functions for each triangle.
- property dirichletleft_mask: ndarray¶
Mask for Dirichlet boundary conditions on the left side of the mesh.
Returns a boolean array of length N_v, where True indicates a vertex is part of the boundary.
- property dirichletright_mask: ndarray¶
Mask for Dirichlet boundary conditions on the right side of the mesh.
Returns a boolean array of length N_v, where True indicates a vertex is part of the boundary.
- property dirichlet_mask: ndarray¶
Mask for all Dirichlet boundary conditions on the mesh.
Returns a boolean array of length N_v, where True indicates a vertex is part of the boundary.
- property free_mask: ndarray¶
Mask for free vertices (not on Dirichlet boundaries) of the mesh.
Returns a boolean array of length N_v, where True indicates a vertex is part of the free vertices.
- property dirichlet_idx: ndarray¶
Indices of Dirichlet vertices (on Dirichlet boundaries) of the mesh.
- property internaledgelengths: ndarray¶
Lengths of the internal edges of the mesh.
Returns a (N_e,) array containing the lengths of the internal edges of the mesh.
- property edgedifference_operator: csr_matrix¶
Operator for the difference of a field across internal.
This csr matrix represents a matrix of shape (N_e, N_t) that calculates the difference of a field across internal edges.
- property gradient_operator_x: csr_matrix¶
Operator for the x-gradient of a field.
This csr matrix represents a matrix of shape (N_t, N_v) that calculates the x-gradient of a field defined on the vertices.
- property gradient_operator_y: csr_matrix¶
Operator for the y-gradient of a field.
This csr matrix represents a matrix of shape (N_t, N_v) that calculates the y-gradient of a field defined on the vertices.
- property stiffness_matrix: csr_matrix¶
Stiffness matrix of the mesh.
This csr matrix represents a matrix of shape (N_v, N_v) that calculates the stiffness, where the (i,j) component is the integral of the product of the gradients of the P1 basis functions i and j.
- property stiffness_matrix_solver: SuperLU¶
SuperLU solver associated with the free part of the stiffness matrix.
- property mass_matrix: csr_matrix¶
Mass matrix of the mesh.
This csr matrix represents a matrix of shape (N_v, N_v) that calculates the mass, where the (i,j) component is the integral of the product of the P1 basis functions i and j.
- class sottools.mesh.LondonSolver(mesh, Pearllength, verbose=False)¶
Bases:
objectSolver for the London equation in a simply connected geometry.
The solver iteratively solved for the streamfunction and the out-of- plane magnetic field until convergence, using dampened Picard iteration.
- Parameters:
mesh (SimplyConnectedCurrentMesh) – The mesh on which to solve the London equation.
Pearllength (float) – The Pearl length of the superconductor, in the same units as the mesh.
verbose (bool) – If true, debug messages are printed to console. Defaults to False.
- MU0¶
The magnetic permeability of free space. Default value is 10^-1*4pi, which is appropriate for units of um, uT and uA.
- Type:
- MU0 = 1.2566370614359172¶
- solve(left_bc, right_bc, max_iter=50, alpha=0.2, rtol=1e-05, diagnostic_plotter=None)¶
Solve the London equation for a given mesh and Pearl length.
- Parameters:
left_bc (float) – Dirichlet boundary condition for the streamfunction on the left side of the mesh. The difference right_bc - left_bc is the total current flowing through the mesh.
right_bc (float) – Dirichlet boundary condition for the streamfunction on the right side of the mesh. The difference right_bc - left_bc is the total current flowing through the mesh.
max_iter (int) – Maximum number of iterations for the Picard iteration. Defaults to 50.
alpha (float) – Damping factor for the Picard iteration. Defaults to 0.2.
rtol (float) – Relative tolerance for convergence of the Picard iteration. Defaults to 1e-5.
diagnostic_plotter (callable[[np.ndarray, np.ndarray, np.ndarray,)
np.ndarray] – Optional function to plot the streamfunction, out-of-plane field, and sheet current density at each iteration. The function should take four arguments: streamfunction, out-of-plane field, x-component of sheet current density, and y-component of sheet current density.
None] – Optional function to plot the streamfunction, out-of-plane field, and sheet current density at each iteration. The function should take four arguments: streamfunction, out-of-plane field, x-component of sheet current density, and y-component of sheet current density.
- Returns:
Dictionary containing the following keys
- “converged” (bool, whether the solver converged within max_iter)
- “streamfunction” (np.ndarray, the streamfunction at the vertices)
- “Bz” (np.ndarray, the out-of-plane magnetic field at the vertices)
- “Kx” (np.ndarray, the x-component of the sheet current density at the)
cell centers
- “Ky” (np.ndarray, the y-component of the sheet current density at the)
cell centers
- Return type: