Skip to content

Commit 0971e20

Browse files
authored
Merge pull request #146 from Loop3D/intrusions
Intrusions
2 parents b36d0eb + 26bfaa2 commit 0971e20

32 files changed

+1614
-2799
lines changed

.github/workflows/release-please.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Installing dependencies
1919
shell: bash -l {0}
2020
run: |
21-
conda install -c conda-forge cython numpy scipy scikit-image scikit-learn pyamg flake8 pytest networkx osqp numba statsmodels scikit-fmm matplotlib -y
21+
conda install -c conda-forge cython numpy scipy scikit-image scikit-learn pyamg flake8 pytest networkx osqp matplotlib -y
2222
- name: Checking formatting of code
2323
shell: bash -l {0}
2424
run: |

Dockerfile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@ RUN apt-get update -qq && \
1313
libopenmpi-dev \
1414
make
1515
# RUN conda install -c conda-forge python=3.9 -y
16-
RUN conda install -c conda-forge -c loop3d pip \
16+
RUN conda install -c conda-forge -c loop3d\
17+
pip \
1718
map2model\
1819
hjson\
1920
owslib\
2021
beartype\
2122
gdal=3.5.2\
2223
rasterio=1.2.10 \
2324
meshio\
24-
scikit-fmm\
25-
statsmodels\
26-
numba\
2725
scikit-learn \
2826
cython \
2927
numpy \
@@ -41,11 +39,16 @@ RUN conda install -c conda-forge -c loop3d pip \
4139
folium \
4240
jupyterlab \
4341
nodejs \
42+
rasterio\
43+
geopandas\
4444
-y
4545

4646
RUN pip install ipyfilechooser
4747
RUN jupyter nbextension enable --py --sys-prefix ipyleaflet
48-
RUN pip install lavavu-osmesa geostatspy mplstereonet
48+
RUN pip install lavavu-osmesa mplstereonet
49+
50+
ENV LD_LIBRARY_PATH=/opt/conda/lib/python3.10/site-packages/lavavu/
51+
4952

5053
ENV NB_USER jovyan
5154
ENV NB_UID 1000
@@ -80,6 +83,7 @@ RUN pip install -e LoopProjectFile
8083
# WORKDIR Tomofast-x
8184
# RUN make
8285
WORKDIR ${HOME}/notebooks
86+
8387
# RUN pip install -e LoopStructural
8488
CMD ["jupyter", "lab", "--ip='0.0.0.0'", "--NotebookApp.token=''", "--no-browser" ]
8589

DockerfileDev

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ RUN apt-get update -qq && \
1313
libopenmpi-dev \
1414
make
1515
# RUN conda install -c conda-forge python=3.9 -y
16-
RUN conda install -c conda-forge pip \
16+
RUN conda install -c conda-forge "python<=3.9" \
17+
pip \
1718
scikit-learn \
1819
cython \
1920
numpy \
@@ -31,11 +32,12 @@ RUN conda install -c conda-forge pip \
3132
folium \
3233
jupyterlab \
3334
nodejs \
35+
rasterio\
3436
-y
3537

3638
RUN pip install ipyfilechooser
3739
RUN jupyter nbextension enable --py --sys-prefix ipyleaflet
38-
RUN pip install lavavu-osmesa
40+
RUN pip install lavavu-osmesa==1.8.32 pyevtk
3941

4042
ENV NB_USER jovyan
4143
ENV NB_UID 1000

LoopStructural/interpolators/_discrete_interpolator.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import numpy as np
88
from scipy.sparse import coo_matrix, bmat, eye
99
from scipy.sparse import linalg as sla
10-
from scipy.sparse.linalg import norm
11-
from sklearn.preprocessing import normalize
1210
from ..interpolators import InterpolatorType
1311

