Skip to content

Commit

Permalink
[NB] update binding equations (#9954)
Browse files Browse the repository at this point in the history
* [NB] update binding equations

 - use start value if no binding is available
  • Loading branch information
kabdelhak committed Dec 16, 2022
1 parent f05ab45 commit 8b7747f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion OMCompiler/Compiler/NBackEnd/Classes/NBEquation.mo
Expand Up @@ -1574,8 +1574,11 @@ public
rhs := match var.binding
local
Binding qual;
Option<Expression> start;
case qual as Binding.TYPED_BINDING() then qual.bindingExp;
case qual as Binding.UNBOUND() then Expression.makeZero(ComponentRef.getSubscriptedType(var.name));
case qual as Binding.UNBOUND() algorithm
start := BackendExtension.VariableAttributes.getStartAttribute(var.backendinfo.attributes);
then Util.getOptionOrDefault(start, Expression.makeZero(ComponentRef.getSubscriptedType(var.name, true)));
else algorithm
Error.addMessage(Error.INTERNAL_ERROR,{getInstanceName() + " failed because of wrong binding type: " + Binding.toString(var.binding) + " for variable " + Variable.toString(Pointer.access(var_ptr))});
then fail();
Expand Down
14 changes: 14 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFBackendExtension.mo
Expand Up @@ -557,6 +557,20 @@ public
end match;
end setStartAttribute;

function getStartAttribute
input VariableAttributes attributes;
output Option<Expression> start;
algorithm
start := match attributes
case VAR_ATTR_REAL() then attributes.start;
case VAR_ATTR_INT() then attributes.start;
case VAR_ATTR_BOOL() then attributes.start;
case VAR_ATTR_STRING() then attributes.start;
case VAR_ATTR_ENUMERATION() then attributes.start;
else NONE();
end match;
end getStartAttribute;

function getStateSelect
input VariableAttributes attributes;
output StateSelect stateSelect;
Expand Down

0 comments on commit 8b7747f

Please sign in to comment.