loop-interpolation 0.1.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/PKG-INFO +3 -1
  2. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/pyproject.toml +2 -1
  3. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/__init__.py +11 -0
  4. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/_constant_norm.py +7 -1
  5. loop_interpolation-0.3.0/src/loop_interpolation/_diagnostics.py +315 -0
  6. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/_discrete_fold_interpolator.py +17 -7
  7. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/_discrete_interpolator.py +250 -18
  8. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/_fd_fold_interpolator.py +22 -12
  9. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/_finite_difference_interpolator.py +52 -19
  10. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/_fold_norm_alignment.py +5 -1
  11. loop_interpolation-0.3.0/src/loop_interpolation/_fold_setup.py +99 -0
  12. loop_interpolation-0.3.0/src/loop_interpolation/_frame_persistence.py +489 -0
  13. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/_geological_interpolator.py +304 -9
  14. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/_interpolator_builder.py +16 -4
  15. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/_interpolator_factory.py +79 -2
  16. loop_interpolation-0.3.0/src/loop_interpolation/_native.py +595 -0
  17. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/_p2_fold_interpolator.py +22 -6
  18. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/_p2interpolator.py +35 -20
  19. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/_solver_pipeline.py +70 -0
  20. loop_interpolation-0.3.0/src/loop_interpolation/_solver_strategy.py +468 -0
  21. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation.egg-info/PKG-INFO +3 -1
  22. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation.egg-info/SOURCES.txt +11 -0
  23. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation.egg-info/requires.txt +3 -0
  24. loop_interpolation-0.3.0/tests/test_cg_position_tolerance.py +208 -0
  25. loop_interpolation-0.3.0/tests/test_cg_tolerances.py +28 -0
  26. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/tests/test_discrete_fold_interpolator.py +4 -3
  27. loop_interpolation-0.3.0/tests/test_native_errors.py +254 -0
  28. loop_interpolation-0.3.0/tests/test_native_inequality.py +345 -0
  29. loop_interpolation-0.3.0/tests/test_native_no_rows.py +263 -0
  30. loop_interpolation-0.3.0/tests/test_native_orthogonal_and_limits.py +92 -0
  31. loop_interpolation-0.3.0/tests/test_native_parity.py +344 -0
  32. loop_interpolation-0.3.0/tests/test_native_warm_start_ridge.py +116 -0
  33. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/tests/test_p0_surfe_nans.py +1 -1
  34. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/tests/test_p2_fold_interpolator.py +23 -14
  35. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/tests/test_quadrature.py +3 -8
  36. loop_interpolation-0.3.0/tests/test_residual_exclusion_report.py +233 -0
  37. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/tests/test_solver_pipeline.py +39 -0
  38. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/tests/test_solver_strategy.py +68 -0
  39. loop_interpolation-0.1.0/src/loop_interpolation/_diagnostics.py +0 -102
  40. loop_interpolation-0.1.0/src/loop_interpolation/_fold_setup.py +0 -39
  41. loop_interpolation-0.1.0/src/loop_interpolation/_solver_strategy.py +0 -225
  42. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/LICENSE +0 -0
  43. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/README.md +0 -0
  44. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/setup.cfg +0 -0
  45. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/_builders.py +0 -0
  46. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/_fold_event.py +0 -0
  47. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/_interpolatortype.py +0 -0
  48. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/_operator.py +0 -0
  49. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/_p1interpolator.py +0 -0
  50. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/_quadrature.py +0 -0
  51. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/_regularisation.py +0 -0
  52. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/_surfe_wrapper.py +0 -0
  53. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/_svariogram.py +0 -0
  54. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/_validation.py +0 -0
  55. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/constraints.py +0 -0
  56. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/fold_function/__init__.py +0 -0
  57. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/fold_function/_base_fold_rotation_angle.py +0 -0
  58. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/fold_function/_fourier_series_fold_rotation_angle.py +0 -0
  59. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/fold_function/_lambda_fold_rotation_angle.py +0 -0
  60. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/loopsolver/__init__.py +0 -0
  61. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/loopsolver/admm_constant_norm.py +0 -0
  62. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/loopsolver/admm_method.py +0 -0
  63. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation/loopsolver/admm_solver.py +0 -0
  64. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation.egg-info/dependency_links.txt +0 -0
  65. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/src/loop_interpolation.egg-info/top_level.txt +0 -0
  66. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/tests/test_admm_matrix_free.py +0 -0
  67. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/tests/test_constraint_diagnostics_report.py +0 -0
  68. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/tests/test_constraints.py +0 -0
  69. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/tests/test_discrete_interpolator.py +0 -0
  70. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/tests/test_fd_fold_interpolator.py +0 -0
  71. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/tests/test_fdi_matrix_free_regularisation.py +0 -0
  72. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/tests/test_geological_interpolator.py +0 -0
  73. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/tests/test_import.py +0 -0
  74. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/tests/test_input_validation.py +0 -0
  75. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/tests/test_interpolator_builder.py +0 -0
  76. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/tests/test_normal_magnitude_interpolators.py +0 -0
  77. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/tests/test_p0_nan_constraints_skipped.py +0 -0
  78. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/tests/test_p2_fold_registration.py +0 -0
  79. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/tests/test_p2_interpolator.py +0 -0
  80. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/tests/test_rectilinear_interpolator.py +0 -0
  81. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/tests/test_regularisation_api.py +0 -0
  82. {loop_interpolation-0.1.0 → loop_interpolation-0.3.0}/tests/test_surfe_rbf_interpolator.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: loop-interpolation
