Skip to content

Commit

Permalink
Merge branch 'master' into clocks
Browse files Browse the repository at this point in the history
  • Loading branch information
niklwors authored and niklwors committed Mar 22, 2016
2 parents 0e205e2 + 0502333 commit 029e82e
Show file tree
Hide file tree
Showing 123 changed files with 3,142 additions and 4,474 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -87,7 +87,7 @@ SimulationRuntime/java_interface/src/org/openmodelica/corba/parser/OMCorbaDefini
SimulationRuntime/java_interface/src/org/openmodelica/corba/parser/OMCorbaDefinitionsParser.java
SimulationRuntime/cpp/Makefile
SimulationRuntime/cpp/Makefile.env
SimulationRuntime/cpp/Build/
SimulationRuntime/cpp/Build_*/
SimulationRuntime/cpp/Debug/
SimulationRuntime/cpp/.cproject
SimulationRuntime/cpp/confdefs.h
Expand Down
24 changes: 22 additions & 2 deletions Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -532,11 +532,28 @@ uniontype TearingSet
record TEARINGSET
list<Integer> tearingvars;
list<Integer> residualequations;
list<tuple<Integer,list<Integer>>> otherEqnVarTpl "list of tuples of indexes for Equation and Variable solved in the equation, in the order they have to be solved";
InnerEquations innerEquations "list of matched equations and variables; these will be solved explicitly in the given order";
Jacobian jac;
end TEARINGSET;
end TearingSet;

type InnerEquations = list<InnerEquation>;

public
uniontype InnerEquation
record INNEREQUATION
Integer eqn;
list<Integer> vars;
end INNEREQUATION;

record INNEREQUATIONCONSTRAINTS
Integer eqn;
list<Integer> vars;
Constraints cons;
end INNEREQUATIONCONSTRAINTS;
end InnerEquation;


public
type StateSets = list<StateSet> "List of StateSets";

Expand Down Expand Up @@ -611,7 +628,7 @@ type IncidenceMatrixT = IncidenceMatrix
contain the state variable and not the derivative have a negative index.";

public
type AdjacencyMatrixElementEnhancedEntry = tuple<Integer,Solvability>;
type AdjacencyMatrixElementEnhancedEntry = tuple<Integer,Solvability,Constraints>;

public
type AdjacencyMatrixElementEnhanced = list<AdjacencyMatrixElementEnhancedEntry>;
Expand Down Expand Up @@ -642,6 +659,9 @@ uniontype Solvability
how the variable occurs in the equation." end SOLVABILITY_SOLVABLE;
end Solvability;

public
type Constraints = list<.DAE.Constraint> "Constraints needed for proper Dynamic Tearing";

public
uniontype IndexType
record ABSOLUTE "incidence matrix with absolute indexes" end ABSOLUTE;
Expand Down
68 changes: 39 additions & 29 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -1582,10 +1582,13 @@ protected
BackendDAE.EqSystem syst;
list<BackendDAE.EqSystem> systs;
BackendDAE.Shared shared;
Integer sz;
BackendDAE.Variables vars;
algorithm
BackendDAE.DAE(systs, shared) := inDAE;
vars := BackendVariable.emptyVarsSized(integer(sum(BackendVariable.varsSize(s.orderedVars) for s in systs)*1.4));
// We can use listReduce as if there is no eq-system something went terribly wrong
syst := List.reduce(systs, mergeIndependentBlocks);
syst := List.fold(listReverse(systs), mergeIndependentBlocks, BackendDAEUtil.createEqSystem(vars));
outDAE := BackendDAE.DAE({syst}, shared);
end collapseIndependentBlocks;

