Exemplo n.º 1
0
    def __init__(self, name, value, dimension = None, description = ''): 
        """
        Constructor.

        See instance variable documentation for more info on derived parameters.
        """

        self.name = name
        """ Name of the derived parameter.
        @type: str """

        self.dimension = dimension
        """ Physical dimensions of the derived parameter.
        @type: str """
        
        self.value = value
        """ Value of the derived parameter.
        @type: str """
        
        self.description = description
        """ Description of the derived parameter.
        @type: str """
        
        try:
            ep = ExprParser(self.value)
            self.expression_tree = ep.parse()
        except:
            raise ParseError("Parse error when parsing value expression "
                                 "'{0}' for derived parameter {1}",
                                 self.value, self.name)
Exemplo n.º 2
0
    def __init__(self, name, value, dimension=None, description=''):
        """
        Constructor.

        See instance variable documentation for more info on derived parameters.
        """

        self.name = name
        """ Name of the derived parameter.
        @type: str """

        self.dimension = dimension
        """ Physical dimensions of the derived parameter.
        @type: str """

        self.value = value
        """ Value of the derived parameter.
        @type: str """

        self.description = description
        """ Description of the derived parameter.
        @type: str """

        try:
            ep = ExprParser(self.value)
            self.expression_tree = ep.parse()
        except:
            raise ParseError(
                "Parse error when parsing value expression "
                "'{0}' for derived parameter {1}", self.value, self.name)
Exemplo n.º 3
0
    def __init__(self, condition, value):
        """
        Constructor.
        """

        self.condition = condition
        """ Condition for this case.
        @type: str """

        self.value = value
        """ Value if the condition is true.
        @type: str """

        self.condition_expression_tree = None
        """ Parse tree for the case condition expression.
        @type: lems.parser.expr.ExprNode """

        self.value_expression_tree = None
        """ Parse tree for the case condition expression.
        @type: lems.parser.expr.ExprNode """

        try:
            self.value_expression_tree = ExprParser(self.value).parse()

            if not self.condition:
                self.condition_expression_tree = None
            else:
                self.condition_expression_tree = ExprParser(self.condition).parse()
        except:
            raise ParseError("Parse error when parsing case with condition "
                             "'{0}' and value {1}",
                             self.condition, self.value)
Exemplo n.º 4
0
    def __init__(self, variable, value):
        """
        Constructor.

        See instance variable documentation for more info on parameters.
        """

        Action.__init__(self)

        self.variable = variable
        """ Name of the variable for which the time derivative is being specified.
        @type: str """

        self.value = value
        """ Derivative expression.
        @type: str """

        self.expression_tree = None
        """ Parse tree for the time derivative expression.
        @type: lems.parser.expr.ExprNode """

        try:
            self.expression_tree = ExprParser(value).parse()
        except:
            raise ParseError("Parse error when parsing state assignment "
                             "value expression "
                             "'{0}' for state variable {1}",
                             self.value, self.variable)
Exemplo n.º 5
0
    def __init__(self, variable, value):
        """
        Constructor.

        @param variable: Name of the state variable
        @type variable: string

        @param value: Time derivative expression of the given state variable.
        @type value: string
        """

        self.variable = variable
        """ State variable whose time derivative is stored in this object.
        @type: string """

        self.value = value
        """ Time derivative expression for the state variable.
        @type: string """

        try:
            self.expression_tree = ExprParser(value).parse()
            """ Parse tree for the time derivative expression.
            @type: lems.parser.expr.ExprNode """
        except:
            raise ParseError("Parse error when parsing value expression "
                             "'{0}' for derived variable {1}".format(\
                                 self.value,
                                 self.variable))
Exemplo n.º 6
0
    def parse_expr(self, expr, val, should_fail=False):

        print('\n---  Parsing %s, checking against %s' % (expr, val))
        ep = ExprParser(expr)
        try:
            pt = ep.parse()
            print("Expr:       %s " % expr)
            print("Parsed as:  %s " % (str(pt)))
            print("Expected :  %s " % (val))
            print("Math :      %s " % (pt.to_python_expr()))

            assert str(pt) == val
            print("Success")
        except Exception as e:
            if not should_fail:
                print("Exception thrown %s" % e)
                assert 1 == 2
            else:
                print("Successfully failed")