3
- Version: 0.1.0
3
+ Version: 0.3.0
4
4
  Summary: Interpolation utilities for LoopStructural
5
5
  Author-email: Lachlan Grose <lachlan.grose@monash.edu>
6
6
  License: MIT
@@ -24,6 +24,8 @@ Requires-Dist: scipy
24
24
  Requires-Dist: pydantic
25
25
  Provides-Extra: tests
26
26
  Requires-Dist: pytest; extra == "tests"
27
+ Provides-Extra: native
28
+ Requires-Dist: loop-interpolation-core; extra == "native"
27
29
  Dynamic: license-file
28
30
 
29
31
  # loop-interpolation
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
5
5
  [project]
6
6
  name = "loop-interpolation"
7
7
  description = "Interpolation utilities for LoopStructural"
8
- version = "0.1.0"
8
+ version = "0.3.0"
9
9
  requires-python = ">=3.9"
10
10
  authors = [{ name = "Lachlan Grose", email = "lachlan.grose@monash.edu" }]
11
11
  readme = "README.md"
@@ -27,6 +27,7 @@ dependencies = ["loop-common", "numpy", "scipy", "pydantic"]
27
27
 
28
28
  [project.optional-dependencies]
29
29
  tests = ["pytest"]
30
+ native = ["loop-interpolation-core"]
30
31
 
31
32
  [tool.setuptools.packages.find]
32
33
  where = ["src"]
