Skip to content

Commit

Permalink
[NB] update state collection for ALWAYS states (OpenModelica#12606)
Browse files Browse the repository at this point in the history
- instead of checking if something is a state, check if it has a derivative variable
 - something can be a state without having a designated derivative if it is marked as StateSelect.ALWAYS
  • Loading branch information
kabdelhak committed Jun 18, 2024
1 parent a195f47 commit fcb11c0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions OMCompiler/Compiler/NBackEnd/Classes/NBVariable.mo
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,16 @@ public
end match;
end getStateCref;

function hasDerVar
input Pointer<Variable> state_var;
output Boolean b;
algorithm
b := match Pointer.access(state_var)
case Variable.VARIABLE(backendinfo = BackendExtension.BACKEND_INFO(varKind = BackendExtension.STATE(derivative = SOME(_)))) then true;
else false;
end match;
end hasDerVar;

function getDerVar
input Pointer<Variable> state_var;
output Pointer<Variable> der_var;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ protected
arguments = {Expression.CREF(cref = state_cref)}))
algorithm
state_var := BVariable.getVarPointer(state_cref);
if BVariable.isState(state_var) then
if BVariable.hasDerVar(state_var) then
// this derivative was already created -> the variable should already have a pointer to its derivative
der_cref := BVariable.getDerCref(state_cref);
if not scalarized then
Expand Down

0 comments on commit fcb11c0

Please sign in to comment.