Skip to content

Commit

Permalink
[NB] support array event variables (OpenModelica#12551)
Browse files Browse the repository at this point in the history
- use type of condition when creating event variable to have correct size
  • Loading branch information
kabdelhak committed Jun 11, 2024
1 parent c4fa787 commit 1490b4f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions OMCompiler/Compiler/NBackEnd/Classes/NBVariable.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,7 @@ public
e.g. (\"$SEV\", 4) --> $SEV_4"
input String name "context name e.g. §WHEN";
input Integer uniqueIndex "unique identifier index";
input Type var_ty "variable type";
input Iterator iterator = Iterator.EMPTY() "optional for-loop iterator";
output Pointer<Variable> var_ptr "pointer to new variable";
output ComponentRef cref "new component reference";
Expand All @@ -1035,10 +1036,10 @@ public
(iter_crefs, _) := Iterator.getFrames(iterator);
iter_subs := list(Subscript.fromTypedExp(Expression.fromCref(iter)) for iter in iter_crefs);
if listEmpty(iter_subs) then
ty := Type.BOOLEAN();
ty := var_ty;
else
sub_sizes := Iterator.sizes(iterator);
ty := Type.ARRAY(Type.BOOLEAN(), list(Dimension.fromInteger(sub_size) for sub_size in sub_sizes));
ty := Type.liftArrayLeftList(var_ty, list(Dimension.fromInteger(sub_size) for sub_size in sub_sizes));
end if;
// create inst node with dummy variable pointer and create cref from it
node := InstNode.VAR_NODE(name + "_" + intString(uniqueIndex), Pointer.create(DUMMY_VARIABLE));
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBEvents.mo
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ public
else
if createAux then
// make a new auxiliary variable and return the expression which replaces the zero crossing
(aux_var, aux_cref) := BVariable.makeEventVar(NBVariable.STATE_EVENT_STR, bucket.auxiliaryStateEventIndex, iter);
(aux_var, aux_cref) := BVariable.makeEventVar(NBVariable.STATE_EVENT_STR, bucket.auxiliaryStateEventIndex, Expression.typeOf(exp), iter);
exp := Expression.fromCref(aux_cref);
else
// make no auxiliary and return the original zero crossing
Expand Down Expand Up @@ -828,7 +828,7 @@ public
if createAux then
// make a new auxiliary variable and return the expression which replaces the zero crossing
(iter, range) := Equation.Iterator.getFrames(condition.iter);
(aux_var, aux_cref) := BVariable.makeEventVar(NBVariable.TIME_EVENT_STR, bucket.auxiliaryTimeEventIndex, Iterator.fromFrames(List.zip(iter, range)));
(aux_var, aux_cref) := BVariable.makeEventVar(NBVariable.TIME_EVENT_STR, bucket.auxiliaryTimeEventIndex, Expression.typeOf(condition.exp), Iterator.fromFrames(List.zip(iter, range)));
exp := Expression.fromCref(aux_cref);
else
// make no auxiliary and return the original zero crossing
Expand Down

0 comments on commit 1490b4f

Please sign in to comment.