loop-interpolation 0.0.1__py3-none-any.whl
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.
- loop_interpolation/__init__.py +152 -0
- loop_interpolation/_builders.py +149 -0
- loop_interpolation/_constant_norm.py +232 -0
- loop_interpolation/_diagnostics.py +102 -0
- loop_interpolation/_discrete_fold_interpolator.py +242 -0
- loop_interpolation/_discrete_interpolator.py +1405 -0
- loop_interpolation/_fd_fold_interpolator.py +237 -0
- loop_interpolation/_finite_difference_interpolator.py +1348 -0
- loop_interpolation/_fold_event.py +185 -0
- loop_interpolation/_fold_norm_alignment.py +118 -0
- loop_interpolation/_fold_setup.py +39 -0
- loop_interpolation/_geological_interpolator.py +920 -0
- loop_interpolation/_interpolator_builder.py +251 -0
- loop_interpolation/_interpolator_factory.py +167 -0
- loop_interpolation/_interpolatortype.py +20 -0
- loop_interpolation/_operator.py +44 -0
- loop_interpolation/_p1interpolator.py +299 -0
- loop_interpolation/_p2interpolator.py +317 -0
- loop_interpolation/_regularisation.py +110 -0
- loop_interpolation/_solver_pipeline.py +138 -0
- loop_interpolation/_solver_strategy.py +218 -0
- loop_interpolation/_surfe_wrapper.py +211 -0
- loop_interpolation/_svariogram.py +133 -0
- loop_interpolation/_validation.py +604 -0
- loop_interpolation/constraints.py +473 -0
- loop_interpolation/fold_function/__init__.py +39 -0
- loop_interpolation/fold_function/_base_fold_rotation_angle.py +219 -0
- loop_interpolation/fold_function/_fourier_series_fold_rotation_angle.py +131 -0
- loop_interpolation/fold_function/_lambda_fold_rotation_angle.py +53 -0
- loop_interpolation/loopsolver/__init__.py +2 -0
- loop_interpolation/loopsolver/admm_constant_norm.py +118 -0
- loop_interpolation/loopsolver/admm_method.py +25 -0
- loop_interpolation/loopsolver/admm_solver.py +463 -0
- loop_interpolation/loopsolver/version.py +1 -0
- loop_interpolation-0.0.1.dist-info/METADATA +34 -0
- loop_interpolation-0.0.1.dist-info/RECORD +39 -0
- loop_interpolation-0.0.1.dist-info/WHEEL +5 -0
- loop_interpolation-0.0.1.dist-info/licenses/LICENSE +21 -0
- loop_interpolation-0.0.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Piecewise linear interpolator using folds
|
|
3
|
+
"""
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from typing import Callable
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
from loop_common.logging import get_logger as getLogger
|
|
10
|
+
from loop_common.math import rng
|
|
11
|
+
|
|
12
|
+
from ._fold_event import FoldEvent
|
|
13
|
+
from ._fold_norm_alignment import resolve_fold_norm_target
|
|
14
|
+
from ._fold_setup import setup_with_fold_constraints
|
|
15
|
+
from ._interpolatortype import InterpolatorType
|
|
16
|
+
from ._p1interpolator import P1Interpolator as PiecewiseLinearInterpolator
|
|
17
|
+
from ._regularisation import DirectionalRegularisation
|
|
18
|
+
|
|
19
|
+
logger = getLogger(__name__)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class DiscreteFoldInterpolator(PiecewiseLinearInterpolator):
|
|
23
|
+
""" """
|
|
24
|
+
|
|
25
|
+
def __init__(self, support, fold: FoldEvent | None = None):
|
|
26
|
+
"""
|
|
27
|
+
A piecewise linear interpolator that can also use fold constraints defined in Laurent et al., 2016
|
|
28
|
+
|
|
29
|
+
Parameters
|
|
30
|
+
----------
|
|
31
|
+
support
|
|
32
|
+
discrete support with nodes and elements etc
|
|
33
|
+
fold FoldEvent
|
|
34
|
+
a fold event with a valid geometry
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
PiecewiseLinearInterpolator.__init__(self, support)
|
|
38
|
+
self.type = InterpolatorType.DISCRETE_FOLD
|
|
39
|
+
self.fold = fold
|
|
40
|
+
|
|
41
|
+
def update_fold(self, fold):
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
Parameters
|
|
45
|
+
----------
|
|
46
|
+
fold : FoldEvent
|
|
47
|
+
a fold that contrains the geometry we are trying to add
|
|
48
|
+
|
|
49
|
+
Returns
|
|
50
|
+
-------
|
|
51
|
+
|
|
52
|
+
"""
|
|
53
|
+
logger.error("updating fold, this should be done by accessing the fold attribute")
|
|
54
|
+
self.fold = fold
|
|
55
|
+
|
|
56
|
+
def setup_interpolator(self, **kwargs):
|
|
57
|
+
return setup_with_fold_constraints(
|
|
58
|
+
fold=self.fold,
|
|
59
|
+
kwargs=kwargs,
|
|
60
|
+
interpolator_name=self.__class__.__name__,
|
|
61
|
+
base_setup=super().setup_interpolator,
|
|
62
|
+
add_fold_constraints=self.add_fold_constraints,
|
|
63
|
+
finalize_report=self.finalize_setup_diagnostics_report,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
def add_fold_constraints(
|
|
67
|
+
self,
|
|
68
|
+
fold_orientation=10.0,
|
|
69
|
+
fold_axis_w=10.0,
|
|
70
|
+
fold_regularisation=(0.1, 0.01, 0.01),
|
|
71
|
+
fold_normalisation=1.0,
|
|
72
|
+
fold_norm=-1.0,
|
|
73
|
+
dgz_alignment="warn",
|
|
74
|
+
step=2,
|
|
75
|
+
mask_fn: Callable | None = None,
|
|
76
|
+
):
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
Parameters
|
|
80
|
+
----------
|
|
81
|
+
fold_orientation : double
|
|
82
|
+
weight for the fold direction/orientation in the least squares system
|
|
83
|
+
fold_axis_w : double
|
|
84
|
+
weight for the fold axis in the least squares system
|
|
85
|
+
fold_regularisation : list
|
|
86
|
+
weight for the fold regularisation in the least squares system
|
|
87
|
+
fold_normalisation : double
|
|
88
|
+
weight for the fold norm constraint in the least squares system
|
|
89
|
+
fold_norm
|
|
90
|
+
length of the interpolation norm in the least squares system
|
|
91
|
+
dgz_alignment : {"none", "warn", "correct"}
|
|
92
|
+
How to handle detected sign mismatch between ``dgz`` and normal
|
|
93
|
+
constraints (if present). ``warn`` logs only, ``correct`` flips
|
|
94
|
+
the effective ``fold_norm`` sign, and ``none`` skips checks.
|
|
95
|
+
step: int
|
|
96
|
+
array step for adding constraints
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
Returns
|
|
100
|
+
-------
|
|
101
|
+
|
|
102
|
+
Notes
|
|
103
|
+
-----
|
|
104
|
+
For more information about the fold weights see EPSL paper by Gautier Laurent 2016
|
|
105
|
+
|
|
106
|
+
"""
|
|
107
|
+
# get the gradient of all of the elements of the mesh
|
|
108
|
+
eg = self.support.get_element_gradients(np.arange(self.support.n_elements))
|
|
109
|
+
# get array of all nodes for all elements N,4,3
|
|
110
|
+
nodes = self.support.nodes[self.support.get_elements()[np.arange(self.support.n_elements)]]
|
|
111
|
+
# calculate the fold geometry for the elements barycentre
|
|
112
|
+
deformed_orientation, fold_axis, dgz = self.fold.get_deformed_orientation(
|
|
113
|
+
self.support.barycentre
|
|
114
|
+
)
|
|
115
|
+
element_idx = np.arange(self.support.n_elements)
|
|
116
|
+
rng.shuffle(element_idx)
|
|
117
|
+
# calculate element volume for weighting
|
|
118
|
+
vecs = nodes[:, 1:, :] - nodes[:, 0, None, :]
|
|
119
|
+
vol = np.abs(np.linalg.det(vecs)) / 6
|
|
120
|
+
weight = np.ones(self.support.n_elements, dtype=float)
|
|
121
|
+
if mask_fn is not None:
|
|
122
|
+
weight[mask_fn(self.support.barycentre)] = 0
|
|
123
|
+
if fold_orientation is not None:
|
|
124
|
+
"""
|
|
125
|
+
dot product between vector in deformed ori plane = 0
|
|
126
|
+
"""
|
|
127
|
+
rng.shuffle(element_idx)
|
|
128
|
+
|
|
129
|
+
logger.info(f"Adding fold orientation constraint to w = {fold_orientation}")
|
|
130
|
+
selected_idx = element_idx[::step]
|
|
131
|
+
A = np.einsum(
|
|
132
|
+
"ij,ijk->ik",
|
|
133
|
+
deformed_orientation[selected_idx, :],
|
|
134
|
+
eg[selected_idx, :, :],
|
|
135
|
+
)
|
|
136
|
+
A *= vol[selected_idx, None]
|
|
137
|
+
B = np.zeros(A.shape[0])
|
|
138
|
+
idc = self.support.get_elements()[selected_idx, :]
|
|
139
|
+
self.add_constraints_to_least_squares(
|
|
140
|
+
A,
|
|
141
|
+
B,
|
|
142
|
+
idc,
|
|
143
|
+
w=weight[selected_idx] * fold_orientation,
|
|
144
|
+
name="fold orientation",
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
if fold_axis_w is not None:
|
|
148
|
+
"""
|
|
149
|
+
dot product between axis and gradient should be 0
|
|
150
|
+
"""
|
|
151
|
+
rng.shuffle(element_idx)
|
|
152
|
+
|
|
153
|
+
logger.info(f"Adding fold axis constraint to w = {fold_axis_w}")
|
|
154
|
+
selected_idx = element_idx[::step]
|
|
155
|
+
A = np.einsum(
|
|
156
|
+
"ij,ijk->ik",
|
|
157
|
+
fold_axis[selected_idx, :],
|
|
158
|
+
eg[selected_idx, :, :],
|
|
159
|
+
)
|
|
160
|
+
A *= vol[selected_idx, None]
|
|
161
|
+
B = np.zeros(A.shape[0]).tolist()
|
|
162
|
+
idc = self.support.get_elements()[selected_idx, :]
|
|
163
|
+
|
|
164
|
+
self.add_constraints_to_least_squares(
|
|
165
|
+
A,
|
|
166
|
+
B,
|
|
167
|
+
idc,
|
|
168
|
+
w=weight[selected_idx] * fold_axis_w,
|
|
169
|
+
name="fold axis",
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
if fold_normalisation is not None:
|
|
173
|
+
"""
|
|
174
|
+
specify scalar norm in X direction
|
|
175
|
+
"""
|
|
176
|
+
rng.shuffle(element_idx)
|
|
177
|
+
|
|
178
|
+
logger.info(f"Adding fold normalisation constraint to w = {fold_normalisation}")
|
|
179
|
+
selected_idx = element_idx[::step]
|
|
180
|
+
A = np.einsum("ij,ijk->ik", dgz[selected_idx, :], eg[selected_idx, :, :])
|
|
181
|
+
A *= vol[selected_idx, None]
|
|
182
|
+
|
|
183
|
+
target_norm = resolve_fold_norm_target(
|
|
184
|
+
fold=self.fold,
|
|
185
|
+
normal_constraints=self.get_norm_constraints(),
|
|
186
|
+
fold_norm=fold_norm,
|
|
187
|
+
dgz_alignment=dgz_alignment,
|
|
188
|
+
logger=logger,
|
|
189
|
+
default_fold_norm=-1.0,
|
|
190
|
+
)
|
|
191
|
+
B = np.ones(A.shape[0]) * target_norm
|
|
192
|
+
B *= fold_normalisation
|
|
193
|
+
B *= vol[selected_idx]
|
|
194
|
+
idc = self.support.get_elements()[selected_idx, :]
|
|
195
|
+
|
|
196
|
+
self.add_constraints_to_least_squares(
|
|
197
|
+
A,
|
|
198
|
+
B,
|
|
199
|
+
idc,
|
|
200
|
+
w=weight[selected_idx] * fold_normalisation,
|
|
201
|
+
name="fold normalisation",
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
if fold_regularisation is not None:
|
|
205
|
+
"""
|
|
206
|
+
fold constant gradient
|
|
207
|
+
"""
|
|
208
|
+
logger.info(
|
|
209
|
+
f"Adding fold regularisation constraint to w = {fold_regularisation[0]} {fold_regularisation[1]} {fold_regularisation[2]}"
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
def _masked_fold_direction(component_index: int):
|
|
213
|
+
def _provider(points: np.ndarray) -> np.ndarray:
|
|
214
|
+
deformed, axis, normal = self.fold.get_deformed_orientation(points)
|
|
215
|
+
vectors = (normal, deformed, axis)[component_index]
|
|
216
|
+
if mask_fn is not None:
|
|
217
|
+
masked = np.asarray(vectors, dtype=float).copy()
|
|
218
|
+
masked[mask_fn(points)] = 0.0
|
|
219
|
+
return masked
|
|
220
|
+
return vectors
|
|
221
|
+
|
|
222
|
+
return _provider
|
|
223
|
+
|
|
224
|
+
self.add_directional_regularisation(
|
|
225
|
+
(
|
|
226
|
+
DirectionalRegularisation(
|
|
227
|
+
weight=fold_regularisation[0],
|
|
228
|
+
direction=_masked_fold_direction(0),
|
|
229
|
+
name="fold regularisation 1",
|
|
230
|
+
),
|
|
231
|
+
DirectionalRegularisation(
|
|
232
|
+
weight=fold_regularisation[1],
|
|
233
|
+
direction=_masked_fold_direction(1),
|
|
234
|
+
name="fold regularisation 2",
|
|
235
|
+
),
|
|
236
|
+
DirectionalRegularisation(
|
|
237
|
+
weight=fold_regularisation[2],
|
|
238
|
+
direction=_masked_fold_direction(2),
|
|
239
|
+
name="fold regularisation 3",
|
|
240
|
+
),
|
|
241
|
+
)
|
|
242
|
+
)
|