Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Conflicts:
	SimulationRuntime/cpp/Makefile.omdev.mingw
  • Loading branch information
niklwors committed Aug 31, 2015
2 parents e9df6e7 + a481fe6 commit 10c501b
Show file tree
Hide file tree
Showing 53 changed files with 2,338 additions and 1,020 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -8,6 +8,7 @@
*.la
*.log
*.stamp
**/*.dylib.dSYM/

# autoconf
autom4te.cache/
Expand Down Expand Up @@ -77,6 +78,7 @@ build/
.externalToolBuilders/OpenModelicaBuilder.launch
.externalToolBuilders/OMDev-MINGW-OpenModelicaBuilder.launch
.project
.metadata
revision.h
SimulationRuntime/c/Makefile
SimulationRuntime/c/util/java_interface/Makefile
Expand All @@ -89,6 +91,7 @@ SimulationRuntime/cpp/Makefile.env
SimulationRuntime/cpp/Build/
SimulationRuntime/cpp/Debug/
SimulationRuntime/cpp/.cproject
SimulationRuntime/cpp/confdefs.h
SimulationRuntime/ParModelica/Makefile
SimulationRuntime/ParModelica/auto/Makefile
SimulationRuntime/ParModelica/explicit/Makefile
Expand Down
24 changes: 20 additions & 4 deletions Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -90,13 +90,13 @@ public uniontype SubClock
end SUBCLOCK;
end SubClock;

public constant SubClock DEFAULT_SUBCLOCK = SUBCLOCK(MMath.RAT1, MMath.RAT0, NONE());

public
uniontype BaseClockPartitionKind
record UNKNOWN_PARTITION end UNKNOWN_PARTITION;
record CLOCKED_PARTITION
Integer baseClock;
SubClock subClock;
Boolean holdEvents;
Integer subPartIdx;
end CLOCKED_PARTITION;
record CONTINUOUS_TIME_PARTITION end CONTINUOUS_TIME_PARTITION;
record UNSPECIFIED_PARTITION "treated as CONTINUOUS_TIME_PARTITION" end UNSPECIFIED_PARTITION;
Expand Down Expand Up @@ -132,9 +132,25 @@ uniontype Shared "Data shared for all equation-systems"
end SHARED;
end Shared;

uniontype BasePartition
record BASE_PARTITION
.DAE.ClockKind clock;
Integer nSubClocks;
end BASE_PARTITION;
end BasePartition;

uniontype SubPartition
record SUB_PARTITION
SubClock clock;
Boolean holdEvents;
list<.DAE.ComponentRef> prevVars;
end SUB_PARTITION;
end SubPartition;

uniontype PartitionsInfo
record PARTITIONS_INFO
array<.DAE.ClockKind> clocks;
array<BasePartition> basePartitions;
array<SubPartition> subPartitions;
end PARTITIONS_INFO;
end PartitionsInfo;

Expand Down
62 changes: 41 additions & 21 deletions Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -148,7 +148,7 @@ algorithm
extObjCls,
BackendDAE.SIMULATION(),
symjacs,inExtraInfo,
BackendDAE.PARTITIONS_INFO(BackendDAEUtil.emptyClocks())));
BackendDAEUtil.emptyPartitionsInfo()));
BackendDAEUtil.checkBackendDAEWithErrorMsg(outBackendDAE);
neqStr := intString(BackendDAEUtil.equationSize(eqnarr));
nvarStr := intString(BackendVariable.varsSize(vars_1));
Expand Down Expand Up @@ -275,29 +275,20 @@ algorithm
();

// when equations
case DAE.WHEN_EQUATION(condition = e, equations = dae_elts, source = src)
case DAE.WHEN_EQUATION(condition = e, equations = dae_elts)
algorithm
if intGe(Flags.getConfigEnum(Flags.LANGUAGE_STANDARD), 33)
and Types.isClockOrSubTypeClock(Expression.typeof(e)) then
cr := DAE.CREF_IDENT(BackendDAE.WHENCLK_PRREFIX + intString(whenClkCnt), DAE.T_CLOCK_DEFAULT, {});
outVars := BackendDAE.VAR (
varName = cr, varKind = BackendDAE.VARIABLE(),
varDirection = DAE.BIDIR(), varParallelism = DAE.NON_PARALLEL(),
varType = DAE.T_CLOCK_DEFAULT, bindExp = NONE(),
bindValue = NONE(), arryDim = {}, source = DAE.emptyElementSource,
values = NONE(), tearingSelectOption = SOME(BackendDAE.DEFAULT()),
comment = NONE(), connectorType = DAE.NON_CONNECTOR(),
innerOuter = DAE.NOT_INNER_OUTER(), unreplaceable = true ) :: outVars;
outEqns := BackendDAE.EQUATION( exp = DAE.CREF(componentRef = cr, ty = DAE.T_CLOCK_DEFAULT),
scalar = e, source = DAE.emptyElementSource,
attr = BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC ) :: outEqns;
eq_attrs := BackendDAE.EQUATION_ATTRIBUTES(false, BackendDAE.CLOCKED_EQUATION(whenClkCnt), BackendDAE.NO_LOOP());
( outVars, outKnVars, outExVars, eqns, outREqns, outIEqns, outConstraints, outClassAttributes,
if intGe(Flags.getConfigEnum(Flags.LANGUAGE_STANDARD), 33) and Types.isClockOrSubTypeClock(Expression.typeof(e)) then

(outEqns, outVars, eq_attrs) := createWhenClock(whenClkCnt, e, outEqns, outVars);
whenClkCnt := whenClkCnt + 1;

( outVars, outKnVars, outExVars, eqns, reqns, outIEqns, outConstraints, outClassAttributes,
outExtObjClasses, outAliasEqns, outInlineHT ) :=
lower2( dae_elts, inFunctions, outInlineHT, outVars, outKnVars, outExVars, {}, outREqns, outIEqns,
outConstraints, outClassAttributes,outExtObjClasses, outAliasEqns );
lower2( dae_elts, inFunctions, outInlineHT, outVars, outKnVars, outExVars, {}, {}, outIEqns,
outConstraints, outClassAttributes, outExtObjClasses, outAliasEqns );

outEqns := listAppend(List.map1(eqns, BackendEquation.setEquationAttributes, eq_attrs), outEqns);
whenClkCnt := whenClkCnt + 1;
outREqns := listAppend(List.map1(reqns, BackendEquation.setEquationAttributes, eq_attrs), outREqns);
else
(eqns, reqns) := lowerWhenEqn(el, inFunctions, {}, {});
outEqns := listAppend(outEqns, eqns);
Expand Down Expand Up @@ -1671,6 +1662,35 @@ algorithm
end match;
end generateEquations;

protected function createWhenClock
input Integer whenClkCnt;
input DAE.Exp e;
input list<BackendDAE.Equation> inEqs;
input list<BackendDAE.Var> inVars;
output list<BackendDAE.Equation> outEqs;
output list<BackendDAE.Var> outVars;
output BackendDAE.EquationAttributes outEqAttrs;
protected
BackendDAE.EquationAttributes eqAttrs;
DAE.ComponentRef cr;
BackendDAE.Equation eq;
BackendDAE.Var var;
algorithm
cr := DAE.CREF_IDENT(BackendDAE.WHENCLK_PRREFIX + intString(whenClkCnt), DAE.T_CLOCK_DEFAULT, {});
outVars := BackendDAE.VAR (
varName = cr, varKind = BackendDAE.VARIABLE(),
varDirection = DAE.BIDIR(), varParallelism = DAE.NON_PARALLEL(),
varType = DAE.T_CLOCK_DEFAULT, bindExp = NONE(),
bindValue = NONE(), arryDim = {}, source = DAE.emptyElementSource,
values = NONE(), tearingSelectOption = SOME(BackendDAE.DEFAULT()),
comment = NONE(), connectorType = DAE.NON_CONNECTOR(),
innerOuter = DAE.NOT_INNER_OUTER(), unreplaceable = true ) :: inVars;
outEqs := BackendDAE.EQUATION( exp = DAE.CREF(componentRef = cr, ty = DAE.T_CLOCK_DEFAULT),
scalar = e, source = DAE.emptyElementSource,
attr = BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC ) :: inEqs;
outEqAttrs := BackendDAE.EQUATION_ATTRIBUTES(false, BackendDAE.CLOCKED_EQUATION(whenClkCnt), BackendDAE.NO_LOOP());
end createWhenClock;


protected function lowerWhenEqn
"This function lowers a when eqn."
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -1639,7 +1639,7 @@ algorithm
b = i > 1;
// bcall2(b,BackendDump.dumpBackendDAE,BackendDAE.DAE({syst},shared), "partitionIndependentBlocksHelper");
// printPartition(b,ixs);
systs = if b then SynchronousFeatures.partitionIndependentBlocksSplitBlocks(i, syst, ixs, rixs, mT, throwNoError) else {syst};
systs = if b then SynchronousFeatures.partitionIndependentBlocksSplitBlocks(i, syst, ixs, rixs, mT, rmT, throwNoError) else {syst};
// print("Number of partitioned systems: " + intString(listLength(systs)) + "\n");
// List.map1_0(systs, BackendDump.dumpEqSystem, "System");
then (systs,shared);
Expand Down
129 changes: 124 additions & 5 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -60,6 +60,7 @@ protected import BackendDAEOptimize;
protected import BackendDAETransform;
protected import BackendDump;
protected import BackendEquation;
protected import BackendDAEEXT;
protected import BackendInline;
protected import BackendVariable;
protected import BackendVarTransform;
Expand Down Expand Up @@ -100,6 +101,7 @@ protected import RemoveSimpleEquations;
protected import ResolveLoops;
protected import SCode;
protected import SimCodeFunctionUtil;
protected import Sorting;
protected import StateMachineFeatures;
protected import SymbolicJacobian;
protected import SynchronousFeatures;
Expand Down Expand Up @@ -2115,6 +2117,27 @@ algorithm
end try;
end incidenceMatrix;

public function incidenceMatrixMasked
input BackendDAE.EqSystem inEqSystem;
input BackendDAE.IndexType inIndexType;
input array<Boolean> inMask;
input Option<DAE.FunctionTree> functionTree;
output BackendDAE.IncidenceMatrix outIncidenceMatrix;
output BackendDAE.IncidenceMatrixT outIncidenceMatrixT;
protected
BackendDAE.Variables vars;
BackendDAE.EquationArray eqns;
algorithm
try
BackendDAE.EQSYSTEM(orderedVars = vars, orderedEqs = eqns) := inEqSystem;
(outIncidenceMatrix, outIncidenceMatrixT) :=
incidenceMatrixDispatchMasked(vars, eqns, inIndexType, inMask, functionTree);
else
Error.addMessage(Error.INTERNAL_ERROR, {"BackendDAEUtil.incidenceMatrix failed."});
fail();
end try;
end incidenceMatrixMasked;

public function incidenceMatrixScalar
"author: PA, adrpo
Calculates the incidence matrix, i.e. which variables are present in each equation.
Expand Down Expand Up @@ -2187,6 +2210,37 @@ algorithm
end for;
end incidenceMatrixDispatch;

public function incidenceMatrixDispatchMasked
input BackendDAE.Variables inVars;
input BackendDAE.EquationArray inEqns;
input BackendDAE.IndexType inIndexType;
input array<Boolean> inMask;
input Option<DAE.FunctionTree> functionTree = NONE();
output BackendDAE.IncidenceMatrix outIncidenceArray;
output BackendDAE.IncidenceMatrixT outIncidenceArrayT;
protected
Integer num_eqs, num_vars;
BackendDAE.Equation eq;
list<Integer> row;
algorithm
num_eqs := equationArraySize(inEqns);
num_vars := BackendVariable.varsSize(inVars);
outIncidenceArray := arrayCreate(num_eqs, {});
outIncidenceArrayT := arrayCreate(num_vars, {});

for idx in 1:num_eqs loop
if inMask[idx] then
// Get the equation.
eq := BackendEquation.equationNth1(inEqns, idx);
// Compute the row.
row := incidenceRow(eq, inVars, inIndexType, functionTree, {});
// Put it in the arrays.
arrayUpdate(outIncidenceArray, idx, row);
outIncidenceArrayT := fillincidenceMatrixT(row, {idx}, outIncidenceArrayT);
end if;
end for;
end incidenceMatrixDispatchMasked;

protected function incidenceMatrixDispatchScalar
"@author: adrpo
Calculates the incidence matrix as an array of list of integers"
Expand Down Expand Up @@ -2281,6 +2335,13 @@ algorithm
cr = DAE.CREF_IDENT(BackendDAE.WHENCLK_PRREFIX + intString(i), DAE.T_CLOCK_DEFAULT, {});
(_, varIxs) = BackendVariable.getVar(cr, vars);
then varIxs;
case BackendDAE.SUBCLOCK_IDX()
equation
BackendDAE.EQUATION_ATTRIBUTES(kind = kind) = BackendEquation.getEquationAttributes(inEquation);
BackendDAE.CLOCKED_EQUATION(i) = kind;
cr = DAE.CREF_IDENT(BackendDAE.WHENCLK_PRREFIX + intString(i), DAE.T_CLOCK_DEFAULT, {});
(_, varIxs) = BackendVariable.getVar(cr, vars);
then varIxs;
else {};
end matchcontinue;
(outIntegerLst,rowSize) := matchcontinue (inEquation)
Expand Down Expand Up @@ -3516,6 +3577,17 @@ algorithm
(outM, outMT) := incidenceMatrixDispatch(inSyst.orderedVars, inSyst.removedEqs, inIndxType, inFunctionTree);
end removedIncidenceMatrix;

public function removedIncidenceMatrixMasked
input BackendDAE.EqSystem inSyst;
input BackendDAE.IndexType inIndxType;
input array<Boolean> inMask;
input Option<DAE.FunctionTree> inFunctionTree;
output BackendDAE.IncidenceMatrix outM;
output BackendDAE.IncidenceMatrix outMT;
algorithm
(outM, outMT) := incidenceMatrixDispatchMasked(inSyst.orderedVars, inSyst.removedEqs, inIndxType, inMask, inFunctionTree);
end removedIncidenceMatrixMasked;

protected function traverseStmts "Author: Frenkel TUD 2012-06
traverese DAE.Statement without change possibility."
input list<DAE.Statement> inStmts;
Expand Down Expand Up @@ -7097,6 +7169,7 @@ algorithm
(EvaluateParameter.evaluateReplaceEvaluateParameters, "evaluateReplaceEvaluateParameters", false),
(EvaluateParameter.evaluateReplaceFinalEvaluateParameters, "evaluateReplaceFinalEvaluateParameters", false),
(EvaluateParameter.evaluateReplaceProtectedFinalEvaluateParameters, "evaluateReplaceProtectedFinalEvaluateParameters", false),
(EvaluateParameter.evaluateAllParameters, "evaluateAllParameters", false),
(BackendDAEOptimize.removeEqualFunctionCalls, "removeEqualFunctionCalls", false),
(BackendDAEOptimize.removeProtectedParameters, "removeProtectedParameters", false),
(BackendDAEOptimize.removeUnusedParameter, "removeUnusedParameter", false),
Expand Down Expand Up @@ -7787,9 +7860,20 @@ protected
algorithm
shared := BackendDAE.SHARED( emptyVars, emptyVars, emptyVars, emptyEqs, emptyEqs, {}, {}, cache, graph,
DAEUtil.avlTreeNew(), emptyEventInfo(), {}, backendDAEType, {}, ei,
BackendDAE.PARTITIONS_INFO(emptyClocks()) );
emptyPartitionsInfo() );
end createEmptyShared;

public function emptyPartitionsInfo
output BackendDAE.PartitionsInfo partitionsInfo;
protected
array<BackendDAE.BasePartition> basePartitions;
array<BackendDAE.SubPartition> subPartitions;
algorithm
basePartitions := arrayCreate(0, BackendDAE.BASE_PARTITION(DAE.INFERRED_CLOCK(), 0));
subPartitions := arrayCreate(0, BackendDAE.SUB_PARTITION(BackendDAE.DEFAULT_SUBCLOCK, false, {}));
partitionsInfo := BackendDAE.PARTITIONS_INFO(basePartitions, subPartitions);
end emptyPartitionsInfo;

public function makeSingleEquationComp
input Integer eqIdx;
input Integer varIdx;
Expand Down Expand Up @@ -8074,11 +8158,19 @@ algorithm
info := BackendDAE.EVENT_INFO({}, {}, {}, {}, 0);
end emptyEventInfo;

public function emptyClocks
output array<DAE.ClockKind> clocks;
public function getSubClock
input BackendDAE.EqSystem inSyst;
input BackendDAE.Shared inShared;
output Option<BackendDAE.SubClock> outSubClock;
algorithm
clocks := arrayCreate(0, DAE.INFERRED_CLOCK());
end emptyClocks;
outSubClock := match inSyst.partitionKind
local
Integer idx;
case BackendDAE.CLOCKED_PARTITION(idx)
then SOME(inShared.partitionsInfo.subPartitions[idx].clock);
else NONE();
end match;
end getSubClock;

public function componentsEqual"outputs true if 1 strongly connected components are equal"
input BackendDAE.StrongComponent comp1;
Expand Down Expand Up @@ -8144,5 +8236,32 @@ algorithm
end matchcontinue;
end otherEqnVarTplEqual;


public function causalizeVarBindSystem"causalizes a system of variables and their binding-equations.
author: waurich TUD 08.2015"
input list<BackendDAE.Var> varLstIn;
output list<list<Integer>> comps;
output array<Integer> ass1;
output array<Integer> ass2;
protected
Integer nVars,nEqs;
list<Integer> order;
BackendDAE.IncidenceMatrix m, mT;
list<DAE.Exp> bindExps;
list<BackendDAE.Equation> eqs;
algorithm
bindExps := List.map(varLstIn,BackendVariable.varBindExp);
eqs := List.threadMap2(List.map(varLstIn,BackendVariable.varExp), bindExps, BackendEquation.generateEquation, DAE.emptyElementSource, BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC);
(m, mT) := BackendDAEUtil.incidenceMatrixDispatch(BackendVariable.listVar1(varLstIn), BackendEquation.listEquation(eqs), BackendDAE.ABSOLUTE(), NONE());
nVars := listLength(varLstIn);
nEqs := listLength(eqs);
ass1 := arrayCreate(nVars, -1);
ass2 := arrayCreate(nEqs, -1);
Matching.matchingExternalsetIncidenceMatrix(nVars, nEqs, m);
BackendDAEEXT.matching(nVars, nEqs, 5, -1, 0.0, 1);
BackendDAEEXT.getAssignment(ass2, ass1);
comps := Sorting.TarjanTransposed(mT, ass2);
end causalizeVarBindSystem;

annotation(__OpenModelica_Interface="backend");
end BackendDAEUtil;

0 comments on commit 10c501b

Please sign in to comment.