ECOdyagnostics/operations.py
def divergence(self, x, axes=None, discretization=None, **kwargs):
        """
        Compute the divergence of a vector field.

        x is a scalar or a vector fields as a type 'list'.

        """
        if discretization is None:
            discretization = self.discretization

        if axes is None:
            axes = ['X', 'Y', 'Z']
        elif type(axes) is list:
            pass
        elif type(axes) is str or type(axes) is tuple:
            axes = list(axes)
        else:
            raise Exception("Input for 'axes' not understood, please provide a list, tuple, or string")

        if type(x) is not list:
            raise Exception("Input is not of type 'list', please provide a vector as type 'list'.")
        if axes == ['X', 'Y', 'Z'] and len(x) != 3:
            raise Exception("Vector is not 3dimensional, please provide axes to compute the gradient")

        # ========
        # Standard
        # ========
        if discretization == 'standard':
            y = sum([self.derivative(x[i], axes[i], **kwargs) for i in range(len(axes))])

        # ====
        # Nemo
        # ====
        elif discretization == 'nemo':
            weight_in = [1] * len(axes)
            x_d = [0] * len(axes)
            weight_out = [1] * len(axes)
            for i in range(len(axes)):
                # Get metrics from input position and multiply it to the data inside the difference
                if axes[i] == 'Z':
                    pass
                else:
                    weight_in[i] = self._combine_metric(x[i], axes, skip=axes[i])
                # Compute derivative
                x_d[i] = self.derivative(x[i] * weight_in[i], axes[i], **kwargs)
                # Get metrics for output position and divide the the derivative by it
                if axes[i] == 'Z':
                    pass
                else:
                    weight_out[i] = self._combine_metric(x_d[i], axes, skip=axes[i])

            y = sum([x_d[i] / weight_out[i] for i in range(len(axes))])

        return y

        Compute the divergence of a vector field.

        x is a scalar or a vector fields as a type 'list'.

        
Compute the divergence of a vector field.
x is a scalar or a vector fields as a type 'list'.
Compute the divergence of a vector field . x is a scalar or a vector fields as a type ' list ' .
def divergence(self, x, axes=None, discretization=None, **kwargs):
        if discretization is None:
            discretization = self.discretization
        if axes is None:
            axes = ['X', 'Y', 'Z']
        elif type(axes) is list:
            pass
        elif type(axes) is str or type(axes) is tuple:
            axes = list(axes)
        else:
            raise Exception("Input for 'axes' not understood, please provide a list, tuple, or string")
        if type(x) is not list:
            raise Exception("Input is not of type 'list', please provide a vector as type 'list'.")
        if axes == ['X', 'Y', 'Z'] and len(x) != 3:
            raise Exception("Vector is not 3dimensional, please provide axes to compute the gradient")
        if discretization == 'standard':
            y = sum([self.derivative(x[i], axes[i], **kwargs) for i in range(len(axes))])
        elif discretization == 'nemo':
            weight_in = [1] * len(axes)
            x_d = [0] * len(axes)
            weight_out = [1] * len(axes)
            for i in range(len(axes)):
                if axes[i] == 'Z':
                    pass
                else:
                    weight_in[i] = self._combine_metric(x[i], axes, skip=axes[i])
                x_d[i] = self.derivative(x[i] * weight_in[i], axes[i], **kwargs)
                if axes[i] == 'Z':
                    pass
                else:
                    weight_out[i] = self._combine_metric(x_d[i], axes, skip=axes[i])
            y = sum([x_d[i] / weight_out[i] for i in range(len(axes))])
        return y
def divergence ( self , x , axes = None , discretization = None , ** kwargs ) : if discretization is None : discretization = self . discretization if axes is None : axes = [ 'X' , 'Y' , 'Z' ] elif type ( axes ) is list : pass elif type ( axes ) is str or type ( axes ) is tuple : axes = list ( axes ) else : raise Exception ( "Input for 'axes' not understood, please provide a list, tuple, or string" ) if type ( x ) is not list : raise Exception ( "Input is not of type 'list', please provide a vector as type 'list'." ) if axes == [ 'X' , 'Y' , 'Z' ] and len ( x ) != 3 : raise Exception ( "Vector is not 3dimensional, please provide axes to compute the gradient" ) if discretization == 'standard' : y = sum ( [ self . derivative ( x [ i ] , axes [ i ] , ** kwargs ) for i in range ( len ( axes ) ) ] ) elif discretization == 'nemo' : weight_in = [ 1 ] * len ( axes ) x_d = [ 0 ] * len ( axes ) weight_out = [ 1 ] * len ( axes ) for i in range ( len ( axes ) ) : if axes [ i ] == 'Z' : pass else : weight_in [ i ] = self . _combine_metric ( x [ i ] , axes , skip = axes [ i ] ) x_d [ i ] = self . derivative ( x [ i ] * weight_in [ i ] , axes [ i ] , ** kwargs ) if axes [ i ] == 'Z' : pass else : weight_out [ i ] = self . _combine_metric ( x_d [ i ] , axes , skip = axes [ i ] ) y = sum ( [ x_d [ i ] / weight_out [ i ] for i in range ( len ( axes ) ) ] ) return y
Compute the divergence of a vector field.
Compute the divergence of a vector field .
"""
        Compute the divergence of a vector field.

        x is a scalar or a vector fields as a type 'list'.

        """ # ======== # Standard # ======== # ==== # Nemo # ==== # Get metrics from input position and multiply it to the data inside the difference # Compute derivative # Get metrics for output position and divide the the derivative by it
self
x
axes
discretization