Skip to content

Commit

Permalink
fix: actually fixing divide by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
Lachlan Grose committed Feb 7, 2022
1 parent 9f17489 commit ef4d7d0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion LoopStructural/interpolators/base_structured_3d_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def __init__(
# we use property decorators to update these when different parts of
# the geometry need to change
# inisialise the private attributes
if np.any(step_vector==0):
logger.warning(f"Step vector {step_vector} has zero values")
self._nsteps = np.array(nsteps, dtype=int)
self._step_vector = np.array(step_vector)
self._origin = np.array(origin)
Expand Down Expand Up @@ -72,7 +74,7 @@ def step_vector(self, step_vector):
newsteps = self._nsteps / change_factor
self._nsteps = np.ceil(newsteps).astype(int)
self._step_vector = step_vector

@property
def origin(self):
return self._origin
Expand Down
9 changes: 5 additions & 4 deletions LoopStructural/interpolators/piecewiselinear_interpolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,12 @@ def add_gradient_orthogonal_constraints(self, points, vector, w=1.0, B=0):
# e, inside = self.support.elements_for_array(points[:, :3])
# nodes = self.support.nodes[self.support.elements[e]]
norm = np.linalg.norm(vector, axis=1)
mask = ~np.isnan(norm)
vector /= norm[mask, None]
mask = np.isnan(norm)
mask = ~np.logical_or(mask, norm==0)
vector[mask,:] /= norm[mask, None]
vecs = vertices[:, 1:, :] - vertices[:, 0, None, :]
vol = np.abs(np.linalg.det(vecs)) / 6
element_gradients /= norm[mask, None, None]
# vol = np.abs(np.linalg.det(vecs)) / 6
element_gradients[mask,:,:] /= norm[mask, None, None]

A = np.einsum("ij,ijk->ik", vector, element_gradients)

Expand Down

0 comments on commit ef4d7d0

Please sign in to comment.