@@ -333,23 +333,18 @@ def calculate_point_cost(u, v, x, y, z, point_list, Cp=1e-3, roi=500.0):
333333 for the_point in point_list :
334334 # Instead of worrying about whole domain, just find points in radius of influence
335335 # Since we know that the weight will be zero outside the sphere of influence anyways
336- xp = tf .ones_like (x ) * the_point ["x" ]
337- yp = tf .ones_like (y ) * the_point ["y" ]
338- zp = tf .ones_like (z ) * the_point ["z" ]
339336 up = tf .ones_like (u ) * the_point ["u" ]
340337 vp = tf .ones_like (v ) * the_point ["v" ]
341-
342- the_box = tf .where (
343- tf .math .logical_and (
344- tf .math .logical_and (
345- tf .math .abs (x - xp ) < roi , tf .math .abs (y - yp ) < roi
346- ),
347- tf .math .abs (z - zp ) < roi ,
348- ),
349- 1.0 ,
350- 0.0 ,
338+ dist = tf .math .sqrt (
339+ (x - the_point ["x" ]) ** 2
340+ + (y - the_point ["y" ]) ** 2
341+ + (z - the_point ["z" ]) ** 2
351342 )
352- J .assign_add (tf .math .reduce_sum (((u - up ) ** 2 + (v - vp ) ** 2 ) * the_box ))
343+ dist = tf .math .maximum (dist , 1.0 )
344+ weight = 1 / dist ** 2
345+ weight = weight / tf .reduce_max (weight )
346+
347+ J .assign_add (tf .math .reduce_sum (((u - up ) ** 2 + (v - vp ) ** 2 ) * weight ))
353348
354349 return J * Cp
355350
@@ -394,24 +389,19 @@ def calculate_point_gradient(u, v, x, y, z, point_list, Cp=1e-3, roi=500.0):
394389 for the_point in point_list :
395390 # Instead of worrying about whole domain, just find points in radius of influence
396391 # Since we know that the weight will be zero outside the sphere of influence anyways
397- xp = tf .ones_like (x , dtype = tf .float32 ) * the_point ["x" ]
398- yp = tf .ones_like (y , dtype = tf .float32 ) * the_point ["y" ]
399- zp = tf .ones_like (z , dtype = tf .float32 ) * the_point ["z" ]
400392 up = tf .ones_like (u , dtype = tf .float32 ) * the_point ["u" ]
401393 vp = tf .ones_like (v , dtype = tf .float32 ) * the_point ["v" ]
402394
403- the_box = tf .where (
404- tf .math .logical_and (
405- tf .math .logical_and (
406- tf .math .abs (x - xp ) < roi , tf .math .abs (y - yp ) < roi
407- ),
408- tf .math .abs (z - zp ) < roi ,
409- ),
410- 1.0 ,
411- 0.0 ,
395+ dist = tf .math .sqrt (
396+ (x - the_point ["x" ]) ** 2
397+ + (y - the_point ["y" ]) ** 2
398+ + (z - the_point ["z" ]) ** 2
412399 )
413- gradJ_u .assign_add ((2 * (u - up ) * the_box ))
414- gradJ_v .assign_add ((2 * (v - vp ) * the_box ))
400+ dist = tf .math .maximum (dist , 1.0 )
401+ weight = 1 / dist ** 2
402+ weight = weight / tf .reduce_max (weight )
403+ gradJ_u .assign_add ((2 * (u - up ) * weight ))
404+ gradJ_v .assign_add ((2 * (v - vp ) * weight ))
415405 gradJ = tf .stack ([gradJ_u , gradJ_v , gradJ_w ], axis = 0 )
416406 gradJ = tf .reshape (gradJ , (3 * np .prod (u .shape ),))
417407 return gradJ * Cp
0 commit comments