How to use the underworld.function._function.Function function in underworld

To help you get started, we’ve selected a few underworld examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github underworldcode / underworld2 / underworld / function / _function.py View on Github external
def __init__(self, fn1, fn2, **kwargs):
        fn1fn = Function.convert( fn1 )
        if not isinstance( fn1fn, Function ):
            raise TypeError("Functions must be of type (or convertible to) 'Function'.")
        fn2fn = Function.convert( fn2 )
        if not isinstance( fn2fn, Function ):
            raise TypeError("Functions must be of type (or convertible to) 'Function'.")

        self._fn1 = fn1fn
        self._fn2 = fn2fn
        # ok finally lets create the fn
        self._fncself = _cfn.Relational_logical_and(self._fn1._fncself, self._fn2._fncself )
        # build parent
        super(logical_and,self).__init__(argument_fns=[fn1fn,fn2fn], **kwargs)

class logical_or(Function):
    """
    This class implements the OR logical operation.
    It is invoked by the overload method __or__.
    """
    def __init__(self, fn1, fn2, **kwargs):
        fn1fn = Function.convert( fn1 )
        if not isinstance( fn1fn, Function ):
            raise TypeError("Functions must be of type (or convertible to) 'Function'.")
        fn2fn = Function.convert( fn2 )
        if not isinstance( fn2fn, Function ):
            raise TypeError("Functions must be of type (or convertible to) 'Function'.")

        self._fn1 = fn1fn
        self._fn2 = fn2fn
        # ok finally lets create the fn
        self._fncself = _cfn.Relational_logical_or(self._fn1._fncself, self._fn2._fncself )
github underworldcode / underworld2 / underworld / function / math.py View on Github external
"""
    def __init__(self, fn=None, *args, **kwargs):

        self._fn = _Function.convert(fn)

        fncself = None
        if self._fn:
            fncself = self._fn._fncself

        # create instance
        self._fncself = _cfn.MathUnary_cos( fncself )

        # build parent
        super(cos,self).__init__(argument_fns=[fn,],**kwargs)

class sin(_Function):
    """
    Computes the sine of its argument function
    (measured in radians).

    Parameters
    ----------
    fn: underworld.function.Function (or convertible).
        Optionally provided for function composition.

    Example
    -------
    >>> import math as sysmath
    >>> import numpy as np
    >>> func = sin()
    >>> np.allclose( func.evaluate(0.1234), sysmath.sin(0.1234) )
    True
github underworldcode / underworld2 / underworld / function / _function.py View on Github external
def __init__(self, fn1, fn2, **kwargs):
        fn1fn = Function.convert( fn1 )
        if not isinstance( fn1fn, Function ):
            raise TypeError("Functions must be of type (or convertible to) 'Function'.")
        fn2fn = Function.convert( fn2 )
        if not isinstance( fn2fn, Function ):
            raise TypeError("Functions must be of type (or convertible to) 'Function'.")

        self._fn1 = fn1fn
        self._fn2 = fn2fn
        # ok finally lets create the fn
        self._fncself = _cfn.Relational_less(self._fn1._fncself, self._fn2._fncself )
        # build parent
        super(less,self).__init__(argument_fns=[fn1fn,fn2fn], **kwargs)

class less_equal(Function):
    """
    This class implements the 'less than or equal to' relational operation.
    It is invoked by the overload method __le__.
    """
    def __init__(self, fn1, fn2, **kwargs):
        fn1fn = Function.convert( fn1 )
        if not isinstance( fn1fn, Function ):
            raise TypeError("Functions must be of type (or convertible to) 'Function'.")
        fn2fn = Function.convert( fn2 )
        if not isinstance( fn2fn, Function ):
            raise TypeError("Functions must be of type (or convertible to) 'Function'.")

        self._fn1 = fn1fn
        self._fn2 = fn2fn
        # ok finally lets create the fn
        self._fncself = _cfn.Relational_less_equal(self._fn1._fncself, self._fn2._fncself )
github underworldcode / underworld2 / underworld / function / math.py View on Github external
"""
    def __init__(self, fn=None, *args, **kwargs):

        self._fn = _Function.convert(fn)

        fncself = None
        if self._fn:
            fncself = self._fn._fncself

        # create instance
        self._fncself = _cfn.MathUnary_acosh( fncself )

        # build parent
        super(acosh,self).__init__(argument_fns=[fn,],**kwargs)

class asinh(_Function):
    """
    Computes the inverse hyperbolic sine of its argument function.

    Parameters
    ----------
    fn: underworld.function.Function (or convertible).
        Optionally provided for function composition.

    Example
    -------
    >>> import math as sysmath
    >>> import numpy as np
    >>> func = asinh()
    >>> np.allclose( func.evaluate(5.1234), sysmath.asinh(5.1234) )
    True
github underworldcode / underworld2 / underworld / function / math.py View on Github external
"""
    def __init__(self, fn=None, *args, **kwargs):

        self._fn = _Function.convert(fn)

        fncself = None
        if self._fn:
            fncself = self._fn._fncself

        # create instance
        self._fncself = _cfn.MathUnary_log10( fncself )

        # build parent
        super(log10,self).__init__(argument_fns=[fn,],**kwargs)

class sqrt(_Function):
    """
    Computes the square root of its argument function.

    Parameters
    ----------
    fn: underworld.function.Function (or convertible).
        Optionally provided for function composition.

    Example
    -------
    >>> import math as sysmath
    >>> import numpy as np
    >>> func = sqrt()
    >>> np.allclose( func.evaluate(0.1234), sysmath.sqrt(0.1234) )
    True
