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.

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 +27805 -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 +168 -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 +339 -0
  35. Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/geological_interpolator.py +178 -0
  36. Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/operator.py +46 -0
  37. Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/piecewiselinear_interpolator.py +300 -0
  38. Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/structured_grid.py +460 -0
  39. Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/structured_tetra.py +637 -0
  40. Miniconda/envs/loop/Lib/site-packages/LoopStructural/interpolators/surfe_wrapper.py +119 -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 +1179 -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 +276 -0
  66. Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/features/geological_feature_builder.py +289 -0
  67. Miniconda/envs/loop/Lib/site-packages/LoopStructural/modelling/features/region_feature.py +31 -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 +191 -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 +373 -0
  91. Miniconda/envs/loop/Lib/site-packages/LoopStructural/utils/map2loop.py +229 -0
  92. Miniconda/envs/loop/Lib/site-packages/LoopStructural/utils/utils.py +76 -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 +122 -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 +704 -0
  103. Miniconda/envs/loop/Lib/site-packages/LoopStructural/visualisation/rotation_angle_plotter.py +66 -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.1-py3.7.egg-info/PKG-INFO +10 -0
  106. Miniconda/envs/loop/Lib/site-packages/LoopStructural-1.0.1-py3.7.egg-info/SOURCES.txt +60 -0
  107. Miniconda/envs/loop/Lib/site-packages/LoopStructural-1.0.1-py3.7.egg-info/dependency_links.txt +1 -0
  108. Miniconda/envs/loop/Lib/site-packages/LoopStructural-1.0.1-py3.7.egg-info/requires.txt +3 -0
  109. Miniconda/envs/loop/Lib/site-packages/LoopStructural-1.0.1-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,460 @@
