Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RuedKamp committed Jul 13, 2015
2 parents 98141da + b25d1f3 commit 403163e
Show file tree
Hide file tree
Showing 66 changed files with 1,538 additions and 1,835 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.

326 changes: 168 additions & 158 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
58 changes: 5 additions & 53 deletions Compiler/BackEnd/BackendQSS.mo
Expand Up @@ -988,60 +988,12 @@ end getEquations;
function replaceDiscontsInOde
input SimCode.SimCode sin;
input list<DAE.Exp> zc_exps;
output SimCode.SimCode sout;
output SimCode.SimCode sout = sin;
protected
list<SimCode.SimEqSystem> eqs;
algorithm
sout:=match (sin,zc_exps)
local
SimCode.ModelInfo modelInfo;
list<DAE.Exp> literals "shared literals";
list<SimCode.RecordDeclaration> recordDecls;
list<String> externalFunctionIncludes;
list<list<SimCode.SimEqSystem>> algebraicEquations,odeEquations;
list<SimCode.SimEqSystem> allEquations,startValueEquations,nominalValueEquations,minValueEquations,maxValueEquations,parameterEquations,removedEquations,algorithmAndEquationAsserts,jacobianEquations;
list<SimCode.SimEqSystem> equationsForZeroCrossings;
list<SimCode.StateSet> stateSets;
Boolean useHomotopy;
list<SimCode.SimEqSystem> initialEquations, removedInitialEquations;
list<DAE.Constraint> constraints;
list<DAE.ClassAttributes> classAttributes;
list<BackendDAE.ZeroCrossing> zeroCrossings,relations;
list<SimCode.SimWhenClause> whenClauses;
list<DAE.ComponentRef> discreteModelVars;
SimCode.ExtObjInfo extObjInfo;
SimCode.MakefileParams makefileParams;
SimCode.DelayedExpression delayedExps;
Option<SimCode.SimulationSettings> simulationSettingsOpt;
String fileNamePrefix;
SimCode.HashTableCrefToSimVar crefToSimVarHT;
list<SimCode.JacobianMatrix> jacobianMatrixes;
list<SimCode.SimEqSystem> eqs;
list<BackendDAE.TimeEvent> timeEvents;
HpcOmSimCode.HpcOmData hpcomData;
HashTableCrIListArray.HashTable varToArrayIndexMapping;
HashTableCrILst.HashTable varToIndexMapping;
Option<SimCode.FmiModelStructure> modelStruct;
list<SimCodeVar.SimVar> mixedArrayVars;
Option<SimCode.BackendMapping> backendMapping;
list<BackendDAE.BaseClockPartitionKind> partitionsKind;
list<DAE.ClockKind> baseClocks;

case (SimCode.SIMCODE( modelInfo, literals, recordDecls, externalFunctionIncludes, allEquations, odeEquations, algebraicEquations, partitionsKind, baseClocks,
useHomotopy, initialEquations, removedInitialEquations, startValueEquations, nominalValueEquations,
minValueEquations, maxValueEquations, parameterEquations, removedEquations, algorithmAndEquationAsserts, equationsForZeroCrossings,
jacobianEquations, stateSets, constraints, classAttributes, zeroCrossings, relations, timeEvents, whenClauses, discreteModelVars,
extObjInfo, makefileParams, delayedExps, jacobianMatrixes, simulationSettingsOpt, fileNamePrefix, hpcomData, varToArrayIndexMapping,
varToIndexMapping, crefToSimVarHT, backendMapping, modelStruct ),_)
equation
{eqs} = odeEquations;
eqs = List.map1(eqs,replaceZC,zc_exps);
then SimCode.SIMCODE( modelInfo, literals, recordDecls, externalFunctionIncludes, allEquations, {eqs}, algebraicEquations, partitionsKind, baseClocks,
useHomotopy, initialEquations, removedInitialEquations, startValueEquations, nominalValueEquations,
minValueEquations, maxValueEquations, parameterEquations, removedEquations, algorithmAndEquationAsserts, equationsForZeroCrossings,
jacobianEquations, stateSets, constraints, classAttributes, zeroCrossings, relations, timeEvents, whenClauses, discreteModelVars,
extObjInfo, makefileParams, delayedExps, jacobianMatrixes, simulationSettingsOpt, fileNamePrefix, hpcomData, varToArrayIndexMapping,
varToIndexMapping, crefToSimVarHT, backendMapping, modelStruct);

end match;
{eqs} := sout.odeEquations;
sout.odeEquations := {List.map1(eqs, replaceZC, zc_exps)};
end replaceDiscontsInOde;


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

0 comments on commit 403163e

Please sign in to comment.