Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d3c44c0
Add lumped ports with Z- and S-parameters for Maxwell
Nov 5, 2026
556dcee
Merge maxwell/3-sweep-abc into maxwell/4-lumped
Nov 5, 2026
8b163cf
Reject lumped-port sheets whose facets lie at different heights
Nov 5, 2026
23a00d7
Merge maxwell/3-sweep-abc into maxwell/4-lumped (PR workflow triggers)
Nov 6, 2026
e3527fe
Merge forge/mwsync-3-sweep-abc into maxwell/4-lumped
Nov 10, 2026
ce187f1
Merge forge/mwsync-3-sweep-abc into 4-lumped
Nov 11, 2026
eebeaee
Lumped ports: use local tetrahedron facet tables instead of non-publi…
Nov 11, 2026
4953ba2
Merge forge/mwsync-3-sweep-abc into 4-lumped
Nov 11, 2026
ca02a47
Test that a sweep keeps independent fields on a lumped-port model
Nov 11, 2026
bb91c83
Reject overlapping ports by facet nodes, not facet indices
Nov 12, 2026
2356b50
Check port facet sets exist before comparing them for overlap
Nov 12, 2026
5e60574
Merge forge/mwsync-3-sweep-abc into 4-lumped
Nov 12, 2026
b7a1470
Merge forge/mwsync-3-sweep-abc into 4-lumped
Nov 12, 2026
a822abc
Wave ports: reject zero frequency in the S-parameter normalisation
Nov 12, 2026
6359f3b
Merge forge/mwsync-3-sweep-abc into 4-lumped
Nov 12, 2026
2f1377e
Wave ports: explain the zero-frequency guard by the singular normalis…
Nov 12, 2026
a52dd7c
Docstring: s_parameters coefficients are power waves for propagating …
Nov 12, 2026
f76412f
Merge forge/mwsync-3-sweep-abc into 4-lumped
Nov 12, 2026
fc963b4
Tests: use the verified facet node table instead of a Ferrite internal
Nov 12, 2026
bbc4b31
Merge forge/mwsync-3-sweep-abc into 4-lumped
Nov 12, 2026
33a6869
Merge forge/mwsync-3-sweep-abc into 4-lumped
Nov 12, 2026
afb1e15
Port sweeps: reject zero frequency for lumped ports too
Nov 12, 2026
9ee571a
Merge forge/mwsync-3-sweep-abc into 4-lumped
Nov 12, 2026
5e138a3
Merge forge/mwsync-3-sweep-abc into 4-lumped
Nov 12, 2026
76656d9
Merge forge/mwsync-3-sweep-abc into 4-lumped
Nov 12, 2026
cd72766
Merge forge/mwsync-3-sweep-abc into 4-lumped
Nov 12, 2026
4327664
Merge forge/mwsync-3-sweep-abc into 4-lumped
Nov 12, 2026
e0a8f64
Merge forge/mwsync-3-sweep-abc into 4-lumped
Nov 12, 2026
62eee67
Merge forge/mwsync-3-sweep-abc into 4-lumped
Nov 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions docs/src/maxwell.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,31 @@ or a non-positive `mu_r` at a port is rejected, because the power-wave normalisa
impedance and the outward power of the TE10 mode is `Re(β/μr) > 0` only for positive `μr` and `εr`. Put loss behind the port, not in its face, and a
facet cannot belong to two ports or to both a port and an `absorbing` set.

## Lumped ports

A [`LumpedPort`](@ref) is a rectangular facet sheet bridging a gap between two conductors, of length `l`
along `direction` and width `w` across it, on the boundary or inside the mesh. It carries a uniform sheet
current `I/w` along `direction`; its voltage is the sheet average of the line integral of `E` across the gap,
`V = (1/w) ∮ E⋅l̂ dS`. Every port is loaded by its reference impedance `Z0`, which adds
`iωμ0 L/(w² Z0) g gᵀ` (`gᵢ = ∮ l̂⋅Nᵢ dS`) to the operator, and the driven port adds a 1 A current source in
parallel, so `Sᵢⱼ = 2Vᵢ/sqrt(Z0ᵢZ0ⱼ) - δᵢⱼ`. Because the load, the source and the voltage use the same `g`,
these circuit identities hold exactly for the discrete system: a lossless structure gives a unitary `S`.
Wave and lumped ports can share one model and one sweep; lumped ports and propagating wave ports are
normalised to power waves.

