22Piecewise linear interpolator using folds
33"""
44
5- from typing import Optional
5+ from typing import Optional , Callable
66
77import numpy as np
88
@@ -64,6 +64,7 @@ def add_fold_constraints(
6464 fold_normalisation = 1.0 ,
6565 fold_norm = 1.0 ,
6666 step = 2 ,
67+ mask_fn : Optional [Callable ] = None ,
6768 ):
6869 """
6970
@@ -104,6 +105,10 @@ def add_fold_constraints(
104105 # calculate element volume for weighting
105106 vecs = nodes [:, 1 :, :] - nodes [:, 0 , None , :]
106107 vol = np .abs (np .linalg .det (vecs )) / 6
108+ weight = np .ones (self .support .n_elements , dtype = float )
109+ if mask_fn is not None :
110+ weight [mask_fn (self .support .barycentre )] = 0
111+ weight = weight [::step ]
107112 if fold_orientation is not None :
108113 """
109114 dot product between vector in deformed ori plane = 0
@@ -120,7 +125,7 @@ def add_fold_constraints(
120125 B = np .zeros (A .shape [0 ])
121126 idc = self .support .get_elements ()[element_idx [::step ], :]
122127 self .add_constraints_to_least_squares (
123- A , B , idc , w = fold_orientation , name = "fold orientation"
128+ A , B , idc , w = weight * fold_orientation , name = "fold orientation"
124129 )
125130
126131 if fold_axis_w is not None :
@@ -139,7 +144,9 @@ def add_fold_constraints(
139144 B = np .zeros (A .shape [0 ]).tolist ()
140145 idc = self .support .get_elements ()[element_idx [::step ], :]
141146
142- self .add_constraints_to_least_squares (A , B , idc , w = fold_axis_w , name = "fold axis" )
147+ self .add_constraints_to_least_squares (
148+ A , B , idc , w = weight * fold_axis_w , name = "fold axis"
149+ )
143150
144151 if fold_normalisation is not None :
145152 """
@@ -160,7 +167,7 @@ def add_fold_constraints(
160167 idc = self .support .get_elements ()[element_idx [::step ], :]
161168
162169 self .add_constraints_to_least_squares (
163- A , B , idc , w = fold_normalisation , name = "fold normalisation"
170+ A , B , idc , w = weight * fold_normalisation , name = "fold normalisation"
164171 )
165172
166173 if fold_regularisation is not None :
0 commit comments