Skip to content

Commit

Permalink
- ConnectionGraph.mo:
Browse files Browse the repository at this point in the history
  + faster handling of overconstrained connections when the connection graph is empty: no DAE walk!
  + handle expression: (NOT Connections.isRoot(A))
  + gather operations into one new function: ConnectionGraph.handleOverconstrainedConnections
    which is called from Inst module when we reach the instantiation of the top level class

- Inst.mo:
  + handle overconstrained connections also in Inst.instantiateClass and Inst.instClassInProgram 
    (was only in instProgram before)
  + removed some old commented out debug prints.

- Static.mo
  + handle the case where the instance function is made of parts instead of being derived (short
    class definition)

- Util.mo
  + implemented listAppendNoCopy that deals with empty lists using 
    special cases by not generating a new copy of the non-empty list.
  + the normal listAppend(L1, L2) will ALWAYS generate a copy of the first parameter (L1)

- Env.mo
  + trivial comment change

- DAEUtil.mo
  + removed extra parentheses around named pattern as it doesn't parse using omc

- DAELow.mo
  + DAELow.COMPLEX_EQUATION describes equations of the form record=functionCall(...).
  + more handling of DAELow.COMPLEX_EQUATION so at least checkModel works.
  + more is needed so that DAELow.COMPLEX_EQUATION works in simulation



git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@4723 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Dec 21, 2009
1 parent 0e115b4 commit 74a0a89
Show file tree
Hide file tree
Showing 7 changed files with 513 additions and 412 deletions.
128 changes: 96 additions & 32 deletions Compiler/ConnectionGraph.mo
Expand Up @@ -89,6 +89,7 @@ public constant ConnectionGraph EMPTY = GRAPH( true, {}, {}, {}, {} );
public constant ConnectionGraph NOUPDATE_EMPTY = GRAPH( false, {}, {}, {}, {} );

protected import Exp;
protected import Debug;

public
function printEdges
Expand Down Expand Up @@ -475,10 +476,10 @@ algorithm
DAE.ComponentRef ref1, ref2;
list<tuple<DAE.ComponentRef, DAE.ComponentRef>> tail;
case(table, ((ref1,ref2)::tail))
equation
(table1,_) = connectComponents(table, ref1, ref2, {}, {}, {});
table2 = addBranchesToTable(table, tail);
then table2;
equation
(table1,_) = connectComponents(table, ref1, ref2, {}, {}, {});
table2 = addBranchesToTable(table, tail);
then table2;
case(table, {})
then table;
end matchcontinue;
Expand Down Expand Up @@ -559,29 +560,34 @@ function findResultGraph
input ConnectionGraph inGraph;
output list<DAE.ComponentRef> outRoots;
output list<DAE.Element> outDae;
list<DAE.ComponentRef> definiteRoots, finalRoots;
list<tuple<DAE.ComponentRef,Real>> potentialRoots;
list<tuple<DAE.ComponentRef,Real>> orderedPotentialRoots;
Edges branches;
DaeEdges connections;
HashTableCG.HashTable table;
DAE.ComponentRef dummyRoot;
Edges brokenConnections, normalConnections;
list<DAE.Element> dae;
algorithm
definiteRoots := getDefiniteRoots(inGraph);
potentialRoots := getPotentialRoots(inGraph);
branches := getBranches(inGraph);
connections := getConnections(inGraph);

table := resultGraphWithRoots(definiteRoots);
table := addBranchesToTable(table, branches);
orderedPotentialRoots := Util.sort(potentialRoots, ord);
dummyRoot := DAE.CREF_IDENT("__DUMMY_ROOT", DAE.ET_INT, {});
(table, dae) := addConnections(table, connections, {});
(table, finalRoots) := addPotentialRootsToTable(table, orderedPotentialRoots, definiteRoots, dummyRoot);
outRoots := finalRoots;
outDae := dae;
(outRoots, outDae) := matchcontinue(inGraph)
local
list<DAE.ComponentRef> definiteRoots, finalRoots;
list<tuple<DAE.ComponentRef,Real>> potentialRoots;
list<tuple<DAE.ComponentRef,Real>> orderedPotentialRoots;
Edges branches;
DaeEdges connections;
HashTableCG.HashTable table;
DAE.ComponentRef dummyRoot;
Edges brokenConnections, normalConnections;
list<DAE.Element> dae;
// deal with empty connection graph
case (GRAPH(_, definiteRoots = {}, potentialRoots = {}, branches = {}, connections = {}))
then ({}, {});

