Skip to content

Commit b9b4a03

Browse files
committed
Revert "IMprove smoothing at octree change"
This reverts commit 1c0c690.
1 parent 1c0c690 commit b9b4a03

2 files changed

Lines changed: 24 additions & 38 deletions

File tree

simpeg_drivers/driver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ def get_regularization(self):
560560
f"aveCC2F{fun.orientation}",
561561
)
562562
fun.set_weights(**{comp: average_op @ weight})
563-
fun.norm = np.round(average_op @ norm, decimals=3)
563+
fun.norm = average_op @ norm
564564
functions.append(fun)
565565

566566
if is_rotated:
@@ -583,7 +583,7 @@ def get_regularization(self):
583583
f"aveCC2F{fun.orientation}",
584584
)
585585
backward_fun.set_weights(**{comp: average_op @ weight})
586-
backward_fun.norm = np.round(average_op @ norm, decimals=3)
586+
backward_fun.norm = average_op @ norm
587587
functions.append(backward_fun)
588588

589589
# Will avoid recomputing operators if the regularization mesh is the same

simpeg_drivers/utils/regularization.py

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -339,20 +339,20 @@ def gradient_operator(
339339
:param volumes: Partial volume array.
340340
:param n_cells: Number of cells in mesh.
341341
"""
342-
grad = ssp.csr_matrix(
342+
Grad = ssp.csr_matrix(
343343
(volumes, (neighbors[:, 0], neighbors[:, 1])), shape=(n_cells, n_cells)
344344
)
345345

346346
# Normalize rows
347-
vol = mkvc(grad.sum(axis=1))
348-
vol[vol > 0] = 1.0 / vol[vol > 0]
349-
grad = -sdiag(vol) * grad
347+
Vol = mkvc(Grad.sum(axis=1))
348+
Vol[Vol > 0] = 1.0 / Vol[Vol > 0]
349+
Grad = -sdiag(Vol) * Grad
350350

351351
diag = np.ones(n_cells)
352-
diag[vol == 0] = 0
353-
grad = sdiag(diag) + grad
352+
diag[Vol == 0] = 0
353+
Grad = sdiag(diag) + Grad
354354

355-
return grad
355+
return Grad
356356

357357

358358
def rotated_gradient(
@@ -399,8 +399,8 @@ def rotated_gradient(
399399
)
400400

401401
unit_grad = gradient_operator(neighbors, volumes, n_cells)
402-
403-
return unit_grad
402+
axes = "xyz" if dim == 3 else "xz"
403+
return sdiag(1 / mesh.h_gridded[:, axes.find(axis)]) @ unit_grad
404404

405405

406406
def ensure_dip_direction_convention(
@@ -464,40 +464,26 @@ def set_rotated_operators(
464464
:param forward: Whether to use forward or backward difference for
465465
derivative approximations.
466466
"""
467-
mesh = function.regularization_mesh
468-
axes = "xyz" if mesh.dim == 3 else "xz"
469-
470-
h_cell = mesh.mesh.h_gridded[:, axes.find(axis)]
471-
472-
unit_grad_op = rotated_gradient(mesh.mesh, neighbors, axis, dip, direction, forward)
473-
474-
count_op = unit_grad_op.copy()
475-
count_op.data = np.ones_like(count_op.data)
476-
477-
grad_op_active = mesh.Pac.T @ (unit_grad_op @ mesh.Pac)
478-
count_op = mesh.Pac.T @ (count_op @ mesh.Pac)
479-
active_faces = np.isclose(grad_op_active @ np.ones(mesh.n_cells), 0)
480-
active_faces &= grad_op_active.max(axis=1).toarray().ravel() != 0
481-
482-
count_op = count_op[active_faces, :]
483-
484-
h_op = sdiag(
485-
(count_op @ (mesh.Pac.T @ h_cell) / np.asarray(count_op.sum(axis=1)).ravel())
486-
** -1.0
467+
grad_op = rotated_gradient(
468+
function.regularization_mesh.mesh, neighbors, axis, dip, direction, forward
469+
)
470+
grad_op_active = function.regularization_mesh.Pac.T @ (
471+
grad_op @ function.regularization_mesh.Pac
472+
)
473+
active_faces = np.isclose(
474+
grad_op_active @ np.ones(function.regularization_mesh.n_cells), 0
487475
)
476+
active_faces &= grad_op_active.max(axis=1).toarray().ravel() != 0
488477

489-
grad_op = h_op @ grad_op_active[active_faces, :]
490-
avg_op = abs(grad_op_active[active_faces, :])
491-
avg_op = sdiag(np.asarray(avg_op.sum(axis=1)).ravel() ** -1.0) @ avg_op
492478
setattr(
493-
mesh,
479+
function.regularization_mesh,
494480
f"_cell_gradient_{function.orientation}",
495-
grad_op,
481+
grad_op_active[active_faces, :],
496482
)
497483
setattr(
498-
mesh,
484+
function.regularization_mesh,
499485
f"_aveCC2F{function.orientation}",
500-
avg_op,
486+
sdiag(np.ones(function.regularization_mesh.n_cells))[active_faces, :],
501487
)
502488

503489
return function

0 commit comments

Comments
 (0)