Skip to content

Commit

Permalink
Cpp: add code for zero crossing of Integer equality (OpenModelica#12557)
Browse files Browse the repository at this point in the history
Zero crossings seems to be generated for models like:

model ZeroCrossings
  input Integer flag;
  output Real y;
equation
  y = if flag == 1 then u else 0;
end ZeroCrossings;
  • Loading branch information
rfranke committed Jun 11, 2024
1 parent e2c9283 commit 7055b41
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions OMCompiler/Compiler/Template/CodegenCpp.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12238,6 +12238,10 @@ template giveZeroFunc3(Integer index1, Exp relation, Text &varDecls /*BUFP*/,Tex
else
f[<%index1%>] = (<%e1%> - _zeroTol - <%e2%>);
>>
case EQUAL(ty = T_INTEGER(__)) then
<<
f[<%index1%>] = std::abs(<%e2%> - <%e1%>);
>>
else
<<
error(sourceInfo(), 'Unsupported relation: <%ExpressionDumpTpl.dumpExp(rel,"\"")%> for <%index1%>')
Expand Down
6 changes: 5 additions & 1 deletion OMCompiler/Compiler/Template/CodegenCppOMSI.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12118,9 +12118,13 @@ template giveZeroFunc3(Integer index1, Exp relation, Text &varDecls /*BUFP*/,Tex
else
f[<%index1%>] = (<%e1%> - 1e-6 - <%e2%>);
>>
case EQUAL(ty = T_INTEGER(__)) then
<<
f[<%index1%>] = std::abs(<%e2%> - <%e1%>);
>>
else
<<
error(sourceInfo(), 'Unknown relation: <%ExpressionDumpTpl.dumpExp(rel,"\"")%> for <%index1%>')
error(sourceInfo(), 'Unsupported relation: <%ExpressionDumpTpl.dumpExp(rel,"\"")%> for <%index1%>')
>>
end match
case CALL(path=IDENT(name="sample"), expLst={_, start, interval}) then
Expand Down

0 comments on commit 7055b41

Please sign in to comment.