1
+ import logging
2
+
3
+ import numpy as np
4
+
5
+ logger = logging.getLogger(__name__)
6
+
7
+
8
+ class StructuredGrid:
9
+ """
10
+
11
+ """
12
+ def __init__(self,
13
+ origin=np.zeros(3),
14
+ nsteps=np.array([10, 10, 10]),
15
+ step_vector=np.ones(3),
16
+ maximum=None
17
+ ):
18
+ """
19
+
20
+ Parameters
21
+ ----------
22
+ origin - 3d list or numpy array
23
+ nsteps - 3d list or numpy array of ints
24
+ step_vector - 3d list or numpy array of int
25
+ maximum
26
+ """
27
+
28
+ self.nsteps = np.array(nsteps)
29
+ self.step_vector = np.array(step_vector)
30
+ self.origin = np.array(origin)
31
+ # self.nsteps+=1
32
+ self.n_nodes = self.nsteps[0] * self.nsteps[1] * self.nsteps[2]
33
+ # self.nsteps-=1
34
+ self.dim = 3
35
+ self.nsteps_cells = self.nsteps - 1
36
+ self.n_cell_x = self.nsteps[0] - 1
37
+ self.n_cell_y = self.nsteps[1] - 1
38
+ self.n_cell_z = self.nsteps[2] - 1
39
+ self.properties = {}
40
+ self.n_elements = self.n_cell_x * self.n_cell_y * self.n_cell_z
41
+
42
+ # calculate the node positions using numpy (this should probably not
43
+ # be stored as it defeats
44
+ # the purpose of a structured grid
45
+
46
+ # self.barycentre = self.cell_centres(np.arange(self.n_elements))
47
+
48
+ self.regions = {}
49
+ self.regions['everywhere'] = np.ones(self.n_nodes).astype(bool)
50
+
51
+ @property
52
+ def nodes(self):
53
+ max = self.origin + self.nsteps_cells * self.step_vector
54
+ x = np.linspace(self.origin[0], max[0], self.nsteps[0])
55
+ y = np.linspace(self.origin[1], max[1], self.nsteps[1])
56
+ z = np.linspace(self.origin[2], max[2], self.nsteps[2])
57
+ xx, yy, zz = np.meshgrid(x, y, z, indexing='ij')
58
+ return np.array([xx.flatten(order='F'), yy.flatten(order='F'),
59
+ zz.flatten(order='F')]).T
60
+
61
+ def barycentre(self):
62
+ return self.cell_centres(np.arange(self.n_elements))
63
+
64
+ def print_geometry(self):
65
+ print('Origin: %f %f %f' % (
66
+ self.origin[0], self.origin[1], self.origin[2]))
67
+ print('Cell size: %f %f %f' % (
68
+ self.step_vector[0], self.step_vector[1], self.step_vector[2]))
69
+ max = self.origin + self.nsteps_cells * self.step_vector
70
+ print('Max extent: %f %f %f' % (max[0], max[1], max[2]))
71
+
72
+ def update_property(self, propertyname, values):
73
+ """[summary]
74
+
75
+ [extended_summary]
76
+
77
+ Parameters
78
+ ----------
79
+ propertyname : [type]
80
+ [description]
81
+ values : [type]
82
+ [description]
83
+ """
84
+ if values.shape[0] == self.n_nodes:
85
+ self.properties[propertyname] = values
86
+ if values.shape[0] == self.n_elements:
87
+ self.cell_properties[propertyname] = values
88
+
89
+ def cell_centres(self, global_index):
90
+ """[summary]
91
+
92
+ [extended_summary]
93
+
94
+ Parameters
95
+ ----------
96
+ global_index : [type]
97
+ [description]
98
+
99
+ Returns
100
+ -------
101
+ [type]
102
+ [description]
103
+ """
104
+ ix, iy, iz = self.global_index_to_cell_index(global_index)
105
+ x = self.origin[None, 0] + self.step_vector[None, 0] * .5 + \
106
+ self.step_vector[None, 0] * ix
107
+ y = self.origin[None, 1] + self.step_vector[None, 1] * .5 + \
108
+ self.step_vector[None, 1] * iy
109
+ z = self.origin[None, 2] + self.step_vector[None, 2] * .5 + \
110
+ self.step_vector[None, 2] * iz
111
+ return np.array([x, y, z]).T
112
+
113
+ def position_to_cell_index(self, pos):
114
+ """[summary]
115
+
116
+ [extended_summary]
117
+
118
+ Parameters
119
+ ----------
120
+ pos : [type]
121
+ [description]
122
+
123
+ Returns
124
+ -------
125
+ [type]
126
+ [description]
127
+ """
128
+
129
+ pos = self.check_position(pos)
130
+
131
+ ix = pos[:, 0] - self.origin[None, 0]
132
+ iy = pos[:, 1] - self.origin[None, 1]
133
+ iz = pos[:, 2] - self.origin[None, 2]
134
+ ix = ix // self.step_vector[None, 0]
135
+ iy = iy // self.step_vector[None, 1]
136
+ iz = iz // self.step_vector[None, 2]
137
+ return ix.astype(int), iy.astype(int), iz.astype(int)
138
+
139
+ def inside(self, pos):
140
+
141
+ # check whether point is inside box
142
+ inside = np.ones(pos.shape[0]).astype(bool)
143
+ for i in range(3):
144
+ inside *= pos[:, i] > self.origin[None, i]
145
+ inside *= pos[:, i] < self.origin[None, i] + \
146
+ self.step_vector[None, i] * self.nsteps_cells[None, i]
147
+ return inside
148
+
149
+ def check_position(self, pos):
150
+ """[summary]
151
+
152
+ [extended_summary]
153
+
154
+ Parameters
155
+ ----------
156
+ pos : [type]
157
+ [description]
158
+
159
+ Returns
160
+ -------
161
+ [type]
162
+ [description]
163
+ """
164
+
165
+ if len(pos.shape) == 1:
166
+ pos = np.array([pos])
167
+ if len(pos.shape) != 2:
168
+ print("Position array needs to be a list of points or a point")
169
+ return False
170
+ return pos
171
+
172
+ def trilinear(self, x, y, z):
173
+ """
174
+ returns the trilinear interpolation for the local coordinates
175
+ Parameters
176
+ ----------
177
+ x - double, array of doubles
178
+ y - double, array of doubles
179
+ z - double, array of doubles
180
+
181
+ Returns
182
+ -------
183
+ array of interpolation coefficients
184
+
185
+ """
186
+ return np.array([(1 - x) * (1 - y) * (1 - z),
187
+ x * (1 - y) * (1 - z),
188
+ (1 - x) * y * (1 - z),
189
+ (1 - x) * (1 - y) * z,
190
+ x * (1 - y) * z,
191
+ (1 - x) * y * z,
192
+ x * y * (1 - z),
193
+ x * y * z])
194
+
195
+ def position_to_local_coordinates(self, pos):
196
+ """
197
+ Convert from global to local coordinates within a cel
198
+ Parameters
199
+ ----------
200
+ pos - array of positions inside
201
+
202
+ Returns
203
+ -------
204
+ localx, localy, localz
205
+
206
+ """
207
+ # TODO check if inside mesh
208
+
209
+ # calculate local coordinates for positions
210
+ local_x = ((pos[:, 0] - self.origin[None, 0]) % self.step_vector[
211
+ None, 0]) / self.step_vector[None, 0]
212
+ local_y = ((pos[:, 1] - self.origin[None, 1]) % self.step_vector[
213
+ None, 1]) / self.step_vector[None, 1]
214
+ local_z = ((pos[:, 2] - self.origin[None, 2]) % self.step_vector[
215
+ None, 2]) / self.step_vector[None, 2]
216
+
217
+ return local_x, local_y, local_z
218
+
219
+ def position_to_dof_coefs(self, pos):
220
+ """
221
+ global posotion to interpolation coefficients
222
+ Parameters
223
+ ----------
224
+ pos
225
+
226
+ Returns
227
+ -------
228
+
229
+ """
230
+ x_local, y_local, local_z = self.position_to_local_coordinates(pos)
231
+ weights = self.trilinear(x_local, y_local, local_z)
232
+ return weights
233
+
234
+ def global_indicies(self, indexes):
235
+ """
236
+ xi, yi, zi to global index
237
+
238
+ Parameters
239
+ ----------
240
+ indexes
241
+
242
+ Returns
243
+ -------
244
+
245
+ """
246
+ indexes = np.array(indexes).swapaxes(0, 2)
247
+ return indexes[:, :, 0] + self.nsteps[None, None, 0] * indexes[:, :,
248
+ 1] + \
249
+ self.nsteps[None, None, 0] * self.nsteps[
250
+ None, None, 1] * indexes[:, :, 2]
251
+
252
+ def neighbour_global_indexes(self, mask = None, **kwargs):
253
+ """
254
+ Get neighbour indexes
255
+
256
+ Parameters
257
+ ----------
258
+ kwargs - indexes array specifying the cells to return neighbours
259
+
260
+ Returns
261
+ -------
262
+
263
+ """
264
+ indexes = None
265
+ if "indexes" in kwargs:
266
+ indexes = kwargs['indexes']
267
+ if "indexes" not in kwargs:
268
+ ii = []
269
+ jj = []
270
+ kk = []
271
+ for i in range(1, self.nsteps[0] - 1):
272
+ for j in range(1, self.nsteps[1] - 1):
273
+ for k in range(1, self.nsteps[2] - 1):
274
+ kk.append(k)
275
+ ii.append(i)
276
+ jj.append(j)
277
+ indexes = np.array([ii, jj, kk])
278
+ # indexes = np.array(indexes).T
279
+ if indexes.ndim != 2:
280
+ print(indexes.ndim)
281
+ return
282
+ # determine which neighbours to return default is diagonals included.
283
+ if mask is None:
284
+ mask = np.array([
285
+ [-1, 0, 1, -1, 0, 1, -1, 0, 1,
286
+ -1, 0, 1, -1, 0, 1, -1, 0, 1,
287
+ -1, 0, 1, -1, 0, 1, -1, 0, 1],
288
+ [-1, -1, -1, 0, 0, 0, 1, 1, 1,
289
+ -1, -1, -1, 0, 0, 0, 1, 1, 1,
290
+ -1, -1, -1, 0, 0, 0, 1, 1, 1],
291
+ [-1, -1, -1, -1, -1, -1, -1, -1, -1,
292
+ 0, 0, 0, 0, 0, 0, 0, 0, 0,
293
+ 1, 1, 1, 1, 1, 1, 1, 1, 1]
294
+ ])
295
+ neighbours = indexes[:, None, :] + mask[:, :, None]
296
+ return neighbours[0, :, :] + self.nsteps[0, None, None] * neighbours[1,
297
+ :, :] + \
298
+ self.nsteps[0, None, None] * self.nsteps[
299
+ 1, None, None] * neighbours[2, :, :]
300
+
301
+ def cell_corner_indexes(self, x_cell_index, y_cell_index, z_cell_index):
302
+ """
303
+ Returns the indexes of the corners of a cell given its location xi,
304
+ yi, zi
305
+
306
+ Parameters
307
+ ----------
308
+ x_cell_index
309
+ y_cell_index
310
+ z_cell_index
311
+
312
+ Returns
313
+ -------
314
+
315
+ """
316
+ xcorner = np.array([0, 1, 0, 0, 1, 0, 1, 1])
317
+ ycorner = np.array([0, 0, 1, 0, 0, 1, 1, 1])
318
+ zcorner = np.array([0, 0, 0, 1, 1, 1, 0, 1])
319
+ xcorners = x_cell_index[:, None] + xcorner[None, :]
320
+ ycorners = y_cell_index[:, None] + ycorner[None, :]
321
+ zcorners = z_cell_index[:, None] + zcorner[None, :]
322
+ return xcorners, ycorners, zcorners
323
+
324
+ def global_index_to_cell_index(self, global_index):
325
+ """
326
+ Convert from global indexes to xi,yi,zi
327
+
328
+ Parameters
329
+ ----------
330
+ global_index
331
+
332
+ Returns
333
+ -------
334
+
335
+ """
336
+ # determine the ijk indices for the global index.
337
+ # remainder when dividing by nx = i
338
+ # remained when dividing modulus of nx by ny is j
339
+
340
+ x_index = global_index % self.nsteps_cells[0, None]
341
+ y_index = global_index // self.nsteps_cells[0, None] % \
342
+ self.nsteps_cells[1, None]
343
+ z_index = global_index // self.nsteps_cells[0, None] // \
344
+ self.nsteps_cells[1, None]
345
+ return x_index, y_index, z_index
346
+
347
+ def node_indexes_to_position(self, xindex, yindex, zindex):
348
+
349
+ x = self.origin[0] + self.step_vector[0] * xindex
350
+ y = self.origin[1] + self.step_vector[1] * yindex
351
+ z = self.origin[2] + self.step_vector[2] * zindex
352
+
353
+ return x, y, z
354
+
355
+ def position_to_cell_corners(self, pos):
356
+
357
+ inside = self.inside(pos)
358
+ ix, iy, iz = self.position_to_cell_index(pos)
359
+ cornersx, cornersy, cornersz = self.cell_corner_indexes(ix, iy, iz)
360
+ globalidx = self.global_indicies(
361
+ np.dstack([cornersx, cornersy, cornersz]).T)
362
+ # if global index is not inside the support set to -1
363
+ globalidx[~inside] = -1
364
+ return globalidx, inside
365
+
366
+ def evaluate_value(self, evaluation_points, property_name):
367
+ """
368
+ Evaluate the value of of the property at the locations.
369
+ Trilinear interpolation dot corner values
370
+
371
+ Parameters
372
+ ----------
373
+ evaluation_points np array of locations
374
+ property_name string of property name
375
+
376
+ Returns
377
+ -------
378
+
379
+ """
380
+ idc, inside = self.position_to_cell_corners(evaluation_points)
381
+ v = np.zeros(idc.shape)
382
+ v[:, :] = np.nan
383
+
384
+ v[inside, :] = self.position_to_dof_coefs(
385
+ evaluation_points[inside, :]).T
386
+ v[inside, :] *= self.properties[property_name][idc[inside, :]]
387
+ return np.sum(v, axis=1)
388
+
389
+ def evaluate_gradient(self, evaluation_points, property_name):
390
+ idc, inside = self.position_to_cell_corners(evaluation_points)
391
+ T = np.zeros((idc.shape[0], 3, 8))
392
+ T[inside, :, :] = self.calcul_T(evaluation_points[inside, :])
393
+ # indices = np.array([self.position_to_cell_index(evaluation_points)])
394
+ # idc = self.global_indicies(indices.swapaxes(0,1))
395
+ # print(idc)
396
+ T[inside, 0, :] *= self.properties[property_name][idc[inside, :]]
397
+ T[inside, 1, :] *= self.properties[property_name][idc[inside, :]]
398
+ T[inside, 2, :] *= self.properties[property_name][idc[inside, :]]
399
+ return np.array(
400
+ [np.sum(T[:, 0, :], axis=1) / 8, np.sum(T[:, 1, :], axis=1) / 8,
401
+ np.sum(T[:, 2, :], axis=1) / 8]).T
402
+
403
+ def calcul_T(self, pos):
404
+ """
405
+ Calculates the gradient matrix at location pos
406
+ :param pos: numpy array of location Nx3
407
+ :return: Nx3x4 matrix
408
+ """
409
+ # 6_ _ _ _ 8
410
+ # /| /|
411
+ # 4 /_| 5/ |
412
+ # | 2|_ _|_| 7
413
+ # | / | /
414
+ # |/_ _ _|/
415
+ # 0 1
416
+ #
417
+ # xindex, yindex, zindex = self.position_to_cell_index(pos)
418
+ # cellx, celly, cellz = self.cell_corner_indexes(xindex, yindex,zindex)
419
+ # x, y, z = self.node_indexes_to_position(cellx, celly, cellz)
420
+ T = np.zeros((pos.shape[0], 3, 8))
421
+ x, y, z = self.position_to_local_coordinates(pos)
422
+ # div = self.step_vector[0] * self.step_vector[1] * self.step_vector[2]
423
+
424
+ T[:, 0, 0] = -(1 - y) * (1 - z) # v000
425
+ T[:, 0, 1] = (1 - y) * (1 - z) # (y[:, 3] - pos[:, 1]) / div
426
+ T[:, 0, 2] = -y * (1 - z) # (pos[:, 1] - y[:, 0]) / div
427
+ T[:, 0, 3] = -(1 - y) * z # (pos[:, 1] - y[:, 1]) / div
428
+ T[:, 0, 4] = (1 - y) * z
429
+ T[:, 0, 5] = - y * z
430
+ T[:, 0, 6] = y * (1 - z)
431
+ T[:, 0, 7] = y * z
432
+
433
+ T[:, 1, 0] = - (1 - x) * (1 - z)
434
+ T[:, 1, 1] = - x * (1 - z)
435
+ T[:, 1, 2] = (1 - x) * (1 - z)
436
+ T[:, 1, 3] = -(1 - x) * z
437
+ T[:, 1, 4] = -x * z
438
+ T[:, 1, 5] = (1 - x) * z
439
+ T[:, 1, 6] = x * (1 - z)
440
+ T[:, 1, 7] = x * z
441
+
442
+ T[:, 2, 0] = -(1 - x) * (1 - y)
443
+ T[:, 2, 1] = - x * (1 - y)
444
+ T[:, 2, 2] = - (1 - x) * y
445
+ T[:, 2, 3] = (1 - x) * (1 - y)
446
+ T[:, 2, 4] = x * (1 - y)
447
+ T[:, 2, 5] = (1 - x) * y
448
+ T[:, 2, 6] = - x * y
449
+ T[:, 2, 7] = x * y
450
+ return T
451
+
452
+ def slice(self, propertyname, isovalue, region):
453
+ logger.error("function has been removed, please use the modelviewer class")
454
+ return
455
+ #
456
+ # verts, faces, normals, values = marching_cubes(
457
+ # self.properties[propertyname].reshape(self.nsteps, order='F'),
458
+ # isovalue,
459
+ # spacing=self.step_vector)
460
+ # return faces, verts + self.origin[None, :]