Skip to content

Commit

Permalink
- print more info on +d=showEquationSource
Browse files Browse the repository at this point in the history
- add more info from where the unconnected flow comes (add Element info to added inside flow) to get nicer
  +d=showEquationSource display.



git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13980 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Nov 20, 2012
1 parent 8929a65 commit 09fafda
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 11 deletions.
25 changes: 16 additions & 9 deletions Compiler/FrontEnd/ConnectUtil.mo
Expand Up @@ -317,21 +317,22 @@ public function addConnectorVariablesFromDAE
input list<DAE.Var> inVars;
input Sets inConnectionSet;
input Absyn.Info info;
input DAE.ElementSource inElementSource;
output Sets outConnectionSet;
algorithm
outConnectionSet :=
match(inIgnore, inClassState, inPrefix, inVars, inConnectionSet, info)
match(inIgnore, inClassState, inPrefix, inVars, inConnectionSet, info, inElementSource)
local
Absyn.Path class_path;
list<DAE.Var> streams, flows;
Sets cs;

// check balance of non expandable connectors!
case (false, ClassInf.CONNECTOR(path = class_path, isExpandable = false), _, _, cs, _)
case (false, ClassInf.CONNECTOR(path = class_path, isExpandable = false), _, _, cs, _, _)
equation
checkConnectorBalance(inVars, class_path, info);
(flows, streams) = getStreamAndFlowVariables(inVars, {}, {});
cs = List.fold(flows, addFlowVariableFromDAE, cs);
cs = List.fold2(flows, addFlowVariableFromDAE, inElementSource, inPrefix, cs);
cs = addStreamFlowAssociations(cs, inPrefix, streams, flows);
then
cs;
Expand All @@ -343,14 +344,16 @@ end addConnectorVariablesFromDAE;
protected function addFlowVariableFromDAE
"Adds a flow variable from the DAE to the sets as an inside flow variable."
input DAE.Var inVariable;
input DAE.ElementSource inElementSource;
input Prefix.Prefix inPrefix;
input Sets inConnectionSet;
output Sets outConnectionSet;
protected
list<DAE.ComponentRef> crefs;
algorithm
crefs := daeVarToCrefs(inVariable);
outConnectionSet := List.fold1r(crefs, addInsideFlowVariable,
DAE.emptyElementSource, inConnectionSet);
outConnectionSet := List.fold2r(crefs, addInsideFlowVariable,
inElementSource, inPrefix, inConnectionSet);
end addFlowVariableFromDAE;

public function isExpandable
Expand Down Expand Up @@ -656,9 +659,10 @@ protected function addInsideFlowVariable
input Connect.Sets inSets;
input DAE.ComponentRef inCref;
input DAE.ElementSource inSource;
input Prefix.Prefix inPrefix;
output Connect.Sets outSets;
algorithm
outSets := matchcontinue(inSets, inCref, inSource)
outSets := matchcontinue(inSets, inCref, inSource, inPrefix)
local
ConnectorElement e;
SetTrie sets;
Expand All @@ -670,17 +674,20 @@ algorithm
DAE.ElementSource src;

// Check if it exists in the sets already.
case (Connect.SETS(sets = sets), _, _)
case (Connect.SETS(sets = sets), _, _, _)
equation
_ = setTrieGetElement(inCref, Connect.INSIDE(), sets);
then
inSets;

// Otherwise, add a new set for it.
case (Connect.SETS(sets, sc, c, cc, o), _, DAE.SOURCE(info = info))
case (Connect.SETS(sets, sc, c, cc, o), _, DAE.SOURCE(info = info), _)
equation
sc = sc + 1;
src = DAEUtil.addAdditionalComment(inSource, " equation generated by unconnected inside flow, maybe connected later");
src = DAEUtil.addAdditionalComment(inSource, " add inside flow(" +&
PrefixUtil.printPrefixStr(inPrefix) +& "." +&
ComponentReference.printComponentRefStr(inCref) +&
")");
e = newElement(inCref, Connect.INSIDE(), Connect.FLOW(), src, sc);
sets = setTrieAdd(e, sets);
then
Expand Down
44 changes: 43 additions & 1 deletion Compiler/FrontEnd/DAEDump.mo
Expand Up @@ -3940,12 +3940,54 @@ algorithm
case (DAE.SOURCE(i, po, iol, ceol, tl, op, cmt))
equation
str = cmtListToString(cmt);
str = str +& " /* models: " +& stringDelimitList(List.map(po, withinString), ", ") +& " */";
str = str +& " /* models: {" +& stringDelimitList(List.map(po, withinString), ", ") +& "}" +&
" connects: {" +& stringDelimitList(connectsStr(ceol), ", ") +& "} */";
then
str;
end matchcontinue;
end getSourceInformationStr;

protected function connectsStr
input list<Option<tuple<DAE.ComponentRef, DAE.ComponentRef>>> inLst;
output list<String> outStr;
algorithm
outstr := matchcontinue(inLst)
local
list<Option<tuple<DAE.ComponentRef, DAE.ComponentRef>>> rest;
list<String> slst;
String str;
DAE.ComponentRef c1, c2;

case ({}) then {};

case ({NONE()}) then {};

case ({SOME((c1,c2))})
equation
str = ComponentReference.printComponentRefStr(c1) +& "," +&
ComponentReference.printComponentRefStr(c2);
str = "connect(" +& str +& ")";
then
{str};

case (SOME((c1,c2))::rest)
equation
str = ComponentReference.printComponentRefStr(c1) +& "," +&
ComponentReference.printComponentRefStr(c2);
str = "connect(" +& str +& ")";
slst = connectsStr(rest);
then
str::slst;

case (NONE()::rest)
equation
slst = connectsStr(rest);
then
slst;

end matchcontinue;
end connectsStr;

protected function withinString
input Absyn.Within w;
output String str;
Expand Down
4 changes: 3 additions & 1 deletion Compiler/FrontEnd/Inst.mo
Expand Up @@ -3261,6 +3261,7 @@ algorithm
Option<SCode.Comment> cmt;
UnitAbsyn.InstStore store;
Option<SCode.ExternalDecl> ed;
DAE.ElementSource elementSource;

/*// uncomment for debugging
case (cache,env,ih,store,mods,pre,csets,ci_state,className,inClassDef6,
Expand Down Expand Up @@ -3436,7 +3437,8 @@ algorithm
// If we are currently instantiating a connector, add all flow variables
// in it as inside connectors.
zero_dims = instDimsHasZeroDims(inst_dims);
csets1 = ConnectUtil.addConnectorVariablesFromDAE(zero_dims, ci_state1, pre, vars, csets, info);
elementSource = DAEUtil.createElementSource(info, Env.getEnvPath(env4), PrefixUtil.prefixToCrefOpt(pre), NONE(), NONE());
csets1 = ConnectUtil.addConnectorVariablesFromDAE(zero_dims, ci_state1, pre, vars, csets, info, elementSource);

// Reorder the connect equations to have non-expandable connect first:
// connect(non_expandable, non_expandable);
Expand Down

0 comments on commit 09fafda

Please sign in to comment.