@@ -13,12 +13,14 @@ __all__ = [
13
13
  "DirectionalRegularisation",
14
14
  "DiscreteFoldInterpolator",
15
15
  "DiscreteInterpolator",
16
+ "ExclusionRecord",
16
17
  "FDFoldInterpolator",
17
18
  "FiniteDifferenceInterpolator",
18
19
  "FoldEvent",
19
20
  "FoldRotationType",
20
21
  "FourierSeriesFoldRotationAngleProfile",
21
22
  "GeologicalInterpolator",
23
+ "InterpolatorFormatError",
22
24
  "InterpolatorType",
23
25
  "LambdaFoldRotationAngleProfile",
24
26
  "P1Interpolator",
@@ -30,11 +32,15 @@ __all__ = [
30
32
  "PiecewiseLinearInterpolator",
31
33
  "RegionCoverageDiagnostics",
32
34
  "RegularisationConfig",
35
+ "ResidualSummary",
36
+ "StaleFrameError",
33
37
  "StructuredGrid",
34
38
  "StructuredGrid2D",
35
39
  "SurfeRBFInterpolator",
36
40
  "TetMesh",
37
41
  "UnStructuredTetMesh",
42
+ "build_exclusion_records",
43
+ "direction_cosines",
38
44
  "get_fold_rotation_profile",
39
45
  ]
40
46
  from loop_common.logging import get_logger as getLogger
@@ -58,7 +64,11 @@ from ._constant_norm import ConstantNormFDIInterpolator, ConstantNormP1Interpola
58
64
  from ._diagnostics import (
59
65
  ConstraintDiagnosticsReport,
60
66
  ConstraintFamilyDiagnostics,
67
+ ExclusionRecord,
61
68
  RegionCoverageDiagnostics,
69
+ ResidualSummary,
70
+ build_exclusion_records,
71
+ direction_cosines,
62
72
  )
63
73
  from ._discrete_fold_interpolator import (
64
74
  DiscreteFoldInterpolator,
@@ -68,6 +78,7 @@ from ._fd_fold_interpolator import FDFoldInterpolator
68
78
  from ._finite_difference_interpolator import (
69
79
  FiniteDifferenceInterpolator,
70
80
  )
81
+ from ._frame_persistence import InterpolatorFormatError, StaleFrameError
71
82
  from ._geological_interpolator import GeologicalInterpolator
72
83
  from ._p1interpolator import P1Interpolator
73
84
  from ._p1interpolator import (
@@ -81,7 +81,13 @@ class ConstantNormInterpolator:
81
81
  np.hstack([self.support.barycentre[element_indices], v_t])
82
82
  )
83
83
  A1 = np.einsum("ij,ijk->ik", v_t, t_g)
84
- volume = self.support.element_size[element_indices]
84
+ # A structured grid gives one size for all elements.
85
+ element_size = np.asarray(self.support.element_size, dtype=float)
86
+ volume = (
87
+ element_size[element_indices]
88
+ if element_size.ndim > 0
89
+ else np.full(element_indices.shape[0], float(element_size))
90
+ )
85
91
  A1 = A1 / volume[:, np.newaxis] # normalise by element size
86
92
 
87
93
  b = np.zeros(A1.shape[0]) + self.norm_length
@@ -0,0 +1,315 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import asdict, dataclass, field
4
+
5
+ import numpy as np
6
+
7
+ EXCLUSION_EXPLANATIONS: dict[str, str] = {
8
+ "invalid_reference_value": "The reference value of the point is not a finite number.",
9
+ "invalid_reference_direction": "The reference direction of the point is zero or not finite.",
10
+ "evaluation_error": "The model could not be evaluated at the point.",
11
+ "outside_model": "The point is outside the model bounds. The count is in points.",
12
+ "unattributed": "The rows were dropped for an unknown reason. The count is in matrix rows.",
13
+ }
14
+ UNKNOWN_EXPLANATION = "No explanation is registered for this reason."
15
+
16
+
17
+ @dataclass(frozen=True)
18
+ class ConstraintFamilyDiagnostics:
19
+ name: str
20
+ active: bool
21
+ row_count: int
22
+ dropped_rows: int | None
23
+ effective_weight_mean: float | None
24
+ effective_weight_min: float | None
25
+ effective_weight_max: float | None
26
+ source_point_count: int = 0
27
+ outside_model_point_count: int = 0
28
+
29
+
30
+ @dataclass(frozen=True)
31
+ class RegionCoverageDiagnostics:
32
+ total_support_nodes: int
33
+ active_region_nodes: int
34
+ inactive_region_nodes: int
35
+ active_fraction: float
36
+
37
+
38
+ @dataclass(frozen=True)
39
+ class ResidualSummary:
40
+ """Statistics of the residuals of one constraint family.
41
+
42
+ Attributes
43
+ ----------
44
+ name : str
45
+ Name of the residual set.
46
+ kind : str
47
+ Either ``"physical"`` or ``"assembled"``.
48
+ unit : str
49
+ One of ``"field"``, ``"degree"`` or ``"assembled"``.
50
+ count : int
51
+ Number of finite residuals.
52
+ nan_count : int
53
+ Number of residuals that are not finite.
54
+ rms : float or None
55
+ Root mean square of the finite residuals. None when ``count`` is 0.
56
+ max_abs : float or None
57
+ Largest absolute finite residual. None when ``count`` is 0.
58
+ mean_abs : float or None
59
+ Mean absolute finite residual. None when ``count`` is 0.
60
+ """
61
+
62
+ name: str
63
+ kind: str
64
+ unit: str
65
+ count: int
66
+ nan_count: int
67
+ rms: float | None
68
+ max_abs: float | None
69
+ mean_abs: float | None
70
+
71
+
72
+ @dataclass(frozen=True)
73
+ class ExclusionRecord:
74
+ """One reason why rows or points were excluded.
75
+
76
+ Attributes
77
+ ----------
78
+ family : str
79
+ Name of the constraint family.
80
+ reason : str
81
+ Short key of the reason.
82
+ count : int
83
+ Number of excluded items.
84
+ explanation : str
85
+ One sentence that explains the reason.
86
+ """
87
+
88
+ family: str
89
+ reason: str
90
+ count: int
91
+ explanation: str
92
+
93
+
94
+ def summarise_residuals(name: str, kind: str, unit: str, residuals: np.ndarray) -> ResidualSummary:
95
+ """Summarise a set of residuals.
96
+
97
+ Parameters
98
+ ----------
99
+ name : str
100
+ Name of the residual set.
101
+ kind : str
102
+ Either ``"physical"`` or ``"assembled"``.
103
+ unit : str
104
+ One of ``"field"``, ``"degree"`` or ``"assembled"``.
105
+ residuals : numpy.ndarray
106
+ The residuals. The array is flattened and is not changed.
107
+
108
+ Returns
109
+ -------
110
+ ResidualSummary
111
+ Statistics of the finite residuals. Values that are not finite
112
+ are only counted.
113
+ """
114
+ flat = np.asarray(residuals, dtype=float).ravel()
115
+ finite = flat[np.isfinite(flat)]
116
+ nan_count = int(flat.size - finite.size)
117
+ if finite.size == 0:
118
+ return ResidualSummary(name, kind, unit, 0, nan_count, None, None, None)
119
+ absolute = np.abs(finite)
120
+ return ResidualSummary(
121
+ name=name,
122
+ kind=kind,
123
+ unit=unit,
124
+ count=int(finite.size),
125
+ nan_count=nan_count,
126
+ rms=float(np.sqrt(np.mean(finite**2))),
127
+ max_abs=float(np.max(absolute)),
128
+ mean_abs=float(np.mean(absolute)),
129
+ )
130
+
131
+
132
+ def direction_cosines(model_vectors: np.ndarray, data_vectors: np.ndarray) -> np.ndarray:
133
+ """Compute the cosine of the angle between paired vectors.
134
+
135
+ Parameters
136
+ ----------
137
+ model_vectors : numpy.ndarray
138
+ Array of shape (n, d).
139
+ data_vectors : numpy.ndarray
140
+ Array of shape (n, d).
141
+
142
+ Returns
143
+ -------
144
+ numpy.ndarray
145
+ Array of shape (n,). A row with a zero or not finite norm gives NaN.
146
+
147
+ Raises
148
+ ------
149
+ ValueError
150
+ If the two arrays do not have the same shape.
151
+ """
152
+ model = np.asarray(model_vectors, dtype=float)
153
+ data = np.asarray(data_vectors, dtype=float)
154
+ if model.shape != data.shape:
155
+ raise ValueError(f"Shape mismatch: model vectors {model.shape}, data vectors {data.shape}.")
156
+ model_norm = np.linalg.norm(model, axis=-1)
157
+ data_norm = np.linalg.norm(data, axis=-1)
158
+ valid = np.isfinite(model_norm) & np.isfinite(data_norm) & (model_norm > 0) & (data_norm > 0)
159
+ result = np.full(model_norm.shape, np.nan)
160
+ dot = np.sum(model * data, axis=-1)
161
+ result[valid] = dot[valid] / (model_norm[valid] * data_norm[valid])
162
+ return result
163
+
164
+
165
+ def build_exclusion_records(
166
+ excluded_rows: dict[str, dict[str, int]],
167
+ families: dict[str, ConstraintFamilyDiagnostics],
168
+ rows_per_point: dict[str, int] | None = None,
169
+ ) -> tuple[ExclusionRecord, ...]:
170
+ """Build the records of excluded rows and points.
171
+
172
+ Parameters
173
+ ----------
174
+ excluded_rows : dict
175
+ Maps a family name to a dict of reason and count.
176
+ families : dict
177
+ Maps a family name to its diagnostics.
178
+ rows_per_point : dict, optional
179
+ Number of matrix rows that one point makes, for each family.
180
+ The default is 1 for each family.
181
+
182
+ Returns
183
+ -------
184
+ tuple of ExclusionRecord
185
+ Records sorted by family and reason. A count of 0 makes no record.
186
+ """
187
+ rows_per_point = rows_per_point or {}
188
+ records = []
189
+
190
+ def add(family: str, reason: str, count: int) -> None:
191
+ """Add one record when the count is more than 0."""
192
+ if count > 0:
193
+ explanation = EXCLUSION_EXPLANATIONS.get(reason, UNKNOWN_EXPLANATION)
194
+ records.append(ExclusionRecord(family, reason, int(count), explanation))
195
+
196
+ for family, reasons in excluded_rows.items():
197
+ for reason, count in reasons.items():
198
+ add(family, reason, count)
199
+ for name, diagnostics in families.items():
200
+ outside = diagnostics.outside_model_point_count
201
+ add(name, "outside_model", outside)
202
+ if diagnostics.dropped_rows is not None:
203
+ k = rows_per_point.get(name, 1)
204
+ add(name, "unattributed", diagnostics.dropped_rows - outside * k)
205
+ return tuple(sorted(records, key=lambda r: (r.family, r.reason)))
206
+
207
+
208
+ @dataclass(frozen=True)
209
+ class ConstraintDiagnosticsReport:
210
+ interpolator_type: str
211
+ families: dict[str, ConstraintFamilyDiagnostics] = field(default_factory=dict)
212
+ region_coverage: RegionCoverageDiagnostics | None = None
213
+ outside_model_points: dict[str, int] = field(default_factory=dict)
214
+ physical_residuals: dict[str, ResidualSummary] = field(default_factory=dict)
215
+ assembled_residuals: dict[str, ResidualSummary] = field(default_factory=dict)
216
+ exclusions: tuple[ExclusionRecord, ...] = ()
217
+
218
+ @property
219
+ def total_rows(self) -> int:
220
+ return int(sum(f.row_count for f in self.families.values()))
221
+
222
+ @property
223
+ def active_families(self) -> dict[str, ConstraintFamilyDiagnostics]:
224
+ return {k: v for k, v in self.families.items() if v.active}
225
+
226
+ def to_dict(self) -> dict:
227
+ data = {
228
+ "interpolator_type": self.interpolator_type,
229
+ "total_rows": self.total_rows,
230
+ "families": {
231
+ name: {
232
+ "active": family.active,
233
+ "row_count": family.row_count,
234
+ "dropped_rows": family.dropped_rows,
235
+ "effective_weight_mean": family.effective_weight_mean,
236
+ "effective_weight_min": family.effective_weight_min,
237
+ "effective_weight_max": family.effective_weight_max,
238
+ "source_point_count": family.source_point_count,
239
+ "outside_model_point_count": family.outside_model_point_count,
240
+ }
241
+ for name, family in self.families.items()
242
+ },
243
+ "region_coverage": (
244
+ None
245
+ if self.region_coverage is None
246
+ else {
247
+ "total_support_nodes": self.region_coverage.total_support_nodes,
248
+ "active_region_nodes": self.region_coverage.active_region_nodes,
249
+ "inactive_region_nodes": self.region_coverage.inactive_region_nodes,
250
+ "active_fraction": self.region_coverage.active_fraction,
251
+ }
252
+ ),
253
+ "outside_model_points": dict(self.outside_model_points),
254
+ }
255
+ if self.physical_residuals:
256
+ data["physical_residuals"] = {
257
+ key: asdict(value) for key, value in self.physical_residuals.items()
258
+ }
259
+ if self.assembled_residuals:
260
+ data["assembled_residuals"] = {
261
+ key: asdict(value) for key, value in self.assembled_residuals.items()
262
+ }
263
+ if self.exclusions:
264
+ data["exclusions"] = [asdict(record) for record in self.exclusions]
265
+ return data
266
+
267
+ def summary(self) -> str:
268
+ lines = [
269
+ f"Constraint diagnostics for {self.interpolator_type}",
270
+ f"Total rows: {self.total_rows}",
271
+ "Active families:",
272
+ ]
273
+ active = self.active_families
274
+ if len(active) == 0:
275
+ lines.append(" - none")
276
+ for name, family in sorted(active.items()):
277
+ dropped = "unknown" if family.dropped_rows is None else str(family.dropped_rows)
278
+ mean_weight = (
279
+ "n/a"
280
+ if family.effective_weight_mean is None
281
+ else f"{family.effective_weight_mean:.4g}"
282
+ )
283
+ lines.append(
284
+ f" - {name}: rows={family.row_count}, dropped={dropped}, mean_weight={mean_weight}"
285
+ )
286
+
287
+ if self.region_coverage is not None:
288
+ lines.append(
289
+ "Region coverage: "
290
+ f"{self.region_coverage.active_region_nodes}/{self.region_coverage.total_support_nodes} "
291
+ f"({self.region_coverage.active_fraction:.1%})"
292
+ )
293
+
294
+ if len(self.outside_model_points) > 0:
295
+ lines.append("Outside-model points:")
296
+ for key, value in sorted(self.outside_model_points.items()):
297
+ lines.append(f" - {key}: {value}")
298
+
299
+ for title, block in (
300
+ ("Physical residuals:", self.physical_residuals),
301
+ ("Assembled residuals:", self.assembled_residuals),
302
+ ):
303
+ if block:
304
+ lines.append(title)
305
+ for key, item in sorted(block.items()):
306
+ lines.append(
307
+ f" - {key}: count={item.count}, nan={item.nan_count}, "
308
+ f"rms={item.rms}, max_abs={item.max_abs} ({item.unit})"
309
+ )
310
+ if self.exclusions:
311
+ lines.append("Exclusions:")
312
+ for record in self.exclusions:
313
+ lines.append(f" - {record.family}: {record.reason}={record.count}")
314
+
315
+ return "\n".join(lines)
@@ -10,7 +10,11 @@ from loop_common.logging import get_logger as getLogger
10
10
 
11
11
  from ._fold_event import FoldEvent
12
12
  from ._fold_norm_alignment import resolve_fold_norm_target
13
- from ._fold_setup import setup_with_fold_constraints
13
+ from ._fold_setup import (
14
+ sample_fold_geometry,
15
+ setup_with_fold_constraints,
16
+ world_norm_constraints,
17
+ )
14
18
  from ._interpolatortype import InterpolatorType
15
19
  from ._p1interpolator import P1Interpolator as PiecewiseLinearInterpolator
16
20
  from ._regularisation import DirectionalRegularisation
@@ -94,7 +98,7 @@ class DiscreteFoldInterpolator(PiecewiseLinearInterpolator):
94
98
  constraints (if present). ``warn`` logs only, ``correct`` flips
95
99
  the effective ``fold_norm`` sign, and ``none`` skips checks.
96
100
  mask_fn : callable, optional
97
- called with the element barycentres; elements for which it returns True get zero weight
101
+ called with the world element barycentres; elements for which it returns True get zero weight
98
102
 
99
103
 
100
104
  Returns
@@ -109,16 +113,20 @@ class DiscreteFoldInterpolator(PiecewiseLinearInterpolator):
109
113
  eg = self.support.get_element_gradients(np.arange(self.support.n_elements))
110
114
  # get array of all nodes for all elements N,4,3
111
115
  nodes = self.support.nodes[self.support.get_elements()[np.arange(self.support.n_elements)]]
112
- # calculate the fold geometry for the elements barycentre
113
- deformed_orientation, fold_axis, dgz = self.fold.get_deformed_orientation(
114
- self.support.barycentre
116
+ # the fold provider works in world coordinates, so sample it at the
117
+ # world barycentres and convert each direction to local coordinates
118
+ world_bc, deformed_w, axis_w, dgz_w = sample_fold_geometry(
119
+ self, self.fold, self.support.barycentre
115
120
  )
121
+ deformed_orientation = self.world_to_local_vectors(deformed_w)
122
+ fold_axis = self.world_to_local_vectors(axis_w)
123
+ dgz = self.world_to_local_vectors(dgz_w)
116
124
  # calculate element volume for weighting
117
125
  vecs = nodes[:, 1:, :] - nodes[:, 0, None, :]
118
126
  vol = np.abs(np.linalg.det(vecs)) / 6
119
127
  weight = np.ones(self.support.n_elements, dtype=float)
120
128
  if mask_fn is not None:
121
- weight[mask_fn(self.support.barycentre)] = 0
129
+ weight[mask_fn(world_bc)] = 0
122
130
  if fold_orientation is not None:
123
131
  """
124
132
  dot product between vector in deformed ori plane = 0
@@ -172,7 +180,7 @@ class DiscreteFoldInterpolator(PiecewiseLinearInterpolator):
172
180
 
173
181
  target_norm = resolve_fold_norm_target(
174
182
  fold=self.fold,
175
- normal_constraints=self.get_norm_constraints(),
183
+ normal_constraints=world_norm_constraints(self),
176
184
  fold_norm=fold_norm,
177
185
  dgz_alignment=dgz_alignment,
178
186
  logger=logger,
@@ -199,6 +207,8 @@ class DiscreteFoldInterpolator(PiecewiseLinearInterpolator):
199
207
  f"Adding fold regularisation constraint to w = {fold_regularisation[0]} {fold_regularisation[1]} {fold_regularisation[2]}"
200
208
  )
201
209
 
210
+ # the base method calls the provider with world points
211
+ # and converts the returned world vectors to local vectors
202
212
  def _masked_fold_direction(component_index: int):
203
213
  def _provider(points: np.ndarray) -> np.ndarray:
204
214
  deformed, axis, normal = self.fold.get_deformed_orientation(points)