@@ -347,6 +347,42 @@ def scalar_field(self, bounding_box=None):
347347 grid .cell_properties [self .name ] = value
348348 return grid
349349
350+ def gradient_norm_scalar_field (self , bounding_box = None ):
351+ """Create a scalar field for the gradient norm of the feature
352+
353+ Parameters
354+ ----------
355+ bounding_box : Optional[BoundingBox], optional
356+ bounding box to evaluate the scalar field in, by default None
357+
358+ Returns
359+ -------
360+ np.ndarray
361+ scalar field of the gradient norm
362+ """
363+ if bounding_box is None :
364+ if self .model is None :
365+ raise ValueError ("Must specify bounding box" )
366+ bounding_box = self .model .bounding_box
367+ grid = bounding_box .structured_grid (name = self .name )
368+ value = np .linalg .norm (
369+ self .evaluate_gradient (bounding_box .regular_grid (local = False , order = 'F' )),
370+ axis = 1 ,
371+ )
372+ if self .model is not None :
373+ value = np .linalg .norm (
374+ self .evaluate_gradient (
375+ self .model .scale (bounding_box .regular_grid (local = False , order = 'F' ))
376+ ),
377+ axis = 1 ,
378+ )
379+ grid .properties [self .name ] = value
380+
381+ value = np .linalg .norm (
382+ self .evaluate_gradient (bounding_box .cell_centres (order = 'F' )), axis = 1
383+ )
384+ grid .cell_properties [self .name ] = value
385+ return grid
350386 def vector_field (self , bounding_box = None , tolerance = 0.05 , scale = 1.0 ):
351387 """Create a vector field for the feature
352388
0 commit comments