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,251 @@
|
|
|
1
|
+
"""Fluent builder for configuring interpolators.
|
|
2
|
+
|
|
3
|
+
This class intentionally stays thin: it delegates object creation to
|
|
4
|
+
InterpolatorFactory and provides a chainable API for adding constraints,
|
|
5
|
+
configuring setup options, and solving.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import numpy as np
|
|
10
|
+
from loop_common.geometry import BoundingBox
|
|
11
|
+
|
|
12
|
+
from ._interpolatortype import InterpolatorType
|
|
13
|
+
from ._interpolator_factory import InterpolatorFactory
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class InterpolatorBuilder:
|
|
17
|
+
def __init__(
|
|
18
|
+
self,
|
|
19
|
+
interpolatortype: str | InterpolatorType = InterpolatorType.FINITE_DIFFERENCE,
|
|
20
|
+
bounding_box: BoundingBox | None = None,
|
|
21
|
+
nelements: int | None = None,
|
|
22
|
+
buffer: float | None = None,
|
|
23
|
+
**kwargs,
|
|
24
|
+
):
|
|
25
|
+
"""This class helps initialise and setup a geological interpolator.
|
|
26
|
+
|
|
27
|
+
Parameters
|
|
28
|
+
----------
|
|
29
|
+
interpolatortype : Union[str, InterpolatorType]
|
|
30
|
+
type of interpolator
|
|
31
|
+
bounding_box : BoundingBox
|
|
32
|
+
bounding box of the area to interpolate
|
|
33
|
+
nelements : int, optional
|
|
34
|
+
degrees of freedom of the interpolator, by default 1000
|
|
35
|
+
buffer : float, optional
|
|
36
|
+
how much of a buffer around the bounding box should be used, by default 0.2
|
|
37
|
+
"""
|
|
38
|
+
self.interpolatortype = interpolatortype
|
|
39
|
+
if bounding_box is None:
|
|
40
|
+
bounding_box = BoundingBox()
|
|
41
|
+
self.bounding_box = bounding_box
|
|
42
|
+
self.nelements = nelements
|
|
43
|
+
self.buffer = buffer
|
|
44
|
+
self.solver = kwargs.pop("solver", None)
|
|
45
|
+
self.kwargs = kwargs
|
|
46
|
+
self.setup_kwargs = {}
|
|
47
|
+
self.solver_kwargs = {}
|
|
48
|
+
self.interpolator = InterpolatorFactory.create_interpolator(
|
|
49
|
+
interpolatortype=self.interpolatortype,
|
|
50
|
+
boundingbox=self.bounding_box,
|
|
51
|
+
nelements=self.nelements,
|
|
52
|
+
buffer=self.buffer,
|
|
53
|
+
solver=self.solver,
|
|
54
|
+
**self.kwargs,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
def use_solver(self, solver: str, **solver_kwargs) -> InterpolatorBuilder:
|
|
58
|
+
"""Configure the solver used when calling solve().
|
|
59
|
+
|
|
60
|
+
Parameters
|
|
61
|
+
----------
|
|
62
|
+
solver : str
|
|
63
|
+
Solver name, e.g. ``"cg"``, ``"lsmr"``, or ``"admm"``.
|
|
64
|
+
**solver_kwargs
|
|
65
|
+
Keyword arguments forwarded to ``solve_system``.
|
|
66
|
+
|
|
67
|
+
Returns
|
|
68
|
+
-------
|
|
69
|
+
InterpolatorBuilder
|
|
70
|
+
reference to the builder
|
|
71
|
+
"""
|
|
72
|
+
self.solver = solver
|
|
73
|
+
self.solver_kwargs = dict(solver_kwargs)
|
|
74
|
+
if self.interpolator is not None:
|
|
75
|
+
self.interpolator.solver = solver
|
|
76
|
+
return self
|
|
77
|
+
|
|
78
|
+
def solve(
|
|
79
|
+
self,
|
|
80
|
+
solver: str | None = None,
|
|
81
|
+
tol: float | None = None,
|
|
82
|
+
**solver_kwargs,
|
|
83
|
+
) -> InterpolatorBuilder:
|
|
84
|
+
"""Solve the configured interpolator system.
|
|
85
|
+
|
|
86
|
+
Parameters
|
|
87
|
+
----------
|
|
88
|
+
solver : Optional[str], optional
|
|
89
|
+
Override solver name for this call.
|
|
90
|
+
tol : Optional[float], optional
|
|
91
|
+
Optional solver tolerance.
|
|
92
|
+
**solver_kwargs
|
|
93
|
+
Additional arguments passed to ``solve_system``.
|
|
94
|
+
|
|
95
|
+
Returns
|
|
96
|
+
-------
|
|
97
|
+
InterpolatorBuilder
|
|
98
|
+
reference to the builder
|
|
99
|
+
"""
|
|
100
|
+
if self.interpolator:
|
|
101
|
+
selected_solver = solver if solver is not None else self.solver
|
|
102
|
+
merged_solver_kwargs = dict(self.solver_kwargs)
|
|
103
|
+
merged_solver_kwargs.update(solver_kwargs)
|
|
104
|
+
self.interpolator.solve_system(
|
|
105
|
+
solver=selected_solver,
|
|
106
|
+
tol=tol,
|
|
107
|
+
solver_kwargs=merged_solver_kwargs,
|
|
108
|
+
)
|
|
109
|
+
return self
|
|
110
|
+
|
|
111
|
+
def use_regularisation_weight_scale(self, enabled: bool = True) -> InterpolatorBuilder:
|
|
112
|
+
"""Configure whether regularisation terms use spatial weighting.
|
|
113
|
+
|
|
114
|
+
Parameters
|
|
115
|
+
----------
|
|
116
|
+
enabled : bool, optional
|
|
117
|
+
If True, enable regularisation-weight scaling in interpolators
|
|
118
|
+
that support it.
|
|
119
|
+
|
|
120
|
+
Returns
|
|
121
|
+
-------
|
|
122
|
+
InterpolatorBuilder
|
|
123
|
+
reference to the builder
|
|
124
|
+
"""
|
|
125
|
+
self.setup_kwargs["use_regularisation_weight_scale"] = bool(enabled)
|
|
126
|
+
return self
|
|
127
|
+
|
|
128
|
+
def regularisation_weight_sigma(self, sigma: float) -> InterpolatorBuilder:
|
|
129
|
+
"""Configure spatial decay sigma for regularisation weight scaling.
|
|
130
|
+
|
|
131
|
+
Parameters
|
|
132
|
+
----------
|
|
133
|
+
sigma : float
|
|
134
|
+
Gaussian decay width used by interpolators that support
|
|
135
|
+
regularisation-weight scaling.
|
|
136
|
+
|
|
137
|
+
Returns
|
|
138
|
+
-------
|
|
139
|
+
InterpolatorBuilder
|
|
140
|
+
reference to the builder
|
|
141
|
+
"""
|
|
142
|
+
self.setup_kwargs["regularisation_weight_sigma"] = float(sigma)
|
|
143
|
+
return self
|
|
144
|
+
|
|
145
|
+
def _set_constraint(self, setter_name: str, values: np.ndarray) -> InterpolatorBuilder:
|
|
146
|
+
"""Forward constraint arrays to the underlying interpolator."""
|
|
147
|
+
if self.interpolator:
|
|
148
|
+
getattr(self.interpolator, setter_name)(values)
|
|
149
|
+
return self
|
|
150
|
+
|
|
151
|
+
def add_value_constraints(self, value_constraints: np.ndarray) -> InterpolatorBuilder:
|
|
152
|
+
"""Add value constraints to the interpolator
|
|
153
|
+
|
|
154
|
+
Parameters
|
|
155
|
+
----------
|
|
156
|
+
value_constraints : np.ndarray
|
|
157
|
+
x,y,z,value of the constraints
|
|
158
|
+
|
|
159
|
+
Returns
|
|
160
|
+
-------
|
|
161
|
+
InterpolatorBuilder
|
|
162
|
+
reference to the builder
|
|
163
|
+
"""
|
|
164
|
+
return self._set_constraint("set_value_constraints", value_constraints)
|
|
165
|
+
|
|
166
|
+
def add_gradient_constraints(self, gradient_constraints: np.ndarray) -> InterpolatorBuilder:
|
|
167
|
+
"""Add gradient constraints to the interpolator.
|
|
168
|
+
|
|
169
|
+
Where g1 and g2 are two vectors that are orthogonal to the gradient:
|
|
170
|
+
f'(X) · g1 = 0 and f'(X) · g2 = 0
|
|
171
|
+
|
|
172
|
+
Parameters
|
|
173
|
+
----------
|
|
174
|
+
gradient_constraints : np.ndarray
|
|
175
|
+
Array with columns [x, y, z, gradient_x, gradient_y, gradient_z] of the constraints
|
|
176
|
+
|
|
177
|
+
Returns
|
|
178
|
+
-------
|
|
179
|
+
bool
|
|
180
|
+
True if constraints were added successfully
|
|
181
|
+
"""
|
|
182
|
+
|
|
183
|
+
return self._set_constraint("set_gradient_constraints", gradient_constraints)
|
|
184
|
+
|
|
185
|
+
def add_normal_constraints(self, normal_constraints: np.ndarray) -> InterpolatorBuilder:
|
|
186
|
+
"""Add normal constraints to the interpolator
|
|
187
|
+
Where n is the normal vector to the surface
|
|
188
|
+
$f'(X).dx = nx$
|
|
189
|
+
$f'(X).dy = ny$
|
|
190
|
+
$f'(X).dz = nz$
|
|
191
|
+
Parameters
|
|
192
|
+
----------
|
|
193
|
+
normal_constraints : np.ndarray
|
|
194
|
+
x,y,z,nx,ny,nz of the constraints
|
|
195
|
+
|
|
196
|
+
Returns
|
|
197
|
+
-------
|
|
198
|
+
InterpolatorBuilder
|
|
199
|
+
reference to the builder
|
|
200
|
+
"""
|
|
201
|
+
return self._set_constraint("set_normal_constraints", normal_constraints)
|
|
202
|
+
|
|
203
|
+
def add_tangent_constraints(self, tangent_constraints: np.ndarray) -> InterpolatorBuilder:
|
|
204
|
+
"""Add tangent constraints to the interpolator.
|
|
205
|
+
|
|
206
|
+
Parameters
|
|
207
|
+
----------
|
|
208
|
+
tangent_constraints : np.ndarray
|
|
209
|
+
Array with columns [x, y, z, tx, ty, tz] where (tx, ty, tz) is a
|
|
210
|
+
vector that lies *in* the surface (orthogonal to the gradient).
|
|
211
|
+
|
|
212
|
+
Returns
|
|
213
|
+
-------
|
|
214
|
+
InterpolatorBuilder
|
|
215
|
+
reference to the builder
|
|
216
|
+
"""
|
|
217
|
+
return self._set_constraint("set_tangent_constraints", tangent_constraints)
|
|
218
|
+
|
|
219
|
+
def add_inequality_constraints(
|
|
220
|
+
self, inequality_constraints: np.ndarray
|
|
221
|
+
) -> InterpolatorBuilder:
|
|
222
|
+
return self._set_constraint("set_value_inequality_constraints", inequality_constraints)
|
|
223
|
+
|
|
224
|
+
def add_inequality_pair_constraints(
|
|
225
|
+
self, inequality_pair_constraints: np.ndarray
|
|
226
|
+
) -> InterpolatorBuilder:
|
|
227
|
+
return self._set_constraint("set_inequality_pairs_constraints", inequality_pair_constraints)
|
|
228
|
+
|
|
229
|
+
def setup_interpolator(self, **kwargs) -> InterpolatorBuilder:
|
|
230
|
+
"""This adds all of the constraints to the interpolator and
|
|
231
|
+
sets the regularisation constraints
|
|
232
|
+
|
|
233
|
+
Returns
|
|
234
|
+
-------
|
|
235
|
+
InterpolatorBuilder
|
|
236
|
+
reference to the builder
|
|
237
|
+
"""
|
|
238
|
+
if self.interpolator:
|
|
239
|
+
setup_kwargs = {**self.setup_kwargs, **kwargs}
|
|
240
|
+
self.interpolator.setup(**setup_kwargs)
|
|
241
|
+
return self
|
|
242
|
+
|
|
243
|
+
def build(self) -> GeologicalInterpolator:
|
|
244
|
+
"""Builds the interpolator and returns it
|
|
245
|
+
|
|
246
|
+
Returns
|
|
247
|
+
-------
|
|
248
|
+
GeologicalInterpolator
|
|
249
|
+
The interpolator fitting all of the constraints provided
|
|
250
|
+
"""
|
|
251
|
+
return self.interpolator
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"""Interpolator creation and reconstruction backend.
|
|
2
|
+
|
|
3
|
+
InterpolatorFactory is the single place that knows how to:
|
|
4
|
+
- map type identifiers to concrete interpolator classes,
|
|
5
|
+
- create supports from bounding boxes, and
|
|
6
|
+
- reconstruct interpolators from serialized dictionaries.
|
|
7
|
+
|
|
8
|
+
Higher-level fluent APIs should delegate construction to this module.
|
|
9
|
+
"""
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
from loop_common.geometry import BoundingBox
|
|
14
|
+
from loop_common.supports import SupportFactory
|
|
15
|
+
|
|
16
|
+
from . import (
|
|
17
|
+
InterpolatorType,
|
|
18
|
+
interpolator_map,
|
|
19
|
+
interpolator_string_map,
|
|
20
|
+
support_interpolator_map,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class InterpolatorFactory:
|
|
25
|
+
"""Authoritative constructor/reconstructor for interpolation objects."""
|
|
26
|
+
|
|
27
|
+
@staticmethod
|
|
28
|
+
def _normalise_interpolator_type(
|
|
29
|
+
interpolatortype: str | InterpolatorType,
|
|
30
|
+
) -> InterpolatorType:
|
|
31
|
+
if isinstance(interpolatortype, str):
|
|
32
|
+
if interpolatortype in interpolator_string_map:
|
|
33
|
+
return interpolator_string_map[interpolatortype]
|
|
34
|
+
if interpolatortype in InterpolatorType.__members__:
|
|
35
|
+
return InterpolatorType[interpolatortype]
|
|
36
|
+
return InterpolatorType(interpolatortype)
|
|
37
|
+
return interpolatortype
|
|
38
|
+
|
|
39
|
+
@staticmethod
|
|
40
|
+
def create_interpolator(
|
|
41
|
+
interpolatortype: str | InterpolatorType | None = None,
|
|
42
|
+
boundingbox: BoundingBox | None = None,
|
|
43
|
+
nelements: int | None = None,
|
|
44
|
+
element_volume: float | None = None,
|
|
45
|
+
support=None,
|
|
46
|
+
buffer: float | None = None,
|
|
47
|
+
solver: str | None = None,
|
|
48
|
+
):
|
|
49
|
+
if interpolatortype is None:
|
|
50
|
+
raise ValueError("No interpolator type specified")
|
|
51
|
+
if support is None and boundingbox is None:
|
|
52
|
+
raise ValueError("No bounding box specified")
|
|
53
|
+
|
|
54
|
+
interpolatortype = InterpolatorFactory._normalise_interpolator_type(interpolatortype)
|
|
55
|
+
if support is None:
|
|
56
|
+
# raise Exception("Support must be specified")
|
|
57
|
+
supporttype = support_interpolator_map[interpolatortype][boundingbox.dimensions]
|
|
58
|
+
|
|
59
|
+
support = SupportFactory.create_support_from_bbox(
|
|
60
|
+
supporttype,
|
|
61
|
+
bounding_box=boundingbox,
|
|
62
|
+
nelements=nelements,
|
|
63
|
+
element_volume=element_volume,
|
|
64
|
+
buffer=buffer,
|
|
65
|
+
)
|
|
66
|
+
interpolator = interpolator_map[interpolatortype](support)
|
|
67
|
+
if boundingbox is not None:
|
|
68
|
+
interpolator.bounding_box = boundingbox
|
|
69
|
+
if solver is not None:
|
|
70
|
+
interpolator.solver = solver
|
|
71
|
+
return interpolator
|
|
72
|
+
|
|
73
|
+
@staticmethod
|
|
74
|
+
def from_dict(d):
|
|
75
|
+
d = d.copy()
|
|
76
|
+
interpolator_type = d.pop("type", None)
|
|
77
|
+
if interpolator_type is None:
|
|
78
|
+
raise ValueError("No interpolator type specified")
|
|
79
|
+
interpolator_type = InterpolatorFactory._normalise_interpolator_type(interpolator_type)
|
|
80
|
+
|
|
81
|
+
support = d.pop("support", None)
|
|
82
|
+
if isinstance(support, dict):
|
|
83
|
+
support_payload = support.copy()
|
|
84
|
+
try:
|
|
85
|
+
support = SupportFactory.from_dict(support_payload)
|
|
86
|
+
except TypeError as exc:
|
|
87
|
+
# Some support classes (e.g., TetMesh) do not accept rotation_xy in __init__.
|
|
88
|
+
if "rotation_xy" in support_payload and "rotation_xy" in str(exc):
|
|
89
|
+
support_payload.pop("rotation_xy", None)
|
|
90
|
+
support = SupportFactory.from_dict(support_payload)
|
|
91
|
+
else:
|
|
92
|
+
raise
|
|
93
|
+
|
|
94
|
+
data = d.pop("data", None)
|
|
95
|
+
c = d.pop("c", None)
|
|
96
|
+
up_to_date = bool(d.pop("up_to_date", False))
|
|
97
|
+
valid = bool(d.pop("valid", True))
|
|
98
|
+
|
|
99
|
+
interpolator = InterpolatorFactory.create_interpolator(
|
|
100
|
+
interpolator_type,
|
|
101
|
+
support=support,
|
|
102
|
+
**d,
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
if data is not None:
|
|
106
|
+
if data.get("value") is not None:
|
|
107
|
+
arr = np.asarray(data["value"], dtype=float)
|
|
108
|
+
if arr.size > 0:
|
|
109
|
+
interpolator.set_value_constraints(arr)
|
|
110
|
+
if data.get("gradient") is not None:
|
|
111
|
+
arr = np.asarray(data["gradient"], dtype=float)
|
|
112
|
+
if arr.size > 0:
|
|
113
|
+
interpolator.set_gradient_constraints(arr)
|
|
114
|
+
if data.get("normal") is not None:
|
|
115
|
+
arr = np.asarray(data["normal"], dtype=float)
|
|
116
|
+
if arr.size > 0:
|
|
117
|
+
interpolator.set_normal_constraints(arr)
|
|
118
|
+
if data.get("tangent") is not None:
|
|
119
|
+
arr = np.asarray(data["tangent"], dtype=float)
|
|
120
|
+
if arr.size > 0:
|
|
121
|
+
interpolator.set_tangent_constraints(arr)
|
|
122
|
+
if data.get("interface") is not None:
|
|
123
|
+
arr = np.asarray(data["interface"], dtype=float)
|
|
124
|
+
if arr.size > 0:
|
|
125
|
+
interpolator.set_interface_constraints(arr)
|
|
126
|
+
if data.get("inequality") is not None:
|
|
127
|
+
arr = np.asarray(data["inequality"], dtype=float)
|
|
128
|
+
if arr.size > 0:
|
|
129
|
+
interpolator.set_value_inequality_constraints(arr)
|
|
130
|
+
if data.get("inequality_pairs") is not None:
|
|
131
|
+
arr = np.asarray(data["inequality_pairs"], dtype=float)
|
|
132
|
+
if arr.size > 0:
|
|
133
|
+
interpolator.set_inequality_pairs_constraints(arr)
|
|
134
|
+
|
|
135
|
+
if c is not None and hasattr(interpolator, "c"):
|
|
136
|
+
interpolator.c = np.asarray(c, dtype=float)
|
|
137
|
+
|
|
138
|
+
interpolator.up_to_date = up_to_date
|
|
139
|
+
interpolator.valid = valid
|
|
140
|
+
return interpolator
|
|
141
|
+
|
|
142
|
+
@staticmethod
|
|
143
|
+
def get_supported_interpolators():
|
|
144
|
+
return interpolator_map.keys()
|
|
145
|
+
|
|
146
|
+
@staticmethod
|
|
147
|
+
def create_interpolator_with_data(
|
|
148
|
+
interpolatortype: str,
|
|
149
|
+
boundingbox: BoundingBox,
|
|
150
|
+
nelements: int,
|
|
151
|
+
element_volume: float | None = None,
|
|
152
|
+
support=None,
|
|
153
|
+
value_constraints: np.ndarray | None = None,
|
|
154
|
+
gradient_norm_constraints: np.ndarray | None = None,
|
|
155
|
+
gradient_constraints: np.ndarray | None = None,
|
|
156
|
+
):
|
|
157
|
+
interpolator = InterpolatorFactory.create_interpolator(
|
|
158
|
+
interpolatortype, boundingbox, nelements, element_volume, support
|
|
159
|
+
)
|
|
160
|
+
if value_constraints is not None:
|
|
161
|
+
interpolator.set_value_constraints(value_constraints)
|
|
162
|
+
if gradient_norm_constraints is not None:
|
|
163
|
+
interpolator.set_normal_constraints(gradient_norm_constraints)
|
|
164
|
+
if gradient_constraints is not None:
|
|
165
|
+
interpolator.set_gradient_constraints(gradient_constraints)
|
|
166
|
+
interpolator.setup()
|
|
167
|
+
return interpolator
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class InterpolatorType(Enum):
|
|
5
|
+
"""
|
|
6
|
+
Enum for the different interpolator types
|
|
7
|
+
|
|
8
|
+
Each value is a unique identifier.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
BASE = "BASE"
|
|
12
|
+
BASE_DISCRETE = "BASE_DISCRETE"
|
|
13
|
+
FINITE_DIFFERENCE = "FINITE_DIFFERENCE"
|
|
14
|
+
DISCRETE_FOLD = "DISCRETE_FOLD"
|
|
15
|
+
PIECEWISE_LINEAR = "PIECEWISE_LINEAR"
|
|
16
|
+
PIECEWISE_QUADRATIC = "PIECEWISE_QUADRATIC"
|
|
17
|
+
BASE_DATA_SUPPORTED = "BASE_DATA_SUPPORTED"
|
|
18
|
+
SURFE = "SURFE"
|
|
19
|
+
PIECEWISE_LINEAR_CONSTANT_NORM = "PIECEWISE_LINEAR_CONSTANT_NORM"
|
|
20
|
+
FINITE_DIFFERENCE_CONSTANT_NORM = "FINITE_DIFFERENCE_CONSTANT_NORM"
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Finite difference masks
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
from loop_common.logging import get_logger as getLogger
|
|
7
|
+
|
|
8
|
+
logger = getLogger(__name__)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Operator:
|
|
12
|
+
"""
|
|
13
|
+
Finite difference masks for adding constraints for the derivatives and second derivatives
|
|
14
|
+
Operator.Dx_mask gives derivative in x direction
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
z = np.zeros((3, 3))
|
|
18
|
+
Dx_mask = np.array([z, [[0.0, 0.0, 0.0], [-0.5, 0.0, 0.5], [0.0, 0.0, 0.0]], z])
|
|
19
|
+
Dy_mask = Dx_mask.swapaxes(1, 2)
|
|
20
|
+
Dz_mask = Dx_mask.swapaxes(0, 2)
|
|
21
|
+
|
|
22
|
+
Dx_forward_mask = np.array([z, [[0.0, 0.0, 0.0], [-1.0, 1.0, 0.0], [0.0, 0.0, 0.0]], z])
|
|
23
|
+
Dx_backward_mask = np.array([z, [[0.0, 0.0, 0.0], [0.0, -1.0, 1.0], [0.0, 0.0, 0.0]], z])
|
|
24
|
+
Dy_forward_mask = Dx_forward_mask.swapaxes(1, 2)
|
|
25
|
+
Dy_backward_mask = Dx_backward_mask.swapaxes(1, 2)
|
|
26
|
+
Dz_forward_mask = Dx_forward_mask.swapaxes(0, 2)
|
|
27
|
+
Dz_backward_mask = Dx_backward_mask.swapaxes(0, 2)
|
|
28
|
+
|
|
29
|
+
Dxx_mask = np.array([z, [[0, 0, 0], [1, -2, 1], [0, 0, 0]], z])
|
|
30
|
+
Dyy_mask = Dxx_mask.swapaxes(1, 2)
|
|
31
|
+
Dzz_mask = Dxx_mask.swapaxes(0, 2)
|
|
32
|
+
|
|
33
|
+
Dxy_mask = np.array([z, [[-0.25, 0, 0.25], [0, 0, 0], [0.25, 0, -0.25]], z]) / np.sqrt(2)
|
|
34
|
+
Dxz_mask = Dxy_mask.swapaxes(0, 1)
|
|
35
|
+
Dyz_mask = Dxy_mask.swapaxes(0, 2)
|
|
36
|
+
|
|
37
|
+
# from https://en.wikipedia.org/wiki/Discrete_Laplace_operator
|
|
38
|
+
Lapacian = np.array(
|
|
39
|
+
[
|
|
40
|
+
[[0, 0, 0], [0, 1, 0], [0, 0, 0]], # first plane
|
|
41
|
+
[[0, 1, 0], [1, -6, 1], [0, 1, 0]], # second plane
|
|
42
|
+
[[0, 0, 0], [0, 1, 0], [0, 0, 0]], # third plane
|
|
43
|
+
]
|
|
44
|
+
)
|