@@ -40,6 +40,7 @@ def __init__(self, mesh):
4040 "tpw" : 1.0 ,
4141 "ipw" : 1.0 ,
4242 }
43+
4344 def _setup_interpolator (self , ** kwargs ):
4445 """
4546 Searches through kwargs for any interpolation weights and updates
@@ -65,17 +66,19 @@ def _setup_interpolator(self, **kwargs):
6566 self .interpolation_weights [key ] = kwargs [key ]
6667 if self .interpolation_weights ["cgw" ] > 0.0 :
6768 self .up_to_date = False
68- self .minimise_edge_jumps (
69- self .interpolation_weights ["cgw" ])
69+ self .minimise_edge_jumps (self .interpolation_weights ["cgw" ])
7070 # direction_feature=kwargs.get("direction_feature", None),
7171 # direction_vector=kwargs.get("direction_vector", None),
7272 # )
73- self .minimise_grad_steepness (w = self .interpolation_weights .get ('steepness_weight' ,.01 ),wtfunc = self .interpolation_weights .get ('steepness_wtfunc' ,None ))
73+ self .minimise_grad_steepness (
74+ w = self .interpolation_weights .get ("steepness_weight" , 0.01 ),
75+ wtfunc = self .interpolation_weights .get ("steepness_wtfunc" , None ),
76+ )
7477 logger .info (
7578 "Using constant gradient regularisation w = %f"
7679 % self .interpolation_weights ["cgw" ]
7780 )
78-
81+
7982 logger .info (
8083 "Added %i gradient constraints, %i normal constraints,"
8184 "%i tangent constraints and %i value constraints"
@@ -87,7 +90,6 @@ def _setup_interpolator(self, **kwargs):
8790 self .add_tangent_constraints (self .interpolation_weights ["tpw" ])
8891 # self.add_interface_constraints(self.interpolation_weights["ipw"])
8992
90-
9193 def copy (self ):
9294 return P2Interpolator (self .support )
9395
@@ -103,8 +105,9 @@ def add_gradient_constraints(self, w=1.0):
103105 B = np .zeros (A .shape [0 ])
104106 elements = self .support [elements [inside ]]
105107 self .add_constraints_to_least_squares (
106- A * wt [:,None ], B , elements , name = "gradient" )
107-
108+ A * wt [:, None ], B , elements , name = "gradient"
109+ )
110+
108111 def add_gradient_orthogonal_constraints (self , points , vector , w = 1.0 , B = 0 ):
109112 """
110113 constraints scalar field to be orthogonal to a given vector
@@ -130,7 +133,8 @@ def add_gradient_orthogonal_constraints(self, points, vector, w=1.0, B=0):
130133 B = np .zeros (A .shape [0 ])
131134 elements = self .support .elements [elements [inside ]]
132135 self .add_constraints_to_least_squares (
133- A * wt [:,None ], B , elements , name = "gradient orthogonal" )
136+ A * wt [:, None ], B , elements , name = "gradient orthogonal"
137+ )
134138
135139 def add_norm_constraints (self , w = 1.0 ):
136140 points = self .get_norm_constraints ()
@@ -156,16 +160,14 @@ def add_norm_constraints(self, w=1.0):
156160
157161 pass
158162
159-
160-
161163 def add_value_constraints (self , w = 1.0 ):
162164 points = self .get_value_constraints ()
163165 if points .shape [0 ] > 1 :
164166 N , elements , mask = self .support .evaluate_shape (points [:, :3 ])
165167 # mask = elements > 0
166168 size = self .support .element_size [elements [mask ]]
167169 wt = np .ones (size .shape [0 ])
168- wt *= w
170+ wt *= w
169171 self .add_constraints_to_least_squares (
170172 N [mask , :] * wt [:, None ],
171173 points [mask , 3 ] * wt ,
@@ -197,10 +199,10 @@ def minimise_grad_steepness(self, w=0.1, maskall=True, wtfunc=None):
197199 d2 = self .support .evaluate_shape_d2 (elements [mask ])
198200 # d2 is [ele_idx, deriv, node]
199201 wt = np .ones (d2 .shape [0 ])
200-
201- wt *= w # * self.support.element_size[mask]
202+
203+ wt *= w # * self.support.element_size[mask]
202204 if callable (wtfunc ):
203- logger .info (' Using function to weight gradient steepness' )
205+ logger .info (" Using function to weight gradient steepness" )
204206 wt = wtfunc (self .support .barycentre ) * self .support .element_size [mask ]
205207 idc = self .support .elements [elements [mask ]]
206208 for i in range (d2 .shape [1 ]):
@@ -210,36 +212,36 @@ def minimise_grad_steepness(self, w=0.1, maskall=True, wtfunc=None):
210212 idc [:, :],
211213 name = f"grad_steepness_{ i } " ,
212214 )
213-
215+
214216 def minimise_edge_jumps (
215217 self , w = 0.1 , wtfunc = None , vector_func = None
216218 ): # NOTE: imposes \phi_T1(xi)-\phi_T2(xi) dot n =0
217219 # iterate over all triangles
218-
220+
219221 cp , weight = self .support .get_quadrature_points (3 )
220222
221223 norm = self .support .shared_element_norm
222224 shared_element_size = self .support .shared_element_size
223-
225+
224226 # evaluate normal if using vector func for cp1
225227 for i in range (cp .shape [1 ]):
226228 if callable (vector_func ):
227- norm = vector_func (cp [:,i , :])
229+ norm = vector_func (cp [:, i , :])
228230 # evaluate the shape function for the edges for each neighbouring triangle
229231 cp_Dt , cp_tri1 = self .support .evaluate_shape_derivatives (
230- cp [:,i , :], elements = self .support .shared_element_relationships [:, 0 ]
232+ cp [:, i , :], elements = self .support .shared_element_relationships [:, 0 ]
231233 )
232234 cp_Dn , cp_tri2 = self .support .evaluate_shape_derivatives (
233- cp [:,i , :], elements = self .support .shared_element_relationships [:, 1 ]
235+ cp [:, i , :], elements = self .support .shared_element_relationships [:, 1 ]
234236 )
235237 # constraint for each cp is triangle - neighbour create a Nx12 matrix
236238 const_t_cp = np .einsum ("ij,ijk->ik" , norm , cp_Dt )
237239 const_n_cp = - np .einsum ("ij,ijk->ik" , norm , cp_Dn )
238-
240+
239241 const_cp = np .hstack ([const_t_cp , const_n_cp ])
240242 tri_cp = np .hstack (
241- [self .support .elements [cp_tri1 ], self .support .elements [cp_tri2 ]]
242- )
243+ [self .support .elements [cp_tri1 ], self .support .elements [cp_tri2 ]]
244+ )
243245 wt = np .zeros (tri_cp .shape [0 ])
244246 wt [:] = w
245247 if wtfunc :
@@ -250,9 +252,6 @@ def minimise_edge_jumps(
250252 tri_cp ,
251253 name = f"shared element jump cp{ i } " ,
252254 )
253-
254-
255-
256255
257256 def evaluate_d2 (self , evaluation_points ):
258257 evaluation_points = np .array (evaluation_points )
0 commit comments