Skip to content

Commit

Permalink
[BE] update backendaeinfo
Browse files Browse the repository at this point in the history
 - add reporting of clocked states
 - fixes ticket #6132
  • Loading branch information
kabdelhak authored and adrpo committed Oct 21, 2020
1 parent 705e5e7 commit 3ffedaa
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
18 changes: 14 additions & 4 deletions OMCompiler/Compiler/BackEnd/BackendDump.mo
Expand Up @@ -3596,11 +3596,11 @@ protected
list<tuple<Integer,Integer>> te_nl,te_nl2;
list<Integer> m_se,m_salg,m_sarr,m_sec;
list<tuple<Integer,Integer>> me_jc,e_jt,me_jt,me_jn,me_nj,me_lt,me_nt;
list<DAE.ComponentRef> states,discvars,discstates;
list<DAE.ComponentRef> states,discvars,discstates,clockedstates={};
HashSet.HashSet HS;
BackendDAE.EqSystems systs;
BackendDAE.EquationArray removedEqs;
String statesStr, sysStr, stStr, dvarStr, dstStr, statesStr, discvarsStr, discstatesStr, inpStr, strcompsStr, seqStr, sarrStr, salgStr, sceStr, sweStr, sieStr, eqsysStr, teqsysStr, meqsysStr, daeType;
String sysStr, stStr, dvarStr, dstStr, clckStr, statesStr, discvarsStr, discstatesStr, clockedstatesStr, inpStr, strcompsStr, seqStr, sarrStr, salgStr, sceStr, sweStr, sieStr, eqsysStr, teqsysStr, meqsysStr, daeType;

list<String> msgs;
DumpCompShortSystemsTpl systemsTpl;
Expand All @@ -3618,6 +3618,11 @@ algorithm
discstates := BaseHashSet.hashSetList(HS);
dst := listLength(discstates);

// collect and print clocked states #6132
for syst in systs loop
clockedstates := BackendVariable.filterCrefs(syst.orderedVars, BackendVariable.isVarClockedState, clockedstates);
end for;

((sys,inp,st,states,dvar,discvars,seq,salg,sarr,sce,swe,sie,systemsTpl,mixedTpl,tornTpl,tornTpl2)) := BackendDAEUtil.foldEqSystem(inDAE,dumpCompShort1,(0,0,0,{},0,{},0,0,0,0,0,0,({},{},{},{}),({},{},{},{},{},{},{},{},{},{}),({},{}),({},{})));
(e_jc,e_jt,e_jn,e_nj) := systemsTpl;
(m_se,m_salg,m_sarr,m_sec,me_jc,me_jt,me_jn,me_nj,me_lt,me_nt) := mixedTpl;
Expand All @@ -3634,6 +3639,7 @@ algorithm
stStr := intString(st);
dvarStr := intString(dvar);
dstStr := intString(dst);
clckStr := intString(listLength(clockedstates));
statesStr := if Flags.isSet(Flags.DUMP_STATESELECTION_INFO)
then " (" + stringDelimitList(List.map(states, ComponentReference.printComponentRefStr),",") + ")"
else " ('-d=stateselection' for list of states)";
Expand All @@ -3643,11 +3649,15 @@ algorithm
discstatesStr := if Flags.isSet(Flags.DUMP_DISCRETEVARS_INFO)
then " (" + stringDelimitList(List.map(discstates, ComponentReference.printComponentRefStr),",") + ")"
else " ('-d=discreteinfo' for list of discrete states)";
inpStr := intString(inp);
clockedstatesStr := if Flags.isSet(Flags.DUMP_DISCRETEVARS_INFO)
then " (" + stringDelimitList(List.map(clockedstates, ComponentReference.printComponentRefStr),",") + ")"
else " ('-d=discreteinfo' for list of clocked states)";
stStr := stStr+statesStr;
dvarStr := dvarStr+discvarsStr;
dstStr := dstStr+discstatesStr;
msgs := {daeType,sysStr,stStr,dvarStr,dstStr,inpStr};
clckStr := clckStr+clockedstatesStr;
inpStr := intString(inp);
msgs := {daeType,sysStr,stStr,dvarStr,dstStr,clckStr,inpStr};
Error.addMessage(Error.BACKENDDAEINFO_STATISTICS, msgs);

