Skip to content

Commit

Permalink
Fixes for bug: #1325
Browse files Browse the repository at this point in the history
- merge cached overconstrained connection graph with the current overconstrained connection graph
   Compiler/ConnectionGraph.mo
   Compiler/Inst.mo
- added test for this bug in
   testsuite/libraries/multibody/elementary/DoublePendulum.mos
   testsuite/libraries/multibody/elementary/Pendulum.mos

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6455 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Oct 19, 2010
1 parent 5b86111 commit c6d2a6a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
47 changes: 47 additions & 0 deletions Compiler/ConnectionGraph.mo
Expand Up @@ -1502,6 +1502,53 @@ algorithm
end matchcontinue;
end elementSourceInBrokenConnects;

public function merge
"merge two ConnectionGraphs"
input ConnectionGraph inGraph1;
input ConnectionGraph inGraph2;
output ConnectionGraph outGraph;
algorithm
outGraph := matchcontinue(inGraph1, inGraph2)
local
Boolean updateGraph, updateGraph1, updateGraph2;
list<DAE.ComponentRef> definiteRoots, definiteRoots1, definiteRoots2;
list<tuple<DAE.ComponentRef,Real>> potentialRoots, potentialRoots1, potentialRoots2;
Edges branches, branches1, branches2;
DaeEdges connections, connections1, connections2;

// left is empty, return right
case (inGraph1, GRAPH(updateGraph = _,definiteRoots = {},potentialRoots = {},branches = {},connections = {}))
then
inGraph1;

// right is empty, return left
case (GRAPH(updateGraph = _,definiteRoots = {},potentialRoots = {},branches = {},connections = {}), inGraph2)
then
inGraph2;

// they are equal, return any
case (inGraph1, inGraph2)
equation
equality(inGraph1 = inGraph2);
then
inGraph1;

// they are NOT equal, merge them
case (GRAPH(updateGraph = updateGraph1,definiteRoots = definiteRoots1,potentialRoots = potentialRoots1,branches = branches1,connections = connections1),
GRAPH(updateGraph = updateGraph2,definiteRoots = definiteRoots2,potentialRoots = potentialRoots2,branches = branches2,connections = connections2))
equation
Debug.fprintln("cgraph", "- ConnectionGraph.merge()");
updateGraph = boolOr(updateGraph1, updateGraph2);
definiteRoots = Util.listUnion(definiteRoots1, definiteRoots2);
potentialRoots = Util.listUnion(potentialRoots1, potentialRoots2);
branches = Util.listUnion(branches1, branches2);
connections = Util.listUnion(connections1, connections2);
then
GRAPH(updateGraph,definiteRoots,potentialRoots,branches,connections);
end matchcontinue;
end merge;


/***********************************************************************************************************************/
/******************************************* GraphViz generation *******************************************************/
/***********************************************************************************************************************/
Expand Down
14 changes: 8 additions & 6 deletions Compiler/Inst.mo
Expand Up @@ -1830,7 +1830,7 @@ algorithm
ConnectionGraph.ConnectionGraph, Option<DAE.ComponentRef>> inputs;
tuple<Env, DAE.DAElist,
Connect.Sets, ClassInf.State, list<DAE.Var>, Option<DAE.Type>,
Option<Absyn.ElementAttributes>, DAE.EqualityConstraint
Option<Absyn.ElementAttributes>, DAE.EqualityConstraint, ConnectionGraph.ConnectionGraph
> outputs;
Absyn.Path fullEnvPathPlusClass;
Option<Absyn.Path> envPathOpt;
Expand All @@ -1848,6 +1848,7 @@ algorithm
replaceable type Type_a subtypeof Any;
Type_a bbx, bby;
CachedInstItem partialFunc;
ConnectionGraph.ConnectionGraph graphCached;

/* Partial packages can sometimes be instantiated here, but should really be done in partialInstClass, since
* it filters out a lot of things. */
Expand All @@ -1871,7 +1872,8 @@ algorithm
bbx = (aa_7, aa_8, aa_1, aa_3, aa_4, aa_5, aa_9);
bby = (inst_dims, impl, mods, csets, ci_state, c, instSingleCref);
equality(bbx = bby);
(env,dae,csets_1,ci_state,tys,bc,oDA,equalityConstraint) = outputs;
(env,dae,csets_1,ci_state,tys,bc,oDA,equalityConstraint,graphCached) = outputs;
graph = ConnectionGraph.merge(graph, graphCached);
/*
Debug.fprintln("cache", "IIII->got from instCache: " +& Absyn.pathString(fullEnvPathPlusClass) +&
"\n\tpre: " +& PrefixUtil.printPrefixStr(pre) +& " class: " +& className +&
Expand All @@ -1894,7 +1896,7 @@ algorithm
fullEnvPathPlusClass = Absyn.selectPathsOpt(envPathOpt, Absyn.IDENT(className));

inputs = (inCache,inEnv,inIH,store,inMod,inPrefix,inSets,inState,inClass,isProtected,inInstDims,implicitInstantiation,inGraph,instSingleCref);
outputs = (env,dae,csets,ci_state,tys,bc,oDA,equalityConstraint);
outputs = (env,dae,csets,ci_state,tys,bc,oDA,equalityConstraint,graph);

addToInstCache(fullEnvPathPlusClass,
SOME(FUNC_instClassIn( // result for full instantiation
Expand Down Expand Up @@ -14161,15 +14163,15 @@ uniontype CachedInstItem
tuple</*Env.Cache, */
Env,
/*InstanceHierarchy, */
/* UnitAbsyn.InstStore, */
/*UnitAbsyn.InstStore, */
DAE.DAElist,
Connect.Sets,
ClassInf.State,
list<DAE.Var>,
Option<DAE.Type>,
Option<Absyn.ElementAttributes>,
DAE.EqualityConstraint
/*ConnectionGraph.ConnectionGraph*/
DAE.EqualityConstraint,
ConnectionGraph.ConnectionGraph
> outputs;
end FUNC_instClassIn;

Expand Down

0 comments on commit c6d2a6a

Please sign in to comment.