Skip to content

Commit 10c501b

Browse files
committed
Conflicts: SimulationRuntime/cpp/Makefile.omdev.mingw
2 parents e9df6e7 + a481fe6 commit 10c501b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2338
-1020
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*.la
99
*.log
1010
*.stamp
11+
**/*.dylib.dSYM/
1112

1213
# autoconf
1314
autom4te.cache/
@@ -77,6 +78,7 @@ build/
7778
.externalToolBuilders/OpenModelicaBuilder.launch
7879
.externalToolBuilders/OMDev-MINGW-OpenModelicaBuilder.launch
7980
.project
81+
.metadata
8082
revision.h
8183
SimulationRuntime/c/Makefile
8284
SimulationRuntime/c/util/java_interface/Makefile
@@ -89,6 +91,7 @@ SimulationRuntime/cpp/Makefile.env
8991
SimulationRuntime/cpp/Build/
9092
SimulationRuntime/cpp/Debug/
9193
SimulationRuntime/cpp/.cproject
94+
SimulationRuntime/cpp/confdefs.h
9295
SimulationRuntime/ParModelica/Makefile
9396
SimulationRuntime/ParModelica/auto/Makefile
9497
SimulationRuntime/ParModelica/explicit/Makefile

Compiler/BackEnd/BackendDAE.mo

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ public uniontype SubClock
9090
end SUBCLOCK;
9191
end SubClock;
9292

93+
public constant SubClock DEFAULT_SUBCLOCK = SUBCLOCK(MMath.RAT1, MMath.RAT0, NONE());
94+
9395
public
9496
uniontype BaseClockPartitionKind
9597
record UNKNOWN_PARTITION end UNKNOWN_PARTITION;
9698
record CLOCKED_PARTITION
97-
Integer baseClock;
98-
SubClock subClock;
99-
Boolean holdEvents;
99+
Integer subPartIdx;
100100
end CLOCKED_PARTITION;
101101
record CONTINUOUS_TIME_PARTITION end CONTINUOUS_TIME_PARTITION;
102102
record UNSPECIFIED_PARTITION "treated as CONTINUOUS_TIME_PARTITION" end UNSPECIFIED_PARTITION;
@@ -132,9 +132,25 @@ uniontype Shared "Data shared for all equation-systems"
132132
end SHARED;
133133
end Shared;
134134

135+
uniontype BasePartition
136+
record BASE_PARTITION
137+
.DAE.ClockKind clock;
138+
Integer nSubClocks;
139+
end BASE_PARTITION;
140+
end BasePartition;
141+
142+
uniontype SubPartition
143+
record SUB_PARTITION
144+
SubClock clock;
145+
Boolean holdEvents;
146+
list<.DAE.ComponentRef> prevVars;
147+
end SUB_PARTITION;
148+
end SubPartition;
149+
135150
uniontype PartitionsInfo
136151
record PARTITIONS_INFO
137-
array<.DAE.ClockKind> clocks;
152+
array<BasePartition> basePartitions;
153+
array<SubPartition> subPartitions;
138154
end PARTITIONS_INFO;
139155
end PartitionsInfo;
140156

Compiler/BackEnd/BackendDAECreate.mo

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ algorithm
148148
extObjCls,
149149
BackendDAE.SIMULATION(),
150150
symjacs,inExtraInfo,
151-
BackendDAE.PARTITIONS_INFO(BackendDAEUtil.emptyClocks())));
151+
BackendDAEUtil.emptyPartitionsInfo()));
152152
BackendDAEUtil.checkBackendDAEWithErrorMsg(outBackendDAE);
153153
neqStr := intString(BackendDAEUtil.equationSize(eqnarr));
154154
nvarStr := intString(BackendVariable.varsSize(vars_1));
@@ -275,29 +275,20 @@ algorithm
275275
();
276276

277277
// when equations
278-
case DAE.WHEN_EQUATION(condition = e, equations = dae_elts, source = src)
278+
case DAE.WHEN_EQUATION(condition = e, equations = dae_elts)
279279
algorithm
280-
if intGe(Flags.getConfigEnum(Flags.LANGUAGE_STANDARD), 33)
281-
and Types.isClockOrSubTypeClock(Expression.typeof(e)) then
282-
cr := DAE.CREF_IDENT(BackendDAE.WHENCLK_PRREFIX + intString(whenClkCnt), DAE.T_CLOCK_DEFAULT, {});
283-
outVars := BackendDAE.VAR (
284-
varName = cr, varKind = BackendDAE.VARIABLE(),
285-
varDirection = DAE.BIDIR(), varParallelism = DAE.NON_PARALLEL(),
286-
varType = DAE.T_CLOCK_DEFAULT, bindExp = NONE(),
287-
bindValue = NONE(), arryDim = {}, source = DAE.emptyElementSource,
288-
values = NONE(), tearingSelectOption = SOME(BackendDAE.DEFAULT()),
289-
comment = NONE(), connectorType = DAE.NON_CONNECTOR(),
290-
innerOuter = DAE.NOT_INNER_OUTER(), unreplaceable = true ) :: outVars;
291-
outEqns := BackendDAE.EQUATION( exp = DAE.CREF(componentRef = cr, ty = DAE.T_CLOCK_DEFAULT),
292-
scalar = e, source = DAE.emptyElementSource,
293-
attr = BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC ) :: outEqns;
294-
eq_attrs := BackendDAE.EQUATION_ATTRIBUTES(false, BackendDAE.CLOCKED_EQUATION(whenClkCnt), BackendDAE.NO_LOOP());
295-
( outVars, outKnVars, outExVars, eqns, outREqns, outIEqns, outConstraints, outClassAttributes,
280+
if intGe(Flags.getConfigEnum(Flags.LANGUAGE_STANDARD), 33) and Types.isClockOrSubTypeClock(Expression.typeof(e)) then
281+
282+
(outEqns, outVars, eq_attrs) := createWhenClock(whenClkCnt, e, outEqns, outVars);
283+
whenClkCnt := whenClkCnt + 1;
284+
285+
( outVars, outKnVars, outExVars, eqns, reqns, outIEqns, outConstraints, outClassAttributes,
296286
outExtObjClasses, outAliasEqns, outInlineHT ) :=
297-
lower2( dae_elts, inFunctions, outInlineHT, outVars, outKnVars, outExVars, {}, outREqns, outIEqns,
298-
outConstraints, outClassAttributes,outExtObjClasses, outAliasEqns );
287+
lower2( dae_elts, inFunctions, outInlineHT, outVars, outKnVars, outExVars, {}, {}, outIEqns,
288+
outConstraints, outClassAttributes, outExtObjClasses, outAliasEqns );
289+
299290
outEqns := listAppend(List.map1(eqns, BackendEquation.setEquationAttributes, eq_attrs), outEqns);
300-
whenClkCnt := whenClkCnt + 1;
291+
outREqns := listAppend(List.map1(reqns, BackendEquation.setEquationAttributes, eq_attrs), outREqns);
301292
else
302293
(eqns, reqns) := lowerWhenEqn(el, inFunctions, {}, {});
303294
outEqns := listAppend(outEqns, eqns);
@@ -1671,6 +1662,35 @@ algorithm
16711662
end match;
16721663
end generateEquations;
16731664

1665+
protected function createWhenClock
1666+
input Integer whenClkCnt;
1667+
input DAE.Exp e;
1668+
input list<BackendDAE.Equation> inEqs;
1669+
input list<BackendDAE.Var> inVars;
1670+
output list<BackendDAE.Equation> outEqs;
1671+
output list<BackendDAE.Var> outVars;
1672+
output BackendDAE.EquationAttributes outEqAttrs;
1673+
protected
1674+
BackendDAE.EquationAttributes eqAttrs;
1675+
DAE.ComponentRef cr;
1676+
BackendDAE.Equation eq;
1677+
BackendDAE.Var var;
1678+
algorithm
1679+
cr := DAE.CREF_IDENT(BackendDAE.WHENCLK_PRREFIX + intString(whenClkCnt), DAE.T_CLOCK_DEFAULT, {});
1680+
outVars := BackendDAE.VAR (
1681+
varName = cr, varKind = BackendDAE.VARIABLE(),
1682+
varDirection = DAE.BIDIR(), varParallelism = DAE.NON_PARALLEL(),
1683+
varType = DAE.T_CLOCK_DEFAULT, bindExp = NONE(),
1684+
bindValue = NONE(), arryDim = {}, source = DAE.emptyElementSource,
1685+
values = NONE(), tearingSelectOption = SOME(BackendDAE.DEFAULT()),
1686+
comment = NONE(), connectorType = DAE.NON_CONNECTOR(),
1687+
innerOuter = DAE.NOT_INNER_OUTER(), unreplaceable = true ) :: inVars;
1688+
outEqs := BackendDAE.EQUATION( exp = DAE.CREF(componentRef = cr, ty = DAE.T_CLOCK_DEFAULT),
1689+
scalar = e, source = DAE.emptyElementSource,
1690+
attr = BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC ) :: inEqs;
1691+
outEqAttrs := BackendDAE.EQUATION_ATTRIBUTES(false, BackendDAE.CLOCKED_EQUATION(whenClkCnt), BackendDAE.NO_LOOP());
1692+
end createWhenClock;
1693+
16741694

16751695
protected function lowerWhenEqn
16761696
"This function lowers a when eqn."

Compiler/BackEnd/BackendDAEOptimize.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1639,7 +1639,7 @@ algorithm
16391639
b = i > 1;
16401640
// bcall2(b,BackendDump.dumpBackendDAE,BackendDAE.DAE({syst},shared), "partitionIndependentBlocksHelper");
16411641
// printPartition(b,ixs);
1642-
systs = if b then SynchronousFeatures.partitionIndependentBlocksSplitBlocks(i, syst, ixs, rixs, mT, throwNoError) else {syst};
1642+
systs = if b then SynchronousFeatures.partitionIndependentBlocksSplitBlocks(i, syst, ixs, rixs, mT, rmT, throwNoError) else {syst};
16431643
// print("Number of partitioned systems: " + intString(listLength(systs)) + "\n");
16441644
// List.map1_0(systs, BackendDump.dumpEqSystem, "System");
16451645
then (systs,shared);

Compiler/BackEnd/BackendDAEUtil.mo

Lines changed: 124 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ protected import BackendDAEOptimize;
6060
protected import BackendDAETransform;
6161
protected import BackendDump;
6262
protected import BackendEquation;
63+
protected import BackendDAEEXT;
6364
protected import BackendInline;
6465
protected import BackendVariable;
6566
protected import BackendVarTransform;
@@ -100,6 +101,7 @@ protected import RemoveSimpleEquations;
100101
protected import ResolveLoops;
101102
protected import SCode;
102103
protected import SimCodeFunctionUtil;
104+
protected import Sorting;
103105
protected import StateMachineFeatures;
104106
protected import SymbolicJacobian;
105107
protected import SynchronousFeatures;
@@ -2115,6 +2117,27 @@ algorithm
21152117
end try;
21162118
end incidenceMatrix;
21172119

2120+
public function incidenceMatrixMasked
2121+
input BackendDAE.EqSystem inEqSystem;
2122+
input BackendDAE.IndexType inIndexType;
2123+
input array<Boolean> inMask;
2124+
input Option<DAE.FunctionTree> functionTree;
2125+
output BackendDAE.IncidenceMatrix outIncidenceMatrix;
2126+
output BackendDAE.IncidenceMatrixT outIncidenceMatrixT;
2127+
protected
2128+
BackendDAE.Variables vars;
2129+
BackendDAE.EquationArray eqns;
2130+
algorithm
2131+
try
2132+
BackendDAE.EQSYSTEM(orderedVars = vars, orderedEqs = eqns) := inEqSystem;
2133+
(outIncidenceMatrix, outIncidenceMatrixT) :=
2134+
incidenceMatrixDispatchMasked(vars, eqns, inIndexType, inMask, functionTree);
2135+
else
2136+
Error.addMessage(Error.INTERNAL_ERROR, {"BackendDAEUtil.incidenceMatrix failed."});
2137+
fail();
2138+
end try;
2139+
end incidenceMatrixMasked;
2140+
21182141
public function incidenceMatrixScalar
21192142
"author: PA, adrpo
21202143
Calculates the incidence matrix, i.e. which variables are present in each equation.
@@ -2187,6 +2210,37 @@ algorithm
21872210
end for;
21882211
end incidenceMatrixDispatch;
21892212

2213+
public function incidenceMatrixDispatchMasked
2214+
input BackendDAE.Variables inVars;
2215+
input BackendDAE.EquationArray inEqns;
2216+
input BackendDAE.IndexType inIndexType;
2217+
input array<Boolean> inMask;
2218+
input Option<DAE.FunctionTree> functionTree = NONE();
2219+
output BackendDAE.IncidenceMatrix outIncidenceArray;
2220+
output BackendDAE.IncidenceMatrixT outIncidenceArrayT;
2221+
protected
2222+
Integer num_eqs, num_vars;
2223+
BackendDAE.Equation eq;
2224+
list<Integer> row;
2225+
algorithm
2226+
num_eqs := equationArraySize(inEqns);
2227+
num_vars := BackendVariable.varsSize(inVars);
2228+
outIncidenceArray := arrayCreate(num_eqs, {});
2229+
outIncidenceArrayT := arrayCreate(num_vars, {});
2230+
2231+
for idx in 1:num_eqs loop
2232+
if inMask[idx] then
2233+
// Get the equation.
2234+
eq := BackendEquation.equationNth1(inEqns, idx);
2235+
// Compute the row.
2236+
row := incidenceRow(eq, inVars, inIndexType, functionTree, {});
2237+
// Put it in the arrays.
2238+
arrayUpdate(outIncidenceArray, idx, row);
2239+
outIncidenceArrayT := fillincidenceMatrixT(row, {idx}, outIncidenceArrayT);
2240+
end if;
2241+
end for;
2242+
end incidenceMatrixDispatchMasked;
2243+
21902244
protected function incidenceMatrixDispatchScalar
21912245
"@author: adrpo
21922246
Calculates the incidence matrix as an array of list of integers"
@@ -2281,6 +2335,13 @@ algorithm
22812335
cr = DAE.CREF_IDENT(BackendDAE.WHENCLK_PRREFIX + intString(i), DAE.T_CLOCK_DEFAULT, {});
22822336
(_, varIxs) = BackendVariable.getVar(cr, vars);
22832337
then varIxs;
2338+
case BackendDAE.SUBCLOCK_IDX()
2339+
equation
2340+
BackendDAE.EQUATION_ATTRIBUTES(kind = kind) = BackendEquation.getEquationAttributes(inEquation);
2341+
BackendDAE.CLOCKED_EQUATION(i) = kind;
2342+
cr = DAE.CREF_IDENT(BackendDAE.WHENCLK_PRREFIX + intString(i), DAE.T_CLOCK_DEFAULT, {});
2343+
(_, varIxs) = BackendVariable.getVar(cr, vars);
2344+
then varIxs;
22842345
else {};
22852346
end matchcontinue;
22862347
(outIntegerLst,rowSize) := matchcontinue (inEquation)
@@ -3516,6 +3577,17 @@ algorithm
35163577
(outM, outMT) := incidenceMatrixDispatch(inSyst.orderedVars, inSyst.removedEqs, inIndxType, inFunctionTree);
35173578
end removedIncidenceMatrix;
35183579

3580+
public function removedIncidenceMatrixMasked
3581+
input BackendDAE.EqSystem inSyst;
3582+
input BackendDAE.IndexType inIndxType;
3583+
input array<Boolean> inMask;
3584+
input Option<DAE.FunctionTree> inFunctionTree;
3585+
output BackendDAE.IncidenceMatrix outM;
3586+
output BackendDAE.IncidenceMatrix outMT;
3587+
algorithm
3588+
(outM, outMT) := incidenceMatrixDispatchMasked(inSyst.orderedVars, inSyst.removedEqs, inIndxType, inMask, inFunctionTree);
3589+
end removedIncidenceMatrixMasked;
3590+
35193591
protected function traverseStmts "Author: Frenkel TUD 2012-06
35203592
traverese DAE.Statement without change possibility."
35213593
input list<DAE.Statement> inStmts;
@@ -7097,6 +7169,7 @@ algorithm
70977169
(EvaluateParameter.evaluateReplaceEvaluateParameters, "evaluateReplaceEvaluateParameters", false),
70987170
(EvaluateParameter.evaluateReplaceFinalEvaluateParameters, "evaluateReplaceFinalEvaluateParameters", false),
70997171
(EvaluateParameter.evaluateReplaceProtectedFinalEvaluateParameters, "evaluateReplaceProtectedFinalEvaluateParameters", false),
7172+
(EvaluateParameter.evaluateAllParameters, "evaluateAllParameters", false),
71007173
(BackendDAEOptimize.removeEqualFunctionCalls, "removeEqualFunctionCalls", false),
71017174
(BackendDAEOptimize.removeProtectedParameters, "removeProtectedParameters", false),
71027175
(BackendDAEOptimize.removeUnusedParameter, "removeUnusedParameter", false),
@@ -7787,9 +7860,20 @@ protected
77877860
algorithm
77887861
shared := BackendDAE.SHARED( emptyVars, emptyVars, emptyVars, emptyEqs, emptyEqs, {}, {}, cache, graph,
77897862
DAEUtil.avlTreeNew(), emptyEventInfo(), {}, backendDAEType, {}, ei,
7790-
BackendDAE.PARTITIONS_INFO(emptyClocks()) );
7863+
emptyPartitionsInfo() );
77917864
end createEmptyShared;
77927865

7866+
public function emptyPartitionsInfo
7867+
output BackendDAE.PartitionsInfo partitionsInfo;
7868+
protected
7869+
array<BackendDAE.BasePartition> basePartitions;
7870+
array<BackendDAE.SubPartition> subPartitions;
7871+
algorithm
7872+
basePartitions := arrayCreate(0, BackendDAE.BASE_PARTITION(DAE.INFERRED_CLOCK(), 0));
7873+
subPartitions := arrayCreate(0, BackendDAE.SUB_PARTITION(BackendDAE.DEFAULT_SUBCLOCK, false, {}));
7874+
partitionsInfo := BackendDAE.PARTITIONS_INFO(basePartitions, subPartitions);
7875+
end emptyPartitionsInfo;
7876+
77937877
public function makeSingleEquationComp
77947878
input Integer eqIdx;
77957879
input Integer varIdx;
@@ -8074,11 +8158,19 @@ algorithm
80748158
info := BackendDAE.EVENT_INFO({}, {}, {}, {}, 0);
80758159
end emptyEventInfo;
80768160

8077-
public function emptyClocks
8078-
output array<DAE.ClockKind> clocks;
8161+
public function getSubClock
8162+
input BackendDAE.EqSystem inSyst;
8163+
input BackendDAE.Shared inShared;
8164+
output Option<BackendDAE.SubClock> outSubClock;
80798165
algorithm
8080-
clocks := arrayCreate(0, DAE.INFERRED_CLOCK());
8081-
end emptyClocks;
8166+
outSubClock := match inSyst.partitionKind
8167+
local
8168+
Integer idx;
8169+
case BackendDAE.CLOCKED_PARTITION(idx)
8170+
then SOME(inShared.partitionsInfo.subPartitions[idx].clock);
8171+
else NONE();
8172+
end match;
8173+
end getSubClock;
80828174

80838175
public function componentsEqual"outputs true if 1 strongly connected components are equal"
80848176
input BackendDAE.StrongComponent comp1;
@@ -8144,5 +8236,32 @@ algorithm
81448236
end matchcontinue;
81458237
end otherEqnVarTplEqual;
81468238

8239+
8240+
public function causalizeVarBindSystem"causalizes a system of variables and their binding-equations.
8241+
author: waurich TUD 08.2015"
8242+
input list<BackendDAE.Var> varLstIn;
8243+
output list<list<Integer>> comps;
8244+
output array<Integer> ass1;
8245+
output array<Integer> ass2;
8246+
protected
8247+
Integer nVars,nEqs;
8248+
list<Integer> order;
8249+
BackendDAE.IncidenceMatrix m, mT;
8250+
list<DAE.Exp> bindExps;
8251+
list<BackendDAE.Equation> eqs;
8252+
algorithm
8253+
bindExps := List.map(varLstIn,BackendVariable.varBindExp);
8254+
eqs := List.threadMap2(List.map(varLstIn,BackendVariable.varExp), bindExps, BackendEquation.generateEquation, DAE.emptyElementSource, BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC);
8255+
(m, mT) := BackendDAEUtil.incidenceMatrixDispatch(BackendVariable.listVar1(varLstIn), BackendEquation.listEquation(eqs), BackendDAE.ABSOLUTE(), NONE());
8256+
nVars := listLength(varLstIn);
8257+
nEqs := listLength(eqs);
8258+
ass1 := arrayCreate(nVars, -1);
8259+
ass2 := arrayCreate(nEqs, -1);
8260+
Matching.matchingExternalsetIncidenceMatrix(nVars, nEqs, m);
8261+
BackendDAEEXT.matching(nVars, nEqs, 5, -1, 0.0, 1);
8262+
BackendDAEEXT.getAssignment(ass2, ass1);
8263+
comps := Sorting.TarjanTransposed(mT, ass2);
8264+
end causalizeVarBindSystem;
8265+
81478266
annotation(__OpenModelica_Interface="backend");
81488267
end BackendDAEUtil;

0 commit comments

Comments
 (0)