Skip to content
Projects

patchwork.solvers.curl_curl

The curl–curl operator on the edge space of a 2D or 3D hierarchy.

CurlCurl solves

∇×(ν ∇×A)+β A=J\nabla\times(\nu\,\nabla\times\mathbf{A}) + \beta\,\mathbf{A} = \mathbf{J}

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,

K=T1⊤(C⊤M2(ν) C+M1(β))T1,K = T_1^\top\big(C^\top M_2(\nu)\, C + M_1(\beta)\big) T_1,

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

NameDescription
CONDITIONSNo description.
CoefficientNo description.
OperatorNo description.
SOLVERSNo description.

Classes

NameDescription
AmsSolverA real symmetric edge system solved with conjugate gradients and hypre's AMS.
CurlCurlSolve $\nabla\times(\nu\nabla\times\mathbf{A}) + \beta\mathbf{A} = \mathbf{J}$ on the edges.

Functions

NameDescription
has_amsWhether 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.sparray

SOLVERSattributemodule 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

NameDescription
iterationsThe conjugate gradient iterations of the last solve.

commattributeinstance attribute#

comm = petsc_comm(comm)

iterationsattributeinstance attribute#

iterations = 0

kspattributeinstance attribute#

ksp = ksp

matrixattributeinstance attribute#

matrix = aij(matrix[lo:hi], (n, n), local)

solvemethod#

def solve(right_hand_side: np.ndarray) -> np.ndarray

Solve; 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 ∇×(ν∇×A)+βA=J\nabla\times(\nu\nabla\times\mathbf{A}) + \beta\mathbf{A} = \mathbf{J} 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

NameDescription
edgesThe CompositeEdges.
facesThe CompositeFaces.
freeEdge numbers of the unknowns: neither hanging nor on an electric face.
fixedWhether an edge lies on an electric face.
matrixThe operator on the unknowns.
solver"lu" or "ams", as chosen.
iterationsThe AMS iterations of the last solve (0 with the LU).

Numerics

problem

∇×(ν ∇×A)+β A=J,A×n=0 (electric faces)\nabla\times(\nu\,\nabla\times\mathbf{A}) + \beta\,\mathbf{A} = \mathbf{J}, \qquad \mathbf{A}\times\mathbf{n} = 0 \ \text{(electric faces)}

operator

K=T1⊤(C⊤M2(ν) C+M1(β)+ϵ M1(ν/h2)+Me) T1K = T_1^\top\big(C^\top M_2(\nu)\,C + M_1(\beta) + \epsilon\, M_1(\nu / h^2) + M_e\big)\,T_1

materials

M2(ν)→M2′ (face_mass),Me (edge_mass),ek=0 (fixed)M_2(\nu) \to M_2' \ (\texttt{face\_mass}), \qquad M_e \ (\texttt{edge\_mass}), \qquad e_k = 0 \ (\texttt{fixed})

load

b=T1⊤ℓ,ℓe=∫J⋅we dV(ℓ=M1j for edge values j of J)b = T_1^\top \ell, \qquad \ell_e = \int \mathbf{J}\cdot\mathbf{w}_e\, dV \quad (\ell = M_1 j \text{ for edge values } j \text{ of } \mathbf{J})

null space

C G=0:K Gr=β-term onlyC\,G = 0: \quad K\,G_r = \beta\text{-term only}

Assumptions:

  • the domain fills its box; electric faces fix the tangential edges on them to zero
  • ϵ\epsilon = gauge: a weak Coulomb gauge, needed by the LU when β=0\beta = 0
  • AMS (hypre) for real coefficients; the LU also for complex β=iωσ\beta = i\omega\sigma
  • face_mass and edge_mass on all faces and edges (hanging ones included), e.g. cut cells or surface impedances; real for AMS

References:

Built from:

  • patchwork.spaces.faces.CompositeFaces
  • patchwork.spaces.edges.CompositeEdges.mass

conditionsattributeinstance attribute#

conditions = {face: faces or {}.get(face, 'electric') for face in known}

curlattributeinstance attribute#

curl = curl

edgesattributeinstance attribute#

edges = CompositeEdges(CompositeNodes(hierarchy)) if edges is None else edges

facesattributeinstance attribute#

faces = CompositeFaces(self.edges)

fixedattributeinstance attribute#

fixed = self._fixed_edges()

freeattributeinstance attribute#

free = np.nonzero(~self.fixed & ~edges.hanging)[0]

iterationsattributeinstance attribute#

iterations = 0

massattributeinstance attribute#

mass = mass

matrixattributeinstance attribute#

matrix = full[self.free][:, self.free].tocsr()

nodesattributeinstance attribute#

nodes = self.edges.nodes

solverattributeinstance attribute#

solver = solver

fluxmethod#

def flux(potential: np.ndarray) -> np.ndarray

The curl of an edge field: fluxes through the faces (3D) or per leaf cell (2D).

loadmethod#

def load(current: np.ndarray) -> np.ndarray

The load M1 j of a current with edge values j (line integrals of J).

solvemethod#

def solve(load: np.ndarray) -> np.ndarray

The 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.

has_amsfunction#

def has_ams() -> bool

Whether petsc4py is installed with hypre (for solver="ams").