// we have something in the connection graph
case (GRAPH(_, definiteRoots = definiteRoots, potentialRoots = potentialRoots,
branches = branches, connections = connections))
equation
table = resultGraphWithRoots(definiteRoots);
table = addBranchesToTable(table, branches);
orderedPotentialRoots = Util.sort(potentialRoots, ord);
dummyRoot = DAE.CREF_IDENT("__DUMMY_ROOT", DAE.ET_INT, {});
(table, dae) = addConnections(table, connections, {});
(table, finalRoots) = addPotentialRootsToTable(table, orderedPotentialRoots, definiteRoots, dummyRoot);
then (finalRoots, dae);
end matchcontinue;
end findResultGraph;

function evalIsRoot
Expand All @@ -591,7 +597,14 @@ function evalIsRoot
input list<DAE.Element> inDae;
output list<DAE.Element> outDae;
algorithm
(outDae, _) := DAEUtil.traverseDAE(inDae, evalIsRootHelper, inRoots);
outDae := matchcontinue(inRoots, inDae)
case ({}, {}) then {};
case ({}, inDae) then inDae;
case (inRoots, inDae)
equation
(outDae, _) = DAEUtil.traverseDAE(inDae, evalIsRootHelper, inRoots);
then outDae;
end matchcontinue;
end evalIsRoot;

function evalIsRootHelper
Expand All @@ -602,19 +615,70 @@ function evalIsRootHelper
output list<DAE.ComponentRef> outRoots;
algorithm
(outExp,outRoots) := matchcontinue(inExp,inRoots)
local
DAE.Exp exp;
list<DAE.ComponentRef> roots;
DAE.ComponentRef cref;
Boolean result;
local
DAE.Exp exp;
list<DAE.ComponentRef> roots;
DAE.ComponentRef cref;
Boolean result;

// no roots, same exp
case (exp, {}) then (exp, {});
// deal with Connections.isRoot
case (DAE.CALL(path=Absyn.QUALIFIED("Connections", Absyn.IDENT("isRoot")),
expLst={DAE.CREF(componentRef = cref)}), roots)
equation
result = Util.listContainsWithCompareFunc(cref, roots, Exp.crefEqual);
//Debug.fprintln("cgraph", Exp.printExpStr(inExp) +& " is found in roots:");
then (DAE.BCONST(result), roots);
// deal with NOT Connections.isRoot
case (DAE.LUNARY(DAE.NOT(), DAE.CALL(path=Absyn.QUALIFIED("Connections", Absyn.IDENT("isRoot")),
expLst={DAE.CREF(componentRef = cref)})), roots)
equation
result = Util.listContainsWithCompareFunc(cref, roots, Exp.crefEqual);
result = boolNot(result);
//Debug.fprintln("cgraph", Exp.printExpStr(inExp) +& " is found in roots!");
then (DAE.BCONST(result), roots);
// no replacement needed
case (exp, roots)
equation
//Debug.fprintln("cgraph", Exp.printExpStr(exp) +& " not found in roots!");
then (exp, roots);
end matchcontinue;
end evalIsRootHelper;

public function handleOverconstrainedConnections
"author: adrpo
this function gets the connection graph and adds the
new connections to the DAE given as input and returns
a new DAE"
input ConnectionGraph inGraph;
input list<DAE.Element> inDAE;
output list<DAE.Element> outDAE;
algorithm
outDAE := matchcontinue(inGraph, inDAE)
local
ConnectionGraph graph;
list<DAE.Element> dae, daeConnections;
list<DAE.ComponentRef> roots;
// empty graph gives you the same dae
case (GRAPH(_, {}, {}, {}, {}), dae) then dae;
// no dae
case (graph, {}) then {};
// handle the connection braking
case (graph, dae)
equation
(roots,daeConnections) = findResultGraph(graph);
dae = evalIsRoot(roots, dae);
dae = Util.listAppendNoCopy(dae, daeConnections);
then
dae;
// handle the connection braking
case (graph, dae)
equation
Debug.fprintln("cgraph", "- ConnectionGraph.handleOverconstrainedConnections failed");
then
fail();
end matchcontinue;
end handleOverconstrainedConnections;

end ConnectionGraph;

0 comments on commit 74a0a89

Please sign in to comment.