strcompsStr := intString(strcomps);
Expand Down
37 changes: 37 additions & 0 deletions OMCompiler/Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -940,6 +940,20 @@ algorithm
end match;
end isVarDiscrete;

public function isVarClockedState
"This functions checks if BackendDAE.Var is a clocked state"
input BackendDAE.Var inVar;
output Boolean outBoolean;
protected
String test;
algorithm
outBoolean := match (inVar)
case (BackendDAE.VAR(varKind = BackendDAE.CLOCKED_STATE())) then true;
else false;
end match;
test := "";
end isVarClockedState;

public function isDiscrete
"This functions checks if BackendDAE.Var is discrete"
input DAE.ComponentRef cr;
Expand Down Expand Up @@ -3571,6 +3585,29 @@ algorithm
outArg := BackendDAEUtil.traverseArrayNoCopy(vars, inFunc, traverseBackendDAEVars2, inArg, num_vars);
end traverseBackendDAEVars;

partial function filterFunc
input BackendDAE.Var var;
output Boolean b;
end filterFunc;

public function filterCrefs
input BackendDAE.Variables variables;
input filterFunc func;
input output list<DAE.ComponentRef> acc;
algorithm
acc := traverseBackendDAEVars(variables, function filterTraverse(func = func), acc);
end filterCrefs;

protected function filterTraverse
input output BackendDAE.Var var;
input filterFunc func;
input output list<DAE.ComponentRef> acc;
algorithm
if func(var) then
acc := var.varName :: acc;
end if;
end filterTraverse;

protected function traverseBackendDAEVars2<ArgT>
input Option<BackendDAE.Var> inVar;
input FuncType inFunc;
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/Util/Error.mo
Expand Up @@ -591,7 +591,7 @@ public constant ErrorTypes.Message UNFIXED_PARAMETER_WITH_BINDING_AND_START_VALU
public constant ErrorTypes.Message BACKENDDAEINFO_LOWER = ErrorTypes.MESSAGE(258, ErrorTypes.SYMBOLIC(), ErrorTypes.NOTIFICATION(),
Gettext.gettext("Model statistics after passing the front-end and creating the data structures used by the back-end:\n * Number of equations: %s\n * Number of variables: %s"));
public constant ErrorTypes.Message BACKENDDAEINFO_STATISTICS = ErrorTypes.MESSAGE(259, ErrorTypes.SYMBOLIC(), ErrorTypes.NOTIFICATION(),
Gettext.gettext("Model statistics after passing the back-end for %s:\n * Number of independent subsystems: %s\n * Number of states: %s\n * Number of discrete variables: %s\n * Number of discrete states: %s\n * Top-level inputs: %s"));
Gettext.gettext("Model statistics after passing the back-end for %s:\n * Number of independent subsystems: %s\n * Number of states: %s\n * Number of discrete variables: %s\n * Number of discrete states: %s\n * Number of clocked states: %s\n * Top-level inputs: %s"));
public constant ErrorTypes.Message BACKENDDAEINFO_MIXED = ErrorTypes.MESSAGE(260, ErrorTypes.SYMBOLIC(), ErrorTypes.NOTIFICATION(),
Gettext.gettext("Mixed equation statistics:\n * Mixed systems with single equation: %s\n * Mixed systems with array equation: %s\n * Mixed systems with algorithm: %s\n * Mixed systems with complex equation: %s\n * Mixed systems with constant Jacobian: %s\n * Mixed systems with linear Jacobian: %s\n * Mixed systems with non-linear Jacobian: %s\n * Mixed systems with analytic Jacobian: %s\n * Mixed systems with linear tearing system: %s\n * Mixed systems with nonlinear tearing system: %s"));
public constant ErrorTypes.Message BACKENDDAEINFO_STRONGCOMPONENT_STATISTICS = ErrorTypes.MESSAGE(261, ErrorTypes.SYMBOLIC(), ErrorTypes.NOTIFICATION(),
Expand Down

0 comments on commit 3ffedaa

Please sign in to comment.