Skip to content

Commit

Permalink
[Template] context based equation handling
Browse files Browse the repository at this point in the history
 - solves ticket #6977
 - new function that takes a context and calls the correct equation create function (for now only jacobian/normal)
 - used inside if equations to actually create jacobian if equations (seems to never have been used because it couldn't work)
 - small fix in backend to have correct size of if equations in advanced adjacency matrices
  • Loading branch information
kabdelhak authored and perost committed Nov 25, 2020
1 parent f5ad9af commit 0c67e1d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -4866,7 +4866,7 @@ algorithm
(row, size) = adjacencyRowEnhancedEqnLst(eqnselse, vars, mark, rowmark, globalKnownVars, trytosolve,shared);
lst = List.map(row,Util.tuple31);

(lst, row, size) = List.fold6(eqnslst, adjacencyRowEnhancedEqnLstIfBranches, vars, mark, rowmark, globalKnownVars, trytosolve, shared, (lst, row, size));
(lst, row, _) = List.fold6(eqnslst, adjacencyRowEnhancedEqnLstIfBranches, vars, mark, rowmark, globalKnownVars, trytosolve, shared, (lst, row, size));

lstall = List.map(row, Util.tuple31);
(_, lst, _) = List.intersection1OnTrue(lstall, lst, intEq);
Expand Down
20 changes: 15 additions & 5 deletions OMCompiler/Compiler/Template/CodegenC.tpl
Expand Up @@ -5333,6 +5333,16 @@ template equation_impl2(Integer clockIndex, SimEqSystem eq, Context context, Str
)
end equation_impl2;

template equation_call_context(SimEqSystem eq, String modelNamePrefix, Context context)
"Generates either a normal or jacobian equation depending on context.
ToDo: add other cases?"
::=
match context
case JACOBIAN_CONTEXT() then equation_callJacobian(eq, modelNamePrefix)
else equation_call(eq, modelNamePrefix)
end match
end equation_call_context;

template equation_call(SimEqSystem eq, String modelNamePrefix)
"Generates an equation.
This template should not be used for a SES_RESIDUAL.
Expand Down Expand Up @@ -5940,13 +5950,13 @@ match eq
case SES_IFEQUATION(ifbranches=ifbranches, elsebranch=elsebranch) then
let &preExp = buffer ""
let IfEquation = (ifbranches |> (e, eqns) hasindex index0 =>
let condition = daeExp(e, context, &preExp, &varDecls, &eqnsDecls)
let &eqnsDecls += ( eqns |> eqn => equation_impl(-1, eqn, context, modelNamePrefixStr, init) ; separator="\n" )
let conditionline = if index0 then 'else if(<%condition%>)' else 'if(<%condition%>)'
let condition = daeExp(e, context, &preExp, &varDecls, &eqnsDecls)
let &eqnsDecls += ( eqns |> eqn => equation_impl(-1, eqn, context, modelNamePrefixStr, init) ; separator="\n" )
let conditionline = if index0 then 'else if(<%condition%>)' else 'if(<%condition%>)'
<<
<%conditionline%>
{
<%( eqns |> eqn => equation_call(eqn, modelNamePrefixStr) ; separator="\n" )%>
<%( eqns |> eqn => equation_call_context(eqn, modelNamePrefixStr, context) ; separator="\n" )%>
}
>>
;separator="\n")
Expand All @@ -5955,7 +5965,7 @@ case SES_IFEQUATION(ifbranches=ifbranches, elsebranch=elsebranch) then
<%preExp%>
<%IfEquation%>else
{
<%elsebranch |> eqn => equation_call(eqn, modelNamePrefixStr)%>
<%elsebranch |> eqn => equation_call_context(eqn, modelNamePrefixStr, context)%>
}
>>
end equationIfEquationAssign;
Expand Down

0 comments on commit 0c67e1d

Please sign in to comment.