Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b17f265
feat(regions): pass a fault block to region checks
lachlangrose Nov 13, 2026
d1b1ddf
feat(features): evaluate a geological feature in one fault block
lachlangrose Nov 13, 2026
ba5143e
feat(fault): restore points in a fault block, frame and tip functions
lachlangrose Nov 13, 2026
5693e77
feat(model): add evaluate_feature_block_value and _gradient
lachlangrose Nov 13, 2026
a1fadcd
test(fault): block fields, fault frames and tip functions
lachlangrose Nov 13, 2026
e5160e5
docs(api): list the fault block methods as provisional
lachlangrose Nov 13, 2026
f65d046
test: move the small faulted models to tests/fixtures/fault_models.py
lachlangrose Nov 13, 2026
d1ecff2
fix(fault): apply_to_points honours reverse=True (LS-E2)
lachlangrose Nov 13, 2026
ed99913
fix(fault): restore a point through a displaced fault once (LS-E1)
lachlangrose Nov 13, 2026
bccb21f
fix(fault): restore_through keeps the plain apply_to_points(points) call
lachlangrose Nov 13, 2026
785c3a8
feat(model): add get_feature_relations (LS-D1)
lachlangrose Nov 13, 2026
cd1a2a6
feat(fault): declare the tip of a displacement profile (LS-C2)
lachlangrose Nov 13, 2026
e0f4f7c
fix(loop_interpolation): CG uses the library rtol when a tol is given…
lachlangrose Nov 13, 2026
8a078f4
perf(loop_common): find cell indexes in one vectorised step (LS-G2)
lachlangrose Nov 13, 2026
715847f
docs(api): list get_feature_relations, tip_ends and restored_through
lachlangrose Nov 13, 2026
36b2ba4
feat(loop_interpolation): add a cg stop in length units of the model …
lachlangrose Nov 15, 2026
31935f0
fix(model): an unconformity truncates the faults that are older than …
lachlangrose Nov 15, 2026
53e7396
docs(compat): list the double restoration fix for the release notes (…
lachlangrose Nov 15, 2026
57d70a0
feat(fault): continue the displacement of a block smoothly across its…
lachlangrose Nov 15, 2026
1a01a19
docs(api): list position_tolerance, the block continuation and the tr…
lachlangrose Nov 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,48 @@ exposed:
- `getLogger` itself is promoted to enforced-**stable** (see below) as
part of this work — its signature/behavior are unchanged, only
tracked by the registry now.
- Fault blocks: evaluation of a feature as it is in one fault block. A block
maps fault names to `+1` (hanging wall), `-1` (footwall) or `0` (absent);
each fault it names restores every point as if the point were on that side,
so the result has no jump across those faults. The block is an argument
only: no state changes, so calls with different blocks can run in parallel.
On the other side of its fault a block takes the smooth continuation of the
displacement profile of its side (C2 at the fault; exact up to 0.25 in gx,
constant beyond 0.5), not the mirror image; the module setting
`LoopStructural.utils._fault_block.BLOCK_EXTENSION = "mirror"` gives the
mirror image for comparisons. See
`tests/unit/modelling/test_fault_block_extension.py`.
- `GeologicalModel.evaluate_feature_block_value(feature_name, xyz, block, *, ignore_regions=True)` /
`GeologicalModel.evaluate_feature_block_gradient(...)`.
- `FaultSegment.evaluate_frame_value(points, coordinate=0, *, block=None)` /
`FaultSegment.evaluate_frame_gradient(...)` — one fault frame coordinate
without the fault regions, optionally in a block of the younger faults.
- `FaultSegment.evaluate_tip_value(points, *, block=None)` /
`FaultSegment.evaluate_tip_gradient(...)` — `min(1 - |g|)` over the
frame coordinates whose displacement profile is zero at `|g| = 1`.
- The keyword `block` on `GeologicalFeature.evaluate_value` /
`evaluate_gradient` and on `FaultSegment.apply_to_points` /
`evaluate_value` / `evaluate_displacement` (both unregistered; the
keyword is new and optional, so existing calls are unchanged).
- See `tests/unit/modelling/test_fault_block_fields.py`.
- `GeologicalModel.get_feature_relations()` — the relations of a model as a
plain dict (event order, displaced-by, abutment with side, truncation by
unconformities); reads the builders, same before and after `update()`.
- `FaultDisplacement.tip_ends` (property) and the `tip_ends` attribute of
the profiles — which frame coordinates carry a tip (unregistered).
- The keyword `restored_through` on `FaultSegment.apply_to_points` /
`apply_to_vectors` and `GeologicalFeature.evaluate_value` /
`evaluate_gradient` — faults the points have already been restored
through (a displaced fault is applied once; unregistered).
- `GeologicalModel.add_unconformity` truncates the faults that are older
than the unconformity (signature unchanged; the rule for "older" is in its
doc string and the changed results are in `COMPAT.md`). The keyword
`restored_through` is also on `UnconformityFeature.evaluate` / `__call__`.
- `GeologicalModel.position_tolerance` (attribute, default None), the keyword
`position_tolerance` of the `create_and_add_*` methods and of
`DiscreteInterpolator.solve_system` — a cg stop on an estimate of the
position error of the isosurfaces, in model length units (an estimate, not
a guarantee; unregistered).

## Known internal-path consumers

Expand Down
4 changes: 4 additions & 0 deletions COMPAT.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ unchanged, but the new path is preferred going forward.
| Known issue, not fixed in S6: the gradient of a model outside the support | Outside the support the FDI gradient is 0 and the PLI gradient is NaN. S6 test T095 pins this behavior (spec 005, stage S6) | 2026-11-06 |
| Known issue, not fixed in S6: `P2Interpolator.add_gradient_constraints` for a P2 foliation with gradient rows | It raises `ValueError`. This is a library defect. S6 does not change it (spec 005, stage S6) | 2026-11-06 |
| Known issue, not fixed in S6: `set_nelements` | It passes a cell count to the node setter. For example, `nelements=1000` gives 729 cells. This is old behavior, not a regression. S6 does not change it (spec 005, stage S6, S5 finding 3) | 2026-11-06 |
| **Changes model results.** `add_unconformity` did not truncate a fault that was already in the model: the fault kept its frame and its surface above the unconformity and moved points there. Only a fault created after the call took the region of the unconformity | `add_unconformity` truncates every fault that is older than the unconformity: the fault takes the region of the unconformity, so its frame and surface exist only below it and it moves no point above it. A fault is younger (not changed) if it displaces the series of the unconformity, or a series above an earlier unconformity. Models change where a fault is added before the call and is left out of the `faults` list of the series of the unconformity, or is added between that series and the call. Models without an unconformity, models whose faults all displace the series of the unconformity, and onlap unconformities do not change (kiridashi requirement LS-D2) | 2026-11-16 |
| **Changes model results.** A fault created after two or more unconformities took the region of the last one only | It takes the region of each erosional unconformity that is before it in the model (LS-D2) | 2026-11-16 |
| **Changes model results.** The unconformity region of a fault that a younger fault displaces was read at a point restored twice through the younger fault (the same error as the double restoration of a displaced fault) | The region is read at the point restored once, so the older fault ends on the unconformity in the space in which its frame is built. Models change where a fault is truncated by an unconformity, is displaced by a younger fault, and both faults displace a series. `UnconformityFeature.evaluate` and `__call__` have a new keyword `restored_through` (LS-D2) | 2026-11-16 |
| **Bug fix that changes model results.** A feature that a fault displaces was restored twice through a younger fault when the younger fault also displaces that fault: the frame of the older fault is built in the space restored by the younger fault, and its evaluation restored the point through the younger fault a second time. The side and the slip of the older fault were read at the wrong point (all versions up to 1.11.0) | Each point is restored once through each fault. There is no flag for the old behaviour. **Models change** where a fault displaces a feature and is itself displaced by a younger fault that also displaces that feature: the restored data and the evaluated field of that feature both change (in the test model by up to 0.059, for an offset of the older fault of 0.082). **Models without displaced faults do not change.** New keyword `restored_through` on `FaultSegment.apply_to_points` / `apply_to_vectors` and `GeologicalFeature.evaluate_value` / `evaluate_gradient`. `LambdaGeologicalFeature` and `AnalyticalGeologicalFeature` keep their own fault loops and are not changed (kiridashi requirement LS-E1) | 2026-11-16 |

The following stable methods remain part of the documented public API surface after the package extraction work and are covered by the snapshot-based contract test: add_onlap_unconformity, add_unconformity, create_and_add_domain_fault, create_and_add_fault, create_and_add_fold_frame, create_and_add_folded_fold_frame, create_and_add_folded_foliation, create_and_add_foliation, evaluate_model, evaluate_model_gradient, from_file, get_fault_surfaces, get_feature_by_name, get_stratigraphic_surfaces, rescale, save, scale.

Expand Down
6 changes: 2 additions & 4 deletions LoopStructural/modelling/core/_model_feature_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from ...modelling.features.fold import FoldEvent, FoldFrame
from ...modelling.intrusions import IntrusionBuilder, IntrusionFeature, IntrusionFrameBuilder
from ...utils import getLogger
from ._model_relationships import FeatureRelationshipManager

if TYPE_CHECKING:
from numpy.typing import ArrayLike
Expand Down Expand Up @@ -775,10 +776,7 @@ def build_fault(
fault.displacement = displacement_scaled
fault.faultfunction = faultfunction

for f in reversed(model.features):
if f.type == FeatureType.UNCONFORMITY:
fault.add_region(f)
break
FeatureRelationshipManager.add_unconformities_above_fault(model, fault, index=index)
if displacement == 0:
fault.type = FeatureType.INACTIVEFAULT
model._add_feature(fault, index=index)
Expand Down
230 changes: 230 additions & 0 deletions LoopStructural/modelling/core/_model_relationships.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,135 @@ def add_unconformity(
continue
else:
f.add_region(uc_feature)
# the faults that are older than the unconformity end on it
for f in list(model.features):
if f.type not in (FeatureType.FAULT, FeatureType.INACTIVEFAULT):
continue
if FeatureRelationshipManager.fault_is_older_than(model, f, feature):
FeatureRelationshipManager.truncate_fault(model, f, uc_feature)
# now add the unconformity to the feature list
model._add_feature(uc_feature, index=index)
return uc_feature

@staticmethod
def _displaced_by(feature: GeologicalFeature) -> list:
"""The faults that displace a feature (read from its builder)."""
builder = getattr(feature, "builder", None)
builders = getattr(builder, "builders", None)
if builders is not None:
# a structural frame: the three coordinates have the same faults
builder = builders[0]
faults = getattr(builder, "faults", None)
if faults is None:
faults = getattr(feature, "faults", [])
return list(faults)

@staticmethod
def fault_is_older_than(
model: GeologicalModel, fault: GeologicalFeature, feature: GeologicalFeature
) -> bool:
"""Whether a fault is older than the unconformity at the base of a feature.

Call it before the unconformity is added to the model.

The features of a model are in the order in which they were added,
and a new feature is displaced by every fault that the model has at
that moment, unless its ``faults`` argument gives another list. An
unconformity truncates the features that the model has back to the
last unconformity or domain fault; the features before that one lie
above an earlier unconformity and are younger. So the rule is:

A fault is **younger** than the unconformity if it displaces
``feature`` (the series whose isovalue is the unconformity), or a
feature that lies above an earlier unconformity. Every other fault
is **older**: a fault added after ``feature``, and a fault added
before it that the ``faults`` argument of ``feature`` leaves out.

Parameters
----------
model : GeologicalModel
fault : FaultSegment
feature : GeologicalFeature
the series that defines the unconformity

Returns
-------
bool
"""
displaced_by = FeatureRelationshipManager._displaced_by
if any(d is fault for d in displaced_by(feature)):
return False
# the features that this unconformity does not truncate: all that
# are before the last unconformity or domain fault
boundary = None
for i in reversed(range(len(model.features))):
if model.features[i].type in (FeatureType.UNCONFORMITY, FeatureType.DOMAINFAULT):
boundary = i
break
if boundary is None:
return True
skip = (
FeatureType.FAULT,
FeatureType.INACTIVEFAULT,
FeatureType.UNCONFORMITY,
FeatureType.ONLAPUNCONFORMITY,
)
for f in model.features[:boundary]:
if f.type not in skip and any(d is fault for d in displaced_by(f)):
return False
return True

@staticmethod
def truncate_fault(
model: GeologicalModel, fault: GeologicalFeature, unconformity: UnconformityFeature
) -> bool:
"""Limit a fault to the region below an unconformity.

The fault frame gets the region of the unconformity: the frame, the
fault surface and the displacement exist only where the series of
the unconformity is below its value. A point above the unconformity
is not moved by the fault, so the fault does not displace the
features above it. The features that the fault displaces are marked
to be built again.

Returns
-------
bool
False if the fault already has this region.
"""
for r in fault.regions:
if (
isinstance(r, UnconformityFeature)
and r.parent is unconformity.parent
and r.value == unconformity.value
and r.sign == unconformity.sign
):
return False
logger.info(f"Adding {unconformity.name} as unconformity to fault {fault.name}")
fault.add_region(unconformity)
for f in model.features:
if any(d is fault for d in FeatureRelationshipManager._displaced_by(f)):
builder = getattr(f, "builder", None)
if builder is not None:
builder.set_not_up_to_date(fault)
return True

@staticmethod
def add_unconformities_above_fault(
model: GeologicalModel, fault: GeologicalFeature, index: int | None = None
) -> None:
"""Truncate a new fault by the unconformities that are younger than it.

A fault that is added after an unconformity is older than it. The
fault takes the region of every erosional unconformity that is
before its place in the model (``index``, or the end of the list).
Onlap unconformities are not used.
"""
features = model.features if index is None else model.features[:index]
for f in reversed(features):
if f.type == FeatureType.UNCONFORMITY:
FeatureRelationshipManager.truncate_fault(model, fault, f)

@staticmethod
def add_onlap_unconformity(
model: GeologicalModel, feature: GeologicalFeature, value: float, index: int | None = None
Expand Down Expand Up @@ -216,3 +341,108 @@ def add_onlap_unconformity(
model._add_feature(uc_feature.inverse(), index=index)

return uc_feature

@staticmethod
def relations(model: GeologicalModel) -> dict:
"""Read the relations between the features of a model.

The relations are read from the builders, which hold them from the
moment a feature is created, so the result does not depend on whether
the model has been built. Nothing is changed.

Parameters
----------
model : GeologicalModel

Returns
-------
dict
``events``: the features in the order they were added
(``{"name", "type"}``, ``type`` a :class:`FeatureType` name). A
feature added later is older; an unconformity entry follows the
series that defines it.

``faults``: for each fault, ``displaced_by`` (the faults that
displace its frame, youngest first), ``abuts`` (``{"fault", "side"}``:
side +1 if the fault exists where the host gx > 0, -1 where it is
< 0), ``truncated_by`` (see below) and ``displacement``.

``features``: for each other feature that is not an unconformity,
``type``, ``faults`` (the faults that displace it, in restore
order: youngest first) and ``truncated_by``.

``unconformities``: for each unconformity, ``feature`` (the series
whose isovalue it is), ``value``, ``onlap`` and ``truncates`` (the
features and faults whose ``truncated_by`` names it).

A ``truncated_by`` entry is ``{"unconformity", "feature", "value",
"keep"}``: the feature exists only where ``feature`` is ``<= value``
(``keep == "below"``) or ``>= value`` (``"above"``).
"""
from ...modelling.features.fault import FaultSegment
from ...utils.regions import NegativeRegion, PositiveRegion

def faults_of(feature):
builder = getattr(feature, "builder", None)
faults = getattr(builder, "faults", None)
if faults is None:
faults = feature.faults
return [f.name for f in faults]

def truncations(regions):
out = []
for r in regions:
if isinstance(r, UnconformityFeature):
out.append(
{
"unconformity": r.name,
"feature": r.parent.name,
"value": float(r.value),
"keep": "below" if r.sign else "above",
}
)
return out

events, faults, features, unconformities = [], {}, {}, {}
for feature in model.features:
events.append({"name": feature.name, "type": FeatureType(feature.type).name})
if isinstance(feature, FaultSegment):
abuts = []
for host, region in feature.abut.items():
if isinstance(region, PositiveRegion):
side = 1
elif isinstance(region, NegativeRegion):
side = -1
else:
side = 0
abuts.append({"fault": host, "side": side})
faults[feature.name] = {
"displaced_by": faults_of(feature[0]),
"abuts": abuts,
"truncated_by": truncations(feature[0].regions),
"displacement": float(feature.displacement),
}
elif isinstance(feature, UnconformityFeature):
unconformities[feature.name] = {
"feature": feature.parent.name,
"value": float(feature.value),
"onlap": feature.type == FeatureType.ONLAPUNCONFORMITY,
"truncates": [],
}
else:
features[feature.name] = {
"type": FeatureType(feature.type).name,
"faults": faults_of(feature),
"truncated_by": truncations(feature.regions),
}
for name, entry in list(faults.items()) + list(features.items()):
for t in entry["truncated_by"]:
for u in unconformities.values():
if u["feature"] == t["feature"] and u["value"] == t["value"]:
u["truncates"].append(name)
return {
"events": events,
"faults": faults,
"features": features,
"unconformities": unconformities,
}
Loading
Loading