parameters: (mesh, func=None, normMap=None, order=1)
return_statement: return diverg
docstring: Divergence for callable function func((x,y,z)).
  
      MOVE THIS to a better place
  
      Divergence for callable function func((x,y,z)).
      Return sum div over boundary.
  
      Parameters
      ----------
  
      Returns
      -------
docstring_summary: Divergence for callable function func((x,y,z)).
docstring_tokens: Divergence for callable function func (( x y z )) .
function: def divergence(mesh, func=None, normMap=None, order=1):
      """Divergence for callable function func((x,y,z)).
  
      MOVE THIS to a better place
  
      Divergence for callable function func((x,y,z)).
      Return sum div over boundary.
  
      Parameters
      ----------
  
      Returns
      -------
      """
      if func is None:
          func = lambda r: r
  
      diverg = 0
      directionCheck = False
  
      if mesh.cellCount() > 0:
          directionCheck = True
  
      bNorms = None
      if normMap is not None:
          bNorms = np.zeros((mesh.boundaryCount(), 2))
          for pair in normMap:
              bounds = mesh.findBoundaryByMarker(pair[0])
              for b in bounds:
                  bN = [0.0, 0.0]
                  if not isinstance(pair[1][0], str):
                      bN[0] = pair[1][0]
                  if not isinstance(pair[1][1], str):
                      bN[1] = pair[1][1]
  
                  bNorms[b.id()] = bN
  
      for b in mesh.boundaries():
  
          if directionCheck:
              if b.leftCell() is None and b.rightCell() is None:
                  # print(b.id(), b.leftCell(), b.rightCell())
                  sw = pg.core.Stopwatch(True)
                  mesh.createNeighborInfos()
                  print("NeighborInfos()", sw.duration(True))
                  # return gauss(grid, F)
  
              # don't calc for inner boundaries
              if b.leftCell() is not None and b.rightCell() is not None:
                  continue
  
          divS = 0
          shape = b.shape()
  
          if order == 1:
              if bNorms is not None:
                  divS = shape.norm().dot(bNorms[b.id()]) * shape.domainSize()
              else:
                  divS = shape.norm().dot(
                      func(shape.center())) * shape.domainSize()
          else:
              weights = pg.core.IntegrationRules.instance().weights(shape, order)
              abscissa = pg.core.IntegrationRules.instance().abscissa(shape, order)
  
              for i, p in enumerate(abscissa):
                  rPos = shape.xyz(p)
                  divS += shape.norm().dot(func(rPos)) * \
                      weights[i] * shape.domainSize()
  
          if directionCheck and b.leftCell() is None:
              divS *= -1
              # raise Exception("invalid mesh: left is None .. every
              # boundary need leftCell")
  
          diverg += divS
  
      return diverg
function_tokens: def divergence ( mesh , func = None , normMap = None , order = 1 ) : if func is None : func = lambda r : r diverg = 0 directionCheck = False if mesh . cellCount ( ) > 0 : directionCheck = True bNorms = None if normMap is not None : bNorms = np . zeros ( ( mesh . boundaryCount ( ) , 2 ) ) for pair in normMap : bounds = mesh . findBoundaryByMarker ( pair [ 0 ] ) for b in bounds : bN = [ 0.0 , 0.0 ] if not isinstance ( pair [ 1 ] [ 0 ] , str ) : bN [ 0 ] = pair [ 1 ] [ 0 ] if not isinstance ( pair [ 1 ] [ 1 ] , str ) : bN [ 1 ] = pair [ 1 ] [ 1 ] bNorms [ b . id ( ) ] = bN for b in mesh . boundaries ( ) : if directionCheck : if b . leftCell ( ) is None and b . rightCell ( ) is None : # print(b.id(), b.leftCell(), b.rightCell()) sw = pg . core . Stopwatch ( True ) mesh . createNeighborInfos ( ) print ( "NeighborInfos()" , sw . duration ( True ) ) # return gauss(grid, F) # don't calc for inner boundaries if b . leftCell ( ) is not None and b . rightCell ( ) is not None : continue divS = 0 shape = b . shape ( ) if order == 1 : if bNorms is not None : divS = shape . norm ( ) . dot ( bNorms [ b . id ( ) ] ) * shape . domainSize ( ) else : divS = shape . norm ( ) . dot ( func ( shape . center ( ) ) ) * shape . domainSize ( ) else : weights = pg . core . IntegrationRules . instance ( ) . weights ( shape , order ) abscissa = pg . core . IntegrationRules . instance ( ) . abscissa ( shape , order ) for i , p in enumerate ( abscissa ) : rPos = shape . xyz ( p ) divS += shape . norm ( ) . dot ( func ( rPos ) ) * weights [ i ] * shape . domainSize ( ) if directionCheck and b . leftCell ( ) is None : divS *= - 1 # raise Exception("invalid mesh: left is None .. every # boundary need leftCell") diverg += divS return diverg