Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
niklwors committed Jul 10, 2015
2 parents 8cb67d0 + 4476180 commit 52eb407
Show file tree
Hide file tree
Showing 47 changed files with 799 additions and 773 deletions.
2 changes: 1 addition & 1 deletion 3rdParty
Submodule 3rdParty updated 184 files
8 changes: 5 additions & 3 deletions Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -70,13 +70,15 @@ type EqSystems = list<EqSystem>;
public
uniontype EqSystem "An independent system of equations (and their corresponding variables)"
record EQSYSTEM
Variables orderedVars "ordered Variables, only states and alg. vars";
EquationArray orderedEqs "ordered Equations";
Variables orderedVars "ordered Variables, only states and alg. vars";
EquationArray orderedEqs "ordered Equations";
Option<IncidenceMatrix> m;
Option<IncidenceMatrixT> mT;
Matching matching;
StateSets stateSets "the state sets of the system";
StateSets stateSets "the state sets of the system";
BaseClockPartitionKind partitionKind;
EquationArray removedEqs "these are equations that cannot solve for a variable.
e.g. assertions, external function calls, algorithm sections without effect";
end EQSYSTEM;
end EqSystem;

Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -135,12 +135,12 @@ algorithm
ieqnarr := BackendEquation.listEquation(ieqns);
einfo := BackendDAE.EVENT_INFO(timeEvents, whenclauses_1, {}, {}, {}, 0);
symjacs := {(NONE(), ({}, {}, ({}, {})), {}), (NONE(), ({}, {}, ({}, {})), {}), (NONE(), ({}, {}, ({}, {})), {}), (NONE(), ({}, {}, ({}, {})), {})};
outBackendDAE := BackendDAE.DAE(BackendDAEUtil.createEqSystem(vars_1, eqnarr)::{},
outBackendDAE := BackendDAE.DAE(BackendDAEUtil.createEqSystem(vars_1, eqnarr, {}, BackendDAE.UNKNOWN_PARTITION(), reqnarr)::{},
BackendDAE.SHARED(knvars,
extVars,
aliasVars,
ieqnarr,
reqnarr,
BackendEquation.emptyEqns(),
constrs,
clsAttrs,
inCache,
Expand Down
176 changes: 85 additions & 91 deletions Compiler/BackEnd/BackendDAEOptimize.mo

Large diffs are not rendered by default.

321 changes: 164 additions & 157 deletions Compiler/BackEnd/BackendDAEUtil.mo

Large diffs are not rendered by default.

80 changes: 26 additions & 54 deletions Compiler/BackEnd/BackendDump.mo
Expand Up @@ -108,7 +108,7 @@ algorithm
end printBackendDAE;

public function printEqSystem "This function prints the BackendDAE.EqSystem representation to stdout."
input BackendDAE.EqSystem inEqSystem;
input BackendDAE.EqSystem inSyst;
protected
BackendDAE.Variables orderedVars;
BackendDAE.EquationArray orderedEqs;
Expand All @@ -118,23 +118,16 @@ protected
BackendDAE.StateSets stateSets;
BackendDAE.BaseClockPartitionKind partitionKind;
algorithm
BackendDAE.EQSYSTEM(orderedVars=orderedVars,
orderedEqs=orderedEqs,
m=m,
mT=mT,
matching=matching,
stateSets=stateSets,
partitionKind=partitionKind) := inEqSystem;

print("\n" + partitionKindString(partitionKind) + "\n" + UNDERLINE + "\n");
dumpVariables(orderedVars, "Variables");
dumpEquationArray(orderedEqs, "Equations");
dumpStateSets(stateSets, "State Sets");
dumpOption(m, dumpIncidenceMatrix);
dumpOption(mT, dumpIncidenceMatrixT);
print("\n" + partitionKindString(inSyst.partitionKind) + "\n" + UNDERLINE + "\n");
dumpVariables(inSyst.orderedVars, "Variables");
dumpEquationArray(inSyst.orderedEqs, "Equations");
dumpEquationArray(inSyst.removedEqs, "Simple Equations");
dumpStateSets(inSyst.stateSets, "State Sets");
dumpOption(inSyst.m, dumpIncidenceMatrix);
dumpOption(inSyst.mT, dumpIncidenceMatrixT);

print("\n");
dumpFullMatching(matching);
dumpFullMatching(inSyst.matching);
print("\n");
end printEqSystem;

Expand Down Expand Up @@ -257,48 +250,27 @@ end printClassAttributes;

public function printShared "This function dumps the BackendDAE.Shared representation to stdout."
input BackendDAE.Shared inShared;
protected
BackendDAE.Variables knownVars, externalObjects, aliasVars;
BackendDAE.EquationArray initialEqs, removedEqs;
list<DAE.Constraint> constraints;
list<BackendDAE.ZeroCrossing> zeroCrossingLst, sampleLst, relationsLst;
list<BackendDAE.WhenClause> whenClauseLst;
list<BackendDAE.TimeEvent> timeEvents;
BackendDAE.ExternalObjectClasses extObjClasses;
BackendDAE.BackendDAEType backendDAEType;
BackendDAE.SymbolicJacobians symjacs;
algorithm
BackendDAE.SHARED(knownVars=knownVars,
externalObjects=externalObjects,
aliasVars=aliasVars,
initialEqs=initialEqs,
removedEqs=removedEqs,
constraints=constraints,
eventInfo=BackendDAE.EVENT_INFO( timeEvents=timeEvents, relationsLst=relationsLst, zeroCrossingLst=zeroCrossingLst,
sampleLst=sampleLst, whenClauseLst=whenClauseLst ),
extObjClasses=extObjClasses,
backendDAEType=backendDAEType,
symjacs=symjacs) := inShared;
algorithm

print("\nBackendDAEType: ");
printBackendDAEType(backendDAEType);
printBackendDAEType(inShared.backendDAEType);
print("\n\n");


dumpVariables(knownVars, "Known Variables (constants)");
dumpVariables(externalObjects, "External Objects");
dumpExternalObjectClasses(extObjClasses, "Classes of External Objects");
dumpVariables(aliasVars, "Alias Variables");
dumpEquationArray(removedEqs, "Simple Equations");
dumpEquationArray(initialEqs, "Initial Equations");
dumpZeroCrossingList(zeroCrossingLst, "Zero Crossings");
dumpZeroCrossingList(relationsLst, "Relations");
dumpVariables(inShared.knownVars, "Known Variables (constants)");
dumpVariables(inShared.externalObjects, "External Objects");
dumpExternalObjectClasses(inShared.extObjClasses, "Classes of External Objects");
dumpVariables(inShared.aliasVars, "Alias Variables");
dumpEquationArray(inShared.removedEqs, "Simple Shared Equations");
dumpEquationArray(inShared.initialEqs, "Initial Equations");
dumpZeroCrossingList(inShared.eventInfo.zeroCrossingLst, "Zero Crossings");
dumpZeroCrossingList(inShared.eventInfo.relationsLst, "Relations");
if stringEqual(Config.simCodeTarget(), "Cpp") then
dumpZeroCrossingList(sampleLst, "Samples");
dumpZeroCrossingList(inShared.eventInfo.sampleLst, "Samples");
else
dumpTimeEvents(timeEvents, "Time Events");
dumpTimeEvents(inShared.eventInfo.timeEvents, "Time Events");
end if;
dumpWhenClauseList(whenClauseLst, "When Clauses");
dumpConstraintList(constraints, "Constraints");
dumpWhenClauseList(inShared.eventInfo.whenClauseLst, "When Clauses");
dumpConstraintList(inShared.constraints, "Constraints");
end printShared;

public function printClocks
Expand Down Expand Up @@ -596,7 +568,6 @@ algorithm
print("\n");
end dumpClocks;


public function dumpVariables "function dumpVariables"
input BackendDAE.Variables inVars;
input String heading;
Expand Down Expand Up @@ -3309,7 +3280,8 @@ protected
DumpCompShortTornTpl tornTpl;
BackendDAE.BackendDAEType backendDAEType;
algorithm
BackendDAE.DAE(systs, BackendDAE.SHARED(removedEqs=removedEqs, backendDAEType=backendDAEType)) := inDAE;
BackendDAE.DAE(systs, BackendDAE.SHARED(backendDAEType=backendDAEType)) := inDAE;
removedEqs := BackendDAEUtil.collapseRemovedEqs(inDAE);
daeType := printBackendDAEType2String(backendDAEType);

HS := HashSet.emptyHashSet();
Expand Down
37 changes: 24 additions & 13 deletions Compiler/BackEnd/BackendEquation.mo
Expand Up @@ -350,6 +350,16 @@ algorithm
end matchcontinue;
end traversingStateRefFinder;

public function assertWithCondTrue "author: Frenkel TUD 2012-12"
input BackendDAE.Equation inEqn;
output Boolean b;
algorithm
b := match inEqn
case BackendDAE.ALGORITHM(alg=DAE.ALGORITHM_STMTS({DAE.STMT_ASSERT(cond=DAE.BCONST(true))})) then false;
else true;
end match;
end assertWithCondTrue;

public function equationsParams "author: marcusw
From a list of equations return all occurring parameter variables. Duplicates are removed."
input list<BackendDAE.Equation> inEquationLst;
Expand Down Expand Up @@ -1250,41 +1260,42 @@ public function equationAddDAE "author: Frenkel TUD 2011-05"
output BackendDAE.EqSystem outEqSystem;
algorithm
outEqSystem := BackendDAEUtil.setEqSystEqs(inEqSystem, addEquation(inEquation, inEqSystem.orderedEqs));
outEqSystem := BackendDAEUtil.setEqSystMatching(outEqSystem, BackendDAE.NO_MATCHING());
outEqSystem.matching := BackendDAE.NO_MATCHING();
end equationAddDAE;

public function equationsAddDAE "author: Frenkel TUD 2011-05"
input list<BackendDAE.Equation> inEquations;
input BackendDAE.EqSystem inEqSystem;
output BackendDAE.EqSystem outEqSystem;
output BackendDAE.EqSystem outEqSystem = inEqSystem;
algorithm
outEqSystem := BackendDAEUtil.setEqSystEqs(inEqSystem, List.fold(inEquations, addEquation, inEqSystem.orderedEqs));
outEqSystem := BackendDAEUtil.setEqSystMatching(outEqSystem, BackendDAE.NO_MATCHING());
outEqSystem.orderedEqs := addEquations(inEquations, outEqSystem.orderedEqs);
outEqSystem.matching := BackendDAE.NO_MATCHING();
end equationsAddDAE;

public function requationsAddDAE "author: Frenkel TUD 2012-10
Add a list of equations to removed equations of a BackendDAE.
If the variable already exists, the function updates the variable."
input list<BackendDAE.Equation> inEquations;
input BackendDAE.Shared inShared;
output BackendDAE.Shared outShared;
input BackendDAE.EqSystem inSyst;
output BackendDAE.EqSystem outSyst;
algorithm
outShared := match inEquations
case {} then inShared;
else then BackendDAEUtil.setSharedRemovedEqns(inShared, List.fold(inEquations, addEquation, inShared.removedEqs));
outSyst := match inEquations
case {} then inSyst;
else then BackendDAEUtil.setEqSystRemovedEqns(inSyst, List.fold(inEquations, addEquation, inSyst.removedEqs));
end match;
end requationsAddDAE;

public function removeRemovedEqs "remove removedEqs"
input BackendDAE.Shared inShared;
output BackendDAE.Shared outShared;
input BackendDAE.EqSystem inSyst;
output BackendDAE.EqSystem outSyst = inSyst;
protected
BackendDAE.EquationArray removedEqs = inShared.removedEqs;
BackendDAE.EquationArray removedEqs = inSyst.removedEqs;
Integer N;
algorithm
for i in 1:removedEqs.numberOfElement loop
removedEqs := equationRemove(i, removedEqs);
end for;
outShared := BackendDAEUtil.setSharedRemovedEqns(inShared, removedEqs);
outSyst.removedEqs := removedEqs;
end removeRemovedEqs;

public function setAtIndex "author: lochel
Expand Down
20 changes: 5 additions & 15 deletions Compiler/BackEnd/BackendInline.mo
Expand Up @@ -80,7 +80,7 @@ algorithm
BackendDAE.EqSystems eqs;
BackendDAE.Shared shared;

case BackendDAE.DAE(eqs, shared as BackendDAE.SHARED())
case BackendDAE.DAE(eqs, shared)
algorithm
tpl := (SOME(shared.functionTree), inITLst);
eqs := List.map1(eqs, inlineEquationSystem, tpl);
Expand All @@ -104,21 +104,11 @@ end inlineCalls;
protected function inlineEquationSystem
input BackendDAE.EqSystem eqs;
input Inline.Functiontuple tpl;
output BackendDAE.EqSystem oeqs;
output BackendDAE.EqSystem oeqs = eqs;
algorithm
oeqs := match eqs
local
BackendDAE.EqSystem syst;
BackendDAE.Variables orderedVars;
BackendDAE.EquationArray orderedEqs;

case syst as BackendDAE.EQSYSTEM(orderedVars=orderedVars, orderedEqs=orderedEqs)
equation
_ = inlineVariables(orderedVars, tpl);
_ = inlineEquationArray(orderedEqs, tpl);
then
syst;
end match;
inlineVariables(oeqs.orderedVars, tpl);
inlineEquationArray(oeqs.orderedEqs, tpl);
inlineEquationArray(oeqs.removedEqs, tpl);
end inlineEquationSystem;

protected function inlineEquationArray "
Expand Down
24 changes: 7 additions & 17 deletions Compiler/BackEnd/DAEQuery.mo
Expand Up @@ -85,24 +85,14 @@ public function getEquations
This function returns the equations"
input BackendDAE.BackendDAE inBackendDAE;
output String strEqs;
protected
BackendDAE.Shared shared;
BackendDAE.EqSystem syst;
list<String> ls1;
algorithm
strEqs := match (inBackendDAE)
local
String s,s1;
list<String> ls1;
list<BackendDAE.Equation> eqnsl;
BackendDAE.EquationArray eqns;
list<BackendDAE.WhenClause> wcLst;

case (BackendDAE.DAE(eqs=BackendDAE.EQSYSTEM(orderedEqs = eqns)::{}, shared=BackendDAE.SHARED(eventInfo = BackendDAE.EVENT_INFO(whenClauseLst = wcLst))))
equation
eqnsl = BackendEquation.equationList(eqns);
ls1 = List.map1(eqnsl, equationStr, wcLst);
s1 = stringDelimitList(ls1, ",");
s = "EqStr = {" + s1 + "};";
then
s;
end match;
BackendDAE.DAE({syst}, shared) := inBackendDAE;
ls1 := List.map1(BackendEquation.equationList(syst.orderedEqs), equationStr, shared.eventInfo.whenClauseLst);
strEqs := "EqStr = {" + stringDelimitList(ls1, ",") + "};";
end getEquations;

public function equationStr
Expand Down
3 changes: 2 additions & 1 deletion Compiler/BackEnd/DynamicOptimization.mo
Expand Up @@ -903,11 +903,12 @@ algorithm
//BackendDump.bltdump("START:reduceDynamicOptimization", inDAE);
BackendDAE.DAE(systlst, shared) := inDAE;
// ToDo
shared := BackendEquation.removeRemovedEqs(shared);
shared := BackendVariable.removeAliasVars(shared);

for syst in systlst loop

syst := BackendEquation.removeRemovedEqs(syst);

BackendDAE.EQSYSTEM(orderedVars = v) := syst;
varlst := BackendVariable.varList(v);

Expand Down
42 changes: 24 additions & 18 deletions Compiler/BackEnd/EvaluateParameter.mo
Expand Up @@ -1064,26 +1064,24 @@ protected function replaceEvaluatedParametersEqns "author Frenkel TUD"
input BackendVarTransform.VariableReplacements inRepl;
output BackendDAE.BackendDAE outDAE;
protected
BackendDAE.EquationArray remeqns, inieqns;
list<BackendDAE.Equation> eqnslst;
list<BackendDAE.Equation> lsteqns;
BackendDAE.EqSystems systs;
Boolean b;
BackendDAE.Shared shared;
algorithm
BackendDAE.DAE(systs, shared as BackendDAE.SHARED(initialEqs=inieqns, removedEqs=remeqns)) := inDAE;
BackendDAE.DAE(systs, shared) := inDAE;

// do replacements in initial equations
eqnslst := BackendEquation.equationList(inieqns);
(eqnslst, b) := BackendVarTransform.replaceEquations(eqnslst, inRepl, NONE());
lsteqns := BackendEquation.equationList(shared.initialEqs);
(lsteqns, b) := BackendVarTransform.replaceEquations(lsteqns, inRepl, NONE());
if b then
shared := BackendDAEUtil.setSharedInitialEqns(shared, BackendEquation.listEquation(eqnslst));
shared.initialEqs := BackendEquation.listEquation(lsteqns);
end if;

// do replacements in simple equations
eqnslst := BackendEquation.equationList(remeqns);
(eqnslst, b) := BackendVarTransform.replaceEquations(eqnslst, inRepl, NONE());
lsteqns := BackendEquation.equationList(shared.removedEqs);
(lsteqns, b) := BackendVarTransform.replaceEquations(lsteqns, inRepl, NONE());
if b then
shared := BackendDAEUtil.setSharedRemovedEqns(shared, BackendEquation.listEquation(eqnslst));
shared.initialEqs := BackendEquation.listEquation(lsteqns);
end if;

// do replacements in systems
Expand All @@ -1096,18 +1094,26 @@ protected function replaceEvaluatedParametersSystemEqns
"author Frenkel TUD
replace the evaluated parameters in the equationsystems"
input BackendDAE.EqSystem isyst;
input BackendVarTransform.VariableReplacements repl;
output BackendDAE.EqSystem osyst;
input BackendVarTransform.VariableReplacements inRepl;
output BackendDAE.EqSystem osyst = isyst;
protected
BackendDAE.EquationArray eqns, eqns1;
list<BackendDAE.Equation> lsteqns;
Boolean b;
algorithm
BackendDAE.EQSYSTEM(orderedEqs=eqns) := isyst;
lsteqns := BackendEquation.equationList(eqns);
(lsteqns, b) := BackendVarTransform.replaceEquations(lsteqns, repl, NONE());
eqns1 := if b then BackendEquation.listEquation(lsteqns) else eqns;
osyst := if b then BackendDAEUtil.clearEqSyst(BackendDAEUtil.setEqSystEqs(isyst, eqns1)) else isyst;
lsteqns := BackendEquation.equationList(osyst.orderedEqs);
(lsteqns, b) := BackendVarTransform.replaceEquations(lsteqns, inRepl, NONE());
if b then
osyst.orderedEqs := BackendEquation.listEquation(lsteqns);
osyst := BackendDAEUtil.clearEqSyst(osyst);
end if;

// do replacements in simple equations
lsteqns := BackendEquation.equationList(osyst.removedEqs);
(lsteqns, b) := BackendVarTransform.replaceEquations(lsteqns, inRepl, NONE());
if b then
osyst.removedEqs := BackendEquation.listEquation(lsteqns);
end if;

end replaceEvaluatedParametersSystemEqns;

annotation(__OpenModelica_Interface="backend");
Expand Down

0 comments on commit 52eb407

Please sign in to comment.