Skip to content

Commit 7dc0605

Browse files
Axel Mengelle-Nicolelachlangrose
authored andcommitted
Renamed nx to dof when it represents the degree of freedom of an interpolator
1 parent f6db4a5 commit 7dc0605

File tree

8 files changed

+32
-32
lines changed

8 files changed

+32
-32
lines changed

LoopStructural/interpolators/_discrete_interpolator.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self, support, data={}, c=None, up_to_date=False):
4242

4343
self.shape = "rectangular"
4444
if self.shape == "square":
45-
self.B = np.zeros(self.nx)
45+
self.B = np.zeros(self.dof)
4646
self.c_ = 0
4747

4848
self.solver = "cg"
@@ -60,7 +60,7 @@ def __init__(self, support, data={}, c=None, up_to_date=False):
6060
self.non_linear_constraints = []
6161
self.constraints = {}
6262
self.interpolation_weights = {}
63-
logger.info("Creating discrete interpolator with {} degrees of freedom".format(self.nx))
63+
logger.info("Creating discrete interpolator with {} degrees of freedom".format(self.dof))
6464
self.type = InterpolatorType.BASE_DISCRETE
6565

6666
def set_nelements(self, nelements: int) -> int:
@@ -78,7 +78,7 @@ def n_elements(self) -> int:
7878
return self.support.n_elements
7979

8080
@property
81-
def nx(self) -> int:
81+
def dof(self) -> int:
8282
"""Number of degrees of freedom for the interpolator
8383
8484
Returns
@@ -125,7 +125,7 @@ def set_region(self, region=None):
125125
# self.region_function = region
126126
logger.info(
127127
"Cannot use region at the moment. Interpolation now uses region and has {} degrees of freedom".format(
128-
self.nx
128+
self.dof
129129
)
130130
)
131131

@@ -175,7 +175,7 @@ def reset(self):
175175
"""
176176
self.constraints = {}
177177
self.c_ = 0
178-
self.regularisation_scale = np.ones(self.nx)
178+
self.regularisation_scale = np.ones(self.dof)
179179
logger.info("Resetting interpolation constraints")
180180

