LoopStructural 1.0.4__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.

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