```julia
using FiniteElementMethod, Ferrite
# A parallel-plate line (PEC plates at y = 0 and y = 5 mm, open sides) with a 50 Ω port at each end.
grid = generate_grid(Tetrahedron, (2, 2, 20), Vec(0.0, 0.0, 0.0), Vec(10.0, 5.0, 20.0))
ports = [LumpedPort("bottom"; direction = (0, 1, 0)), LumpedPort("top"; direction = (0, 1, 0))]
model = MaxwellModel(grid; pec = ["front", "back"], ports, length_scale = 1.0e-3)
S = solve_sweep(model, [2π * 3.0e9]).S[:, :, 1] # S11 ≈ 0.846 + 0.136i, S21 ≈ 0.082 - 0.508i
Z = FiniteElementMethod.z_parameters(model, S)
```

The port couples all its edge dofs to each other, which widens the sparsity pattern, so keep the sheet a
few elements across.

```@docs
MaxwellModel
MaxwellMaterial
Expand All @@ -83,6 +108,11 @@ FiniteElementMethod.maxwell_rhs
FiniteElementMethod.add_term!
WavePort
FiniteElementMethod.WavePortData
LumpedPort
FiniteElementMethod.LumpedPortData
FiniteElementMethod.port_voltage
FiniteElementMethod.port_current
FiniteElementMethod.z_parameters
solve_sweep
MaxwellSweep
FiniteElementMethod.umfpack_solver
Expand Down
5 changes: 3 additions & 2 deletions src/FiniteElementMethod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using DiffEqBase: BrownFullBasicInit
using DomainSets: DomainSets
using Ferrite: Ferrite, Lagrange, RefLine, RefTriangle, RefQuadrilateral, RefTetrahedron, RefHexahedron
using ForwardDiff: ForwardDiff
using LinearAlgebra: cross, dot, lu, lu!, mul!, norm
using LinearAlgebra: Diagonal, I, cross, dot, lu, lu!, mul!, norm
using ModelingToolkit: ModelingToolkit, @parameters, @variables, Differential, MTKParameters,
ProblemTypeCtx, System, complete, getmetadata
using NonlinearSolveFirstOrder: NewtonRaphson
Expand Down Expand Up @@ -53,14 +53,15 @@ export MeshDomain, Region, boundarypiece, boundarypieces, NormalDerivative
export Weighted

# Frequency-domain Maxwell: a separate entry point assembled directly on Ferrite, not through the PDESystem front end.
include("maxwell/lumped.jl")
include("maxwell/ports.jl")
include("maxwell/model.jl")
include("maxwell/driven.jl")
include("maxwell/sweep.jl")
include("maxwell/adjoint.jl")
export MaxwellMaterial, MaxwellModel, MaxwellTerm, maxwell_operator, maxwell_operator!
export MaxwellSolution, driven_problem, solve_driven, field_values
export WavePort, MaxwellSweep, solve_sweep
export WavePort, LumpedPort, MaxwellSweep, solve_sweep
export MaxwellSensitivities, s_parameter_sensitivities, adjoint_gradient

include("precompile.jl")
Expand Down
164 changes: 164 additions & 0 deletions src/maxwell/lumped.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Lumped ports of a MaxwellModel: a uniform sheet current across a planar gap, loaded by its reference
# impedance and driven by a Norton current source.

"""
LumpedPort(facetset; direction, Z0 = 50.0)

A lumped port on the planar facet set `facetset` of a [`MaxwellModel`](@ref): a rectangular sheet of length
`l` along `direction` (in the sheet plane, from one conductor to the other) and width `w` across it,
bridging a gap. The sheet may lie on the boundary or inside the mesh; a facet listed from both of its cells
counts once.

The port carries a uniform sheet current `I / w` along `direction`, so the gap voltage is the sheet average
of the line integral of `E` along `direction`, `V = (1/w) ∮ E⋅l̂ dS` (positive when the start of `direction`
is the + terminal). Every port is loaded by its real reference impedance `Z0` (ohm) and the driven port adds a
1 A current source in parallel (see [`FiniteElementMethod.port_excitations`](@ref)). The port couples all of
its edge dofs to each other, so keep the sheet a few elements across.
"""
struct LumpedPort
facetset::String
direction::Ferrite.Vec{3, Float64}
Z0::Float64
end
function LumpedPort(facetset; direction, Z0::Real = 50.0)
Z0 > 0 || throw(ArgumentError("the reference impedance Z0 of a lumped port must be positive, got $Z0"))
return LumpedPort(String(facetset), Ferrite.Vec{3, Float64}(Tuple(direction)), float(Z0))
end

"""
LumpedPortData

A [`LumpedPort`](@ref) assembled on a [`MaxwellModel`](@ref), in `model.ports`. Fields: `port`, `profile`
(`gᵢ = ∮ l̂⋅Nᵢ dS` over the sheet, so that `V = L gᵀu / w`), `dofs` (the edge dofs of the sheet), `block`
(`g gᵀ` on the model's sparsity pattern), `normal`, `length` and `width` (`l` and `w`, mesh units).
"""
struct LumpedPortData
port::LumpedPort
profile::Vector{Float64}
dofs::Vector{Int}
block::SparseMatrixCSC{Float64, Int}
normal::Ferrite.Vec{3, Float64}
length::Float64
width::Float64
end

# The facets of a set with each geometric facet once, whichever of its two cells lists it.
function _unique_facets(grid, facets)
seen = Set{Vector{Int}}()
unique_facets = Ferrite.FacetIndex[]
for facet in facets
cell, local_facet = facet[1], facet[2]
cell_nodes = Ferrite.getcells(grid, cell).nodes
nodes = sort!([cell_nodes[i] for i in _TET_FACET_NODES[local_facet]])
nodes in seen && continue
push!(seen, nodes)
push!(unique_facets, Ferrite.FacetIndex(cell, local_facet))
end
return unique_facets
end

# Profile, dofs and geometry of a lumped port; the block needs the model's pattern, which needs the dofs.
function _lumped_port_geometry(port::LumpedPort, dh)
grid = dh.grid
_check_facetset(grid, port.facetset)
facets = _unique_facets(grid, Ferrite.getfacetset(grid, port.facetset))
isempty(facets) && throw(ArgumentError("port facet set $(repr(port.facetset)) is empty"))
fv = _facet_values()
local_dofs = _TET_FACET_EDGE_DOFS
profile = zeros(Ferrite.ndofs(dh))
normal = nothing
nodes = Ferrite.Vec{3, Float64}[]
area = 0.0
l̂ = port.direction / norm(port.direction)
for (cell, local_facet) in facets
x = Ferrite.getcoordinates(grid, cell)
Ferrite.reinit!(fv, Ferrite.getcells(grid, cell), x, local_facet)
nq = Ferrite.getnormal(fv, 1)
normal === nothing && (normal = nq)
abs(dot(nq, normal)) >= 1 - 1.0e-8 || throw(ArgumentError("port facet set $(repr(port.facetset)) is not planar"))
dofs = Ferrite.celldofs(dh, cell)
for q in 1:Ferrite.getnquadpoints(fv)
dS = Ferrite.getdetJdV(fv, q)
area += dS
# l̂ is tangential, so only the edges of this facet contribute.
for i in local_dofs[local_facet]
profile[dofs[i]] += dot(l̂, Ferrite.shape_value(fv, q, i)) * dS
end
end
append!(nodes, x[i] for i in _TET_FACET_NODES[local_facet])
end
abs(dot(l̂, normal)) <= 1.0e-8 || throw(ArgumentError("direction of port $(repr(port.facetset)) is not in the port plane"))
t̂ = cross(normal, l̂)
(s0, s1), (t0, t1) = extrema(dot(x, l̂) for x in nodes), extrema(dot(x, t̂) for x in nodes)
len, width = s1 - s0, t1 - t0
heights = [dot(x, normal) for x in nodes]
maximum(heights) - minimum(heights) <= 1.0e-8 * max(len, width) ||
throw(ArgumentError("port facet set $(repr(port.facetset)) is not planar"))
abs(area - len * width) <= 1.0e-6 * len * width ||
throw(ArgumentError("port facet set $(repr(port.facetset)) is not a rectangle with a side along direction"))
dofs = sort!(unique(Ferrite.celldofs(dh, f[1])[i] for f in facets for i in local_dofs[f[2]]))
return (; profile, dofs, normal, len, width)
end

# The cell pattern of `dh` plus every pair of edge dofs within each lumped port.
function _sparsity_pattern(dh, port_dofs)
pattern = Ferrite.allocate_matrix(dh)
isempty(port_dofs) && return pattern
rows, cols, _ = findnz(pattern)
for dofs in port_dofs, i in dofs, j in dofs
push!(rows, i)
push!(cols, j)
end
n = Ferrite.ndofs(dh)
pattern = sparse(rows, cols, ones(length(rows)), n, n)
fill!(nonzeros(pattern), 0.0)
return pattern
end

function _lumped_port(port::LumpedPort, geometry, pattern)
(; profile, dofs, normal, len, width) = geometry
block = copy(pattern)
Ferrite.assemble!(Ferrite.start_assemble(block), dofs, profile[dofs] * profile[dofs]')
return LumpedPortData(port, profile, dofs, block, normal, len, width)
end

# The sheet current I = V/Z0 = L gᵀu / (w Z0) gives +iωμ0 L / (w² Z0) g gᵀ on the operator.
function _port_term(data::LumpedPortData, mu0, eps0, L)
scale = mu0 * L / (data.width^2 * data.port.Z0)
return MaxwellTerm(data.block, ω -> im * ω * scale)
end

function _lumped(model, port::Integer)
data = model.ports[port]
data isa LumpedPortData || throw(ArgumentError("port $port of the model is not a lumped port"))
return data
end

"""
port_voltage(model::MaxwellModel, port, u)

The gap voltage `V = (1/w) ∮ E⋅l̂ dS` (volt) of lumped port number `port` of `model` in the edge-dof vector `u`.
"""
port_voltage(model, port::Integer, u::AbstractVector) =
(data = _lumped(model, port); model.length_scale * dot(data.profile, u) / data.width)

"""
port_current(model::MaxwellModel, port, u; source = 0)

The current (ampere) that lumped port number `port` delivers into the structure in the solution `u`,
`source - V / Z0`, with `source` the current of its Norton source: 1 for the driven port of a
[`solve_sweep`](@ref) column, 0 for the others.
"""
port_current(model, port::Integer, u::AbstractVector; source::Number = 0) =
source - port_voltage(model, port, u) / _lumped(model, port).port.Z0

"""
z_parameters(model::MaxwellModel, S)

The impedance matrix (ohm) `Z = G^½ (I + S)(I - S)⁻¹ G^½`, `G = diag(Z0)`, of a scattering matrix `S` of a
model whose ports are all lumped ports, inverting `Sᵢⱼ = 2 Vᵢ / sqrt(Z0ᵢ Z0ⱼ) - δᵢⱼ` for a 1 A source at port `j`.
"""
function z_parameters(model, S::AbstractMatrix)
sqrtZ0 = Diagonal([sqrt(_lumped(model, i).port.Z0) for i in eachindex(model.ports)])
return sqrtZ0 * ((I + S) / (I - S)) * sqrtZ0
end
65 changes: 34 additions & 31 deletions src/maxwell/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct MaxwellTerm
end

"""
MaxwellModel(grid; materials = Dict(), pec = String[], absorbing = String[], ports = WavePort[],
MaxwellModel(grid; materials = Dict(), pec = String[], absorbing = String[], ports = [],
length_scale = 1.0, eps0 = EPS0, mu0 = MU0, quadrature = 2)

The time-harmonic electric-field model on a Ferrite `grid` of `Tetrahedron` cells, with the field `:E` in
Expand All @@ -54,7 +54,7 @@ The time-harmonic electric-field model on a Ferrite `grid` of `Tetrahedron` cell
with `n × E = 0` on the facet sets named in `pec` and the natural condition `n × (μr⁻¹ ∇ × E) = 0` on the
rest of the boundary, except for the facet sets named in `absorbing`, which carry the first-order
Silver-Müller absorbing condition `n × (μr⁻¹ ∇ × E) = -i k0 sqrt(εc/μr) n × (n × E)` with `εc = εr - iσ/(ωε0)` (the outgoing root: for a negative real `εc/μr`, `-i sign(ω) sign(μr) sqrt(|εc/μr|)`), and the
[`WavePort`](@ref)s in `ports`.
[`WavePort`](@ref)s and [`LumpedPort`](@ref)s in `ports`, numbered in the order given.

`materials` maps cell set names of `grid` (as `FerriteGmsh.togrid` makes from Gmsh physical groups) to
[`MaxwellMaterial`](@ref)s; cells in no named set are vacuum, and a cell in two named sets is an error.
Expand All @@ -70,14 +70,16 @@ sparse blocks on one sparsity pattern, each with a complex coefficient that is a
mesh (so `Im(εr) = -ε''` gives the `+iω²μ0ε0L² ε''` loss term). The absorbing boundary adds
`+i k0 L ∮ sqrt(εc/μr) (n × Nᵢ)⋅(n × Nⱼ) dS` (`k0 = ω sqrt(μ0 ε0)`, material of the adjacent cell) and each
wave port `+i (β(ω)/μr) L p pᵀ / norm`, the rank-one term of the TE10 projection of its face (see [`WavePort`](@ref) and
[`FiniteElementMethod.WavePortData`](@ref)), whose dof pairs widen the cell-based sparsity pattern. `A` is complex
symmetric, not Hermitian.
[`FiniteElementMethod.WavePortData`](@ref)); each lumped port adds `+iω μ0 L / (w² Z0) g gᵀ` (see
[`FiniteElementMethod.LumpedPortData`](@ref)). The dof pairs of the port faces and lumped sheets widen the cell-based
sparsity pattern. `A` is complex symmetric, not Hermitian.


Fields: `grid`, `dh`, `ch` (zero `AffineConstraint`s on the PEC edge dofs), `cellvalues`, `materials` (one
per cell), `pec`, `eps0`, `mu0`, `length_scale`, `blocks` (the volume blocks `curlcurl`, `eps_real`,
`eps_imag` and `sigma` above), `absorbing`, `ports` (the [`FiniteElementMethod.WavePortData`](@ref) in the
order given) and `terms`, the [`MaxwellTerm`](@ref)s that [`maxwell_operator!`](@ref)
combines; [`FiniteElementMethod.add_term!`](@ref) appends further blocks, such as boundary terms.
`eps_imag` and `sigma` above), `absorbing`, `ports` (the [`FiniteElementMethod.WavePortData`](@ref) and
[`FiniteElementMethod.LumpedPortData`](@ref) in the order given) and `terms`, the [`MaxwellTerm`](@ref)s
that [`maxwell_operator!`](@ref) combines; [`FiniteElementMethod.add_term!`](@ref) appends further blocks, such as boundary terms.
"""
struct MaxwellModel{G, DH, CH, CV}
grid::G
Expand All @@ -92,12 +94,19 @@ struct MaxwellModel{G, DH, CH, CV}
blocks::NamedTuple{(:curlcurl, :eps_real, :eps_imag, :sigma), NTuple{4, SparseMatrixCSC{Float64, Int}}}
terms::Vector{MaxwellTerm}
absorbing::Vector{String}
ports::Vector{WavePortData}
ports::Vector{Union{WavePortData, LumpedPortData}}
end

function _facet_node_sets(grid, name)
return Set(
sort!([Ferrite.getcells(grid, cell).nodes[i] for i in _TET_FACET_NODES[local_facet]])
for (cell, local_facet) in Ferrite.getfacetset(grid, name)
)
end

function MaxwellModel(
grid::Ferrite.Grid; materials = Dict{String, MaxwellMaterial}(), pec = String[], absorbing = String[],
ports = WavePort[], length_scale::Real = 1.0, eps0::Real = EPS0, mu0::Real = MU0, quadrature::Int = 2
ports = [], length_scale::Real = 1.0, eps0::Real = EPS0, mu0::Real = MU0, quadrature::Int = 2
)
Ferrite.getcelltype(grid) === Ferrite.Tetrahedron ||
throw(ArgumentError("MaxwellModel needs a grid of Tetrahedron cells, got $(Ferrite.getcelltype(grid))"))
Expand All @@ -106,10 +115,13 @@ function MaxwellModel(
ports = collect(ports)
foreach(name -> _check_facetset(grid, name), pec)
foreach(name -> _check_facetset(grid, name), absorbing)
# Each boundary condition assembles its own term, so a facet in two of them would get both.
conditions = [[("absorbing", name) for name in absorbing]; [("wave port", port.facetset) for port in ports]]
# Each boundary condition assembles its own term, so a facet in two of them would get both. An interior facet is
# the same facet from both of its cells, so facets are compared by their nodes.
conditions = [[("absorbing", name) for name in absorbing]; [("port", port.facetset) for port in ports]]
foreach(((_, name),) -> _check_facetset(grid, name), conditions)
node_sets = Dict(name => _facet_node_sets(grid, name) for (_, name) in conditions)
for (i, (kind_i, name_i)) in pairs(conditions), (kind_j, name_j) in conditions[(i + 1):end]
isdisjoint(Ferrite.getfacetset(grid, name_i), Ferrite.getfacetset(grid, name_j)) ||
isdisjoint(node_sets[name_i], node_sets[name_j]) ||
throw(ArgumentError("facet sets $(repr(name_i)) ($kind_i) and $(repr(name_j)) ($kind_j) share facets: a facet can carry only one absorbing or wave port condition"))
end
cell_materials = _cell_materials(grid, materials)
Expand All @@ -125,7 +137,9 @@ function MaxwellModel(
Ferrite.close!(ch)
cv = Ferrite.CellValues(Ferrite.QuadratureRule{RefTetrahedron}(quadrature), ip)

pattern = _sparsity_pattern(dh, [_wave_port_dofs(port, dh) for port in ports])
lumped = Dict(i => _lumped_port_geometry(port, dh) for (i, port) in pairs(ports) if port isa LumpedPort)
wave_dofs = [_wave_port_dofs(port, dh) for port in ports if port isa WavePort]
pattern = _sparsity_pattern(dh, [[geometry.dofs for geometry in values(lumped)]; wave_dofs])
blocks = _assemble_blocks(pattern, dh, cv, cell_materials)
L2 = float(length_scale)^2
k2 = mu0 * eps0 * L2
Expand All @@ -137,8 +151,11 @@ function MaxwellModel(
]
L = float(length_scale)
isempty(absorbing) || append!(terms, _absorbing_terms(dh, blocks.curlcurl, absorbing, cell_materials, mu0, eps0, L))
port_data = WavePortData[_wave_port(port, dh, blocks.curlcurl, cell_materials, L, ch.prescribed_dofs) for port in ports]
append!(terms, [_port_term(data, mu0 * eps0, L) for data in port_data])
port_data = Union{WavePortData, LumpedPortData}[
port isa LumpedPort ? _lumped_port(port, lumped[i], pattern) :
_wave_port(port, dh, pattern, cell_materials, L, ch.prescribed_dofs) for (i, port) in pairs(ports)
]
append!(terms, [_port_term(data, mu0, eps0, L) for data in port_data])
return MaxwellModel(
grid, dh, ch, cv, cell_materials, pec, float(eps0), float(mu0), L, blocks, terms, absorbing, port_data
)
Expand Down Expand Up @@ -183,21 +200,6 @@ function _pec_dofs(dh, grid, pec)
return sort!(collect(dofs))
end

# The cell pattern of `dh` plus every pair of edge dofs within each port face: a wave port couples its whole face.
function _sparsity_pattern(dh, port_dofs)
pattern = Ferrite.allocate_matrix(dh)
isempty(port_dofs) && return pattern
rows, cols, _ = findnz(pattern)
for dofs in port_dofs, i in dofs, j in dofs
push!(rows, i)
push!(cols, j)
end
n = Ferrite.ndofs(dh)
pattern = sparse(rows, cols, ones(length(rows)), n, n)
fill!(nonzeros(pattern), 0.0)
return pattern
end

function _assemble_blocks(pattern, dh, cv, cell_materials)
mats = (curlcurl = pattern, eps_real = copy(pattern), eps_imag = copy(pattern), sigma = copy(pattern))
assemblers = map(Ferrite.start_assemble, mats)
Expand Down Expand Up @@ -233,8 +235,9 @@ _same_pattern(A, B) = A.colptr == B.colptr && rowvals(A) == rowvals(B)
add_term!(model::MaxwellModel, block, coefficient)

Append the term `coefficient(ω) * block` to the system matrix of `model`. `block` must have the sparsity
pattern of `model.blocks`, which a wave port widens beyond that of `Ferrite.allocate_matrix(model.dh)`: make it as a copy
pattern of `model.blocks`, which a port widens beyond that of `Ferrite.allocate_matrix(model.dh)`: make it as a copy
of `model.blocks.curlcurl` with its values zeroed, or with `tangential_mass` for a boundary term.

"""
function add_term!(model::MaxwellModel, block::SparseMatrixCSC{Float64, Int}, coefficient)
_same_pattern(block, model.blocks.curlcurl) ||
Expand Down
Loading
Loading