LoopStructural 1.0.1__zip
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.
Potentially problematic release.
This version of LoopStructural might be problematic. Click here for more details.
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/__init__.py +33 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/__pycache__/__init__.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/datasets/__init__.py +12 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/datasets/__pycache__/__init__.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/datasets/__pycache__/_base.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/datasets/_base.py +65 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/datasets/data/claudius.csv +21049 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/datasets/data/claudiusbb.txt +2 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/datasets/data/duplex.csv +126 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/datasets/data/duplexbb.txt +2 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/datasets/data/intrusion.csv +1017 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/datasets/data/intrusionbb.txt +2 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/datasets/data/onefoldbb.txt +2 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/datasets/data/onefolddata.csv +2226 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/datasets/data/refolded_bb.txt +2 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/datasets/data/refolded_fold.csv +2126 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/__init__.py +31 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/__pycache__/__init__.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/__pycache__/discrete_fold_interpolator.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/__pycache__/discrete_interpolator.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/__pycache__/finite_difference_interpolator.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/__pycache__/geological_interpolator.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/__pycache__/operator.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/__pycache__/piecewiselinear_interpolator.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/__pycache__/structured_grid.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/__pycache__/structured_tetra.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/__pycache__/surfe_wrapper.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/cython/__init__.py +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/cython/__pycache__/__init__.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/cython/dsi_helper.c +27805 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/cython/dsi_helper.cp37-win_amd64.pyd +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/discrete_fold_interpolator.py +168 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/discrete_interpolator.py +551 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/finite_difference_interpolator.py +339 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/geological_interpolator.py +178 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/operator.py +46 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/piecewiselinear_interpolator.py +300 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/structured_grid.py +460 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/structured_tetra.py +637 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/surfe_wrapper.py +119 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/__init__.py +46 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/__pycache__/__init__.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/core/__init__.py +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/core/__pycache__/__init__.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/core/__pycache__/geological_model.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/core/geological_model.py +1179 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/fault/__init__.py +3 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/fault/__pycache__/__init__.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/fault/__pycache__/fault_function.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/fault/__pycache__/fault_function_feature.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/fault/__pycache__/fault_segment.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/fault/fault_function.py +187 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/fault/fault_function_feature.py +75 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/fault/fault_segment.py +270 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/features/__init__.py +7 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/features/__pycache__/__init__.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/features/__pycache__/cross_product_geological_feature.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/features/__pycache__/geological_feature.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/features/__pycache__/geological_feature_builder.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/features/__pycache__/region_feature.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/features/__pycache__/structural_frame.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/features/__pycache__/structural_frame_builder.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/features/__pycache__/unconformity_feature.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/features/cross_product_geological_feature.py +77 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/features/geological_feature.py +276 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/features/geological_feature_builder.py +289 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/features/region_feature.py +31 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/features/structural_frame.py +116 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/features/structural_frame_builder.py +179 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/features/unconformity_feature.py +69 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/fold/__init__.py +8 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/fold/__pycache__/__init__.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/fold/__pycache__/fold.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/fold/__pycache__/fold_rotation_angle.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/fold/__pycache__/fold_rotation_angle_feature.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/fold/__pycache__/foldframe.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/fold/__pycache__/svariogram.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/fold/fold.py +135 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/fold/fold_rotation_angle.py +132 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/fold/fold_rotation_angle_feature.py +57 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/fold/foldframe.py +191 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/fold/svariogram.py +179 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/utils/__init__.py +14 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/utils/__pycache__/__init__.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/utils/__pycache__/exceptions.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/utils/__pycache__/helper.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/utils/__pycache__/map2loop.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/utils/__pycache__/utils.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/utils/exceptions.py +9 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/utils/helper.py +373 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/utils/map2loop.py +229 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/utils/utils.py +76 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/visualisation/__init__.py +19 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/visualisation/__pycache__/__init__.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/visualisation/__pycache__/map_viewer.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/visualisation/__pycache__/model_plotter.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/visualisation/__pycache__/model_visualisation.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/visualisation/__pycache__/rotation_angle_plotter.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/visualisation/__pycache__/sphinx_scraper.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/visualisation/map_viewer.py +122 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/visualisation/model_plotter.py +16 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/visualisation/model_visualisation.py +704 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/visualisation/rotation_angle_plotter.py +66 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural/visualisation/sphinx_scraper.py +34 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural-1.0.1-py3.7.egg-info/PKG-INFO +10 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural-1.0.1-py3.7.egg-info/SOURCES.txt +60 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural-1.0.1-py3.7.egg-info/dependency_links.txt +1 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural-1.0.1-py3.7.egg-info/requires.txt +3 -0
- Miniconda/envs/loop/Lib/site-packages/LoopStructural-1.0.1-py3.7.egg-info/top_level.txt +2 -0
- Miniconda/envs/loop/Lib/site-packages/tests/__init__.py +0 -0
- Miniconda/envs/loop/Lib/site-packages/tests/__pycache__/__init__.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/tests/__pycache__/test_faults.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/tests/__pycache__/test_fold.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/tests/__pycache__/test_interpolator.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/tests/__pycache__/test_refolded.cpython-37.pyc +0 -0
- Miniconda/envs/loop/Lib/site-packages/tests/test_faults.py +17 -0
- Miniconda/envs/loop/Lib/site-packages/tests/test_fold.py +57 -0
- Miniconda/envs/loop/Lib/site-packages/tests/test_interpolator.py +88 -0
- Miniconda/envs/loop/Lib/site-packages/tests/test_refolded.py +22 -0
Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/piecewiselinear_interpolator.py
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
from LoopStructural.interpolators.discrete_interpolator import \
|
|
6
|
+
DiscreteInterpolator
|
|
7
|
+
from LoopStructural.utils.helper import get_vectors
|
|
8
|
+
|
|
9
|
+
logger = logging.getLogger(__name__)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class PiecewiseLinearInterpolator(DiscreteInterpolator):
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
"""
|
|
16
|
+
def __init__(self, mesh):
|
|
17
|
+
"""
|
|
18
|
+
Piecewise Linear Interpolator
|
|
19
|
+
Approximates scalar field by finding coefficients to a piecewise linear
|
|
20
|
+
equation on a tetrahedral mesh. Uses constant gradient regularisation.
|
|
21
|
+
|
|
22
|
+
Parameters
|
|
23
|
+
----------
|
|
24
|
+
mesh - TetMesh
|
|
25
|
+
interpolation support
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
self.shape = 'rectangular'
|
|
29
|
+
DiscreteInterpolator.__init__(self, mesh)
|
|
30
|
+
# whether to assemble a rectangular matrix or a square matrix
|
|
31
|
+
self.interpolator_type = 'PLI'
|
|
32
|
+
self.nx = len(self.support.nodes[self.region])
|
|
33
|
+
self.support = mesh
|
|
34
|
+
|
|
35
|
+
self.set_interpolation_weights({'cgw': 0.1, 'cpw': 1., 'npw': 1.,
|
|
36
|
+
'gpw': 1., 'tpw': 1.})
|
|
37
|
+
self.__str = 'Piecewise Linear Interpolator with %i unknowns. \n' % \
|
|
38
|
+
self.nx
|
|
39
|
+
|
|
40
|
+
def __str__(self):
|
|
41
|
+
return self.__str
|
|
42
|
+
|
|
43
|
+
def copy(self):
|
|
44
|
+
return PiecewiseLinearInterpolator(self.support)
|
|
45
|
+
|
|
46
|
+
def _setup_interpolator(self, **kwargs):
|
|
47
|
+
"""
|
|
48
|
+
Searches through kwargs for any interpolation weights and updates
|
|
49
|
+
the dictionary.
|
|
50
|
+
Then adds the constraints to the linear system using the
|
|
51
|
+
interpolation weights values
|
|
52
|
+
Parameters
|
|
53
|
+
----------
|
|
54
|
+
kwargs -
|
|
55
|
+
interpolation weights
|
|
56
|
+
|
|
57
|
+
Returns
|
|
58
|
+
-------
|
|
59
|
+
|
|
60
|
+
"""
|
|
61
|
+
# can't reset here, clears fold constraints
|
|
62
|
+
# self.reset()
|
|
63
|
+
logger.info("Setting up PLI interpolator for %s"%self.propertyname)
|
|
64
|
+
for key in kwargs:
|
|
65
|
+
if 'regularisation' in kwargs:
|
|
66
|
+
self.interpolation_weights['cgw'] = 0.1 * kwargs[
|
|
67
|
+
'regularisation']
|
|
68
|
+
self.up_to_date = False
|
|
69
|
+
self.interpolation_weights[key] = kwargs[key]
|
|
70
|
+
if self.interpolation_weights['cgw'] > 0.:
|
|
71
|
+
self.up_to_date = False
|
|
72
|
+
self.add_constant_gradient(self.interpolation_weights['cgw'])
|
|
73
|
+
logger.info("Using constant gradient regularisation w = %f"
|
|
74
|
+
%self.interpolation_weights['cgw'])
|
|
75
|
+
logger.info("Added %i gradient constraints, %i normal constraints,"
|
|
76
|
+
"%i tangent constraints and %i value constraints"
|
|
77
|
+
"to %s" % (self.n_g, self.n_n,
|
|
78
|
+
self.n_t, self.n_i, self.propertyname))
|
|
79
|
+
self.add_gradient_ctr_pts(self.interpolation_weights['gpw'])
|
|
80
|
+
self.add_norm_ctr_pts(self.interpolation_weights['npw'])
|
|
81
|
+
self.add_ctr_pts(self.interpolation_weights['cpw'])
|
|
82
|
+
self.add_tangent_ctr_pts(self.interpolation_weights['tpw'])
|
|
83
|
+
|
|
84
|
+
def add_constant_gradient(self, w=0.1):
|
|
85
|
+
"""
|
|
86
|
+
Add the constant gradient regularisation to the system
|
|
87
|
+
|
|
88
|
+
Parameters
|
|
89
|
+
----------
|
|
90
|
+
w (double) - weighting of the cg parameter
|
|
91
|
+
|
|
92
|
+
Returns
|
|
93
|
+
-------
|
|
94
|
+
|
|
95
|
+
"""
|
|
96
|
+
# iterate over all elements
|
|
97
|
+
A, idc, B = self.support.get_constant_gradient(region=self.region)
|
|
98
|
+
A = np.array(A)
|
|
99
|
+
B = np.array(B)
|
|
100
|
+
idc = np.array(idc)
|
|
101
|
+
|
|
102
|
+
gi = np.zeros(self.support.n_nodes)
|
|
103
|
+
gi[:] = -1
|
|
104
|
+
gi[self.region] = np.arange(0, self.nx)
|
|
105
|
+
idc = gi[idc]
|
|
106
|
+
outside = ~np.any(idc == -1, axis=1)
|
|
107
|
+
|
|
108
|
+
# w/=A.shape[0]
|
|
109
|
+
self.add_constraints_to_least_squares(A[outside, :] * w,
|
|
110
|
+
B[outside] * w, idc[outside, :],
|
|
111
|
+
name='regularisation')
|
|
112
|
+
return
|
|
113
|
+
|
|
114
|
+
def add_gradient_ctr_pts(self, w=1.0):
|
|
115
|
+
"""
|
|
116
|
+
Adds gradient constraints to the least squares system with a weight
|
|
117
|
+
defined by w
|
|
118
|
+
Parameters
|
|
119
|
+
----------
|
|
120
|
+
w : either numpy array of length number of
|
|
121
|
+
|
|
122
|
+
Returns
|
|
123
|
+
-------
|
|
124
|
+
Notes
|
|
125
|
+
-----
|
|
126
|
+
Gradient constraints add a constraint that the gradient of the
|
|
127
|
+
implicit function should
|
|
128
|
+
be orthogonal to the strike vector and the dip vector defined by the
|
|
129
|
+
normal.
|
|
130
|
+
This does not control the direction of the gradient and therefore
|
|
131
|
+
requires at least two other
|
|
132
|
+
value constraints OR a norm constraint for the interpolant to solve.
|
|
133
|
+
"""
|
|
134
|
+
points = self.get_gradient_constraints()
|
|
135
|
+
if points.shape[0] > 0:
|
|
136
|
+
vertices, element_gradients, tetras, inside = self.support.get_tetra_gradient_for_location(points[:,:3])
|
|
137
|
+
#e, inside = self.support.elements_for_array(points[:, :3])
|
|
138
|
+
#nodes = self.support.nodes[self.support.elements[e]]
|
|
139
|
+
vecs = vertices[:, 1:, :] - vertices[:, 0, None, :]
|
|
140
|
+
vol = np.abs(np.linalg.det(vecs)) # / 6
|
|
141
|
+
# d_t = self.support.get_elements_gradients(e)
|
|
142
|
+
norm = np.linalg.norm(element_gradients, axis=2)
|
|
143
|
+
element_gradients /= norm[:, :, None]
|
|
144
|
+
# d_t *= vol[:,None,None]
|
|
145
|
+
strike_vector, dip_vector = get_vectors(points[:, 3:6])
|
|
146
|
+
A = np.einsum('ji,ijk->ik', strike_vector, element_gradients)
|
|
147
|
+
|
|
148
|
+
A *= vol[:, None]
|
|
149
|
+
|
|
150
|
+
gi = np.zeros(self.support.n_nodes).astype(int)
|
|
151
|
+
gi[:] = -1
|
|
152
|
+
gi[self.region] = np.arange(0, self.nx).astype(int)
|
|
153
|
+
w /= 3
|
|
154
|
+
idc = gi[tetras]
|
|
155
|
+
B = np.zeros(idc.shape[0])
|
|
156
|
+
outside = ~np.any(idc == -1, axis=1)
|
|
157
|
+
# self.add_constraints_to_least_squares(A[outside, :] * w,
|
|
158
|
+
# B[outside], idc[outside, :],
|
|
159
|
+
# name = 'gradient')
|
|
160
|
+
A2 = np.einsum('ji,ijk->ik', dip_vector, element_gradients)
|
|
161
|
+
A2 *= vol[:, None]
|
|
162
|
+
A+=A2
|
|
163
|
+
self.add_constraints_to_least_squares(A[outside, :] * w,
|
|
164
|
+
B[outside], idc[outside, :],
|
|
165
|
+
name='gradient')
|
|
166
|
+
|
|
167
|
+
def add_norm_ctr_pts(self, w=1.0):
|
|
168
|
+
"""
|
|
169
|
+
Extracts the norm vectors from the interpolators p_n list and adds
|
|
170
|
+
these to the implicit
|
|
171
|
+
system
|
|
172
|
+
|
|
173
|
+
Parameters
|
|
174
|
+
----------
|
|
175
|
+
w : double
|
|
176
|
+
weighting of the norm constraints in a least squares system
|
|
177
|
+
|
|
178
|
+
Returns
|
|
179
|
+
-------
|
|
180
|
+
Notes
|
|
181
|
+
-----
|
|
182
|
+
Controls the direction and magnitude of the norm of the scalar field
|
|
183
|
+
gradient.
|
|
184
|
+
This constraint can conflict with value constraints if the magnitude
|
|
185
|
+
of the vector doesn't
|
|
186
|
+
match with the value constraints added to the implicit system.
|
|
187
|
+
"""
|
|
188
|
+
|
|
189
|
+
points = self.get_norm_constraints()
|
|
190
|
+
if points.shape[0] > 0:
|
|
191
|
+
vertices, element_gradients, tetras, inside = self.support.get_tetra_gradient_for_location(points[:, :3])
|
|
192
|
+
# e, inside = self.support.elements_for_array(points[:, :3])
|
|
193
|
+
# nodes = self.support.nodes[self.support.elements[e]]
|
|
194
|
+
vol = np.zeros(element_gradients.shape[0])
|
|
195
|
+
vecs = vertices[inside, 1:, :] - vertices[inside, 0, None, :]
|
|
196
|
+
vol[inside] = np.abs(np.linalg.det(vecs)) # / 6
|
|
197
|
+
# d_t = self.support.get_elements_gradients(e)
|
|
198
|
+
norm = np.zeros((element_gradients.shape[0],element_gradients.shape[1]))
|
|
199
|
+
norm[inside,:] = np.linalg.norm(element_gradients[inside,:,:], axis=2)
|
|
200
|
+
element_gradients /= norm[:, :, None]
|
|
201
|
+
|
|
202
|
+
d_t = element_gradients
|
|
203
|
+
d_t[inside,:,:] *= vol[inside, None, None]
|
|
204
|
+
# w*=10^11
|
|
205
|
+
|
|
206
|
+
# add in the element gradient matrix into the inte
|
|
207
|
+
idc = np.tile(tetras[inside,:], (3, 1, 1))
|
|
208
|
+
idc = idc.swapaxes(0,1)
|
|
209
|
+
# idc = self.support.elements[e]
|
|
210
|
+
gi = np.zeros(self.support.n_nodes).astype(int)
|
|
211
|
+
gi[:] = -1
|
|
212
|
+
gi[self.region] = np.arange(0, self.nx).astype(int)
|
|
213
|
+
w /= 3
|
|
214
|
+
idc = gi[idc]
|
|
215
|
+
outside = ~np.any(idc == -1, axis=2)
|
|
216
|
+
outside = outside[:, 0]
|
|
217
|
+
w /= 3
|
|
218
|
+
|
|
219
|
+
self.add_constraints_to_least_squares(d_t[inside,:,:][outside, :, :] * w,
|
|
220
|
+
points[inside,:][outside, 3:6] * w *
|
|
221
|
+
vol[outside, None],
|
|
222
|
+
idc[outside],
|
|
223
|
+
name='norm')
|
|
224
|
+
|
|
225
|
+
def add_ctr_pts(self, w=1.0): # for now weight all value points the same
|
|
226
|
+
"""
|
|
227
|
+
Adds value constraints to the least squares system
|
|
228
|
+
|
|
229
|
+
Parameters
|
|
230
|
+
----------
|
|
231
|
+
w
|
|
232
|
+
|
|
233
|
+
Returns
|
|
234
|
+
-------
|
|
235
|
+
|
|
236
|
+
"""
|
|
237
|
+
|
|
238
|
+
# get elements for points
|
|
239
|
+
points = self.get_value_constraints()
|
|
240
|
+
if points.shape[0] > 1:
|
|
241
|
+
vertices, c, tetras, inside = self.support.get_tetra_for_location(points[:,:3])
|
|
242
|
+
# calculate volume of tetras
|
|
243
|
+
vecs = vertices[inside, 1:, :] - vertices[inside, 0, None, :]
|
|
244
|
+
vol = np.abs(np.linalg.det(vecs)) / 6
|
|
245
|
+
A = c[inside]
|
|
246
|
+
A *= vol[:,None]
|
|
247
|
+
idc = tetras[inside,:]
|
|
248
|
+
# now map the index from global to region create array size of mesh
|
|
249
|
+
# initialise as np.nan, then map points inside region to 0->nx
|
|
250
|
+
gi = np.zeros(self.support.n_nodes).astype(int)
|
|
251
|
+
gi[:] = -1
|
|
252
|
+
|
|
253
|
+
gi[self.region] = np.arange(0, self.nx)
|
|
254
|
+
idc = gi[idc]
|
|
255
|
+
outside = ~np.any(idc == -1, axis=1)
|
|
256
|
+
self.add_constraints_to_least_squares(A[outside,:] * w,
|
|
257
|
+
points[inside,:][outside, 3] * w * vol[outside],
|
|
258
|
+
idc[outside, :], name='value')
|
|
259
|
+
|
|
260
|
+
def add_gradient_orthogonal_constraint(self, points, vector, w=1.0,
|
|
261
|
+
B=0):
|
|
262
|
+
"""
|
|
263
|
+
constraints scalar field to be orthogonal to a given vector
|
|
264
|
+
|
|
265
|
+
Parameters
|
|
266
|
+
----------
|
|
267
|
+
position
|
|
268
|
+
normals
|
|
269
|
+
w
|
|
270
|
+
B
|
|
271
|
+
|
|
272
|
+
Returns
|
|
273
|
+
-------
|
|
274
|
+
|
|
275
|
+
"""
|
|
276
|
+
if points.shape[0] > 0:
|
|
277
|
+
vertices, element_gradients, tetras, inside = self.support.get_tetra_gradient_for_location(points[:,:3])
|
|
278
|
+
#e, inside = self.support.elements_for_array(points[:, :3])
|
|
279
|
+
#nodes = self.support.nodes[self.support.elements[e]]
|
|
280
|
+
vecs = vertices[:, 1:, :] - vertices[:, 0, None, :]
|
|
281
|
+
vol = np.abs(np.linalg.det(vecs)) # / 6
|
|
282
|
+
# d_t = self.support.get_elements_gradients(e)
|
|
283
|
+
norm = np.linalg.norm(element_gradients, axis=2)
|
|
284
|
+
element_gradients /= norm[:, :, None]
|
|
285
|
+
|
|
286
|
+
A = np.einsum('ij,ijk->ik', vector, element_gradients)
|
|
287
|
+
|
|
288
|
+
A *= vol[:, None]
|
|
289
|
+
|
|
290
|
+
gi = np.zeros(self.support.n_nodes).astype(int)
|
|
291
|
+
gi[:] = -1
|
|
292
|
+
gi[self.region] = np.arange(0, self.nx).astype(int)
|
|
293
|
+
w /= 3
|
|
294
|
+
idc = gi[tetras]
|
|
295
|
+
B = np.zeros(idc.shape[0])
|
|
296
|
+
outside = ~np.any(idc == -1, axis=1)
|
|
297
|
+
self.add_constraints_to_least_squares(A[outside, :] * w,
|
|
298
|
+
B[outside], idc[outside, :])
|
|
299
|
+
|
|
300
|
+
|