github underworldcode / underworld2 / underworld / function / view.py View on Github external
##                                                                                   ##
##  This file forms part of the Underworld geophysics modelling application.         ##
##                                                                                   ##
##  For full license and copyright information, please refer to the LICENSE.md file  ##
##  located at the project root, or contact the authors.                             ##
##                                                                                   ##
##~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~##
"""
This module includes functions which provide views into the results of
function queries.  These functions never modify query data. 
"""

import libUnderworld.libUnderworldPy.Function as _cfn
from . import _function

class min_max(_function.Function):
    """ 
    This function records the min & max result from a queried function.
    
    Note that this function simply records the min/max values encountered 
    when it is evaluated. Therefore, if it has not been evaluated at all,
    the values returned via one of its methods ('min_local',
    'min_global', etc ) will simply be initialisation values.
    
    For vector input types, this function will report on the magnitude
    of the vector.
    
    Parameters
    ----------
    fn: underworld.function.Function
        The primary function. If `fn_norm` is not provided, this is 
        used to calculate the min_max. Results from this function are
github underworldcode / underworld2 / underworld / function / rheology.py View on Github external
##  This file forms part of the Underworld geophysics modelling application.         ##
##                                                                                   ##
##  For full license and copyright information, please refer to the LICENSE.md file  ##
##  located at the project root, or contact the authors.                             ##
##                                                                                   ##
##~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~##
"""
This module contains functions relating to rheological operations.
"""

import libUnderworld.libUnderworldPy.Function as _cfn
from ._function import Function as _Function
from . import tensor as _tensor
from . import branching as _branching

class stress_limiting_viscosity(_Function):
    """
    Returns a viscosity value which effectively limits the maximum fluid
    stress. Where the stress invariant (as calculated using the provided
    fn_stress) is greater than the stress limit (as provided by the
    fn_stresslimit), the returned viscosity will affect a fluid stress
    at the stress limit. Otherwise, fn_inputviscosity is passed through.

    Parameters
    ----------
    fn_stress: underworld.function.Function
        Function which returns the current stress in the fluid.
        Function should return a symmetric tensor of floating point values.
    fn_stresslimit: underworld.function.Function
        Function which defines the stress limit.
        Function should return a scalar floating point value.
    fn_inputviscosity: underworld.function.Function
github underworldcode / underworld2 / underworld / function / exception.py View on Github external
def __init__(self, fn, *args, **kwargs):

        _fn = _Function.convert(fn)
        if _fn == None:
            raise ValueError( "provided 'fn' must a 'Function' or convertible.")
        self._fn = _fn

        # create instance
        self._fncself = _cfn.SafeMaths( self._fn._fncself )

        # build parent
        super(SafeMaths,self).__init__(argument_fns=[_fn,],**kwargs)
github underworldcode / underworld2 / underworld / function / branching.py View on Github external
self._map = {}

        for key, value in mapping.items():
            if not isinstance(key, int) or key < 0:
                raise ValueError("Key '{}' not valid. Mapping keys must be unsigned integers.".format(key))
            funcVal = _Function.convert(value)
            if funcVal == None:
                raise ValueError("'None' is not valid for mapped functions.")
            
            self._underlyingDataItems.update(funcVal._underlyingDataItems) # update dictionary
            # insert mapping and keep handles in py dict
            self._map[key] = funcVal
            self._fncself.insert( key, funcVal._fncself )

class conditional(_Function):
    """
    This function provides 'if/elif' type conditional behaviour.
    
    The user provides a list of tuples, with each tuple being of the 
    form (fn_condition, fn_resultant). Effectively, each tuple provides a clause
    within the if/elif statement. 
    
    When evaluated, the function traverses the clauses, stopping at the first 
    fn_condition which returns 'true'. It then executes the corresponding 
    fn_resultant and returns the results.
    
    If none of the provided clauses return a 'True' result, an exception is 
    raised.

    For a set of condition functions { fc_0, fc_1, ... ,fc_n }, and
    corresponding resultant functions { fr_0, fr_1, ... ,fr_n },
github underworldcode / underworld2 / underworld / function / _function.py View on Github external
def __init__(self, fn1, fn2, **kwargs):
        fn1fn = Function.convert( fn1 )
        if not isinstance( fn1fn, Function ):
            raise TypeError("Functions must be of type (or convertible to) 'Function'.")
        fn2fn = Function.convert( fn2 )
        if not isinstance( fn2fn, Function ):
            raise TypeError("Functions must be of type (or convertible to) 'Function'.")

        self._fn1 = fn1fn
        self._fn2 = fn2fn
        # ok finally lets create the fn
        self._fncself = _cfn.Add(self._fn1._fncself, self._fn2._fncself )
        # build parent
        super(add,self).__init__(argument_fns=[fn1fn,fn2fn], **kwargs)

class subtract(Function):
    """
    This class implements the difference of two functions.
    It is invoked by the overload methods __sub__ and __rsub__.
    """
    def __init__(self, x_Fn, y_Fn, **kwargs):
        fn1fn = Function.convert( x_Fn )
        if not isinstance( fn1fn, Function ):
            raise TypeError("Functions must be of type (or convertible to) 'Function'.")
        fn2fn = Function.convert( y_Fn )
        if not isinstance( fn2fn, Function ):
            raise TypeError("Functions must be of type (or convertible to) 'Function'.")

        self._fn1 = fn1fn
        self._fn2 = fn2fn
        # ok finally lets create the fn
        self._fncself = _cfn.Subtract(self._fn1._fncself, self._fn2._fncself )