Expand All @@ -1598,10 +1601,10 @@ protected
BackendDAE.EquationArray eqs, removedEqs;
BackendDAE.StateSets stateSets;
algorithm
vars := BackendVariable.mergeVariables(syst2.orderedVars, syst1.orderedVars);
eqs := BackendEquation.addEquations(BackendEquation.equationList(syst2.orderedEqs), syst1.orderedEqs);
removedEqs := BackendEquation.addEquations(BackendEquation.equationList(syst2.removedEqs), syst1.removedEqs);
stateSets := listAppend(syst2.stateSets, syst1.stateSets);
vars := BackendVariable.addVariables(syst1.orderedVars, syst2.orderedVars);
eqs := BackendEquation.addEquations(BackendEquation.equationList(syst1.orderedEqs), syst2.orderedEqs);
removedEqs := BackendEquation.addEquations(BackendEquation.equationList(syst1.removedEqs), syst2.removedEqs);
stateSets := listAppend(syst1.stateSets, syst2.stateSets);
syst := BackendDAEUtil.createEqSystem(vars, eqs, stateSets, BackendDAE.UNKNOWN_PARTITION(), removedEqs);
end mergeIndependentBlocks;

Expand Down Expand Up @@ -1779,8 +1782,9 @@ algorithm
DAE.FunctionTree funcs;
list<BackendDAE.Var> varlst;
list<DAE.Exp> explst;
list<tuple<Integer,list<Integer>>> eqnvartpllst;
BackendDAE.InnerEquations innerEquations;
list<Integer> vlst;
list<list<Integer>> vLstLst;
case ({},_,_,_) then compInfosIn;
case (BackendDAE.SINGLEEQUATION(eqn=eqIdx)::rest,_,_,_)
equation
Expand Down Expand Up @@ -1857,7 +1861,7 @@ algorithm
then
countOperationstraverseComps(rest,isyst,ishared,compInfo::compInfosIn);

case (BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(tearingvars=vlst, residualequations=tornEqs, otherEqnVarTpl= eqnvartpllst), linear = true)::rest,_,BackendDAE.SHARED(functionTree=funcs),_)
case (BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(tearingvars=vlst, residualequations=tornEqs, innerEquations= innerEquations), linear = true)::rest,_,BackendDAE.SHARED(functionTree=funcs),_)
equation
comp = listHead(inComps);
eqns = BackendEquation.getEqnsFromEqSystem(isyst);
Expand All @@ -1869,8 +1873,8 @@ algorithm
(_,(numAdd,numMul,numDiv,numTrig,numRel,numLog,numOth,numFuncs)) = Expression.traverseExpList(explst,function countOperationsExp(shared=ishared),(0,0,0,0,0,0,0,0));
torn = BackendDAE.COUNTER(comp,numAdd,numMul,numDiv,numTrig,numRel,numLog,numOth,numFuncs);
// the other eqs
otherEqs = List.map(eqnvartpllst,Util.tuple21);
vlst = List.flatten(List.map(eqnvartpllst,Util.tuple22));
(otherEqs,vLstLst,_) = List.map_3(innerEquations, BackendDAEUtil.getEqnAndVarsFromInnerEquation);
vlst = List.flatten(vLstLst);
eqnlst = BackendEquation.getEqns(otherEqs,eqns);
varlst = List.map1(vlst,BackendVariable.getVarAtIndexFirst, vars);
(explst,_) = BackendDAEUtil.getEqnSysRhs(BackendEquation.listEquation(eqnlst),BackendVariable.listVar1(varlst),SOME(funcs));
Expand All @@ -1879,7 +1883,7 @@ algorithm
compInfo = BackendDAE.TORN_ANALYSE(comp,torn,other,listLength(tornEqs));
then
countOperationstraverseComps(rest,isyst,ishared,compInfo::compInfosIn);
case (BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(residualequations=tornEqs, otherEqnVarTpl= eqnvartpllst), linear = false)::rest,_,BackendDAE.SHARED(),_)
case (BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(residualequations=tornEqs, innerEquations = innerEquations), linear = false)::rest,_,BackendDAE.SHARED(),_)
equation
comp = listHead(inComps);
eqns = BackendEquation.getEqnsFromEqSystem(isyst);
Expand All @@ -1890,7 +1894,7 @@ algorithm
(_,(numAdd,numMul,numDiv,numTrig,numRel,numLog,numOth,numFuncs)) = Expression.traverseExpList(explst,function countOperationsExp(shared=ishared),(0,0,0,0,0,0,0,0));
torn = BackendDAE.COUNTER(comp,numAdd,numMul,numDiv,numTrig,numRel,numLog,numOth,numFuncs);
// the other eqs
otherEqs = List.map(eqnvartpllst,Util.tuple21);
(otherEqs,_,_) = List.map_3(innerEquations, BackendDAEUtil.getEqnAndVarsFromInnerEquation);
eqnlst = BackendEquation.getEqns(otherEqs,eqns);
explst = List.map(eqnlst,BackendEquation.getEquationRHS);
(_,(numAdd,numMul,numDiv,numTrig,numRel,numLog,numOth,numFuncs)) = Expression.traverseExpList(explst,function countOperationsExp(shared=ishared),(0,0,0,0,0,0,0,0));
Expand All @@ -1910,18 +1914,24 @@ protected function getNumJacEntries
input BackendDAE.Jacobian inJac;
output Integer numEntries;
algorithm
numEntries := match(inJac)
numEntries := match inJac
local
list<tuple<Integer, Integer, BackendDAE.Equation>> jac;
case (BackendDAE.FULL_JACOBIAN(NONE()))
equation
then -1;
case (BackendDAE.FULL_JACOBIAN(SOME(jac)))
equation
list<BackendDAE.Var> vars1, vars2;
case BackendDAE.FULL_JACOBIAN(NONE())
then -1;
case BackendDAE.FULL_JACOBIAN(SOME(jac))
then listLength(jac);
/* TODO: implement for GENERIC_JACOBIAN */
case (_)
case BackendDAE.EMPTY_JACOBIAN()
then -1;
/* TODO: implement/check for GENERIC_JACOBIAN */
case BackendDAE.GENERIC_JACOBIAN(jacobian=(_,_,vars1,vars2,_))
guard
listLength(vars1) == listLength(vars2)
then listLength(vars1);
else
equation
//print(BackendDump.jacobianString(inJac));
print("another JAC\n");
then -1;
end match;
Expand Down Expand Up @@ -4369,8 +4379,8 @@ protected
BackendDAE.Matching matching;
BackendDAE.StateSets stateSets;
BackendDAE.BaseClockPartitionKind partitionKind;
list<tuple<Integer,list<Integer>>> otherEqnVarTpl;
tuple<Integer,list<Integer>> tpl;
BackendDAE.InnerEquations innerEquations;
BackendDAE.InnerEquation innerEquation;
Integer i,j;
BackendDAE.Equation eqn;
list<Integer> tvars "be careful with states, this are solved for der(x)";
Expand All @@ -4386,10 +4396,10 @@ algorithm
for comp in comps loop
if BackendEquation.isTornSystem(comp) then

