Skip to content

Commit

Permalink
fix: method names for FDI/PLI are consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
Lachlan Grose committed Oct 5, 2021
1 parent 03b9e73 commit aebba23
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 56 deletions.
20 changes: 10 additions & 10 deletions LoopStructural/interpolators/finite_difference_interpolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,16 @@ def _setup_interpolator(self, **kwargs):
weight = self.interpolation_weights['dzz'] / \
1#self.support.step_vector[2]**2
self.assemble_inner(operator,weight)
self.add_norm_constraint(
self.add_norm_constraints(
self.interpolation_weights['npw'])
self.add_gradient_constraint(
self.add_gradient_constraints(
self.interpolation_weights['gpw'])
self.add_vaue_constraint(
self.add_vaue_constraints(
self.interpolation_weights['cpw'])
self.add_tangent_ctr_pts(
self.add_tangent_constraints(
self.interpolation_weights['tpw']
)
self.add_interface_ctr_pts(
self.add_interface_constraints(
self.interpolation_weights['ipw']
)

Expand All @@ -147,7 +147,7 @@ def copy(self):
"""
return FiniteDifferenceInterpolator(self.support)

def add_vaue_constraint(self, w=1.):
def add_vaue_constraints(self, w=1.):
"""
Parameters
Expand Down Expand Up @@ -181,7 +181,7 @@ def add_vaue_constraint(self, w=1.):
points[inside, 3] * w,
idc[inside, :],
name='value')
def add_interface_ctr_pts(self, w=1.0): # for now weight all value points the same
def add_interface_constraints(self, w=1.0): # for now weight all value points the same
"""
Adds a constraint that defines all points with the same 'id' to be the same value
Sets all P1-P2 = 0 for all pairs of points
Expand Down Expand Up @@ -232,7 +232,7 @@ def add_interface_ctr_pts(self, w=1.0): # for now weight all value points the s
np.zeros(A[outside,:].shape[0]),
interface_idc[outside, :], name='interface')

def add_gradient_constraint(self, w=1.):
def add_gradient_constraints(self, w=1.):
"""
Parameters
Expand Down Expand Up @@ -273,7 +273,7 @@ def add_gradient_constraint(self, w=1.):
A = np.einsum('ij,ijk->ik', dip_vector.T, T)
self.add_constraints_to_least_squares(A * w, B, idc[inside, :], name='gradient')

def add_norm_constraint(self, w=1.):
def add_norm_constraints(self, w=1.):
"""
Add constraints to control the norm of the gradient of the scalar field
Expand Down Expand Up @@ -317,7 +317,7 @@ def add_norm_constraint(self, w=1.):
points[inside, 5] * w ,
idc[inside, :], name='norm')

def add_gradient_orthogonal_constraint(self, points, vector, w=1.0,
def add_gradient_orthogonal_constraints(self, points, vector, w=1.0,
B=0):
"""
constraints scalar field to be orthogonal to a given vector
Expand Down
61 changes: 15 additions & 46 deletions LoopStructural/interpolators/piecewiselinear_interpolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,12 @@ def _setup_interpolator(self, **kwargs):
"%i tangent constraints and %i value constraints"
"to %s" % (self.n_g, self.n_n,
self.n_t, self.n_i, self.propertyname))
self.add_gradient_ctr_pts(self.interpolation_weights['gpw'])
self.add_norm_ctr_pts(self.interpolation_weights['npw'])
self.add_ctr_pts(self.interpolation_weights['cpw'])
self.add_tangent_ctr_pts(self.interpolation_weights['tpw'])
self.add_interface_ctr_pts(self.interpolation_weights['ipw'])
if 'constant_norm' in kwargs:
self.add_constant_norm(w=kwargs['constant_norm'])
self.add_gradient_constraints(self.interpolation_weights['gpw'])
self.add_norm_constraints(self.interpolation_weights['npw'])
self.add_value_constraints(self.interpolation_weights['cpw'])
self.add_tangent_constraints(self.interpolation_weights['tpw'])
self.add_interface_constraints(self.interpolation_weights['ipw'])


def add_constant_gradient(self, w= 0.1, direction_vector=None, direction_feature=None):
"""
Expand Down Expand Up @@ -173,37 +172,7 @@ def add_direction_constant_gradient(self, w= 0.1, direction_vector=None, directi
return


def add_constant_norm(self, w=0.1):
"""
Add the constant gradient regularisation to the system
Parameters
----------
w (double) - weighting of the cg parameter
Returns
-------
"""
# iterate over all elements
A, idc, B = self.support.get_constant_norm(region=self.region)
A = np.array(A)
B = np.array(B)
idc = np.array(idc)

gi = np.zeros(self.support.n_nodes)
gi[:] = -1
gi[self.region] = np.arange(0, self.nx)
idc = gi[idc]
outside = ~np.any(idc == -1, axis=1)

# w/=A.shape[0]
self.add_constraints_to_least_squares(A[outside, :] * w,
B[outside] * w, idc[outside, :],
name='norm_regularisation')
return

def add_gradient_ctr_pts(self, w=1.0):
def add_gradient_constraints(self, w=1.0):
"""
Adds gradient constraints to the least squares system with a weight
defined by w
Expand Down Expand Up @@ -257,7 +226,7 @@ def add_gradient_ctr_pts(self, w=1.0):
B[outside], idc[outside, :],
name='gradient')

def add_norm_ctr_pts(self, w=1.0):
def add_norm_constraints(self, w=1.0):
"""
Extracts the norm vectors from the interpolators p_n list and adds
these to the implicit
Expand Down Expand Up @@ -301,19 +270,19 @@ def add_norm_ctr_pts(self, w=1.0):
gi = np.zeros(self.support.n_nodes).astype(int)
gi[:] = -1
gi[self.region] = np.arange(0, self.nx).astype(int)
w /= 3
idc = gi[idc]
outside = ~np.any(idc == -1, axis=2)
outside = outside[:, 0]
w /= 3
w = points[:, 6]*w
# w /= 3

self.add_constraints_to_least_squares(d_t[outside, :, :] * w,
points[outside, 3:6] * w *
self.add_constraints_to_least_squares(d_t[outside, :, :] * w[:,None,None],
points[outside, 3:6] * w[:,None] *
vol[outside, None],
idc[outside],
name='norm')

def add_ctr_pts(self, w=1.0): # for now weight all value points the same
def add_value_constraints(self, w=1.0): # for now weight all value points the same
"""
Adds value constraints to the least squares system
Expand Down Expand Up @@ -349,7 +318,7 @@ def add_ctr_pts(self, w=1.0): # for now weight all value points the same
points[inside,:][outside, 3] * w * vol[outside],
idc[outside, :], name='value')

def add_interface_ctr_pts(self, w=1.0): # for now weight all value points the same
def add_interface_constraints(self, w=1.0): # for now weight all value points the same
"""
Adds a constraint that defines all points with the same 'id' to be the same value
Sets all P1-P2 = 0 for all pairs of points
Expand Down Expand Up @@ -473,6 +442,6 @@ def add_gradient_orthogonal_constraint(self, points, vector, w=1.0,
B = np.zeros(idc.shape[0])+B
outside = ~np.any(idc == -1, axis=1)
self.add_constraints_to_least_squares(A[outside, :] * w,
B[outside], idc[outside, :], name='gradient_orthogonal')
B[outside], idc[outside, :], name='gradient orthogonal')


0 comments on commit aebba23

Please sign in to comment.