Exemplo n.º 7
0
    def parse_expr(self, expr, val, should_fail=False):
        
        print('\n---  Parsing %s, checking against %s'%(expr, val))
        ep = ExprParser(expr)
        try:
            pt = ep.parse()
            print("Expr:       %s "%expr)
            print("Parsed as:  %s "%(str(pt)))
            print("Expected :  %s "%(val))
            print("Math :      %s "%(pt.to_python_expr()))

            assert str(pt) == val
            print("Success")
        except Exception as e:
            if not should_fail:
                print("Exception thrown %s"%e)
                assert 1==2 
            else:
                print("Successfully failed")
Exemplo n.º 8
0
    def __init__(self, name, **params):
        """
        Constructor.

        See instance variable documentation for more info on parameters.
        """

        self.name = name
        """ Name of the derived variable.
        @type: str """

        self.dimension = params['dimension'] if 'dimension' in params else None
        """ Dimension of the derived variable or None if computed.
        @type: str """

        self.exposure = params['exposure'] if 'exposure' in params else None
        """ Exposure name for the derived variable.
        @type: str """

        self.select = params['select'] if 'select' in params else None
        """ Selection path/expression for the derived variable.
        @type: str """

        self.expression = params[
            'expression'] if 'expression' in params else None
        """ Value of the derived variable.
        @type: str """

        self.reduce = params['reduce'] if 'reduce' in params else None
        """ Reduce method for the derived variable.
        @type: str """

        self.required = params['required'] if 'required' in params else None
        """ Requried or not.
        @type: str """

        self.expression_tree = None
        """ Parse tree for the time derivative expression.
        @type: lems.parser.expr.ExprNode """

        if self.expression != None:
            try:
                self.expression_tree = ExprParser(self.expression).parse()
            except:
                raise ParseError(
                    "Parse error when parsing value expression "
                    "'{0}' for derived variable {1}", self.expression,
                    self.name)
Exemplo n.º 9
0
    def __init__(self, test):
        """
        Constructor.

        @param test: Test expression.
        @type test: string
        """

        EventHandler.__init__(self, EventHandler.ON_CONDITION)

        self.test = test
        """ Test expression.
        @type: string """

        self.expression_tree = ExprParser(test).parse()
        """ Parse tree for the test expression.
Exemplo n.º 10
0
    def __init__(self, test):
        """
        Constructor.

        See instance variable documentation for more details on parameters.
        """

        EventHandler.__init__(self)

        self.test = test
        """ Condition to be tested for.
        @type: str """

        try:
            self.expression_tree = ExprParser(test).parse()
        except:
            raise ParseError("Parse error when parsing OnCondition test '{0}'", test)
Exemplo n.º 11
0
    def __init__(self, variable, value):
        """
        Constructor.

        @param variable: Name of the state variable
        @type variable: string

        @param value: Assignment expression of the given state variable.
        @type value: string
        """

        Action.__init__(self, Action.STATE_ASSIGNMENT)

        self.variable = variable
        """ State variable whose assignment expression is stored in this
        object.
        @type: string """

        self.value = value
        """ Assignment expression for the state variable.
        @type: string """

        self.expression_tree = ExprParser(value).parse()
        """ Parse tree for the assignment expression.
Exemplo n.º 12
0
    def __init__(self, name, exposure, dimension, value, select, reduce):
        """
        Constructor.

        @param name: Name (internal) of the derived variable.
        @type name: string

        @param exposure: Name (external) of the derived variable.
        @type exposure: string

        @param dimension: Dimension of the derived variable.
        @type dimension: string

        @param value: Value expression for the derived variable.
        @type value: string

        @param select: Target component selection for reduction operations.
        @type select: string

        @param reduce: Reduce operation.
        @type reduce: string
        """

        self.name = name
        """ Internal name of the derived variable. This is the name used to
        refer to this variable inside the <Behavior> element.
        @type: string """

        self.exposure = exposure
        """ Exposure name of the derived variable. This is the name used to
        refer to this variable from other objects.
        @type: string """

        self.dimension = dimension
        """ Dimension of this derived variable.
        @type: string """

        self.value = value
        """ Expression used for computing the value of the derived variable.
        @type: string """

        self.select = select
        """ Selected target object for the reduce operation.
        @type: string """

        self.reduce = reduce
        """ Reduce operation to be applied over the selected target.
        @type: string """

        if value != None:
            try:
                self.expression_tree = ExprParser(value).parse()
                """ Parse tree for the time derivative expression.
                @type: lems.parser.expr.ExprNode """
            except:
                raise ParseError("Parse error when parsing value expression "
                                 "'{0}' for derived variable {1}".format(\
                                     self.value,
                                     self.name))
        else:
            self.expression_tree = None