181181
def add_constraints_to_least_squares(self, A, B, idc, w=1.0, name="undefined"):
@@ -245,7 +245,7 @@ def add_constraints_to_least_squares(self, A, B, idc, w=1.0, name="undefined"):
245245
rows = np.tile(rows, (A.shape[-1], 1)).T
246246
self.constraints[name] = {
247247
'matrix': sparse.coo_matrix(
248-
(A.flatten(), (rows.flatten(), idc.flatten())), shape=(n_rows, self.nx)
248+
(A.flatten(), (rows.flatten(), idc.flatten())), shape=(n_rows, self.dof)
249249
).tocsc(),
250250
'b': B.flatten(),
251251
'w': w,
@@ -286,7 +286,7 @@ def add_inequality_constraints_to_matrix(
286286
A : numpy array
287287
matrix of coefficients
288288
bounds : numpy array
289-
nx3 lower, upper, 1
289+
n*3 lower, upper, 1
290290
idc : numpy array
291291
index of constraints in the matrix
292292
Returns
@@ -296,14 +296,14 @@ def add_inequality_constraints_to_matrix(
296296
# map from mesh node index to region node index
297297
gi = np.zeros(self.support.n_nodes, dtype=int)
298298
gi[:] = -1
299-
gi[self.region] = np.arange(0, self.nx, dtype=int)
299+
gi[self.region] = np.arange(0, self.dof, dtype=int)
300300
idc = gi[idc]
301301
rows = np.arange(0, idc.shape[0])
302302
rows = np.tile(rows, (A.shape[-1], 1)).T
303303

304304
self.ineq_constraints[name] = {
305305
'matrix': sparse.coo_matrix(
306-
(A.flatten(), (rows.flatten(), idc.flatten())), shape=(rows.shape[0], self.nx)
306+
(A.flatten(), (rows.flatten(), idc.flatten())), shape=(rows.shape[0], self.dof)
307307
).tocsc(),
308308
"bounds": bounds,
309309
}
@@ -431,7 +431,7 @@ def add_inequality_feature(
431431
np.ones((value.shape[0], 1)),
432432
l,
433433
u,
434-
np.arange(0, self.nx, dtype=int),
434+
np.arange(0, self.dof, dtype=int),
435435
)
436436

437437
def add_equality_constraints(self, node_idx, values, name="undefined"):
@@ -454,7 +454,7 @@ def add_equality_constraints(self, node_idx, values, name="undefined"):
454454
# map from mesh node index to region node index
455455
gi = np.zeros(self.support.n_nodes)
456456
gi[:] = -1
457-
gi[self.region] = np.arange(0, self.nx)
457+
gi[self.region] = np.arange(0, self.dof)
458458
idc = gi[node_idx]
459459
outside = ~(idc == -1)
460460

@@ -515,7 +515,7 @@ def add_equality_block(self, A, B):
515515
if len(self.equal_constraints) > 0:
516516
ATA = A.T.dot(A)
517517
ATB = A.T.dot(B)
518-
logger.info(f"Equality block is {self.eq_const_c} x {self.nx}")
518+
logger.info(f"Equality block is {self.eq_const_c} x {self.dof}")
519519
# solving constrained least squares using
520520
# | ATA CT | |c| = b
521521
# | C 0 | |y| d
@@ -540,7 +540,7 @@ def add_equality_block(self, A, B):
540540

541541
C = sparse.coo_matrix(
542542
(np.array(a), (np.array(rows), cols)),
543-
shape=(self.eq_const_c, self.nx),
543+
shape=(self.eq_const_c, self.dof),
544544
dtype=float,
545545
).tocsr()
546546

@@ -557,7 +557,7 @@ def build_inequality_matrix(self):
557557
mats.append(c['matrix'])
558558
bounds.append(c['bounds'])
559559
if len(mats) == 0:
560-
return sparse.csr_matrix((0, self.nx), dtype=float), np.zeros((0, 3))
560+
return sparse.csr_matrix((0, self.dof), dtype=float), np.zeros((0, 3))
561561
Q = sparse.vstack(mats)
562562
bounds = np.vstack(bounds)
563563
return Q, bounds

LoopStructural/interpolators/_finite_difference_interpolator.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def add_value_constraints(self, w=1.0):
160160
# print(points[inside,:].shape)
161161
gi = np.zeros(self.support.n_nodes, dtype=int)
162162
gi[:] = -1
163-
gi[self.region] = np.arange(0, self.nx, dtype=int)
163+
gi[self.region] = np.arange(0, self.dof, dtype=int)
164164
idc = np.zeros(node_idx.shape)
165165
idc[:] = -1
166166
idc[inside, :] = gi[node_idx[inside, :]]
@@ -204,7 +204,7 @@ def add_interface_constraints(self, w=1.0):
204204
)
205205
gi = np.zeros(self.support.n_nodes, dtype=int)
206206
gi[:] = -1
207-
gi[self.region] = np.arange(0, self.nx, dtype=int)
207+
gi[self.region] = np.arange(0, self.dof, dtype=int)
208208
idc = np.zeros(node_idx.shape).astype(int)
209209
idc[:] = -1
210210
idc[inside, :] = gi[node_idx[inside, :]]
@@ -227,11 +227,11 @@ def add_interface_constraints(self, w=1.0):
227227
interface_A = np.hstack([A[mask, :][ij[:, 0], :], -A[mask, :][ij[:, 1], :]])
228228
interface_idc = np.hstack([idc[mask, :][ij[:, 0], :], idc[mask, :][ij[:, 1], :]])
229229
# now map the index from global to region create array size of mesh
230-
# initialise as np.nan, then map points inside region to 0->nx
230+
# initialise as np.nan, then map points inside region to 0->dof
231231
gi = np.zeros(self.support.n_nodes).astype(int)
232232
gi[:] = -1
233233

234-
gi[self.region] = np.arange(0, self.nx)
234+
gi[self.region] = np.arange(0, self.dof)
235235
interface_idc = gi[interface_idc]
236236
outside = ~np.any(interface_idc == -1, axis=1)
237237
self.add_constraints_to_least_squares(
@@ -266,7 +266,7 @@ def add_gradient_constraints(self, w=1.0):
266266
# magnitude
267267
gi = np.zeros(self.support.n_nodes)
268268
gi[:] = -1
269-
gi[self.region] = np.arange(0, self.nx)
269+
gi[self.region] = np.arange(0, self.dof)
270270
idc = np.zeros(node_idx.shape)
271271
idc[:] = -1
272272
idc[inside, :] = gi[node_idx[inside, :]]
@@ -331,7 +331,7 @@ def add_norm_constraints(self, w=1.0):
331331
)
332332
gi = np.zeros(self.support.n_nodes)
333333
gi[:] = -1
334-
gi[self.region] = np.arange(0, self.nx)
334+
gi[self.region] = np.arange(0, self.dof)
335335
idc = np.zeros(node_idx.shape)
336336
idc[:] = -1
337337
idc[inside, :] = gi[node_idx[inside, :]]
@@ -421,7 +421,7 @@ def add_gradient_orthogonal_constraints(
421421
# magnitude
422422
gi = np.zeros(self.support.n_nodes)
423423
gi[:] = -1
424-
gi[self.region] = np.arange(0, self.nx)
424+
gi[self.region] = np.arange(0, self.dof)
425425
idc = np.zeros(node_idx.shape)
426426
idc[:] = -1
427427

@@ -472,7 +472,7 @@ def add_gradient_orthogonal_constraints(
472472

473473
# """
474474
# # First get the global indicies of the pairs of neighbours this should be an
475-
# # Nx27 array for 3d and an Nx9 array for 2d
475+
# # N*27 array for 3d and an N*9 array for 2d
476476

477477
# global_indexes = self.support.neighbour_global_indexes()
478478

@@ -490,7 +490,7 @@ def assemble_inner(self, operator, w, name='regularisation'):
490490
491491
"""
492492
# First get the global indicies of the pairs of neighbours this should be an
493-
# Nx27 array for 3d and an Nx9 array for 2d
493+
# N*27 array for 3d and an N*9 array for 2d
494494

495495
global_indexes = self.support.neighbour_global_indexes() # np.array([ii,jj]))
496496

@@ -499,7 +499,7 @@ def assemble_inner(self, operator, w, name='regularisation'):
499499

500500
gi = np.zeros(self.support.n_nodes)
501501
gi[:] = -1
502-
gi[self.region] = np.arange(0, self.nx)
502+
gi[self.region] = np.arange(0, self.dof)
503503
idc = gi[idc]
504504
inside = ~np.any(idc == -1, axis=1) # np.ones(a.shape[0],dtype=bool)#
505505
# a[idc==-1] = 0

LoopStructural/interpolators/_geological_interpolator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def to_json(self):
9696
json["constraints"] = self.constraints
9797
json["data"] = self.data
9898
json["type"] = self.type
99-
# json["dof"] = self.nx
99+
# json["dof"] = self.dof
100100
json["up_to_date"] = self.up_to_date
101101
return json
102102

LoopStructural/interpolators/_surfe_wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def evaluate_gradient(self, evaluation_points):
203203
return
204204

205205
@property
206-
def nx(self):
206+
def dof(self):
207207
return self.get_data_locations().shape[0]
208208
@property
209209
def n_elements(self)->int:

LoopStructural/interpolators/supports/_2d_base_unstructured.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(self, elements, vertices, neighbours, aabb_nsteps=None):
3030
self.order = 1
3131
elif self.elements.shape[1] == 6:
3232
self.order = 2
33-
self.nx = self.vertices.shape[0]
33+
self.dof = self.vertices.shape[0]
3434
self.neighbours = neighbours
3535
self.minimum = np.min(self.nodes, axis=0)
3636
self.maximum = np.max(self.nodes, axis=0)

LoopStructural/modelling/core/geological_model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,15 +1670,15 @@ def update(self, verbose=False, progressbar=True):
16701670
for f in self.features:
16711671
if f.type == FeatureType.FAULT:
16721672
nfeatures += 3
1673-
total_dof += f[0].interpolator.nx * 3
1673+
total_dof += f[0].interpolator.dof * 3
16741674
continue
16751675
if isinstance(f, StructuralFrame):
16761676
nfeatures += 3
1677-
total_dof += f[0].interpolator.nx * 3
1677+
total_dof += f[0].interpolator.dof * 3
16781678
continue
16791679
if f.type == FeatureType.INTERPOLATED:
16801680
nfeatures += 1
1681-
total_dof += f.interpolator.nx
1681+
total_dof += f.interpolator.dof
16821682
continue
16831683
if verbose:
16841684
print(

LoopStructural/modelling/features/builders/_geological_feature_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ def set_interpolation_geometry(self, origin, maximum, rotation=None):
452452
self.interpolator.support.rotation_xy = rotation
453453
self._up_to_date = False
454454

455-
while self.interpolator.nx < 100:
455+
while self.interpolator.dof < 100:
456456
self.interpolator.support.step_vector = self.interpolator.support.step_vector * 0.9
457457

458458
def check_interpolation_geometry(self, data, buffer=0.3):

tests/unit/interpolator/test_discrete_interpolator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
def test_nx(interpolator, data):
2-
assert interpolator.nx == 21 * 21 * 21
2+
assert interpolator.dof == 21 * 21 * 21
33

44

55
def test_region(interpolator, data, region_func):

0 commit comments

Comments
 (0)