BackendDAE.TORNSYSTEM(strictTearingSet = BackendDAE.TEARINGSET(tearingvars=tvars, residualequations=teqns, otherEqnVarTpl= otherEqnVarTpl)) := comp;
for tpl in otherEqnVarTpl loop
BackendDAE.TORNSYSTEM(strictTearingSet = BackendDAE.TEARINGSET(tearingvars=tvars, residualequations=teqns, innerEquations = innerEquations)) := comp;
for innerEquation in innerEquations loop
try
(i,{j}) := tpl;
(i,{j},_) := BackendDAEUtil.getEqnAndVarsFromInnerEquation(innerEquation);
eqn := BackendEquation.equationNth1(eqns, i);
BackendDAE.VAR(varName = cr) := BackendVariable.getVarAt(vars, j);
eqn := BackendEquation.solveEquation(eqn, Expression.crefExp(cr), SOME(shared.functionTree));
Expand Down Expand Up @@ -4681,8 +4691,8 @@ protected
BackendDAE.Equation eqn;
Boolean update, linear;
Integer i, k;
list<tuple<Integer,list<Integer>>> otherEqnVarTpl;
tuple<Integer,list<Integer>> tpl;
BackendDAE.InnerEquations innerEquations;
BackendDAE.InnerEquation innerEquation;
algorithm

if BackendEquation.isEquationsSystem(inComp) then
Expand All @@ -4697,16 +4707,16 @@ algorithm
end if;

