@@ -79,58 +79,62 @@ def _setup_interpolator(self, **kwargs):
7979 for key in kwargs :
8080 self .up_to_date = False
8181 if 'regularisation' in kwargs :
82- self .interpolation_weights ['dxy' ] = kwargs [
83- 'regularisation' ] * 0.7
84- self .interpolation_weights ['dyz' ] = kwargs [
85- 'regularisation' ] * 0.7
86- self .interpolation_weights ['dxz' ] = kwargs [
87- 'regularisation' ] * 0.7
88- self .interpolation_weights ['dxx' ] = kwargs [
89- 'regularisation' ] * 1.
90- self .interpolation_weights ['dyy' ] = kwargs [
91- 'regularisation' ] * 1.
92- self .interpolation_weights ['dzz' ] = kwargs [
93- 'regularisation' ] * 1.
82+ self .interpolation_weights ['dxy' ] = 0.1 * kwargs [
83+ 'regularisation' ]
84+ self .interpolation_weights ['dyz' ] = 0.1 * kwargs [
85+ 'regularisation' ]
86+ self .interpolation_weights ['dxz' ] = 0.1 * kwargs [
87+ 'regularisation' ]
88+ self .interpolation_weights ['dxx' ] = 0.1 * kwargs [
89+ 'regularisation' ]
90+ self .interpolation_weights ['dyy' ] = 0.1 * kwargs [
91+ 'regularisation' ]
92+ self .interpolation_weights ['dzz' ] = 0.1 * kwargs [
93+ 'regularisation' ]
9494 self .interpolation_weights [key ] = kwargs [key ]
9595 # if we want to define the operators manually
9696 if 'operators' in kwargs :
9797 for n , o in kwargs ['operators' ].items ():
9898 self .assemble_inner (o [0 ], o [1 ])
9999 # otherwise just use defaults
100100 if 'operators' not in kwargs :
101+
101102 operator = Operator .Dxy_mask
102-
103- self .assemble_inner ( operator , np . sqrt ( 2 * self .vol ) *
104- self .interpolation_weights [ 'dxy' ] )
103+ weight = self . interpolation_weights [ 'dxy' ] / \
104+ 1 #(4* self.support.step_vector[0]* self.support.step_vector[1])
105+ self .assemble_inner ( operator , weight )
105106 operator = Operator .Dyz_mask
106- self .assemble_inner (operator , np .sqrt (2 * self .vol ) *
107- self .interpolation_weights ['dyz' ])
107+ weight = self .interpolation_weights ['dyz' ] / \
108+ 1 #(4*self.support.step_vector[1]*self.support.step_vector[2])
109+ self .assemble_inner (operator , weight )
108110 operator = Operator .Dxz_mask
109- self .assemble_inner (operator , np .sqrt (2 * self .vol ) *
110- self .interpolation_weights ['dxz' ])
111+ weight = self .interpolation_weights ['dxz' ] / \
112+ 1 #(4*self.support.step_vector[0]*self.support.step_vector[2])
113+ self .assemble_inner (operator , weight )
111114 operator = Operator .Dxx_mask
115+ weight = self .interpolation_weights ['dxx' ] \
116+ / 1 #self.support.step_vector[0]**2
112117 self .assemble_inner (operator ,
113- np .sqrt (self .vol ) * self .interpolation_weights [
114- 'dxx' ])
118+ weight )
115119 operator = Operator .Dyy_mask
116- self .assemble_inner ( operator ,
117- np . sqrt ( self .vol ) * self . interpolation_weights [
118- 'dyy' ] )
120+ weight = self .interpolation_weights [ 'dyy' ] / \
121+ 1 # self.support.step_vector[1]**2
122+ self . assemble_inner ( operator , weight )
119123 operator = Operator .Dzz_mask
120- self .assemble_inner ( operator ,
121- np . sqrt ( self .vol ) * self . interpolation_weights [
122- 'dzz' ] )
124+ weight = self .interpolation_weights [ 'dzz' ] / \
125+ 1 # self.support.step_vector[2]**2
126+ self . assemble_inner ( operator , weight )
123127 self .add_norm_constraint (
124- np . sqrt ( self . vol ) * self .interpolation_weights ['npw' ])
128+ self .interpolation_weights ['npw' ])
125129 self .add_gradient_constraint (
126- np . sqrt ( self . vol ) * self .interpolation_weights ['gpw' ])
130+ self .interpolation_weights ['gpw' ])
127131 self .add_vaue_constraint (
128- np . sqrt ( self . vol ) * self .interpolation_weights ['cpw' ])
132+ self .interpolation_weights ['cpw' ])
129133 self .add_tangent_ctr_pts (
130- np . sqrt ( self . vol ) * self .interpolation_weights ['tpw' ]
134+ self .interpolation_weights ['tpw' ]
131135 )
132136 self .add_interface_ctr_pts (
133- np . sqrt ( self . vol ) * self .interpolation_weights ['ipw' ]
137+ self .interpolation_weights ['ipw' ]
134138 )
135139
136140 def copy (self ):
@@ -172,7 +176,7 @@ def add_vaue_constraint(self, w=1.):
172176 inside = np .logical_and (~ np .any (idc == - 1 , axis = 1 ), inside )
173177 a = self .support .position_to_dof_coefs (points [inside , :3 ])
174178 # a*=w
175-
179+ # a/=np.product(self.support.step_vector)
176180 self .add_constraints_to_least_squares (a .T * w ,
177181 points [inside , 3 ] * w ,
178182 idc [inside , :],
@@ -259,6 +263,8 @@ def add_gradient_constraint(self, w=1.):
259263 inside = np .logical_and (~ np .any (idc == - 1 , axis = 1 ), inside )
260264
261265 T = self .support .calcul_T (points [inside , :3 ])
266+ norm = np .linalg .norm (T ,axis = 2 )
267+ T /= norm [:,:,None ]
262268 strike_vector , dip_vector = get_vectors (points [inside , 3 :6 ])
263269 A = np .einsum ('ij,ijk->ik' , strike_vector .T , T )
264270
@@ -284,7 +290,6 @@ def add_norm_constraint(self, w=1.):
284290 if points .shape [0 ] > 0 :
285291 # calculate unit vector for orientation data
286292 # points[:,3:]/=np.linalg.norm(points[:,3:],axis=1)[:,None]
287-
288293 node_idx , inside = self .support .position_to_cell_corners (
289294 points [:, :3 ])
290295 gi = np .zeros (self .support .n_nodes )
@@ -299,16 +304,17 @@ def add_norm_constraint(self, w=1.):
299304 # this means we are only constraining direction of grad not the
300305 # magnitude
301306 T = self .support .calcul_T (points [inside , :3 ])
302-
307+ # T*=np.product(self.support.step_vector)
308+ # T/=self.support.step_vector[0]
303309 w /= 3
304310 self .add_constraints_to_least_squares (T [:, 0 , :] * w ,
305- points [inside , 3 ] * w ,
311+ points [inside , 3 ] * w ,
306312 idc [inside , :], name = 'norm' )
307313 self .add_constraints_to_least_squares (T [:, 1 , :] * w ,
308- points [inside , 4 ] * w ,
314+ points [inside , 4 ] * w ,
309315 idc [inside , :], name = 'norm' )
310316 self .add_constraints_to_least_squares (T [:, 2 , :] * w ,
311- points [inside , 5 ] * w ,
317+ points [inside , 5 ] * w ,
312318 idc [inside , :], name = 'norm' )
313319
314320 def add_gradient_orthogonal_constraint (self , points , vector , w = 1.0 ,
@@ -345,9 +351,15 @@ def add_gradient_orthogonal_constraint(self, points, vector, w=1.0,
345351 idc [inside , :] = gi [node_idx [inside , :]]
346352 inside = np .logical_and (~ np .any (idc == - 1 , axis = 1 ), inside )
347353
354+ #normalise element vector to unit vector for dot product
348355 T = self .support .calcul_T (points [inside , :3 ])
356+ norm = np .linalg .norm (T ,axis = 1 )
357+ T /= norm [:,None ,:]
358+ # normalise vector to unit vector for dot product
359+ vector [inside ,:3 ] /= np .linalg .norm (vector [inside ,:3 ],axis = 1 )[:,None ]
360+ # dot product of vector and element gradient
349361 A = np .einsum ('ij,ijk->ik' , vector [inside , :3 ], T )
350-
362+
351363 B = np .zeros (points [inside , :].shape [0 ])
352364 self .add_constraints_to_least_squares (A * w , B , idc [inside , :], name = 'gradient orthogonal' )
353365
@@ -390,9 +402,11 @@ def assemble_inner(self, operator, w):
390402 gi [:] = - 1
391403 gi [self .region ] = np .arange (0 , self .nx )
392404 idc = gi [idc ]
393- inside = ~ np .any (idc == - 1 , axis = 1 )
405+ inside = ~ np .any (idc == - 1 , axis = 1 )#np.ones(a.shape[0],dtype=bool)#
406+ # a[idc==-1] = 0
407+ # idc[idc==-1] = 0
394408 B = np .zeros (global_indexes .shape [1 ])
395- self .add_constraints_to_least_squares (a [inside , :] * w ,
409+ self .add_constraints_to_least_squares (a [inside , :] * w ,
396410 B [inside ],
397411 idc [inside , :],
398412 name = 'regularisation'
0 commit comments