Solver¶
The solver layer holds the numerics: the Engine (configuration and
solve), the FieldResult (potentials, currents, impedances,
metadata) and the multi-port functions solve_mutual_matrix /
solve_mutual_field. The backends themselves are registered in the
backend registry; their theory is on the
engine pages.
Mathematical and physical context¶
Every backend solves the same problem — the quasi-static potential of
the electrodes in layered soil, coupled to the conductor network — for
each frequency of Engine.frequencies. The electrodes are cut into \(N\)
segments (length at most segment_length) carrying leakage currents
\(I_k\); the potential of segment \(i\) is
with \(G_{ik}\) the potential at segment \(i\) per unit current on segment \(k\) (the Green's function of the layered half-space integrated over the segments). The galvanic clusters are equipotential, the conductor branches add Kirchhoff's laws, and the source currents are the right-hand side of the augmented system. The backends differ in how they evaluate \(G\) and which current ansatz they use:
| Backend | Green's function | Current ansatz |
|---|---|---|
image |
free space + surface image, closed form | uniform current per unit length on each straight wire of an electrode (one unknown per wire line of a grid, arm of a star, straight run of a polyline, and soil layer; user decision Q30); exact line-source kernel by default |
image_2layer |
Tagg/Sunde image series, closed form; layered Sommerfeld correction for wires through the interface | as image |
mom |
the same closed-form kernels | point matching: one unknown current per segment, midpoint point sources |
mom_sommerfeld |
numerical Sommerfeld quadrature of the layered Green's function, any number of layers | as mom |
fem (experimental) |
none: conforming finite elements of the soil, axisymmetric for coaxial rods and rings, three-dimensional otherwise (fem3d extra) |
volume solution (axisymmetric: the electrodes as solid bodies; 3-D: smoothed line sources) |
The uniform-current ansatz gives accurate impedances at low cost; near grids, stars, strip ends and bonded multi-electrode clusters its surface potentials are impedance-grade, not field-grade (see Known limitations).
Engine(backend="image"), the default, forwards a TwoLayerSoil to
image_2layer and a MultiLayerSoil with at most two distinct layers
to the image dispatcher; three or more layers need mom_sommerfeld.
FieldResult.metadata["effective_backend"] and ["kernel"] record
what ran.
Engine settings¶
| Field | Default | Meaning |
|---|---|---|
backend |
"image" |
registered backend name (see registry) |
frequencies |
[50.0] |
Hz; the given order is kept (a non-monotonic list warns with EngineFrequencyOrderWarning, with_frequencies(..., preserve_order=True) silences it) |
segment_length |
0.5 |
maximum segment length in m |
kernel |
None |
None: the backend's preferred kernel ("line" for the image family); "line" or "point" explicitly; "point" reproduces the numbers of releases up to 0.15.0 |
earth_inductive_model |
"sommerfeld" |
earth return of inductive conductors: "sommerfeld", "carson_series", "perfect_mirror" (see Coupling) |
sommerfeld_assembly |
"tabulated" |
assembly of the Sommerfeld correction of inductive conductors: "tabulated" (one table of the spectral integral per pair of depth groups and frequency; default since 2026.11) or "exact" (one quadrature per segment pair, the default up to 0.15.0) |
max_segments |
None |
resource limit of this engine: the largest number of leakage segments and of nodal unknowns it solves, ResourceLimitError above it before anything is allocated; None takes groundfield.diagnostics.HARD_LIMIT (20 000); recorded in metadata["max_segments"] |
warn_segments |
None |
size of the soft notice of this engine, counted like max_segments: at or above it the solve warns that it may take minutes (an info finding of diagnose); None takes groundfield.diagnostics.SOFT_LIMIT (5 000); not checked against max_segments (a notice above the hard limit never appears) |
image_max_terms, image_series_tol |
300, 10⁻⁶ | cap and stop tolerance of the Tagg/Sunde series (tail bound \(\lvert K\rvert^{n+1}/(1-\lvert K\rvert)\)) |
image_far_field |
"quadrupole" |
form of the far images of the line kernel in two-layer soil (Tagg/Sunde images and images of the cross-layer correction): "quadrupole" (point value plus the quadrupole term of the segment average) or "point" (point sources beyond the near-pair reach: the dense far term is left out, the near image pairs stay Galerkin integrals on both paths, audit W3R2A-01; faster; networks move by 3 · 10⁻⁶ … 4.3 · 10⁻⁴, not the result before wave 3 of the 2026.11 work); any other value raises ValueError; recorded in metadata["series"], used by FieldResult.potential and solve_mutual_*; no effect with kernel="point" or in homogeneous soil (the author's decision of 2026-11-15) |
options |
{} |
backend-specific settings, e.g. {"mom_sommerfeld": {"epsrel": 1e-9}} (see the backend pages for the options of each backend) |
tolerance and max_iterations have no effect and are deprecated
(see Deprecations).
Example¶
import groundfield as gf
world = gf.create_world(soil=gf.TwoLayerSoil(rho_1=100.0, rho_2=300.0, h_1=2.0))
gf.create_electrode(world, "rod", name="a", position=(0.0, 0.0, 0.0), length=3.0)
gf.create_electrode(world, "ring", name="b", center=(20.0, 0.0, 0.8), radius=2.0)
engine = gf.create_engine(frequencies=[50.0])
# Mutual grounding-impedance matrix of the two earths in one assembly:
# Z[i, j] = potential of cluster i per ampere leaking from cluster j.
Z = gf.solve_mutual_matrix(world, engine, anchors=["a", "b"]) # Ω
# The same entries from an ordinary solve with 1 A at "a":
gf.create_source(world, attached_to="a", magnitude=1.0)
result = engine.solve(world)
assert abs(Z[0, 0] - result.cluster_impedance("a")[0]) < 1e-9 # 51.40 Ω
assert abs(Z[1, 0] - result.electrode_potentials["b"][0]) < 1e-9 # 2.26 Ω
assert result.metadata["effective_backend"] == "image_2layer"
solve_mutual_matrix returns the galerkin off-diagonal (the reaction of
the leakage distributions: reciprocal, and the matrix that reproduces a
solve of the clusters joined by branches) for every call since 2026.11.
offdiag="probe" with probe_points samples the potential at one point
per cluster instead, the definition up to 0.15.0; probe points passed
without it are ignored with a ProbePointsIgnoredWarning.
FieldResult.potential(points, frequency_index=0) evaluates the
potential in V at arbitrary points of shape (M, 3) (homogeneous and
two-layer soil), to_dataframe() returns the per-electrode table,
to_dataframe("sources") the per-source table (impressed or solved
current, the voltage and internal impedance of a voltage source, the
input impedance), and metadata["provenance"] records the package
and library versions, the engine configuration, a fingerprint of the
world and the solve time stamp. Results are saved and loaded with
save_result / load_result.
API reference¶
engine ¶
Numerical computation core (Engine).
An Engine bundles everything that is purely numerical: the
chosen backend (image, MoM, FEM, ...), the frequency list, the
discretisation and the backend settings. It is deliberately separated
from the World, so that the same physical configuration can be run
against different backends.
Backends are registered in groundfield.solver.registry, which
records for each name the solve function, the declared capabilities
(soil layer counts, conductor models, concrete shells, two-terminal
sources, source kernels) and the backend-specific options model. The
built-in backends fall into three families:
Closed-form / image-charge.
image is the homogeneous-soil image-charge sum (closed form,
uniform current per unit length, cheapest backend). image_2layer
implements the Tagg / Sunde geometric series for two-layer soil with
convergence \(|K|^n\). Both use the exact line-source kernel by default
(Engine.kernel). image_nlayer (deprecated name) routes a layered
soil with one or two distinct layers to image / image_2layer
and rejects three or more; cim is a deprecated name of the image
auto-dispatch.
Integral equation. mom solves for the segment currents by point
matching (collocation) with the closed-form kernels above;
mom_sommerfeld does the same with direct numerical Sommerfeld
quadrature of the layered Green's function and is the only integral
backend for \(n \ge 3\) layers. bem is a deprecated name of mom.
Volume PDE. fem (experimental) solves the field in the soil by
conforming finite elements: an axisymmetric model for rods on one axis and
rings around it, a three-dimensional one for every other world (the
optional fem3d extra), described in groundfield.solver.fem.
Notes
Engine.solve() performs an automatic dispatch when
backend="image" is requested: the call is forwarded to
"image_2layer" if the world holds a TwoLayerSoil, and to
"image_nlayer" if it holds a MultiLayerSoil. Notebooks
written for the homogeneous case therefore keep working when the soil
is replaced by a layered one.
Every result carries the metadata core CORE_METADATA_KEYS,
filled here for all backends, next to the backend-specific keys.
Backend
module-attribute
¶
Backend = Literal['image', 'image_2layer', 'image_nlayer', 'cim', 'mom', 'mom_sommerfeld', 'bem', 'fem']
Names of the built-in backends, for type hints.
The registry is the authority at runtime and also accepts registered
third-party names (available_backends()).
"cim", "bem" and "image_nlayer" are deprecated aliases of
"image" and "mom".
CORE_METADATA_KEYS
module-attribute
¶
CORE_METADATA_KEYS: tuple[str, ...] = ('backend', 'effective_backend', 'kernel', 'groundfield_version', 'frequencies', 'n_segments', 'soil_kind', 'earth_inductive_model', 'solve_time_s', 'series', 'max_segments', 'provenance')
Metadata keys that Engine.solve() writes into every result.
backend: Backend name as requested (Engine.backend).effective_backend: Registered backend that ran, after alias resolution and the auto-forwarding by soil model.kernel: Source kernel used ("point"/"line");femreports the kernel of the point sources of its result (the engine's, default"line"), which the field evaluation uses.groundfield_version: Version of the package that solved.frequencies: Frequencies in Hz, in solve order.n_segments: Number of current-carrying source segments (forfemthe display segments that carry the point sources of its result).soil_kind:kindof the soil model ("homogeneous","two_layer","multi_layer").earth_inductive_model: Earth model of the inductive coupling.solve_time_s: Wall time of the backend call in s.series: Image-series controls of the engine,{"max_terms", "tol", "far_field"}, for the post-solve field evaluation.max_segments: Problem-size limit the solve was checked against (Engine.max_segments, orgroundfield.diagnostics.HARD_LIMITwhen the engine leaves it atNone);femchecks its display segments against it and limits its mesh byFemOptions.max_nodes/max_nodes_3d.provenance: Versions, platform, engine configuration, world fingerprint and UTC timestamp (seegroundfield.solver.result.solve_provenance()).
DEFAULT_IMAGE_MAX_TERMS
module-attribute
¶
Default cap on the number of Tagg / Sunde image-series terms.
One value for the engine, every layered backend and the post-solve field evaluation. The geometric tail bound |K|^(n+1)/(1-|K|) falls below the default tolerance after 277 terms for the AP1 corner soil rho_1 = 1000, rho_2 = 30 Ohm m (|K| = 0.9417), so the cap stays unused there.
DEFAULT_IMAGE_SERIES_TOL
module-attribute
¶
Default stop tolerance of the Tagg / Sunde image series.
Summation ends when the geometric tail bound |K|^(n+1)/(1-|K|) falls below this value.
DEFAULT_KERNEL
module-attribute
¶
Kernel an engine requests when it leaves the choice to the backend.
Applies to Engine.kernel = None, the default since 2026.11 (review
pass 10, 10.28): the exact line-source kernel wherever a backend implements it
(the image family), the backend's own kernel elsewhere.
EarthInductiveModel
module-attribute
¶
Earth-return models of the inductive coupling.
The values of Engine.earth_inductive_model:
"perfect_mirror": the earth as a perfect magnetic mirror (ADR-0004), a fast diagnostic baseline;"carson_series": Carson's (1926) per-metre series correction for long parallel wires over homogeneous earth (ADR-0005);"sommerfeld": the geometric Sommerfeld / Pollaczek integral for any geometry and any number of layers (ADR-0006), the engine's default.
Engine ¶
Bases: BaseModel
Configuration of the numerical kernel.
Attributes:
| Name | Type | Description |
|---|---|---|
backend |
str
|
Numerical method, a name registered in
|
frequencies |
list[float]
|
Frequency list in Hz. Default |
segment_length |
float
|
Maximum segment length used to discretise the geometry, in m. |
max_segments |
int | None
|
Resource limit of this engine: the largest problem size it
solves, counted as the number of leakage segments and as the
number of unknowns of the dense nodal system (current owners,
nodes and branches, every conductor sub-piece included). A world
above it raises |
warn_segments |
int | None
|
Size of the soft notice of this engine, counted like
|
tolerance, max_iterations |
Deprecated, no effect (no backend reads them). A non-default
value warns; both fields will be removed no earlier than
|
|
earth_inductive_model |
EarthInductiveModel
|
How the earth contributes to the inductive coupling between
distributed-conductor segments (only effective when at least
one conductor sets
|
image_max_terms, image_series_tol |
Controls of the Tagg / Sunde image-charge series (maximum
number of terms; stop tolerance on the geometric tail bound
\(|K|^{n+1}/(1-|K|)\), dimensionless). Common to every layered
backend that evaluates the series ( |
|
image_far_field |
Literal['quadrupole', 'point']
|
Form of the far images of the line kernel in two-layer soil — the
Tagg/Sunde images (
Against the default, |
options |
Mapping[str, SerializeAsAny[BackendOptions] | Mapping[str, Any]]
|
Backend-specific settings, keyed by backend name and validated
against the backend's options model:
|
sommerfeld_assembly |
Literal['exact', 'tabulated']
|
Assembly of the Sommerfeld earth-return correction of inductive
conductors (
On a TN network of 8 houses with an inductive PEN (78 inductive
branches, four frequencies) the tabulated solve took 1.0 s CPU
instead of 16.6 s, and its input impedance is within 2e-10 of
two independent refined references (per-pair rule with 200
nodes, tables of 400 nodes, both with a refined \(\lambda\) grid;
they agree to 2e-10), the per-pair rule within 1.2e-8. Read by every
backend that assembles the inductive branches through the shared
pipeline (the image family, |
kernel |
Literal['point', 'line'] | None
|
Green's-function kernel of the image family (
An explicit |
Notes
Every field is validated on construction, on assignment
(engine.frequencies = [] raises) and in model_copy()
(unlike pydantic's default model_copy, which stores update
unchecked). Lists mutated in place are checked when the engine
solves.
Examples:
>>> eng = Engine(backend="mom_sommerfeld", options={"mom_sommerfeld": {"epsabs": 1e-8}})
>>> eng.backend_options().epsabs
1e-08
backend_options ¶
Options a backend runs with: the stored entry or the defaults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Backend name or alias. Default: |
None
|
Returns:
| Type | Description |
|---|---|
BackendOptions or None
|
The validated options model of the backend, or |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an entry put into |
Source code in src/groundfield/solver/engine.py
model_copy ¶
Copy of the engine with update validated like the constructor.
pydantic's model_copy stores update without validation; a
deprecated flat name such as sommerfeld_epsrel was then
shadowed by its property and silently ignored (audit A1-02), and
an empty frequency list or a raw option mapping went through
(A1-04).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
update
|
Mapping[str, Any] | None
|
Field values to change. Validated together with the unchanged
fields; the deprecated flat |
None
|
deep
|
bool
|
Deep copy instead of a shallow one. |
False
|
Returns:
| Type | Description |
|---|---|
Engine
|
The copy (the receiver is not changed). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a key of |
Notes
Only warnings that the update introduces are emitted; those of the unchanged fields (e.g. a non-monotonic frequency list) were emitted when the engine was built.
Source code in src/groundfield/solver/engine.py
solve ¶
Run the simulation with the configured backend.
Resolves backend in the registry, checks the backend's
declared capabilities against world and runs it. When
backend == "image" the backend is auto-forwarded to
"image_2layer" for a
TwoLayerSoil and to
"image_nlayer" for a
MultiLayerSoil, so notebooks
written for the homogeneous case keep working when the soil
model is replaced.
The sources of world are snapshotted before the backend runs
and restored afterwards onto the caller's objects, exactly as in
World.solve: solving
never rewrites the input world, whichever entry point is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world
|
World
|
The assembled world (soil, electrodes, conductors and at least one source) the backend should solve. |
required |
Returns:
| Type | Description |
|---|---|
FieldResult
|
Container with per-frequency potentials, currents, cluster
impedances, the source snapshot and metadata: the core keys
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
KeyError
|
If a source terminal or conductor end names no node of
|
BackendCapabilityError
|
If the backend cannot represent the world (soil layer count, concrete-shell electrodes, explicitly requested kernel). The message names the registered backends that can. |
ResourceLimitError
|
If the predicted number of segments or of nodal unknowns
exceeds |
Warns:
| Type | Description |
|---|---|
BackendCapabilityWarning
|
If the backend solves the world with a documented
simplification (reduced conductor model, ignored
|
DeprecationWarning
|
If |
ExperimentalBackendWarning
|
On the first solve with an experimental backend in a process. |
Source code in src/groundfield/solver/engine.py
1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 | |
with_frequencies ¶
Return a copy of this engine with a new frequencies list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*frequencies
|
float
|
One or more frequencies in Hz. Variadic to make the
common case readable: |
()
|
preserve_order
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
Engine
|
A new |
Examples:
>>> eng = Engine(backend="image").with_frequencies(50, 5000,
... preserve_order=True)
>>> eng.frequencies
[50.0, 5000.0]
Source code in src/groundfield/solver/engine.py
EngineFrequencyOrderWarning ¶
Bases: UserWarning
Engine.frequencies is not strictly monotonically increasing.
A dedicated category for the monotonic-order warning emitted by
Engine._validate_frequencies(). Using a dedicated class lets
notebook authors silence the diagnostic with a stable
warnings.simplefilter("once",
EngineFrequencyOrderWarning) — the default UserWarning filter
deduplicates by message text, and because the message embeds the
offending list literal, every distinct non-monotonic list
triggers a fresh warning even when the underlying convention is
the same.
result ¶
Result object of a simulation run.
A FieldResult is the unified return value of
Engine.solve() and World.solve(). It contains:
electrode_potentials/electrode_currents— node values per frequency, used to derive input and transfer impedances.point_sources— the discretised current distribution. The post-processing layer can use these to evaluate the potential at arbitrary field points (contour plots, profiles, touch and step voltages).soil_resistivityandsoil— provide the parameters needed to evaluate the appropriate Green's function (homogeneous or 2-layer) insidepotential().sources— the source snapshot of the solve, read byFieldResult.input_impedance(): the impressed current of every current source; the impressed voltage and the solved current of every voltage source.metadata— the core keys every backend reports (seegroundfield.solver.engine.CORE_METADATA_KEYS), including theprovenanceblock, plus backend-specific keys.
Serialisation
model_dump_json / model_validate_json round-trip a result
losslessly and produce standard JSON (no NaN / Infinity
tokens). Values that JSON cannot express in metadata are written as
single-key tagged objects and restored on validation:
{"$float": "inf" | "-inf" | "nan"}— non-finite float;{"$complex": [re, im]}— complex number;{"$tuple": [...]}— tuple;{"$dict": [[key, value], ...]}— mapping with non-string keys (e.g.penetration_depthkeyed by frequency) or with a key that looks like a tag;{"$ndarray": {"dtype": ..., "shape": [...], "data": [...]}}— numpy array (bool, integer, float, complex or string dtype).
numpy scalars are stored as the equal Python scalar. The tag names are
reserved: a metadata value that is a single-key mapping with one of the
keys above is decoded on validation. The versioned file format around
this JSON is groundfield.io.save_result() /
groundfield.io.load_result().
The decoder reads only what the encoder writes, so a result file from
an untrusted source cannot allocate more memory than a small multiple
of its own size: $ndarray dtypes are limited to bool, integer,
float16 … float64, complex64 / complex128 and unicode
strings (no object, datetime, void, structured or sub-array dtypes);
the shape must match the number of items before anything is allocated;
every item must be a scalar of the dtype's kind; a string array may
take at most 64 bytes per character of its items (plus 4 KiB); and
metadata may nest at most MAX_METADATA_DEPTH levels. A tag that
breaks these rules raises ValueError naming the metadata key
(a pydantic.ValidationError when it is read through validation).
The encoder applies the same limits, so every file it writes loads.
MAX_METADATA_DEPTH
module-attribute
¶
Deepest nesting of containers the metadata codec writes and reads.
Containers are lists, mappings, tuples and tagged objects.
FieldResult ¶
Bases: BaseModel
Result of a field computation.
cluster_impedance ¶
Grounding impedance of the galvanic cluster containing an electrode.
Definition: \(Z_{\text{cluster}}(f) =
\varphi_{\text{cluster}}/\sum_{e \in c} I_e\). For a
stand-alone electrode this is identical to
grounding_impedance(). For connected electrodes it
corresponds to the parallel combination of the individual
grounding admittances.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
electrode_name
|
str
|
Name of any electrode in the target cluster. The cluster
members are looked up in |
required |
Returns:
| Type | Description |
|---|---|
list[complex]
|
Complex cluster impedance per frequency in ohms, one entry
per entry in |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the resolved cluster is empty, or if none of its members carries potential and current data. |
Notes
The cluster potential is the length-weighted (Galerkin) average over all members,
with the per-electrode lengths taken from
point_sources. Since every member potential
\(\varphi_e\) is itself the length-weighted average over
that electrode's segments, \(\varphi_c\) is exactly the
length-weighted average over the whole cluster surface — the
quantity the augmented system constrains to one value (see
solver/image.py, block 1 of the multi-port system).
Up to 0.14.1 this method read members[0], i.e. the
alphabetically first member name. Because the reported
member potentials were unweighted segment means they did not
agree with each other, so renaming an electrode changed the
reported cluster impedance of an unchanged geometry (19.4393 Ω
→ 19.2314 Ω in the audit case, 2026-07-28, F11). With the
weighted reduction the members agree to round-off for the
image family and the result is invariant under renaming for
every backend.
Numerator and denominator run over different member sets, deliberately:
- \(\varphi_c\) averages over members that carry both potential and current data — a member with no potential cannot contribute a term to the average.
- \(\sum_e I_e\) sums over every member that carries current data, whether or not its potential was stored, because its injected current is part of the cluster total regardless.
Every backend in this package populates both mappings for
every member, so the two sets coincide in practice. They
differ only for hand-built FieldResult instances,
where restricting the current sum to the potential-carrying
members would silently under-count the cluster current
(audit 2026-07-29).
Source code in src/groundfield/solver/result.py
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 | |
grounding_impedance ¶
Input impedance \(Z(f) = U/I\) of an electrode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
electrode_name
|
str
|
Name of the electrode whose input impedance is requested.
Must be present in both |
required |
Returns:
| Type | Description |
|---|---|
list[complex]
|
Complex impedance per frequency in ohms, one entry per
entry in |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Notes
For galvanically connected electrodes (cluster with more than
one member) this quantity is the cluster potential divided by
the electrode's share of the total current. The physically
meaningful quantity is the cluster impedance (see
cluster_impedance()).
Source code in src/groundfield/solver/result.py
input_impedance ¶
Driving-point impedance seen by a source.
Definition:
with \(\varphi_a\) the potential of the galvanic cluster the
source feeds (attached_to), \(\varphi_r\) the potential of
the return cluster (return_to; zero for a return through
remote earth) and \(I_s\) the source current. Cluster potentials
are the length-weighted averages used by
cluster_impedance().
- Current source: \(I_s\) is the impressed current.
- Voltage source (since 2026.11): the solve fixes
\(\varphi_a - \varphi_r = U - Z_q I_s\), so
\(Z_\text{in} = U / I_s - Z_q\) with the impressed voltage \(U\),
the solved source current \(I_s\) and the internal impedance
\(Z_q = R + j\omega L\) of the source
(
SourceRecord.voltage,SourceRecord.current,SourceRecord.internal_impedance()). It is the impedance the source sees at its terminals, without its own \(Z_q\) (the current is \(U / (Z_q + Z_\text{in})\)). For a world with this one source it equals the impedance a 1 A current source at the same terminals reports, to round-off; with several sources it is an apparent impedance (see Notes).
This is the impedance a measurement instrument or a fault sees
at the feeding point. It differs from cluster_impedance()
(cluster potential over the cluster's own leakage current)
as soon as part of the injected current leaves the cluster
through conductors (PEN, cable shields, measurement leads):
then the cluster impedance describes the local electrode only,
the input impedance the whole connected system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str | None
|
Name of the source. May be omitted when the result carries exactly one source. |
None
|
Returns:
| Type | Description |
|---|---|
list[complex]
|
Complex input impedance per frequency in ohms. Frequencies
with zero source current return |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the result carries no source snapshot (hand-built
results), no source, or several sources and |
KeyError
|
If |
Notes
With several simultaneous sources the potential difference
includes the contribution of the other sources, so the ratio is
an apparent impedance of the named source. Two 230 V sources
on two 3 m rods 5 m apart (100 Ω·m, image) report 38.90 Ω
each, against 35.99 Ω of the 1 A solve of one rod (+8.1 %).
Source code in src/groundfield/solver/result.py
908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 | |
potential ¶
Evaluate the potential at field points (image-charge sum).
Picks the appropriate Green's-function kernel automatically:
- homogeneous (
HomogeneousSoilor noself.soilset butsoil_resistivityavailable): classic image-charge sum \(1/r + 1/r_{\text{img}}\). - 2-layer (
TwoLayerSoil, orMultiLayerSoilwith exactly two layers): Tagg/Sunde series truncated with the controls of the solve,metadata["series"](the engine'simage_max_termsandimage_series_tol; defaults 300 and1e-6for results without the record). - 1-layer (
MultiLayerSoilwith a single layer): degenerate case, dispatched to the homogeneous kernel.
The dispatch reads the canonical layer stack of self.soil
(adjacent layers of one resistivity merged, review pass 10,
10.48): TwoLayerSoil(rho, rho, h) and a MultiLayerSoil of
one resistivity are evaluated like homogeneous soil, exactly as
they are solved (before audit A3S-04 their sources below h
took the point form of the two-layer kernel, +2.7 % next to a
rod), and a MultiLayerSoil with at most two distinct layers
like the two-layer soil.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
Field points, array of shape |
required |
frequency_index
|
int
|
Index into |
0
|
min_distance
|
float
|
Numerical cutoff for 1/r singularities, in metres. |
0.001
|
Returns:
| Name | Type | Description |
|---|---|---|
phi |
(ndarray, shape(M))
|
Complex potential in V. |
Warns:
| Type | Description |
|---|---|
SeriesTruncationWarning
|
If the two-layer series reaches |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If |
Notes
Prior to 0.2.0 a MultiLayerSoil with n ≥ 3 silently
fell through to the homogeneous kernel, returning incorrect
potentials, profiles, touch / step voltages and VTK exports.
The error is now raised explicitly so the regime is visible
rather than silent.
Point sources at projected (UTM) coordinates, beyond 10 km from the origin, are evaluated in a local frame: points and sources are shifted by the rounded centre of the sources' bounding box (exact for nearby doubles) before the kernel runs (since 2026.11; see Units and conventions in the reference).
Source code in src/groundfield/solver/result.py
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 | |
summary ¶
Compact one-line description of the result.
Returns:
| Type | Description |
|---|---|
str
|
Human-readable summary listing the backend name, the number of frequencies, the number of electrodes for which potentials were stored and the number of discretised point sources. Intended for logging and notebook output; the format is informational and not stable across versions. |
Source code in src/groundfield/solver/result.py
to_dataframe ¶
Tidy table of the result, one row per frequency and object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
str
|
|
'electrodes'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The table; rows ordered by frequency, then by electrode /
source in result order. Values that the result does not
carry (hand-built results) are |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ImportError
|
If pandas is not installed (it is imported on first use). |
Examples:
>>> df = result.to_dataframe()
>>> df.pivot(index="frequency_hz", columns="electrode",
... values="potential_v").abs()
Source code in src/groundfield/solver/result.py
1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 | |
PointSource ¶
Bases: BaseModel
A discretised current source (segment midpoint, length, direction).
Filled by the backend; not instantiated directly by the user. With
the point kernel the current sits at position; with the line
kernel (FieldResult.metadata["kernel"] == "line") it is spread
uniformly along the segment given by length and direction.
SourceRecord ¶
Bases: BaseModel
Snapshot of one source as it was solved.
Filled by Engine.solve() (and, for a world with voltage
sources, by the backend); not instantiated directly by the user.
FieldResult.input_impedance() reads it, so the result stays
self-contained after the world has changed.
For a current source current is the impressed current and
voltage is empty. For a voltage source voltage is the
impressed voltage \(U\) and current the source current \(I\) the
solve returned — the current the source drives into attached_to
(and takes back from return_to), the same sign convention as a
current source; internal_resistance_ohm and
internal_inductance_h are its internal impedance
\(Z_q = R + j\omega L\) (0 for an ideal source and for current
sources), so the terminal voltage is \(U - Z_q I\).
A record pickled before 2026.11 lacks the two fields of the internal impedance and unpickles with 0 / 0, as its JSON loads (audit W2R2-01).
internal_impedance ¶
Internal impedance \(Z_q = R + j\omega L\) in Ω at frequency (Hz).
0j for a current source and an ideal voltage source.
Source code in src/groundfield/solver/result.py
solve_provenance ¶
Provenance block of a solve (without the timestamp).
Engine.solve calls
this before the backend runs and adds solved_at_utc when it
returns; the block is stored as FieldResult.metadata["provenance"].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world
|
World
|
The world as built by the caller. |
required |
engine
|
Engine
|
The engine configuration. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
|
Source code in src/groundfield/solver/result.py
world_fingerprint ¶
SHA-256 fingerprint of the canonical JSON of a world.
The canonical form is json.dumps(world.model_dump(mode="json"),
sort_keys=True, separators=(",", ":")). Pydantic writes floats in
their shortest round-trip form, so equal worlds give equal
fingerprints, also after a JSON round trip of the world. The
fingerprint depends on the world schema of the installed version:
renamed or added model fields change it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world
|
World
|
The world to fingerprint. |
required |
Returns:
| Type | Description |
|---|---|
str
|
|
Source code in src/groundfield/solver/result.py
mutual ¶
Mutual grounding-impedance matrix and field matrix in one assembly.
solve_mutual_matrix() computes the full nG × nG mutual
grounding-impedance matrix Z_G of a set of grounding clusters
("gnodes"), solve_mutual_field() the potential at arbitrary points
per unit excitation, each in one matrix assembly instead of one
Engine.solve per excitation.
Motivation
The AP1 catalogue builds Z_G for every site and soil. The historic
loop (one world per excitation, cluster_impedance on the diagonal,
FieldResult.potential at a probe point off the diagonal) assembled
the N × N segment reaction matrix nG times. Here:
- The segment reaction matrix is assembled once, directly (the
kernel operators'
matrixmethod; v0.15.0 applied the kernel to anN × Nidentity, oneO(N³)product per image term — review pass 10, 10.59), including the ADR-0012 V2 concrete shell. - The leakage distribution of every excitation is a solve of the same
augmented nodal system as
Engine.solve(), with one owner per straight wire of an electrode (a wire line of a grid, an arm of a star, an edge of a polyline; user decision Q30) and per soil layer for electrodes through the layer interface (10.15). - The off-diagonal entries are either the reaction of the leakage
columns (
offdiag="galerkin", the default, no further kernel evaluation) or the probe-point potentials (offdiag="probe", one probe kernel for all columns).
Discretisation, topology and the branch block come from the shared
image-family pipeline (groundfield.solver._pipeline); only the
image family is accepted (10.34).
Consistency with Engine.solve
The diagonal equals FieldResult.cluster_impedance() of a
per-excitation solve with the same engine to round-off (10.26), probe
off-diagonals equal FieldResult.potential() at the probe point,
and the columns of solve_mutual_field() equal
FieldResult.potential at the field points
(tests/test_mutual_matrix.py, tests/test_mutual_field.py).
OffDiagonal
module-attribute
¶
Off-diagonal definitions of solve_mutual_matrix() (10.34).
"galerkin" (the default since 2026.11): the reaction of the leakage
distributions, reciprocal; "probe": the potential at one probe point
per cluster, the definition up to 0.15.0.
ProbePointsIgnoredWarning ¶
Bases: UserWarning
solve_mutual_matrix was given probe points it does not use.
Since the user decision Q15 of 2026.11 the off-diagonal of
solve_mutual_matrix() is offdiag="galerkin" whatever the
call. Up to 0.15.0 passing probe_points selected the potential at
those points as the off-diagonal; such a call now returns the galerkin
matrix, ignores the points and emits this warning. Pass
offdiag="probe" to keep the 0.15.0 definition, or drop the probe
points.
solve_mutual_field ¶
solve_mutual_field(world: 'World', engine: 'Engine', anchors: list[str], field_points: ndarray, *, frequency_index: int = 0, matrix_min_distance: float = 0.001, matrix_max_terms: int | None = None, matrix_tol: float | None = None) -> np.ndarray
Galvanic Green-function matrix: potential at arbitrary field points per node.
Returns R of shape (M, nG) with R[i, j] = potential at
field_points[i] (x, y, depth) under unit current (1 A) injected
into anchors[j] while all other clusters stay floating. This is the
off-diagonal field evaluation of solve_mutual_matrix(), generalised
to an arbitrary number of field points (decoupled from nG) and
without the self/diagonal term — the building block for the
frequency-dependent surface-potential distribution by superposition::
phi(field_points, f) = R @ I_leak(f)
with I_leak(f) = Y_G @ u(f) from the reduced network
(Y_L(f) + Y_G) u = i. Uses the same one-shot assembly as
solve_mutual_matrix() (reaction matrix and per-excitation leakage
columns built once); only the field-point evaluation is generalised. The
expensive 3D part is therefore frequency-independent and computed once, so
a frequency sweep over I_leak(f) is cheap.
world must already carry all nG grounding clusters (every
anchor in anchors must be a real electrode in world) and the soil
model. Any current source is ignored — the excitations are applied
internally, one cluster at a time, exactly as the historic per-excitation
loop did.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world
|
'World'
|
Assembled world holding all |
required |
engine
|
'Engine'
|
Engine configuration. |
required |
anchors
|
list[str]
|
Length- |
required |
field_points
|
ndarray
|
|
required |
frequency_index
|
int
|
Index into |
0
|
matrix_min_distance
|
float
|
Clamp distance in m and series controls of the field evaluation.
|
0.001
|
matrix_max_terms
|
float
|
Clamp distance in m and series controls of the field evaluation.
|
0.001
|
matrix_tol
|
float
|
Clamp distance in m and series controls of the field evaluation.
|
0.001
|
Returns:
| Name | Type | Description |
|---|---|---|
R |
(ndarray, shape(M, nG), complex)
|
Galvanic Green-function matrix; |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
KeyError
|
If an entry of |
NotImplementedError
|
If the soil is a |
TypeError
|
If the soil model type is not supported. |
See Also
solve_mutual_matrix : Full nG × nG mutual grounding-impedance matrix.
Source code in src/groundfield/solver/mutual.py
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 | |
solve_mutual_matrix ¶
solve_mutual_matrix(world: 'World', engine: 'Engine', anchors: list[str], probe_points: ndarray | None = None, *, frequency_index: int = 0, symmetrize: bool = True, offdiag: OffDiagonal = 'galerkin', matrix_min_distance: float = 0.001, matrix_max_terms: int | None = None, matrix_tol: float | None = None) -> np.ndarray
Full mutual grounding-impedance matrix Z_G in one assembly.
Column j belongs to 1 A injected into anchors[j]; the other
clusters float (zero net current, review pass 10, 10.29), exactly as
in Engine.solve() with one source. The segment reaction matrix and the
leakage distribution of every excitation are computed once and
reused for all entries.
- Diagonal.
Z[j, j]is the cluster impedance ofanchors[j], the length-weighted (Galerkin) potential average over every member of its cluster divided by the cluster current — the same reduction asFieldResult.cluster_impedance()after a per-excitationEngine.solve()(equal to round-off). Up to 2026.11 the diagonal was the unweighted mean over the alphabetically first member: +0.150 % for an L-shaped footprint at ds = 2 m, -3.8 … -9.1 % for a rod split at the layer interface (review pass 10, 10.26). - Off-diagonal,
offdiag="galerkin"(default): the reactionZ[i, j] = T_iᵀ (K + S) T_jof the leakage columnsTwith the reaction matrixKand the concrete-shell diagonalS. It is the current-weighted potential of clusteriunder excitationj— the off-diagonal counterpart of the diagonal, reciprocal to round-off, and the matrix that reproduces a solve of the clusters joined by branches (see Notes). - Off-diagonal,
offdiag="probe": the potential atprobe_points[i]under excitationj, asFieldResult.potential()returns it after a per-excitation solve — the definition of releases up to 0.15.0. A point potential is not the potential of clusteri: the matrix is not reciprocal (Z[i, j]andZ[j, i]differ by up to 35 % in two-layer soil, review pass 10, 10.34), andsymmetrize=Trueaverages that asymmetry away. On an AP1-like site (a station and twelve house foundations, ds = 2 m, five soils) the symmetrised probe matrix misses the input impedance of the joined network by -0.15 … -0.88 %, and its off-diagonal entries differ from the galerkin ones by 0.15 … 1.1 % (median) and up to 41 %; the galerkin matrix reproduces the network solve to 1e-12.
The galerkin off-diagonal is the default of every call since the
user decision Q15 of 2026.11. Up to 0.15.0 passing probe_points
selected the probe definition; such a call now returns the galerkin
matrix and ignores the points with a ProbePointsIgnoredWarning
— pass offdiag="probe" to keep the 0.15.0 definition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world
|
'World'
|
Assembled world holding all |
required |
engine
|
'Engine'
|
Engine of the image family ( |
required |
anchors
|
list[str]
|
Length- |
required |
probe_points
|
ndarray | None
|
|
None
|
frequency_index
|
int
|
Index into |
0
|
symmetrize
|
bool
|
If |
True
|
offdiag
|
OffDiagonal
|
|
'galerkin'
|
matrix_min_distance
|
float
|
Clamp distance in m and series controls of the probe-point
evaluation ( |
0.001
|
matrix_max_terms
|
float
|
Clamp distance in m and series controls of the probe-point
evaluation ( |
0.001
|
matrix_tol
|
float
|
Clamp distance in m and series controls of the probe-point
evaluation ( |
0.001
|
Returns:
| Name | Type | Description |
|---|---|---|
Z |
(ndarray, shape(nG, nG), complex)
|
Mutual grounding-impedance matrix in Ω. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
BackendCapabilityError
|
If the engine's backend is not the image family (a subclass of
|
ResourceLimitError
|
If the problem exceeds |
KeyError
|
If an entry of |
Warns:
| Type | Description |
|---|---|
ProbePointsIgnoredWarning
|
If |
Notes
With the uniform current per owner of the image family, the
potential of a cluster is the current-weighted average of its
segment potentials. With every other cluster floating,
T_iᵀ (K + S) T_j therefore equals the potential of cluster i
under excitation j exactly (reciprocity of the reaction matrix),
bonded groups and rods through the layer interface included, and
(Y_L + Z_G⁻¹) u = i reproduces the solve of the clusters joined
by the branches Y_L. With probe off-diagonals it does not
(evidence in the 2026.11 changelog).
Source code in src/groundfield/solver/mutual.py
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 | |
Backend solve functions¶
Each built-in backend is one solve function, solve_<name>(world, engine),
registered in the backend registry. Engine.solve resolves
the backend name, checks the capabilities against the world, calls the
function and fills the common metadata of the result
(CORE_METADATA_KEYS); call the functions directly only to bypass that
dispatch, for example in a test. The theory of each backend is on its
engine page.
solve_image ¶
Image-charge solver for homogeneous soil.
Runs the shared image-family pipeline
(groundfield.solver._pipeline) with the half-space Green's
function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world
|
'World'
|
World whose |
required |
engine
|
'Engine'
|
Engine configuration; relevant fields are |
required |
Returns:
| Type | Description |
|---|---|
FieldResult
|
Node potentials and leakage currents per frequency, point sources and metadata. |
Raises:
| Type | Description |
|---|---|
BackendCapabilityError
|
If the soil is a layered model ( |
TypeError
|
If |
ValueError
|
If the world has no electrodes, or the geometry fails a discretisation guard (thin wire, burial depth). |
Source code in src/groundfield/solver/image.py
solve_image_2layer ¶
solve_image_2layer(world: 'World', engine: 'Engine', *, max_terms: int | None = None, tol: float | None = None, far_field: str | None = None) -> FieldResult
Image-charge solver for 2-layer soil (Tagg / Sunde).
Runs the shared image-family pipeline
(groundfield.solver._pipeline) with the two-layer Green's
function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world
|
'World'
|
World whose |
required |
engine
|
'Engine'
|
Engine configuration. |
required |
max_terms
|
int | None
|
Maximum number of series terms; |
None
|
tol
|
float | None
|
Series truncation: stop as soon as the geometric tail bound
\(|K|^{n+1}/(1-|K|)\) falls below |
None
|
far_field
|
str | None
|
Form of the far images with the line kernel, |
None
|
Returns:
| Type | Description |
|---|---|
FieldResult
|
Result object. |
Raises:
| Type | Description |
|---|---|
BackendCapabilityError
|
If the soil is a |
TypeError
|
If |
ValueError
|
If the world has no electrodes, if |
Warns:
| Type | Description |
|---|---|
SeriesTruncationWarning
|
If the series is used and reaches |
Source code in src/groundfield/solver/image_2layer.py
1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 | |
solve_mom ¶
solve_mom(world: World, engine: Engine, *, two_layer_max_terms: int | None = None, two_layer_tol: float | None = None) -> FieldResult
Point-matching method-of-moments backend.
Supports HomogeneousSoil, TwoLayerSoil and a
MultiLayerSoil whose canonical stack has at most two layers
(10.48). The Green's-function kernel is taken from the matching
image backend; only the resolution scheme (one current per segment,
point matching at the segment midpoints, instead of one uniform
current per straight wire of an electrode) differs. Clusters without a source float
(zero net current, 10.29). Concrete-encased electrodes carry the
per-segment shell term of ADR-0012 (since 2026.11). See the module
docstring for the accuracy of the scheme and the shared solve flow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world
|
World
|
World to evaluate. |
required |
engine
|
Engine
|
Engine configuration; |
required |
two_layer_max_terms
|
int | None
|
Truncation parameters for the Tagg/Sunde series (term count,
dimensionless tail bound), only used for two-layer soil.
|
None
|
two_layer_tol
|
int | None
|
Truncation parameters for the Tagg/Sunde series (term count,
dimensionless tail bound), only used for two-layer soil.
|
None
|
Returns:
| Type | Description |
|---|---|
FieldResult
|
Result object compatible with |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the world has no electrodes, or a segment lies partly above the soil surface. |
BackendCapabilityError
|
For a |
TypeError
|
If |
Source code in src/groundfield/solver/mom.py
1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 | |
solve_mom_sommerfeld ¶
solve_mom_sommerfeld(world: World, engine: Engine, *, lambda_max_factor: float = 200.0, epsabs: float = 1e-09, epsrel: float = 1e-07, max_osc_panels: int = _MAX_OSC_PANELS, tabulate: bool = True) -> FieldResult
Point-matching MoM with direct Sommerfeld quadrature for layered soil.
The discretisation and the linear solve are those of mom (point
matching at the segment midpoints, point-source near field,
source-free clusters floating), run through the shared solve
pipeline (10.75). Every off-diagonal reaction-matrix entry is the
Sommerfeld kernel of sommerfeld_kernel_value(), i.e. the
closed-form direct pair plus a numerically integrated reflected
remainder; no image series and no fit enter the off-diagonal
kernel. For \(n = 2\) the diagonal is the Tagg/Sunde series diagonal
of mom, so on two-layer soil this backend reproduces mom and
checks the kernel, not the scheme; for \(n \ge 3\) distinct layers it
is the only integral-equation backend.
Cost (review pass 10, 10.61): pairs that share a depth pair and a
horizontal distance share one quadrature, which halves the work of
every world and collapses it for regular geometries. For
\(n \ge 3\) the reflected remainder of a depth group with many
distinct distances is tabulated on log-spaced nodes and interpolated
(tabulate=True, the default): about \(10^{-7}\) relative error of
the kernel at the verification points and below \(10^{-6}\) on the
reaction matrix of the benchmark grid B12, for a cost that no longer
grows with the number of pairs. tabulate=False evaluates every
distinct pair by quadrature (the kernel reference). For \(n = 2\)
every pair is evaluated by quadrature: this backend is the kernel
check of the closed-form series there.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world
|
World
|
World to evaluate. |
required |
engine
|
Engine
|
Engine configuration. |
required |
lambda_max_factor
|
float
|
Truncation of the remainder quadrature in units of the
remainder decay length \(1 / d_{\text{rem}}\); saturates at
60. See |
200.0
|
epsabs
|
float
|
Convergence thresholds of the remainder quadrature (absolute in 1/m, relative). |
1e-09
|
epsrel
|
float
|
Convergence thresholds of the remainder quadrature (absolute in 1/m, relative). |
1e-09
|
max_osc_panels
|
int
|
Budget for the \(J_0\) half-period panel family. |
_MAX_OSC_PANELS
|
tabulate
|
bool
|
Depth-group tabulation of the reflected kernel for \(n \ge 3\) (see above). |
True
|
Returns:
| Type | Description |
|---|---|
FieldResult
|
|
Warns:
| Type | Description |
|---|---|
SommerfeldConvergenceWarning
|
Once per solve, if any reaction-matrix entry's remainder quadrature failed to converge. |
Notes
The quadrature keywords are reachable through
Engine.options["mom_sommerfeld"]
(MomSommerfeldOptions); the
signature defaults equal the option defaults, so a direct call
without keywords behaves exactly like
solve().
Raises:
| Type | Description |
|---|---|
TypeError
|
If the soil is not a |
ValueError
|
If the world has no electrodes. |
Source code in src/groundfield/solver/mom_sommerfeld.py
1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 | |
sommerfeld_kernel_value ¶
sommerfeld_kernel_value(stack: LayerStack, s: float, z: float, z_s: float, *, lambda_max_factor: float = 200.0, epsabs: float = 1e-09, epsrel: float = 1e-07, max_osc_panels: int = _MAX_OSC_PANELS, issues: list[_QuadratureIssue] | None = None) -> float
Evaluate the layered-soil Sommerfeld kernel at one point.
Returns the full top-layer kernel
$$
G(s, z, z_s) \;=\; \int_0^{\infty}
\frac{e^{-\lambda |z - z_s|}
+ \Gamma_1 e^{-\lambda (2 h_1 - |z - z_s|)}
+ e^{-\lambda (z + z_s)}
+ \Gamma_1 e^{-\lambda (2 h_1 - z - z_s)}}
{1 - \Gamma_1(\lambda)\, e^{-2 \lambda h_1}}
J_0(\lambda s)\, d\lambda ,
$$
i.e. both image families plus the full multiple-reflection
multiplier between the free surface (\(R_{\text{air}} = +1\))
and the layer interface. The potential of a point source \(I\)
is then ρ_1 · I · G / (4 π).
The integral is not evaluated by a bare real-axis quadrature:
the two \(\Gamma_1 \to 0\) terms (which converge only through
the oscillation of \(J_0\) and are the reason the pre-0.15.0
implementation could return a negative value) are taken from
Lipschitz' integral
\(\int_0^\infty e^{-\lambda d} J_0(\lambda s) d\lambda
= (s^2 + d^2)^{-1/2}\), so that
$$
G = \frac{1}{\sqrt{s^2 + (z - z_s)^2}}
+ \frac{1}{\sqrt{s^2 + (z + z_s)^2}}
+ G_{\text{refl}},
$$
and only the exponentially decaying reflected remainder
\(G_{\text{refl}}\) is integrated numerically — see
_reflected_integral().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stack
|
LayerStack
|
Layer stack. |
required |
s
|
float
|
Cylindrical radius \(s = \sqrt{(x - x_s)^2 + (y - y_s)^2}\) in metres. |
required |
z
|
float
|
Field-point depth and source depth (positive into the soil). |
required |
z_s
|
float
|
Field-point depth and source depth (positive into the soil). |
required |
lambda_max_factor
|
float
|
Truncation of the remainder quadrature, in units of \(1 / d_{\text{rem}}\), where \(d_{\text{rem}}\) is the decay length of the remainder (not, as before 0.15.0, a characteristic length of the geometry). The discarded tail is bounded by \(e^{-\texttt{lambda\_max\_factor}}\); the factor saturates at 60 (\(\sim 10^{-26}\)), so raising it beyond the default cannot change the result. On the delegated \(n = 2\) cross-layer path (\(z > h_1\) or
\(z_s > h_1\), forwarded to
|
200.0
|
epsabs
|
float
|
Absolute / relative thresholds of the grid-refinement
convergence test of the remainder quadrature. |
1e-09
|
epsrel
|
float
|
Absolute / relative thresholds of the grid-refinement
convergence test of the remainder quadrature. |
1e-09
|
max_osc_panels
|
int
|
Budget for the half-period panel family that resolves the
\(J_0(\lambda s)\) oscillation, default 200 000 panels
(× 12 Gauss nodes). Only binds for
\(s / d_{\text{rem}} \gtrsim 1.9 \cdot 10^{4}\), i.e. a
centimetre-thin intermediate layer combined with a
kilometre-scale horizontal separation; there the coverage is
incomplete, a |
_MAX_OSC_PANELS
|
issues
|
list[_QuadratureIssue] | None
|
Optional collector for non-convergence diagnostics; see
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
G |
float
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
For \(n \ge 3\) with \(z > h_1\) or \(z_s > h_1\): the expression above is a top-layer form, so the kernel refuses instead of silently returning a diverging number (before 0.15.0 it returned \(\approx -2 \cdot 10^{127}\) there). |
Warns:
| Type | Description |
|---|---|
SommerfeldConvergenceWarning
|
If the remainder quadrature does not reach the requested tolerance. The returned value is then not converged and its sign may be wrong. |
Notes
Limits and special cases:
stack.n_layers == 1(homogeneous, \(\Gamma_1 \equiv 0\)): short-circuited to \(1/r + 1/r_{\text{img}}\), bit-exact.- \(\rho_1 = \rho_2\) in a declared 2-layer stack (\(K_1 = 0\), hence \(\Gamma_1 \equiv 0\)): the reflected remainder is identically zero, so the same closed form is returned bit-exact. This is the strongest available accuracy test of the backend.
stack.n_layers == 2with \(z > h_1\) or \(z_s > h_1\): delegated togroundfield.coupling.layered_green.two_layer_real_space_kernel(), which solves the cross-layer spectral matching.
Distances are floored at 1 mm (_MIN_DISTANCE), consistently
with the homogeneous image backend, so the coincident-point
limit stays finite.
Source code in src/groundfield/solver/mom_sommerfeld.py
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 | |
solve_fem ¶
solve_fem(world: 'World', engine: 'Engine', *, refinement: int = 0, extrapolate: bool = True, r_far_factor: float = 1000.0, far_field: str = 'robin', max_nodes: int = 2000000, max_nodes_3d: int = 2000000, max_ports_3d: int = 100, model: str = 'auto', source_radius: float | None = None, growth: float = 0.5, concrete_resistivity: float | None = None, _concrete_mesh: float | None = None, n_radial: int | None = None, n_axial: int | None = None, z_far_factor: float | None = None) -> FieldResult
Conforming finite-element solve (see the module docstring).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world
|
'World'
|
World to solve, any horizontally layered soil, bare or encased
electrodes (see |
required |
engine
|
'Engine'
|
Engine; its |
required |
refinement
|
int
|
Refinement level of the coarser of the two meshes (axisymmetric
model: each level bisects every interval of the graded mesh lines,
about four times the nodes; 3-D model: about eight times). |
0
|
extrapolate
|
bool
|
Solve at |
True
|
r_far_factor
|
float
|
Size of the truncation box in characteristic lengths (the electrodes' size, or the depth of the deepest interface times the layer contrast if larger); dimensionless, default 1000. |
1000.0
|
far_field
|
str
|
|
'robin'
|
max_nodes
|
int
|
Resource limit of the axisymmetric model: the node count of the finer mesh, estimated before anything is assembled (the estimate errs high). Default 2 million: the solve needs about 4 GB per million nodes of the finer mesh, so about 8 GB at the limit. |
2000000
|
max_nodes_3d
|
int
|
Resource limit of the three-dimensional model: the node count of its finer mesh, predicted before meshing and counted before the finer level is built. The solve adds about 2.9 GB per million nodes to the peak memory of the process (3.0 ... 3.1 GB with the process itself). |
2000000
|
max_ports_3d
|
int
|
Resource limit of the three-dimensional model: the number of ports (every electrode and every leaking piece of a galvanic distributed conductor), checked before meshing. Default 100: every port costs one conjugate-gradient solve per mesh level, about 0.9 s per port and level at 600 000 nodes of the finer mesh. |
100
|
model
|
str
|
|
'auto'
|
source_radius
|
float | None
|
3-D model: radius in m of the disc over which each wire's leakage
is smoothed; |
None
|
growth
|
float
|
3-D model: growth of the element size per metre away from the wires (default 0.5; smaller is finer and slower). |
0.5
|
concrete_resistivity
|
float | None
|
3-D model: |
None
|
_concrete_mesh
|
float | None
|
Private, for the overlap study of user decision Q40 (see
|
None
|
n_radial
|
int | None
|
Deprecated: the mesh controls of the equivalent-hemisphere mesh (0.15.0); a value has no effect and warns. |
None
|
n_axial
|
int | None
|
Deprecated: the mesh controls of the equivalent-hemisphere mesh (0.15.0); a value has no effect and warns. |
None
|
z_far_factor
|
int | None
|
Deprecated: the mesh controls of the equivalent-hemisphere mesh (0.15.0); a value has no effect and warns. |
None
|
Returns:
| Type | Description |
|---|---|
FieldResult
|
Electrode potentials and currents (every electrode an
equipotential port), point sources with the leakage distribution of
the model, and |
Raises:
| Type | Description |
|---|---|
BackendCapabilityError
|
With |
ImportError
|
If the world needs the three-dimensional model and the |
ValueError
|
If an electrode or a galvanic distributed conductor lies at or
above the soil surface (as every backend), or the world fails
|
ResourceLimitError
|
If the finer mesh would exceed |
TypeError
|
If |
Warns:
| Type | Description |
|---|---|
MixedCoordinatesWarning
|
For a world that mixes local and projected coordinates (user decision D5), as every backend. |
InterfaceContactWarning
|
3-D model: for a rod end within one wire radius of a layer interface (audit W4R2A-03: a rod tip on 1000/30 Ohm m read +43 % against the solid rod, with an estimate of 6e-3) and for a horizontal wire within the reach of a contrasting one (audits W4A-07, W4B-02), where the smoothed line source shares the thin-wire error of the integral engines; once per rule and solve, as there. The axisymmetric model resolves rod end faces and ring wires and does not warn. |
DeprecationWarning
|
For |
Notes
Without extrapolation the resistance of the axisymmetric model converges at second order and, in every case tested away from interfaces, from below; this is not guaranteed (the O-grid of a ring is not nested between levels), and next to an interface cut into a ring's mesh block it did not hold before that block was refined (audit W4A-01) and graded towards the points where the interface meets the wire (audit W4R2A-02: touching a 1000 times more conductive layer the levels converged at about first order, the default read -1.6e-2 with an estimate of 1.1e-2). The error estimate bounds the error of the extrapolated value while both levels lie on the same side of the converged value and the finer level's error is at most 1/2.5 of the coarser level's (about 1/3.9 is observed for rods and rings, 1/3.9 ... 1/4.0 for a ring touching a 100 or 1000 times more conductive layer).
Source code in src/groundfield/solver/fem/__init__.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | |
Deprecated backend names¶
cim, bem and image_nlayer are deprecated names of image and mom
(see Deprecations); their solve functions forward
to the current backends. The complex-image fit of the cim module
(fit_complex_images, ComplexImageFit) is a stand-alone tool that no
backend evaluates. equivalent_hemisphere_radius is deprecated: it
belongs to the hemisphere reduction that fem no longer uses.
solve_cim ¶
Run the image auto-dispatch under the deprecated backend name cim.
cim never evaluated a complex-image fit on a reachable path: for
\(n = 1\) it used the homogeneous image kernel and for \(n = 2\) the
exact Tagg/Sunde series, i.e. it reproduced image and
image_2layer (bit for bit since the length-weighted read-back of
10.30). Since review pass 10 (10.76) the name is a deprecated alias:
this function runs the backend image would run for the soil
model — solve_image() for a
HomogeneousSoil,
solve_image_2layer() for a
TwoLayerSoil and the layered router for a
MultiLayerSoil — with the engine's series controls, so a
two-layer world also gets the cross-layer treatment of
image_2layer. fit_complex_images() stays available as a
spectral helper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world
|
World
|
World to evaluate. |
required |
engine
|
Engine
|
Engine configuration; |
required |
Returns:
| Type | Description |
|---|---|
FieldResult
|
The result of the image backend, labelled |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
For three or more distinct soil layers (use |
Warns:
| Type | Description |
|---|---|
DeprecationWarning
|
Always: use |
Source code in src/groundfield/solver/cim.py
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 | |
fit_complex_images ¶
fit_complex_images(stack: LayerStack, *, n_images: int = 8, n_samples: int = 64, lambda_min_factor: float = 0.001, lambda_max_factor: float = 50.0, rms_tol: float = _DEFAULT_RMS_TOL, warn: bool = True) -> ComplexImageFit
Fit Γ_1(λ) of an n-layer stack by n_images complex exponentials.
Physical / mathematical context
The upward-looking reflection coefficient of a stratified
half-space (see groundfield.solver._layered.reflection_gamma())
is a rational function of the interface attenuations
\(e^{-2 \lambda h_i}\). It is not a decaying function: it
tends to the top-interface Fresnel coefficient
while a sum \(\sum_k a_k e^{-2\lambda\beta_k}\) with \(\Re\{\beta_k\} > 0\) tends to 0. The asymptote is hence split off analytically and carried by an image at \(\beta_0 = 0\) (weight \(K_1\); in the spatial domain an image at the air-mirror position \(z = -z_s\), integrable through the Sommerfeld identity because \(d = z + z_s > 0\)), and the matrix pencil only sees the genuinely decaying remainder \(\Gamma_1(\lambda) - K_1\).
Steps:
- Build a uniform sampling grid \(\lambda_j = \lambda_{\min} + j \Delta\). Only the thicknesses \(h_2, \dots, h_{n-1}\) enter \(\Gamma_1\) (the recursion never uses \(h_1\)), so the structure scale is \(h_{\max} = \max_i h_{i\ge2}\) and the decay scale is \(h_{\min} = \min_i h_{i\ge2}\): the step is capped at \(\Delta \le 1/(8 h_{\max})\) so the slowest exponential is resolved, and the window reaches up to \(\lambda_{\max} = \lambda_{\max,\text{factor}}/h_{\min}\) where the fastest one has died.
- Sample \(g_j = \Gamma_1(\lambda_j)\) and subtract \(K_1\).
- Apply the matrix-pencil method to the remainder to recover the poles \(p_k = e^{-2 \Delta \beta_k}\), filtered to \(|p_k| < 0.999\) and \(\Re\{\beta_k\} > 0\).
- Re-solve the least-squares coefficients \(a_k\) for the surviving \(\{\beta_k\} \cup \{0\}\) on the original samples of \(\Gamma_1\) — the filtered model is therefore self-consistent (up to 0.14.1 the coefficients were solved before the filter and then merely sliced, so the reported weights belonged to a different model).
Special cases:
stack.n_layers <= 1→ empty fit (\(\Gamma_1 \equiv 0\)).stack.n_layers == 2→ \(\Gamma_1 \equiv K_1\) exactly; the single \(\beta = 0\) image reproduces it withrms = 0(up to 0.14.1 this returnedP = 0andrms = nan).- \(\rho_1 = \dots = \rho_n\) → empty fit.
Notes
No solver path calls this function: the backend name cim is a
deprecated alias of the closed-form image backends (see the module
docstring). It is kept public as the spectral building block for a
future complete \(n \ge 3\) complex-image kernel, and it reports
failure instead of hiding it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stack
|
LayerStack
|
Layer stack to fit. |
required |
n_images
|
int
|
Target number of decaying complex images. Sensible range 4–12; the returned \(P\) is one larger when the asymptote image is present, and may be smaller when the SVD truncates poles. |
8
|
n_samples
|
int
|
Number of samples drawn from Γ_1(λ). |
64
|
lambda_min_factor
|
float
|
Lower grid bound as a multiple of \(1/h_{\max}\). |
0.001
|
lambda_max_factor
|
float
|
Upper grid bound as a multiple of \(1/h_{\min}\) (an upper bound only — the step cap of item 1 above may stop the grid earlier). |
50.0
|
rms_tol
|
float
|
Error bound (dimensionless, \(|\Gamma_1| \le 1\)): the RMS
residual on the fitting grid, the RMS residual on the
verification grid and the maximum error on the verification
grid including \(\lambda = 0\) must not exceed it, otherwise the
fit counts as failed ( |
_DEFAULT_RMS_TOL
|
warn
|
bool
|
Set to |
True
|
Returns:
| Type | Description |
|---|---|
ComplexImageFit
|
|
Warns:
| Type | Description |
|---|---|
ComplexImageFitWarning
|
If |
Source code in src/groundfield/solver/cim.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 | |
ComplexImageFit
dataclass
¶
ComplexImageFit(a: ndarray, beta: ndarray, rms: float, k_inf: float = 0.0, rms_extrapolated: float = 0.0, converged: bool = True, max_error: float = 0.0)
Result of fit_complex_images().
The fit represents \(\Gamma_1(\lambda) \approx \sum_k a_k e^{-2 \lambda \beta_k}\). Index 0 is the analytic asymptote image (\(\beta_0 = 0\), \(a_0 \approx K_1\)) whenever the stack has one; the remaining entries are the decaying images recovered by the matrix pencil.
Attributes:
| Name | Type | Description |
|---|---|---|
a |
(ndarray, shape(P), complex)
|
Image weights \(a_k\). |
beta |
(ndarray, shape(P), complex)
|
Image depths \(\beta_k\) (units of metres). |
rms |
float
|
RMS of the residual \(|\text{fit} - \Gamma_1|\) on the sample
grid. Always finite: a failed fit reports the residual it
actually achieved (and warns) instead of |
k_inf |
float
|
The \(\lambda \to \infty\) asymptote
\(K_1 = (\rho_2 - \rho_1)/(\rho_2 + \rho_1)\) that the
\(\beta = 0\) image carries. |
rms_extrapolated |
float
|
RMS of the same residual on an independent log-spaced
verification grid covering the full requested
\(\lambda\) range. Larger than |
converged |
bool
|
Both residuals and |
max_error |
float
|
Maximum of \(|\text{fit} - \Gamma_1|\) over \(\lambda = 0\)
and the verification grid. The RMS values average a localised
miss away: between the uniform fitting samples the model can be
off by more than |
solve_bem ¶
Run the point-matching mom solver under the deprecated name bem.
Runs groundfield.solver.mom.solve_mom() (review pass 10,
10.76); bem assembled the identical point-matching system, see
the module docstring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world
|
World
|
World to evaluate. |
required |
engine
|
Engine
|
Engine configuration; |
required |
Returns:
| Type | Description |
|---|---|
FieldResult
|
The |
Warns:
| Type | Description |
|---|---|
DeprecationWarning
|
Always: use |
Source code in src/groundfield/solver/bem.py
solve_image_nlayer ¶
solve_image_nlayer(world: 'World', engine: 'Engine', *, max_terms: int | None = None, tol: float | None = None) -> FieldResult
Image-charge dispatcher for n-layer soil.
Routes to image for n = 1 and to image_2layer for
n = 2. For n \ge 3 raises a clear ValueError
pointing the caller to the engines that actually support that
regime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world
|
'World'
|
World whose soil is any layered soil model. |
required |
engine
|
'Engine'
|
Engine configuration; |
required |
max_terms
|
int | None
|
Series controls forwarded to |
None
|
tol
|
int | None
|
Series controls forwarded to |
None
|
Returns:
| Type | Description |
|---|---|
FieldResult
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If the soil is not a |
ValueError
|
If the world has no electrodes. |
BackendCapabilityError
|
If the soil has three or more layers (a |
Source code in src/groundfield/solver/image_nlayer.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
equivalent_hemisphere_radius ¶
Radius of the hemisphere with an electrode's closed-form resistance.
.. deprecated:: 2026.11
fem no longer reduces electrodes to a hemisphere (user decision
Q37); the function is kept for scripts that use the closed forms.
Compute \(a_\text{eq} = \rho/(2\pi R)\) from the formulas of
groundfield.references.dwight1936 instead. Removal no earlier
than 2027.5.
The hemisphere radius \(a_\text{eq} = \rho/(2\pi R)\) with \(R\) the
closed form of Dwight (1936) for a rod, a ring and a strip, Sverak's
formula for a GridMeshElectrode and one strip along the diagonal for
a MeshElectrode (the formulas of 0.15.0, unchanged, valid only for
shallow electrodes: a strip down to half its length, a ring down to
its diameter).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
electrode
|
'_ElectrodeBase'
|
Single electrode primitive. |
required |
rho_top
|
float
|
Resistivity in Ω·m used inside the formula. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Hemisphere radius \(a_\text{eq}\) in m. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the electrode is of a kind without a closed form here (a polyline or a star). |
Warns:
| Type | Description |
|---|---|
DeprecationWarning
|
On every call. |
Source code in src/groundfield/solver/fem/_legacy.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
Solver warnings¶
The warning categories of the solve. Each one can be filtered on its
own, e.g. warnings.simplefilter("ignore", ShallowSegmentWarning);
Warnings and errors explains what each one means and
what to do.
ShallowSegmentWarning ¶
Bases: UserWarning
A leakage segment is shallow compared with its own length.
The diagonal self-image entry of the reaction matrix uses the point image at distance \(2z\) instead of the image line of the segment, i.e. the \(L \ll 4 z\) limit
For \(L \gtrsim 4 z\) the point form overestimates that entry by
more than 13 % (and unboundedly as \(z \to 0\)), so the reported
grounding impedance is biased high and keeps moving under mesh
refinement. Typical triggers: a counterpoise or PEN conductor
discretised with segments much longer than its burial depth,
surface-near tapes, and rings or meshes whose arc/wire segments
are longer than four times the burial depth (a ring of radius
25 m at \(z = 0.8\) m with segment_length = 5 m gives 4.909 m
arc segments and warns "by 26 %") — the warning is not
restricted to distributed conductors.
Scope of the quantified bias
The percentage quoted in the message is the horizontal-segment
figure \(\bigl(L/(4z)\bigr)/\operatorname{arsinh}
\bigl(L/(4z)\bigr) - 1\). That is the applicable figure for every
segment that can still reach the warning: a segment inclined by
more than \(30°\) to the horizontal and satisfying \(L > 4 z\) would
have its upper end above \(z = 0\), which
_check_segment_depths() rejects with a ValueError first
(proof: \(L > 4 z\) together with \(L\,|e_z| \le 2 z\) forces
\(|e_z| < 1/2\)). The message states the inclination it assumed so
the reader can check that reasoning.
Emission scope
The bias belongs to the point form of the self image. The warning
is raised wherever a solve uses it: by the image family
(image, image_2layer; cim is an alias) with
kernel="point", and by the point-matching family (mom,
mom_sommerfeld; bem is an alias), whose self image is always
the point form. It is not raised for the exact line kernel
(kernel="line", the default of the image family since 2026.11),
whose Galerkin self image has no such bias: a 10 m strip at 0.1 m
depth gives 17.37863 Ω with 2 m segments and 17.37859 Ω with
0.25 m segments, where the point kernel gives 21.57 Ω and 17.23 Ω
(audit A1-numerics F08). solve_mutual_* assemble the same
reaction matrix without this advisory.
Silence with
warnings.simplefilter("ignore", ShallowSegmentWarning) once
the bias has been accepted, or refine
Engine.segment_length / Conductor.discretize_segment_length
until the impedance stabilises.
InterfaceContactWarning ¶
Bases: UserWarning
A wire lies too close to a layer interface for the thin-wire model.
The thin-wire model carries the current on the wire axis. Two limits follow next to a layer interface:
Rod ends (audit A3S-05). A rod head or tip within one wire radius of an interface: the thin wire has no end face, so a rod that ends exactly at the interface \(h_1\) is a wire entirely on one side of it, and a rod that reaches past the interface by a few micrometres touches the other layer only through a part much shorter than its radius. The solid rod with a flat end face is continuous in between: its end face carries the contact. Against an axisymmetric finite-volume model of the solid rod (4.5 m, \(a\) = 8 mm, 1000/30 Ω·m) the thin wire reads +21 % with its tip at the interface, +7 % 1 mm above it and −4.6 % 1 mm below it; beyond two radii it is within a few per cent, like anywhere else (+0.9 % in homogeneous soil). An end that meets the end of another rod has no free end face and is not reported.
Horizontal wires (audits W4A-07, W4B-02). A horizontal wire (every
electrode but a rod, and the leaking pieces of a galvanic distributed
conductor) whose axis lies within the reach wire_contact_reach()
of an interface: next to a more conductive layer the current crowds to
the wire's near side, which a current on the axis cannot follow. Against
the solid torus (the axisymmetric fem, confirmed by a Hankel thin
ring plus the exact 2-D proximity correction to 5.2e-4, to 2e-4 from two
radii on) a ring (a = 5 mm)
over a layer 33 times more conductive reads +0.59 % at 4 radii, +1.2 %
at 3, +3.6 % at 2, +8.6 % at 1.5 and +32 % at 1.1 radii, and +89 % when
the interface cuts the wire 0.99 radii below its axis; under a more
resistive layer up to +2.6 % (a 55 mm wire on a 1 m ring at 1.01
radii, contrast 1000). The reach is the largest distance at which the
thin wire (converged in its segment length) is 1 % off, in five ring
geometries (r0 / a = 18 ... 400: rings of 0.5 ... 5 m at 0.3 ... 2 m,
a = 5 ... 55 mm; the more conductive layer below the wire, for the 2 m
ring also above it; the more resistive layer below and above every
one; the thick wire on the 1 m ring is the widest everywhere), rounded
up to 0.1 a, plus 0.1 a for the contrasts between the nodes (the
conductive side from the thin wire at one segment length, its node at
1000 raised so that the converged distances lie inside; audits
W4R2A-04, W4R3A-02; up to W4R2A-04 four geometries, 0.2 ... 0.4 a short
of the thick wire; up to W4R3A-02 the resistive side measured above
the wire for the thin ring only, the thick wire 1 % off up to 0.74 a
beyond it):
====================== ===== ===== ===== ===== ===== ===== ===== ===== ===== contrast 1.4 2 3 5.5 10 18 33 100 1000 more conductive beyond 1.0 a 1.3 a 1.9 a 2.7 a 3.3 a 3.7 a 3.9 a 4.1 a 4.3 a ====================== ===== ===== ===== ===== ===== ===== ===== ===== =====
====================== ===== ===== ===== ===== ===== ===== contrast 1.4 3 10 33 100 1000 more resistive beyond 1.0 a 1.3 a 1.9 a 2.2 a 2.2 a 2.3 a ====================== ===== ===== ===== ===== ===== =====
(log-linear in the contrast between the nodes, held beyond the last
and at 1.0 a down to the contrast 1.3; 1.0 a: only a wire that the
interface cuts.) Checked against every distance measured at the nodes
and between them (conductive 1.3 ... 1.9, 2.5, 4, 7, 14, 25, 50, 300;
resistive 2, 5.5, 18, 300): no thin wire 1 % or more off lies outside
the reach (2348 conductive points at one segment length, the largest
outside +0.94 %; 2470 resistive points converged in it, +0.93 %). The
thick wire's conductive 1 % distances, converged in the segment length,
lie 0.004 ... 0.17 a inside the reach; the node at 1000 is 4.3 a (it
was 4.2) for the 4.15 a at 300. Below a contrast of 1.3 nothing is
reported: a cut wire reads at most +0.96 % off at 1.3 and +1.06 % at
1.35 (the thick wire cut 0.5 a below its axis by a more resistive layer
above it; up to audit W4R3A-02 the limit was 1.4, where it reads
+1.16 %, and up to W4R2A-04 2, where a wire cut at a contrast of 1.9
read -1.46 %). Pieces of a galvanic distributed
conductor count as horizontal while their slope |e_z| is at most
0.1 (5.7 deg): a steeper piece passes the reach of an interface over at
most 2 reach / |e_z| wire radii of its length, like a rod through an
interface, and is not reported (a step in reporting at the cutoff,
kept as documented). The image family, mom, mom_sommerfeld and
the three-dimensional fem share this limit (the 3-D model's smoothed
line source lies between the thin wire and the solid torus); the
axisymmetric fem resolves the wire and does not warn.
Remedy: keep rod ends and horizontal wires a few wire radii from a
contrasting interface; bracket a rod end by moving it by
\(\pm 2a\); check a ring with fem's axisymmetric model
(FemOptions.model="axisymmetric"), which solves the wire as the
solid torus it is.
PointKernelInterfaceWarning ¶
Bases: UserWarning
A horizontal segment lies close to a layer interface (point form).
The point form of the reaction matrix (kernel="point" of the image
family, the mom family and solve_mutual_* with the point kernel)
cannot represent a horizontal wire next to a layer interface, on either
side of it:
- on the cross-layer path of a two-layer soil (an electrode reaches the interface \(h_1\)) it averages the layered correction on the diagonal over a 3-point rule along the depth axis, \(\pm 0.387 L\) around the segment midpoint, whatever the segment's orientation;
- with every segment above \(h_1\) (the Tagg/Sunde series, and the
Sommerfeld diagonal of
mom_sommerfeld) it takes the image of a segment in the interface as a point source \(2|z - h_1|\) away, where the image line of a horizontal segment is much closer to the wire than that point (audit A3S-02).
A horizontal segment within \(0.6 L\) of \(h_1\) draws this
warning: measured −3 % … −17 % against the exact line kernel on the
cross-layer path (a 20 m strip and a ring r = 3 m in 300/50 and
100/1000 Ω·m), −2.5 % and −0.4 % above \(h_1\) (a ring r = 3 m,
segment_length = 0.5 m, 0.2 m above \(h_1\) = 5 m in 1000/30
and 30/1000 Ω·m). Closer still (\(|z - h_1| < 0.387 L\)), or where
the 3-point rule reaches above the soil surface, the solve raises
BackendCapabilityError instead
(negative impedances: −552 % on the cross-layer path; −1931 Ω instead
of 4.18 Ω for the ring 1 µm above \(h_1\)). The exact line kernel,
the default of the image family, integrates these segments exactly.
SeriesTruncationWarning ¶
Bases: UserWarning
The Tagg/Sunde image series hit max_terms before tol.
Emitted (in addition to the logger record) whenever a backend
truncates the two-layer image-charge series without reaching the
requested tail tolerance — typically at high layer contrast
(\(|K| \to 1\)). Silence with
warnings.simplefilter("ignore", SeriesTruncationWarning) or
raise Engine.image_max_terms.
SommerfeldConvergenceWarning ¶
Bases: UserWarning
The reflected-remainder quadrature did not reach epsrel.
Emitted (in addition to the logger record) whenever the grid
refinement ladder of _reflected_integral() exhausts all of
_REFINEMENTS without two successive grids agreeing within
max(epsabs, epsrel · |G|). The returned value is then not
converged, and because the integrand is oscillatory
(\(J_0(\lambda s)\)) a non-converged panel grid does not merely
lose digits — it can return a Green's function with the wrong
sign (the pre-0.15.0 failure mode of this backend, review-pass-9
finding F04). Up to 0.15.0 the same situation was only logged at
DEBUG level and the least accurate of the four grid values
was returned silently.
Two mechanisms reach this branch:
- Oscillation budget.
max_osc_panels(default 200 000, i.e.Engine.sommerfeld_max_osc_panels) bounds the half-period panel family \(\pi / s\) that resolves \(J_0(\lambda s)\) on \([0, 34 / d_{\text{rem}}]\). The budget binds when \(s / d_{\text{rem}} \gtrsim 1.9 \cdot 10^4\) — a centimetre-thin intermediate layer (\(d_{\text{rem}} = 2\min(h_1,h_2)\)) combined with a kilometre-scale horizontal separation. Remedy: raisemax_osc_panels(runtime and memory grow linearly with it). - Layer contrast. For \(|K_1| \to 1\) the multiple-reflection
multiplier \(1/(1 - \Gamma_1 e^{-2\lambda h_1})\) develops a
\(\lambda\)-scale \((1 - \Gamma_1(0)) / 2 h_1\) that the graded
base grid has to resolve. Since 0.15.0 a geometric panel family
covers that scale explicitly, which removed the historic
\(-12.9\,\%\) error at \(\rho_2/\rho_1 = 10^8\); if the
warning still appears here the contrast is outside the validated
envelope \(\rho_2/\rho_1 \in [10^{-2}, 10^{2}]\) and no knob
fixes it — use
image_2layer(exact geometric series) instead.
Silence with
warnings.simplefilter("ignore", SommerfeldConvergenceWarning)
only if the affected entries are known to be negligible.
ComplexImageFitWarning ¶
Bases: UserWarning
The complex-image fit of \(\Gamma_1(\lambda)\) is unreliable.
Emitted by fit_complex_images() when the RMS residual on the
sample grid or on the independent verification grid exceeds
rms_tol, or when the matrix pencil returned no usable pole for
a remainder that is not numerically flat. All three situations
mean the returned images do not represent \(\Gamma_1\) and must
not be fed into a Green's function.
Up to 0.14.1 the same situations were silent: the pole filters
(|p| < 0.999, Re β > 0) discarded the constant term that
carries the \(\lambda \to \infty\) asymptote \(K_1\), so the
residual was of order \(|K_1|\) for every stack, and a two-layer
stack (where that constant is the whole function) returned
P = 0 with rms = nan (review pass 9, F39).
A dedicated category lets callers opt in / out with
warnings.simplefilter("error", ComplexImageFitWarning).
FemReductionWarning ¶
Bases: UserWarning
The equivalent-hemisphere reduction did not represent the world.
Emitted by fem up to 2026.11, when it reduced every cluster to an
equivalent hemisphere. Since the conforming model (user decision Q37)
fem solves the electrodes as they are and never emits it; the class
is kept so that filters and pytest.warns written against it still
import.