Analysis routines¶
Higher-level analysis workflows that orchestrate repeated
run_fault calls and answer parametric questions about an existing
network — currently the inverse rho problem at the bus-grounding
side.
Physical / modelling context¶
A fully built Network solves a forward problem: given the bus
grounding impedances \(Z_{\text{B},i}(\rho_E, f)\), find the EPR at the
fault bus. The natural inverse question — "how poor can the soil
get before the EPR exceeds a touch-voltage limit \(u_{\max}\)?" — is
recurring in safety-engineering workflows: it sets the worst-case
specific earth resistance the network can tolerate while still
satisfying the relevant standard (e.g. EN 50522) at the assumed
fault current.
find_max_rho_scaling solves that problem by log-bisection over
a uniform scaling factor \(c\) of \(\rho_E\) on a user-supplied list of
selected buses. At every trial \(c\), the bus-grounding impedance is
re-evaluated through the bus's own BusType.impedance_formula and
run_fault is invoked. The bracket converges on the largest \(c\) for
which \(|U_\text{EPR}(f)|_{\text{RMS}} \le u_{\max}\) at the fault bus.
The sister routine find_max_rho_f_scaling (and the diagnostic helper
evaluate_max_epr_under_k) extend the same idea to a frequency-
dependent rho-f characteristic: rho is scaled while a separate
factor \(k\) tunes the imaginary, frequency-coupling part of the
formula, so the inverse problem can be posed against a parametric
rho-f curve rather than a single scalar.
The shape of the rho-f curve at each bus is controlled entirely by
the existing BusType.impedance_formula; the analysis routines only
vary the scalar factors, so any user-defined parametric form
(linear, square root, frequency-dependent, …) is supported
transparently. Original rho values are restored via a finally
block, so the network is left untouched even if the bisection fails.
Example¶
import groundinsight as gi
# Assume `net` is a built network with at least one fault and one
# source. Pick the buses whose specific_earth_resistance should be
# scaled jointly — typically all buses sharing a soil environment.
result = gi.find_max_rho_scaling(
network=net,
fault_name="fault1",
bus_names=["bus_substation", "bus_fault"],
u_max=200.0, # touch-voltage limit in volts (RMS)
c_bounds=(0.1, 100.0), # search bracket on the scaling factor
tol_rel=1e-3,
max_iter=40,
)
# `result` is a dict with keys: c_max, u_epr_rms_at_c_max,
# rho_max (per-bus dict), iterations.
print(f"c_max = {result['c_max']:.3f}")
print(f"EPR at c_max = {result['u_epr_rms_at_c_max']:.1f} V")
for bus, rho_max in result["rho_max"].items():
print(f" {bus}: rho_max = {rho_max:.0f} Ω·m")
print(f"converged in {result['iterations']} iterations")
For the rho-f variant — useful when the bus impedance carries a
frequency-coupling term whose magnitude should also be probed —
see :func:find_max_rho_f_scaling.
API reference¶
analysis ¶
Analysis subpackage.
Contains higher-level analysis routines on top of :mod:network_operations,
such as inverse problems for the bus-grounding rho-f characteristic. These
functions assume that the network is already fully built (buses, branches,
faults, sources, paths) and orchestrate repeated :func:run_fault calls.
evaluate_max_epr_under_k ¶
evaluate_max_epr_under_k(
network: Network,
bus_names: List[str],
k: KVector,
*,
fault_scalings: Optional[Dict[float, float]] = None,
run_fault_kwargs: Optional[Dict[str, Any]] = None
) -> Dict[str, float]
Evaluate the RMS EPR at each selected bus for a given k vector.
For every name in bus_names the bus grounding impedance is
overwritten with the rho-f linear form Z(rho, f) = k1*rho +
(k2+jk3)*f + (k4+jk5)*rho*f -- using the bus' own
:attr:Bus.specific_earth_resistance for rho -- and the bus is
swept as the active fault: an existing fault at that bus is reused,
otherwise a temporary one is created with fault_scalings (or
1.0 at every simulation frequency by default) and removed at the
end. The original bus impedances, the temporary faults and the
previous active_fault are restored in a finally block, so the
network is left exactly as it was on entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
The simulation network. Sources, branches, paths and the buses to be swept must already be configured. |
required |
bus_names
|
List[str]
|
Buses whose impedance is rewritten and which are
swept as fault locations one by one. Must be non-empty and
refer to buses in |
required |
k
|
KVector
|
5-tuple |
required |
fault_scalings
|
Optional[Dict[float, float]]
|
Frequency-resolved scalings used for any fault
that has to be created on the fly (no pre-existing fault at
the swept bus). Defaults to |
None
|
run_fault_kwargs
|
Optional[Dict[str, Any]]
|
Extra keyword arguments forwarded to
:func: |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, float]
|
Dict mapping each |
Dict[str, float]
|
bus when it is the active fault. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/groundinsight/analysis/inverse_rho_f.py
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 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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
find_max_rho_f_scaling ¶
find_max_rho_f_scaling(
network: Network,
bus_names: List[str],
u_limit: float,
k_ref: KVector,
*,
c_bounds: Tuple[float, float] = (0.001, 1000.0),
tol_rel: float = 0.001,
max_iter: int = 60,
fault_scalings: Optional[Dict[float, float]] = None,
run_fault_kwargs: Optional[Dict[str, Any]] = None
) -> Dict[str, Any]
Find the largest scaling factor c of a reference k-vector.
Performs a log-scale bisection on c so that k = c * k_ref
yields a maximum RMS EPR (across all buses swept as faults) that is
at or below u_limit. k_ref is typically a fit produced by
:func:groundmeas.services.analytics.rho_f_model from measured
impedance points; this function answers how much head-room the
network has around that characteristic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
The simulation network. Buses, branches, sources and paths must already be configured. |
required |
bus_names
|
List[str]
|
Buses whose impedance is parameterised by |
required |
u_limit
|
float
|
Upper bound on the RMS EPR (in volts) at any swept bus. Must be strictly positive. |
required |
k_ref
|
KVector
|
Reference 5-tuple |
required |
c_bounds
|
Tuple[float, float]
|
Search interval for |
(0.001, 1000.0)
|
tol_rel
|
float
|
Bisection tolerance on the relative bracket width
|
0.001
|
max_iter
|
int
|
Hard cap on bisection steps. Defaults to |
60
|
fault_scalings
|
Optional[Dict[float, float]]
|
See :func: |
None
|
run_fault_kwargs
|
Optional[Dict[str, Any]]
|
Forwarded to :func: |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict with keys |
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
For invalid input or if |
Examples:
>>> import groundinsight as gi
>>> from groundinsight.models.core_models import BusType, BranchType
>>> from groundinsight.analysis import find_max_rho_f_scaling
>>> bt = BusType(name="BT", system_type="Grounded",
... voltage_level=20.0,
... impedance_formula="rho * 0.01 + 0*f")
>>> brt = BranchType(name="BRT", grounding_conductor=True,
... self_impedance_formula="(0.25 + I*0.6)*l",
... mutual_impedance_formula="(0.0 + I*0.6)*l")
>>> net = gi.create_network(name="N", frequencies=[50])
>>> _ = gi.create_bus(name="b0", type=bt, network=net)
>>> _ = gi.create_bus(name="b1", type=bt, network=net)
>>> _ = gi.create_branch(name="br", type=brt, from_bus="b0",
... to_bus="b1", length=1.0, network=net)
>>> _ = gi.create_source(name="src", bus="b0",
... values={50: 100.0}, network=net)
>>> # k_ref reproducing the original Z = 0.01*rho on b0/b1.
>>> res = find_max_rho_f_scaling(
... net, ["b0", "b1"], u_limit=200.0,
... k_ref=(0.01, 0.0, 0.0, 0.0, 0.0),
... )
>>> isinstance(res["c_max"], float)
True
Source code in src/groundinsight/analysis/inverse_rho_f.py
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 | |
find_max_rho_scaling ¶
find_max_rho_scaling(
network: Network,
fault_name: str,
bus_names: List[str],
u_max: float,
*,
c_bounds: Tuple[float, float] = (0.001, 1000.0),
tol_rel: float = 0.001,
max_iter: int = 60,
run_fault_kwargs: Dict[str, Any] = None
) -> Dict[str, Any]
Find the largest uniform rho-scaling factor compatible with an EPR limit.
Bisects the scalar c such that scaling every selected bus' specific
earth resistance to c * rho_0 yields an RMS earth potential rise at
the fault bus that just satisfies |u_EPR|_rms <= u_max. The bus
impedance formula is re-evaluated through the existing
:meth:Bus.calculate_impedance machinery, so any user-defined rho-f
characteristic is honoured.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
The simulation network. Must already contain the
named fault, the sources, the buses listed in |
required |
fault_name
|
str
|
Name of the fault to evaluate. Used as
|
required |
bus_names
|
List[str]
|
Names of the buses whose specific earth
resistance is uniformly scaled by the same factor |
required |
u_max
|
float
|
Upper bound on the RMS earth potential rise at the
fault bus, in volts. Must be strictly positive. The RMS is
taken over all simulation frequencies, matching
:attr: |
required |
c_bounds
|
Tuple[float, float]
|
Search interval for the
scaling factor |
(0.001, 1000.0)
|
tol_rel
|
float
|
Relative tolerance on the bracket width
|
0.001
|
max_iter
|
int
|
Hard cap on the number of bisection
steps. Defaults to |
60
|
run_fault_kwargs
|
Dict[str, Any]
|
Extra keyword
arguments forwarded to :func: |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary with keys
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import groundinsight as gi
>>> from groundinsight.models.core_models import BusType, BranchType
>>> from groundinsight.analysis import find_max_rho_scaling
>>> bt = BusType(name="BT", system_type="Grounded",
... voltage_level=20.0,
... impedance_formula="rho * 0.01 + I * f * 0")
>>> brt = BranchType(name="BRT", grounding_conductor=True,
... self_impedance_formula="(0.25 + I*0.6)*l",
... mutual_impedance_formula="(0.0 + I*0.6)*l")
>>> net = gi.create_network(name="N", frequencies=[50])
>>> _ = gi.create_bus(name="b0", type=bt, network=net)
>>> _ = gi.create_bus(name="b1", type=bt, network=net)
>>> _ = gi.create_branch(name="br", type=brt, from_bus="b0",
... to_bus="b1", length=1.0, network=net)
>>> _ = gi.create_source(name="src", bus="b0",
... values={50: 100.0}, network=net)
>>> _ = gi.create_fault(name="flt", bus="b1",
... scalings={50: 1.0}, network=net)
>>> res = find_max_rho_scaling(net, "flt", ["b0", "b1"],
... u_max=200.0)
>>> isinstance(res["c_max"], float)
True
Source code in src/groundinsight/analysis/inverse_rho.py
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 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 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 | |
select_rho_f_from_catalog ¶
select_rho_f_from_catalog(
network: Network,
bus_names: List[str],
u_limit: float,
candidates: Dict[str, KVector],
*,
fault_scalings: Optional[Dict[float, float]] = None,
run_fault_kwargs: Optional[Dict[str, Any]] = None,
sort_by: Literal[
"max_epr_asc", "max_epr_desc", "name"
] = "max_epr_asc"
) -> pl.DataFrame
Pick admissible rho-f characteristics from a user-provided catalog.
Evaluates every candidate k in the catalog with
:func:evaluate_max_epr_under_k and reports, per candidate, the
maximum RMS EPR observed across the bus sweep, the per-bus EPRs and
whether the candidate satisfies the limit u_limit. The catalog is
typically a hand-curated list of soil scenarios (e.g. dry sand, wet
clay, permafrost) or rho-f fits from previous measurements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
The simulation network. Sources, branches and the buses to be swept must already be configured. |
required |
bus_names
|
List[str]
|
Buses whose impedance is parameterised by every
candidate |
required |
u_limit
|
float
|
Upper bound on the RMS EPR (in volts) at any swept bus. Must be strictly positive. |
required |
candidates
|
Dict[str, KVector]
|
Mapping |
required |
fault_scalings
|
Optional[Dict[float, float]]
|
Frequency-resolved scalings for any fault that
has to be created on the fly. See
:func: |
None
|
run_fault_kwargs
|
Optional[Dict[str, Any]]
|
Forwarded to :func: |
None
|
sort_by
|
Literal['max_epr_asc', 'max_epr_desc', 'name']
|
How to sort the result rows.
|
'max_epr_asc'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
A Polars DataFrame with one row per candidate and the columns |
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import groundinsight as gi
>>> from groundinsight.models.core_models import BusType, BranchType
>>> from groundinsight.analysis import select_rho_f_from_catalog
>>> bt = BusType(name="BT", system_type="Grounded",
... voltage_level=20.0,
... impedance_formula="rho * 0.01 + 0*f")
>>> brt = BranchType(name="BRT", grounding_conductor=True,
... self_impedance_formula="(0.25 + I*0.6)*l",
... mutual_impedance_formula="(0.0 + I*0.6)*l")
>>> net = gi.create_network(name="N", frequencies=[50])
>>> _ = gi.create_bus(name="b0", type=bt, network=net)
>>> _ = gi.create_bus(name="b1", type=bt, network=net)
>>> _ = gi.create_branch(name="br", type=brt, from_bus="b0",
... to_bus="b1", length=1.0, network=net)
>>> _ = gi.create_source(name="src", bus="b0",
... values={50: 100.0}, network=net)
>>> catalog = {
... "low": (0.005, 0.0, 0.0, 0.0, 0.0),
... "med": (0.01, 0.0, 0.0, 0.0, 0.0),
... "high": (0.05, 0.0, 0.0, 0.0, 0.0),
... }
>>> df = select_rho_f_from_catalog(
... net, ["b0", "b1"], u_limit=20.0, candidates=catalog,
... )
>>> set(df.columns) >= {"name", "k1", "max_epr_rms_V", "admissible"}
True
Source code in src/groundinsight/analysis/inverse_rho_f.py
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 | |