def add_ode_shape_to_variable(ode_shape):
    """
    Adds the shape as the defining equation.
    :param ode_shape: a single shape object.
    :type ode_shape: ast_ode_shape
    """
    if ode_shape.get_variable().get_differential_order() == 0:
        # we only update those which define an ode
        return
    # we check if the corresponding symbol already exists, e.g. V_m' has already been declared
    existing_symbol = ode_shape.get_scope().resolve_to_symbol(
        ode_shape.get_variable().get_name_of_lhs(), SymbolKind.VARIABLE)
    if existing_symbol is not None:
        existing_symbol.set_ode_definition(ode_shape.get_expression())
        existing_symbol.set_variable_type(VariableType.SHAPE)
        ode_shape.get_scope().update_variable_symbol(existing_symbol)
        code, message = Messages.get_ode_updated(
            ode_shape.get_variable().get_name_of_lhs())
        Logger.log_message(error_position=existing_symbol.
                           get_referenced_object().get_source_position(),
                           code=code,
                           message=message,
                           log_level=LoggingLevel.INFO)
    else:
        code, message = Messages.get_no_variable_found(
            ode_shape.get_variable().get_name_of_lhs())
        Logger.log_message(code=code,
                           message=message,
                           error_position=ode_shape.get_source_position(),
                           log_level=LoggingLevel.ERROR)
    return
def add_ode_to_variable(ode_equation):
    """
    Resolves to the corresponding symbol and updates the corresponding ode-declaration. In the case that
    :param ode_equation: a single ode-equation
    :type ode_equation: ast_ode_equation
    """
    # the definition of a differential equations is defined by stating the derivation, thus derive the actual order
    diff_order = ode_equation.get_lhs().get_differential_order() - 1
    # we check if the corresponding symbol already exists, e.g. V_m' has already been declared
    existing_symbol = (ode_equation.get_scope().resolve_to_symbol(
        ode_equation.get_lhs().get_name() + '\'' * diff_order,
        SymbolKind.VARIABLE))
    if existing_symbol is not None:
        existing_symbol.set_ode_definition(ode_equation.get_rhs())
        # todo added on merge
        ode_equation.get_scope().update_variable_symbol(existing_symbol)
        code, message = Messages.get_ode_updated(
            ode_equation.get_lhs().get_name_of_lhs())
        Logger.log_message(error_position=existing_symbol.
                           get_referenced_object().get_source_position(),
                           code=code,
                           message=message,
                           log_level=LoggingLevel.INFO)
    else:
        code, message = Messages.get_no_variable_found(
            ode_equation.get_lhs().get_name_of_lhs())
        Logger.log_message(code=code,
                           message=message,
                           error_position=ode_equation.get_source_position(),
                           log_level=LoggingLevel.ERROR)
    return
Esempio n. 3
0
def add_ode_to_variable(ode_equation):
    """
    Resolves to the corresponding symbol and updates the corresponding ode-declaration.
    :param ode_equation: a single ode-equation
    :type ode_equation: ast_ode_equation
    """
    for diff_order in range(ode_equation.get_lhs().get_differential_order()):
        var_name = ode_equation.get_lhs().get_name() + "'" * diff_order
        existing_symbol = ode_equation.get_scope().resolve_to_symbol(
            var_name, SymbolKind.VARIABLE)

        if existing_symbol is None:
            code, message = Messages.get_no_variable_found(
                ode_equation.get_lhs().get_name_of_lhs())
            Logger.log_message(
                code=code,
                message=message,
                error_position=ode_equation.get_source_position(),
                log_level=LoggingLevel.ERROR)
            return

        existing_symbol.set_ode_or_kernel(ode_equation)

        ode_equation.get_scope().update_variable_symbol(existing_symbol)
        code, message = Messages.get_ode_updated(
            ode_equation.get_lhs().get_name_of_lhs())
        Logger.log_message(error_position=existing_symbol.
                           get_referenced_object().get_source_position(),
                           code=code,
                           message=message,
                           log_level=LoggingLevel.INFO)
def add_ode_to_variable(ode_equation):
    """
    Resolves to the corresponding symbol and updates the corresponding ode-declaration. In the case that
    :param ode_equation: a single ode-equation
    :type ode_equation: ast_ode_equation
    """
    # the definition of a differential equations is defined by stating the derivation, thus derive the actual order
    diff_order = ode_equation.get_lhs().get_differential_order() - 1
    # we check if the corresponding symbol already exists, e.g. V_m' has already been declared
    existing_symbol = (ode_equation.get_scope().resolve_to_symbol(ode_equation.get_lhs().get_name() + '\'' * diff_order,
                                                                  SymbolKind.VARIABLE))
    if existing_symbol is not None:
        existing_symbol.set_ode_definition(ode_equation.get_rhs())
        # todo added on merge
        ode_equation.get_scope().update_variable_symbol(existing_symbol)
        code, message = Messages.get_ode_updated(ode_equation.get_lhs().get_name_of_lhs())
        Logger.log_message(error_position=existing_symbol.get_referenced_object().get_source_position(),
                           code=code, message=message, log_level=LoggingLevel.INFO)
    else:
        code, message = Messages.get_no_variable_found(ode_equation.get_lhs().get_name_of_lhs())
        Logger.log_message(code=code, message=message, error_position=ode_equation.get_source_position(),
                           log_level=LoggingLevel.ERROR)
    return
def add_ode_shape_to_variable(ode_shape):
    """
    Adds the shape as the defining equation.
    :param ode_shape: a single shape object.
    :type ode_shape: ast_ode_shape
    """
    if ode_shape.get_variable().get_differential_order() == 0:
        # we only update those which define an ode
        return
    # we check if the corresponding symbol already exists, e.g. V_m' has already been declared
    existing_symbol = ode_shape.get_scope().resolve_to_symbol(ode_shape.get_variable().get_name_of_lhs(),
                                                              SymbolKind.VARIABLE)
    if existing_symbol is not None:
        existing_symbol.set_ode_definition(ode_shape.get_expression())
        existing_symbol.set_variable_type(VariableType.SHAPE)
        ode_shape.get_scope().update_variable_symbol(existing_symbol)
        code, message = Messages.get_ode_updated(ode_shape.get_variable().get_name_of_lhs())
        Logger.log_message(error_position=existing_symbol.get_referenced_object().get_source_position(),
                           code=code, message=message, log_level=LoggingLevel.INFO)
    else:
        code, message = Messages.get_no_variable_found(ode_shape.get_variable().get_name_of_lhs())
        Logger.log_message(code=code, message=message, error_position=ode_shape.get_source_position(),
                           log_level=LoggingLevel.ERROR)
    return