def getEquationsExpressionParser(model): """ Returns the ExpressionParser object needed to parse NineML mathematical and logical expressions. :param model: daeModel-derived object :rtype: ExpressionParser object :raises: """ dictIdentifiers = getEquationsExpressionParserIdentifiers(model) dictFunctions = getEquationsExpressionParserFunctions() parser = expression_parser.ExpressionParser(dictIdentifiers, dictFunctions) return parser
def getParametersValuesInitialConditionsExpressionParser(model): """ Returns the ExpressionParser object needed to parse the expressions for parameters' values and initial conditions: :param model: daeModel-derived object :rtype: ExpressionParser object :raises: """ dictIdentifiers = getParametersValuesInitialConditionsExpressionParserIdentifiers( model) dictFunctions = getParametersValuesInitialConditionsExpressionParserFunctions( ) parser = expression_parser.ExpressionParser(dictIdentifiers, dictFunctions) return parser
def eval_expression(expression, base_node_name='', name_generator=None): """Evaluate Expression Args: expression (str): Math expression to evaluate base_node_name (str): Base name used to initialize new node name generator name_generator (NodeNameGenerator): Node name generator used by the builder Returns: str: Returns resulting output attribute for generated node graph """ if not name_generator: name_generator = NodeNameGenerator(base_node_name) ast = expression_parser.ExpressionParser(expression).parse() builder = expression_builder.ExpresionBuilder(name_generator) output = builder.generate(ast) builder.build() return output.value
def getAnalogPortsExpressionParser(): """ Returns the ExpressionParser object needed to parse inputs for the analogue ports: :param model: daeModel-derived object :rtype: ExpressionParser object :raises: """ dictIdentifiers = {} dictFunctions = {} dictIdentifiers['pi'] = math.pi dictIdentifiers['e'] = math.e # Standard math. functions (single argument) dictFunctions['sin'] = math.sin dictFunctions['cos'] = math.cos dictFunctions['tan'] = math.tan dictFunctions['asin'] = math.asin dictFunctions['acos'] = math.acos dictFunctions['atan'] = math.atan dictFunctions['sinh'] = math.sinh dictFunctions['cosh'] = math.cosh dictFunctions['tanh'] = math.tanh dictFunctions['asinh'] = math.asinh dictFunctions['acosh'] = math.acosh dictFunctions['atanh'] = math.atanh dictFunctions['log10'] = math.log10 dictFunctions['log'] = math.log dictFunctions['sqrt'] = math.sqrt dictFunctions['exp'] = math.exp dictFunctions['floor'] = math.floor dictFunctions['ceil'] = math.ceil dictFunctions['fabs'] = math.fabs # Non-standard functions (multiple arguments) dictFunctions['pow'] = math.pow parser = expression_parser.ExpressionParser(dictIdentifiers, dictFunctions) return parser
def createExpressionParser(): return expression_parser.ExpressionParser()