1412
from ..interpolators import GeologicalInterpolator
@@ -88,6 +86,7 @@ def region(self) -> np.ndarray:
8886
np.ndarray
8987
9088
"""
89+
9190
return self.region_function(self.support.nodes).astype(bool)
9291

9392
@property
@@ -126,7 +125,8 @@ def set_region(self, region=None):
126125
"""
127126
# evaluate the region function on the support to determine
128127
# which nodes are inside update region map and degrees of freedom
129-
self.region_function = region
128+
print("Cannot use region")
129+
# self.region_function = region
130130
logger.info(
131131
"Interpolation now uses region and has {} degrees of freedom".format(
132132
self.nx
@@ -800,7 +800,9 @@ def _solve(self, solver="cg", **kwargs):
800800
)
801801
return
802802
self.valid = True
803-
logging.info(f"Solving interpolation: {self.propertyname} took: {time()-starttime}")
803+
logging.info(
804+
f"Solving interpolation: {self.propertyname} took: {time()-starttime}"
805+
)
804806

805807
def update(self):
806808
"""

LoopStructural/interpolators/_geological_interpolator.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,9 @@ def __init__(self):
2424
this should be callable by using any of these functions. This will
2525
enable interpolators to be interchanged.
2626
"""
27+
self.data = {} # None
28+
self.clean() # init data structure
2729

28-
self.data = {
29-
"gradient": np.zeros((0, 7)),
30-
"value": np.zeros((0, 5)),
31-
"normal": np.zeros((0, 7)),
32-
"tangent": np.zeros((0, 7)),
33-
"interface": np.zeros((0, 5)),
34-
"inequality": np.zeros((0, 6)),
35-
}
3630
self.n_g = 0
3731
self.n_i = 0
3832
self.n_n = 0
@@ -200,7 +194,7 @@ def get_data_locations(self):
200194
numpy array
201195
Nx3 - X,Y,Z location of all data points
202196
"""
203-
return np.vstack([d for d in self.data.values()[:, :3]])
197+
return np.vstack([d[:, :3] for d in self.data.values()])
204198

205199
def get_interface_constraints(self):
206200
"""Get the location of interface constraints
@@ -231,14 +225,23 @@ def solve_system(self, **kwargs):
231225
def update(self):
232226
return False
233227

234-
def reset(self):
228+
def clean(self):
235229
"""
236230
Removes all of the data from an interpolator
237231
238232
Returns
239233
-------
240234
241235
"""
236+
self.data = {
237+
"gradient": np.zeros((0, 7)),
238+
"value": np.zeros((0, 5)),
239+
"normal": np.zeros((0, 7)),
240+
"tangent": np.zeros((0, 7)),
241+
"interface": np.zeros((0, 5)),
242+
"inequality": np.zeros((0, 6)),
243+
}
244+
self.up_to_date = False
242245
self.n_g = 0
243246
self.n_i = 0
244247
self.n_n = 0

LoopStructural/interpolators/piecewiselinear_interpolator.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ def add_constant_gradient(
186186
gi[:] = -1
187187
gi[self.region] = np.arange(0, self.nx)
188188
idc = gi[idc]
189+
189190
outside = ~np.any(idc == -1, axis=1)
191+
190192
# w/=A.shape[0]
191193
self.add_constraints_to_least_squares(
192194
A[outside, :], B[outside], idc[outside, :], w=w, name="regularisation"
@@ -239,12 +241,20 @@ def add_gradient_constraints(self, w=1.0):
239241
outside = ~np.any(idc == -1, axis=1)
240242
w *= points[:, 6]
241243
self.add_constraints_to_least_squares(
242-
A[outside, :], B[outside], idc[outside, :], w=w, name="gradient strike"
244+
A[outside, :],
245+
B[outside],
246+
idc[outside, :],
247+
w=w[outside],
248+
name="gradient strike",
243249
)
244250
A = np.einsum("ji,ijk->ik", dip_vector, element_gradients)
245251
# A *= vol[:, None]
246252
self.add_constraints_to_least_squares(
247-
A[outside, :], B[outside], idc[outside, :], w=w, name="gradient dip"
253+
A[outside, :],
254+
B[outside],
255+
idc[outside, :],
256+
w=w[outside],
257+
name="gradient dip",
248258
)
249259

250260
def add_norm_constraints(self, w=1.0):
@@ -299,7 +309,11 @@ def add_norm_constraints(self, w=1.0):
299309
# w /= 3
300310

301311
self.add_constraints_to_least_squares(
302-
d_t[outside, :, :], points[outside, 3:6], idc[outside], w=w, name="norm"
312+
d_t[outside, :, :],
313+
points[outside, 3:6],
314+
idc[outside],
315+
w=w[outside],
316+
name="norm",
303317
)
304318

305319
def add_value_constraints(self, w=1.0): # for now weight all value points the same
@@ -339,9 +353,9 @@ def add_value_constraints(self, w=1.0): # for now weight all value points the s
339353
w *= points[inside, 4]
340354
self.add_constraints_to_least_squares(
341355
A[outside, :],
342-
points[inside, :][outside, 3] * vol[:],
356+
points[inside, :][outside, 3] * vol[outside],
343357
idc[outside, :],
344-
w=w,
358+
w=w[outside],
345359
name="value",
346360
)
347361

LoopStructural/interpolators/supports/_3d_base_structured.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def check_position(self, pos):
218218
return False
219219
return pos
220220

221-
def _global_indicies(self, indexes, nsteps):
221+
def _global_indicies(self, indexes: np.ndarray, nsteps: np.ndarray) -> np.ndarray:
222222
"""
223223
Convert from cell indexes to global cell index
224224
@@ -285,7 +285,9 @@ def position_to_cell_corners(self, pos):
285285
inside = self.inside(pos)
286286
ix, iy, iz = self.position_to_cell_index(pos)
287287
cornersx, cornersy, cornersz = self.cell_corner_indexes(ix, iy, iz)
288-
globalidx = self.global_indicies(np.dstack([cornersx, cornersy, cornersz]).T)
288+
globalidx = self.global_node_indicies(
289+
np.dstack([cornersx, cornersy, cornersz]).T
290+
)
289291
# if global index is not inside the support set to -1
290292
globalidx[~inside] = -1
291293
return globalidx, inside
@@ -360,7 +362,7 @@ def global_index_to_node_index(self, global_index):
360362
z_index = global_index // self.nsteps[0, None] // self.nsteps[1, None]
361363
return x_index, y_index, z_index
362364

363-
def global_node_indicies(self, indexes):
365+
def global_node_indicies(self, indexes) -> np.ndarray:
364366
"""
365367
Convert from node indexes to global node index
366368
@@ -374,7 +376,7 @@ def global_node_indicies(self, indexes):
374376
"""
375377
return self._global_indicies(indexes, self.nsteps)
376378

377-
def global_cell_indicies(self, indexes):
379+
def global_cell_indicies(self, indexes) -> np.ndarray:
378380
"""
379381
Convert from cell indexes to global cell index
380382

LoopStructural/interpolators/supports/_3d_structured_grid.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -141,25 +141,6 @@ def position_to_dof_coefs(self, pos):
141141
weights = self.trilinear(x_local, y_local, local_z)
142142
return weights
143143

144-
def global_indicies(self, indexes):
145-
"""
146-
xi, yi, zi to global index
147-
148-
Parameters
149-
----------
150-
indexes
151-
152-
Returns
153-
-------
154-
155-
"""
156-
indexes = np.array(indexes).swapaxes(0, 2)
157-
return (
158-
indexes[:, :, 0]
159-
+ self.nsteps[None, None, 0] * indexes[:, :, 1]
160-
+ self.nsteps[None, None, 0] * self.nsteps[None, None, 1] * indexes[:, :, 2]
161-
)
162-
163144
def neighbour_global_indexes(self, mask=None, **kwargs):
164145
"""
165146
Get neighbour indexes
@@ -475,6 +456,11 @@ def get_element_for_location(self, pos):
475456
[description]
476457
"""
477458
vertices, inside = self.position_to_cell_vertices(pos)
459+
vertices = np.array(vertices)
460+
vertices = vertices.reshape((vertices.shape[1], 8, 3))
478461
elements, inside = self.position_to_cell_corners(pos)
479462
a = self.position_to_dof_coefs(pos)
480463
return vertices, a.T, elements, inside
464+
465+
def get_elements(self):
466+
return

0 commit comments

Comments
 (0)