else
BackendDAE.TORNSYSTEM(linear=linear, strictTearingSet = BackendDAE.TEARINGSET(tearingvars=vars, residualequations=eqns, otherEqnVarTpl= otherEqnVarTpl)) := inComp;
BackendDAE.TORNSYSTEM(linear=linear, strictTearingSet = BackendDAE.TEARINGSET(tearingvars=vars, residualequations=eqns, innerEquations = innerEquations)) := inComp;
if linear then
return;
end if;
if Flags.isSet(Flags.DUMP_SIMPLIFY_LOOPS) then
print("------ Tearing ------\n");
end if;

for tpl in otherEqnVarTpl loop
(k,vv) := tpl;
for innerEquation in innerEquations loop
(k,vv) := BackendDAEUtil.getEqnAndVarsFromInnerEquation(innerEquation);
eqns := k :: eqns;
vars := listAppend(vv,vars);
end for;
Expand Down
22 changes: 13 additions & 9 deletions Compiler/BackEnd/BackendDAETransform.mo
Expand Up @@ -438,12 +438,13 @@ algorithm
(outEquation, outVar, outIndex) := match inComp
local
Integer v, e;
list<Integer> elst, vlst;
list<Integer> elst, vlst, otherEqns, otherVars;
list<list<Integer>> otherVarsLst;
BackendDAE.Equation eqn;
BackendDAE.Var var;
list<BackendDAE.Equation> eqnlst, eqnlst1;
list<BackendDAE.Var> varlst, varlst1;
list<tuple<Integer, list<Integer>>> eqnvartpllst;
BackendDAE.InnerEquations innerEquations;

case BackendDAE.SINGLEEQUATION(eqn=e, var=v) equation
eqn = BackendEquation.equationNth1(inEquationArray, e);
Expand Down Expand Up @@ -481,11 +482,13 @@ algorithm
varlst = List.map1r(vlst, BackendVariable.getVarAt, inVariables);
then ({eqn}, varlst, e);

case BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(tearingvars=vlst, residualequations=elst, otherEqnVarTpl=eqnvartpllst)) equation
case BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(tearingvars=vlst, residualequations=elst, innerEquations=innerEquations)) equation
eqnlst = BackendEquation.getEqns(elst, inEquationArray);
varlst = List.map1r(vlst, BackendVariable.getVarAt, inVariables);
eqnlst1 = BackendEquation.getEqns(List.map(eqnvartpllst, Util.tuple21), inEquationArray);
varlst1 = List.map1r(List.flatten(List.map(eqnvartpllst, Util.tuple22)), BackendVariable.getVarAt, inVariables);
(otherEqns,otherVarsLst,_) = List.map_3(innerEquations, BackendDAEUtil.getEqnAndVarsFromInnerEquation);
otherVars = List.flatten(otherVarsLst);
eqnlst1 = BackendEquation.getEqns(otherEqns, inEquationArray);
varlst1 = List.map1r(otherVars, BackendVariable.getVarAt, inVariables);
e = listHead(elst);
then (listAppend(eqnlst, eqnlst1), listAppend(varlst, varlst1), e);

Expand All @@ -507,8 +510,9 @@ algorithm
local
Integer v, e;
list<Integer> elst, vlst, elst1, vlst1;
list<list<Integer>> vLstLst;
BackendDAE.StrongComponent comp;
list<tuple<Integer, list<Integer>>> eqnvartpllst;
BackendDAE.InnerEquations innerEquations;

case (BackendDAE.SINGLEEQUATION(eqn=e, var=v))
then ({e}, {v});
Expand All @@ -531,9 +535,9 @@ algorithm
case BackendDAE.SINGLEWHENEQUATION(eqn=e, vars=vlst)
then ({e}, vlst);

case BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(tearingvars=vlst, residualequations=elst, otherEqnVarTpl=eqnvartpllst)) equation
elst1 = List.map(eqnvartpllst, Util.tuple21);
vlst1 = List.flatten(List.map(eqnvartpllst, Util.tuple22));
case BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(tearingvars=vlst, residualequations=elst, innerEquations=innerEquations)) equation
(elst1,vLstLst,_) = List.map_3(innerEquations, BackendDAEUtil.getEqnAndVarsFromInnerEquation);
vlst1 = List.flatten(vLstLst);
elst = listAppend(elst1, elst);
vlst = listAppend(vlst1, vlst);
then (elst, vlst);
Expand Down

0 comments on commit 029e82e

Please sign in to comment.