Skip to content

Commit 3f8e490

Browse files
author
Lachlan Grose
committed
refactor: 🎨 black reformat
1 parent 2dbc29e commit 3f8e490

17 files changed

+247
-170
lines changed

LoopStructural/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import tempfile
1010
from pathlib import Path
1111
from .version import __version__
12+
1213
experimental = False
1314
ch = logging.StreamHandler()
1415
formatter = logging.Formatter(

LoopStructural/analysis/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
"""
77
from LoopStructural.utils import getLogger
88
import LoopStructural
9+
910
logger = getLogger(__name__)
1011
if LoopStructural.experimental:
11-
logger.warning("LoopStructural.analysis is experimental and may not perform as expected")
12+
logger.warning(
13+
"LoopStructural.analysis is experimental and may not perform as expected"
14+
)
1215
from ._fault_displacement import displacement_missfit
1316
from ._fault_intersection import calculate_fault_intersections
1417
from ._topology import calculate_fault_topology_matrix

LoopStructural/analysis/_topology.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ def calculate_fault_topology_matrix(model, xyz=None, threshold=0.001, scale=True
2222
topology_matrix : np.array
2323
matrix containing nan (outside), 0 (footwall), 1 (hangingwall)
2424
"""
25-
if xyz is not None and scale==True:
25+
if xyz is not None and scale == True:
2626
logger.warning("Scaling XYZ to model coordinate system")
27-
xyz = model.scale(xyz,inplace=False)
27+
xyz = model.scale(xyz, inplace=False)
2828
if xyz is None:
2929
xyz = model.regular_grid(rescale=False, shuffle=False)
3030
topology_matrix = np.zeros((xyz.shape[0], len(model.faults)))

LoopStructural/interpolators/__init__.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
from LoopStructural.utils import getLogger
88
import LoopStructural
9+
910
logger = getLogger(__name__)
11+
12+
1013
class InterpolatorType(IntEnum):
1114
"""
1215
Enum for the different interpolator types
@@ -27,7 +30,15 @@ class InterpolatorType(IntEnum):
2730

2831
from LoopStructural.interpolators._geological_interpolator import GeologicalInterpolator
2932
from LoopStructural.interpolators._discrete_interpolator import DiscreteInterpolator
30-
from LoopStructural.interpolators.supports import TetMesh, StructuredGrid, UnStructuredTetMesh, P1Unstructured2d, P2Unstructured2d, StructuredGrid2D, P2UnstructuredTetMesh
33+
from LoopStructural.interpolators.supports import (
34+
TetMesh,
35+
StructuredGrid,
36+
UnStructuredTetMesh,
37+
P1Unstructured2d,
38+
P2Unstructured2d,
39+
StructuredGrid2D,
40+
P2UnstructuredTetMesh,
41+
)
3142

3243

3344
from LoopStructural.interpolators._finite_difference_interpolator import (
@@ -39,7 +50,10 @@ class InterpolatorType(IntEnum):
3950
from LoopStructural.interpolators._discrete_fold_interpolator import (
4051
DiscreteFoldInterpolator,
4152
)
53+
4254
if LoopStructural.experimental:
43-
logger.warning("Using experimental interpolators: P1Interpolator and P2Interpolator")
55+
logger.warning(
56+
"Using experimental interpolators: P1Interpolator and P2Interpolator"
57+
)
4458
from ._p1interpolator import P1Interpolator
4559
from ._p2interpolator import P2Interpolator

LoopStructural/interpolators/_discrete_interpolator.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def add_constraints_to_least_squares(self, A, B, idc, w=1.0, name="undefined"):
173173

174174
if len(A.shape) > 2:
175175
nr = A.shape[0] * A.shape[1]
176-
if isinstance(w,np.ndarray):
176+
if isinstance(w, np.ndarray):
177177
w = np.tile(w, (A.shape[1]))
178178
A = A.reshape((A.shape[0] * A.shape[1], A.shape[2]))
179179
idc = idc.reshape((idc.shape[0] * idc.shape[1], idc.shape[2]))
@@ -280,7 +280,7 @@ def add_equality_constraints(self, node_idx, values, name="undefined"):
280280
gi[self.region] = np.arange(0, self.nx)
281281
idc = gi[node_idx]
282282
outside = ~(idc == -1)
283-
283+
284284
self.equal_constraints[name] = {
285285
"A": np.ones(idc[outside].shape[0]),
286286
"B": values[outside],
@@ -451,7 +451,6 @@ def build_matrix(self, square=True, damp=0.0, ie=False):
451451
cols.extend(c["col"].flatten()[~mask].tolist())
452452

453453
C = coo_matrix(
454-
455454
(np.array(a), (np.array(rows), cols)),
456455
shape=(self.eq_const_c, self.nx),
457456
dtype=float,
@@ -502,7 +501,7 @@ def _solve_osqp(self, P, A, q, l, u, mkl=False):
502501
try:
503502
import osqp
504503
except ImportError:
505-
raise LoopImportError("Missing osqp pip install osqp")
504+
raise LoopImportError("Missing osqp pip install osqp")
506505
prob = osqp.OSQP()
507506

508507
# Setup workspace

LoopStructural/interpolators/_geological_interpolator.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ def __init__(self):
4747
self.valid = False
4848

4949
def __str__(self):
50-
name = f'{self.type} \n'
51-
name += f'{self.n_g} gradient points\n'
52-
name += f'{self.n_i} interface points\n'
53-
name += f'{self.n_n} normal points\n'
54-
name += f'{self.n_t} tangent points\n'
55-
name += f'{self.n_g + self.n_i + self.n_n + self.n_t} total points\n'
50+
name = f"{self.type} \n"
51+
name += f"{self.n_g} gradient points\n"
52+
name += f"{self.n_i} interface points\n"
53+
name += f"{self.n_n} normal points\n"
54+
name += f"{self.n_t} tangent points\n"
55+
name += f"{self.n_g + self.n_i + self.n_n + self.n_t} total points\n"
5656
return name
5757

5858
def set_region(self, **kwargs):

LoopStructural/interpolators/_p1interpolator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ def add_gradient_ctr_pts(self, w=1.0):
4646
def add_norm_ctr_pts(self, w=1.0):
4747
points = self.get_norm_constraints()
4848
if points.shape[0] > 0:
49-
grad, elements, inside = self.support.evaluate_shape_derivatives(points[:, :3])
49+
grad, elements, inside = self.support.evaluate_shape_derivatives(
50+
points[:, :3]
51+
)
5052
size = self.support.element_size[inside]
5153
wt = np.ones(size.shape[0])
5254
wt *= w * size
@@ -123,5 +125,3 @@ def minimize_edge_jumps(
123125
name="edge jump",
124126
)
125127
# p2.add_constraints_to_least_squares(const_cp2*e_len[:,None]*w,np.zeros(const_cp1.shape[0]),tri_cp2, name='edge jump cp2')
126-
127-

LoopStructural/interpolators/_p2interpolator.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def __init__(self, mesh):
4040
"tpw": 1.0,
4141
"ipw": 1.0,
4242
}
43+
4344
def _setup_interpolator(self, **kwargs):
4445
"""
4546
Searches through kwargs for any interpolation weights and updates
@@ -65,17 +66,19 @@ def _setup_interpolator(self, **kwargs):
6566
self.interpolation_weights[key] = kwargs[key]
6667
if self.interpolation_weights["cgw"] > 0.0:
6768
self.up_to_date = False
68-
self.minimise_edge_jumps(
69-
self.interpolation_weights["cgw"])
69+
self.minimise_edge_jumps(self.interpolation_weights["cgw"])
7070
# direction_feature=kwargs.get("direction_feature", None),
7171
# direction_vector=kwargs.get("direction_vector", None),
7272
# )
73-
self.minimise_grad_steepness(w=self.interpolation_weights.get('steepness_weight',.01),wtfunc=self.interpolation_weights.get('steepness_wtfunc',None))
73+
self.minimise_grad_steepness(
74+
w=self.interpolation_weights.get("steepness_weight", 0.01),
75+
wtfunc=self.interpolation_weights.get("steepness_wtfunc", None),
76+
)
7477
logger.info(
7578
"Using constant gradient regularisation w = %f"
7679
% self.interpolation_weights["cgw"]
7780
)
78-
81+
7982
logger.info(
8083
"Added %i gradient constraints, %i normal constraints,"
8184
"%i tangent constraints and %i value constraints"
@@ -87,7 +90,6 @@ def _setup_interpolator(self, **kwargs):
8790
self.add_tangent_constraints(self.interpolation_weights["tpw"])
8891
# self.add_interface_constraints(self.interpolation_weights["ipw"])
8992

90-
9193
def copy(self):
9294
return P2Interpolator(self.support)
9395

@@ -103,8 +105,9 @@ def add_gradient_constraints(self, w=1.0):
103105
B = np.zeros(A.shape[0])
104106
elements = self.support[elements[inside]]
105107
self.add_constraints_to_least_squares(
106-
A*wt[:,None], B, elements, name="gradient")
107-
108+
A * wt[:, None], B, elements, name="gradient"
109+
)
110+
108111
def add_gradient_orthogonal_constraints(self, points, vector, w=1.0, B=0):
109112
"""
110113
constraints scalar field to be orthogonal to a given vector
@@ -130,7 +133,8 @@ def add_gradient_orthogonal_constraints(self, points, vector, w=1.0, B=0):
130133
B = np.zeros(A.shape[0])
131134
elements = self.support.elements[elements[inside]]
132135
self.add_constraints_to_least_squares(
133-
A*wt[:,None], B, elements, name="gradient orthogonal")
136+
A * wt[:, None], B, elements, name="gradient orthogonal"
137+
)
134138

135139
def add_norm_constraints(self, w=1.0):
136140
points = self.get_norm_constraints()
@@ -156,16 +160,14 @@ def add_norm_constraints(self, w=1.0):
156160

157161
pass
158162

159-
160-
161163
def add_value_constraints(self, w=1.0):
162164
points = self.get_value_constraints()
163165
if points.shape[0] > 1:
164166
N, elements, mask = self.support.evaluate_shape(points[:, :3])
165167
# mask = elements > 0
166168
size = self.support.element_size[elements[mask]]
167169
wt = np.ones(size.shape[0])
168-
wt *= w
170+
wt *= w
169171
self.add_constraints_to_least_squares(
170172
N[mask, :] * wt[:, None],
171173
points[mask, 3] * wt,
@@ -197,10 +199,10 @@ def minimise_grad_steepness(self, w=0.1, maskall=True, wtfunc=None):
197199
d2 = self.support.evaluate_shape_d2(elements[mask])
198200
# d2 is [ele_idx, deriv, node]
199201
wt = np.ones(d2.shape[0])
200-
201-
wt *= w #* self.support.element_size[mask]
202+
203+
wt *= w # * self.support.element_size[mask]
202204
if callable(wtfunc):
203-
logger.info('Using function to weight gradient steepness')
205+
logger.info("Using function to weight gradient steepness")
204206
wt = wtfunc(self.support.barycentre) * self.support.element_size[mask]
205207
idc = self.support.elements[elements[mask]]
206208
for i in range(d2.shape[1]):
@@ -210,36 +212,36 @@ def minimise_grad_steepness(self, w=0.1, maskall=True, wtfunc=None):
210212
idc[:, :],
211213
name=f"grad_steepness_{i}",
212214
)
213-
215+
214216
def minimise_edge_jumps(
215217
self, w=0.1, wtfunc=None, vector_func=None
216218
): # NOTE: imposes \phi_T1(xi)-\phi_T2(xi) dot n =0
217219
# iterate over all triangles
218-
220+
219221
cp, weight = self.support.get_quadrature_points(3)
220222

221223
norm = self.support.shared_element_norm
222224
shared_element_size = self.support.shared_element_size
223-
225+
224226
# evaluate normal if using vector func for cp1
225227
for i in range(cp.shape[1]):
226228
if callable(vector_func):
227-
norm = vector_func(cp[:,i,:])
229+
norm = vector_func(cp[:, i, :])
228230
# evaluate the shape function for the edges for each neighbouring triangle
229231
cp_Dt, cp_tri1 = self.support.evaluate_shape_derivatives(
230-
cp[:,i, :], elements=self.support.shared_element_relationships[:, 0]
232+
cp[:, i, :], elements=self.support.shared_element_relationships[:, 0]
231233
)
232234
cp_Dn, cp_tri2 = self.support.evaluate_shape_derivatives(
233-
cp[:,i, :], elements=self.support.shared_element_relationships[:, 1]
235+
cp[:, i, :], elements=self.support.shared_element_relationships[:, 1]
234236
)
235237
# constraint for each cp is triangle - neighbour create a Nx12 matrix
236238
const_t_cp = np.einsum("ij,ijk->ik", norm, cp_Dt)
237239
const_n_cp = -np.einsum("ij,ijk->ik", norm, cp_Dn)
238-
240+
239241
const_cp = np.hstack([const_t_cp, const_n_cp])
240242
tri_cp = np.hstack(
241-
[self.support.elements[cp_tri1], self.support.elements[cp_tri2]]
242-
)
243+
[self.support.elements[cp_tri1], self.support.elements[cp_tri2]]
244+
)
243245
wt = np.zeros(tri_cp.shape[0])
244246
wt[:] = w
245247
if wtfunc:
@@ -250,9 +252,6 @@ def minimise_edge_jumps(
250252
tri_cp,
251253
name=f"shared element jump cp{i}",
252254
)
253-
254-
255-
256255

257256
def evaluate_d2(self, evaluation_points):
258257
evaluation_points = np.array(evaluation_points)

LoopStructural/interpolators/supports/_2d_base_unstructured.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ def __init__(self, elements, vertices, neighbours):
2323
self.n_nodes = self.nx
2424
self.neighbours = neighbours
2525

26-
2726
self.properties = {}
2827
# build an array of edges and edge relationships
2928
self.edges = np.zeros((self.nelements * 3, 2), dtype=int)
@@ -55,6 +54,7 @@ def ncps(self):
5554
Returns the number of nodes for an element in the mesh
5655
"""
5756
return self.elements.shape[1]
57+
5858
@property
5959
def nodes(self):
6060
"""
@@ -66,6 +66,7 @@ def nodes(self):
6666
Fortran ordered
6767
"""
6868
return self.vertices
69+
6970
@property
7071
def barycentre(self):
7172
"""

0 commit comments

Comments
 (0)