patchwork.solvers.curl_curl
The curl–curl operator on the edge space of a 2D or 3D hierarchy.
CurlCurl solves
for a vector potential (or an electric field) on the edges of the leaf cells:
the magnetoquasistatic field of a current (beta = 0, or beta = i omega sigma in a conductor), or a time step of an implicit Maxwell solver. The
discrete operator is assembled from the spaces of patchwork.spaces,
with the curl C from the edges to the faces (in 2D to the leaf cells), the
face mass M2 weighted by nu and the edge mass M1 by beta, both
lumped (the finite-integration / Yee scheme) or consistent (Nédélec elements),
and the hanging edges eliminated by their constraints T1. Faces of the
domain are "electric" (tangential A zero, a perfect conductor) or
"magnetic" (the natural condition, tangential nu curl A zero);
periodic axes take none. C G = 0 holds exactly, so the gradients are the
null space of the curl term: without beta the operator is singular, and
either a small gauge term (a weak Coulomb gauge) or hypre’s AMS, which
solves the singular system for a divergence-free current, makes it solvable.
Material models the leaf-cell coefficients cannot express (cut cells, surface
impedances, conductances per edge) enter through face_mass (in place of
M2(nu)), edge_mass (an extra edge term) and fixed (more edges held
at zero, e.g. inside a perfect conductor); they may be complex, for the LU.
Attributes
| Name | Description |
|---|---|
CONDITIONS | No description. |
Coefficient | No description. |
Operator | No description. |
SOLVERS | No description. |
Classes
Functions
| Name | Description |
|---|---|
has_ams | Whether petsc4py is installed with hypre (for solver="ams"). |
CONDITIONSattributemodule attribute#
CONDITIONS = ('electric', 'magnetic')Coefficientattributemodule attribute#
Coefficient = float | complex | np.ndarray | Callable[..., Any]Operatorattributemodule attribute#
Operator = np.ndarray | sparse.spmatrix | sparse.sparraySOLVERSattributemodule attribute#
SOLVERS = ('lu', 'ams', 'auto')AmsSolverclass#
class AmsSolver(matrix: sparse.csr_matrix, gradient: sparse.csr_matrix, constants: list[np.ndarray], comm: Any, *, singular: bool, rtol: float = 1e-10, options: Mapping[str, Any] | None = None)A real symmetric edge system solved with conjugate gradients and hypre’s AMS.
matrix is the whole system on every rank; the rows are split evenly
over the ranks of comm for PETSc. gradient maps the interior nodes
to the unknown edges (AMS’s discrete gradient) and constants are the
edge values of the uniform fields along each axis. With singular (no
beta term) AMS solves the curl–curl alone, for a right-hand side
orthogonal to the gradients.
Attributes
| Name | Description |
|---|---|
iterations | The conjugate gradient iterations of the last solve. |
commattributeinstance attribute#
comm = petsc_comm(comm)iterationsattributeinstance attribute#
iterations = 0kspattributeinstance attribute#
ksp = kspmatrixattributeinstance attribute#
matrix = aij(matrix[lo:hi], (n, n), local)solvemethod#
def solve(right_hand_side: np.ndarray) -> np.ndarraySolve; the solution on every rank. Collective.
CurlCurlclass#
class CurlCurl(hierarchy: AMRHierarchy, *, reluctivity: Coefficient = 1.0, beta: Coefficient = 0.0, faces: Mapping[str, str] | None = None, mass: str = 'lumped', gauge: float = 0.0, solver: str = 'lu', edges: CompositeEdges | None = None, rtol: float = 1e-10, options: Mapping[str, Any] | None = None, face_mass: Operator | None = None, edge_mass: Operator | None = None, fixed: np.ndarray | None = None)Solve on the edges.
reluctivity (nu) and beta are coefficients on the leaf cells:
numbers, arrays over the leaf cells or functions of the cell centres
(beta may be complex with the LU). faces maps the faces of the
box ("x_lower", …) to "electric" (the default) or
"magnetic". mass is "lumped" (finite integration, the
staggered Yee scheme) or "consistent" (lowest-order Nédélec elements).
gauge adds gauge * M1(nu / h**2), a weak Coulomb gauge that makes
the operator nonsingular without beta; it shifts the solution by
O(gauge). solver is "lu" (SuperLU, every rank),
"ams" (PETSc’s conjugate gradients with hypre’s AMS, rows split over
the ranks; real coefficients) or "auto" (AMS where it applies, else
the LU).
face_mass replaces the face mass M2(nu) (in 2D the per-cell
nu / area) by a matrix, or its diagonal as an array, on all faces
(hanging ones included): the reluctance of cut faces, a surface
impedance. edge_mass, likewise on all edges, is added to the
operator: conductances per edge, e.g. sampled below the cell size.
fixed marks more edges to hold at zero, e.g. those inside a
perfect or a surface-impedance conductor. face_mass and
edge_mass may be complex (with the LU).
Attributes
| Name | Description |
|---|---|
edges | The CompositeEdges. |
faces | The CompositeFaces. |
free | Edge numbers of the unknowns: neither hanging nor on an electric face. |
fixed | Whether an edge lies on an electric face. |
matrix | The operator on the unknowns. |
solver | "lu" or "ams", as chosen. |
iterations | The AMS iterations of the last solve (0 with the LU). |
Numerics
problem
operator
materials
load
null space
Assumptions:
- the domain fills its box; electric faces fix the tangential edges on them to zero
- =
gauge: a weak Coulomb gauge, needed by the LU when - AMS (hypre) for real coefficients; the LU also for complex
face_massandedge_masson all faces and edges (hanging ones included), e.g. cut cells or surface impedances; real for AMS
References:
- Hiptmair and Xu, SIAM J. Numer. Anal. 45, 2483 (2007): the auxiliary space preconditioner
- Kolev and Vassilevski, J. Comput. Math. 27, 604 (2009): AMS
- Weiland, AEÜ 31, 116 (1977): finite integration
Built from:
patchwork.spaces.faces.CompositeFacespatchwork.spaces.edges.CompositeEdges.mass
conditionsattributeinstance attribute#
conditions = {face: faces or {}.get(face, 'electric') for face in known}curlattributeinstance attribute#
curl = curledgesattributeinstance attribute#
edges = CompositeEdges(CompositeNodes(hierarchy)) if edges is None else edgesfacesattributeinstance attribute#
faces = CompositeFaces(self.edges)fixedattributeinstance attribute#
fixed = self._fixed_edges()freeattributeinstance attribute#
free = np.nonzero(~self.fixed & ~edges.hanging)[0]iterationsattributeinstance attribute#
iterations = 0massattributeinstance attribute#
mass = massmatrixattributeinstance attribute#
matrix = full[self.free][:, self.free].tocsr()nodesattributeinstance attribute#
nodes = self.edges.nodessolverattributeinstance attribute#
solver = solverfluxmethod#
def flux(potential: np.ndarray) -> np.ndarrayThe curl of an edge field: fluxes through the faces (3D) or per leaf cell (2D).
loadmethod#
def load(current: np.ndarray) -> np.ndarrayThe load M1 j of a current with edge values j (line integrals of J).
solvemethod#
def solve(load: np.ndarray) -> np.ndarrayThe potential on all edges for a load (n1,); hanging edges filled.
load is the current integrated against the edge functions,
integral of J . w_e: what CompositeEdges.deposit and
CompositeEdges.deposit_paths give for markers, or load of edge
values of J.