Skip to content

Commit cb8e341

Browse files
committed
2 parents 2a6e756 + db371fa commit cb8e341

File tree

7 files changed

+103
-104
lines changed

7 files changed

+103
-104
lines changed

Compiler/BackEnd/BackendDAEUtil.mo

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6536,7 +6536,10 @@ algorithm
65366536
// generate system for initialization
65376537
(outInitDAE, outUseHomotopy, outRemovedInitialEquationLst, outPrimaryParameters, outAllPrimaryParameters) := Initialization.solveInitialSystem(dae);
65386538

6539-
simDAE := BackendDAEOptimize.addInitialStmtsToAlgorithms(dae);
6539+
// use function tree from initDAE further for simDAE
6540+
simDAE := BackendDAEUtil.setFunctionTree(dae, BackendDAEUtil.getFunctions(outInitDAE.shared));
6541+
6542+
simDAE := BackendDAEOptimize.addInitialStmtsToAlgorithms(simDAE);
65406543
simDAE := Initialization.removeInitializationStuff(simDAE);
65416544

65426545
// post-optimization phase

Compiler/BackEnd/SynchronousFeatures.mo

Lines changed: 50 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ algorithm
233233
(outExp, outPrevVars) := Expression.traverseExpBottomUp(inExp, collectPrevVars1, inPrevVars);
234234
end collectPrevVars;
235235

236-
public function collectPrevVars1
236+
protected function collectPrevVars1
237237
input DAE.Exp inExp;
238238
input list<DAE.ComponentRef> inPrevCompRefs;
239239
output DAE.Exp outExp = inExp;
@@ -1278,29 +1278,21 @@ protected function substitutePartitionOpExps
12781278
Also when clauses are created for boolean clocks."
12791279
input BackendDAE.EqSystem inSyst;
12801280
input BackendDAE.Shared inShared;
1281-
output BackendDAE.EqSystem outSyst;
1281+
output BackendDAE.EqSystem outSyst = inSyst;
1282+
protected
1283+
list<BackendDAE.Equation> newEqs = {};
1284+
list<BackendDAE.Var> newVars = {};
1285+
Integer cnt = 1;
1286+
BackendDAE.Equation eq;
12821287
algorithm
1283-
outSyst := match inSyst
1284-
local
1285-
BackendDAE.Variables vars;
1286-
BackendDAE.EquationArray eqs;
1287-
BackendDAE.EqSystem syst;
1288-
list<BackendDAE.Equation> newEqs = {};
1289-
list<BackendDAE.Var> newVars = {};
1290-
Integer cnt = 1;
1291-
BackendDAE.Equation eq;
1292-
case syst as BackendDAE.EQSYSTEM(orderedVars=vars, orderedEqs=eqs)
1293-
algorithm
1294-
for i in 1:BackendDAEUtil.equationArraySize(eqs) loop
1295-
eq := BackendEquation.equationNth1(eqs, i);
1296-
(eq, (newEqs, newVars, cnt, _)) :=
1297-
BackendEquation.traverseExpsOfEquation(eq, substitutePartitionOpExp, (newEqs, newVars, cnt, inShared));
1298-
newEqs := eq::newEqs;
1299-
end for;
1300-
syst.orderedEqs := BackendEquation.listEquation(listReverse(newEqs));
1301-
syst.orderedVars := BackendVariable.addVars(newVars, vars);
1302-
then BackendDAEUtil.clearEqSyst(syst);
1303-
end match;
1288+
for i in 1:BackendDAEUtil.equationArraySize(inSyst.orderedEqs) loop
1289+
eq := BackendEquation.equationNth1(inSyst.orderedEqs, i);
1290+
(eq, (newEqs, newVars, cnt, _)) := BackendEquation.traverseExpsOfEquation(eq, substitutePartitionOpExp, (newEqs, newVars, cnt, inShared));
1291+
newEqs := eq::newEqs;
1292+
end for;
1293+
outSyst.orderedEqs := BackendEquation.listEquation(listReverse(newEqs));
1294+
outSyst.orderedVars := BackendVariable.addVars(newVars, inSyst.orderedVars);
1295+
outSyst := BackendDAEUtil.clearEqSyst(outSyst);
13041296
end substitutePartitionOpExps;
13051297

13061298
protected function substitutePartitionOpExp
@@ -1318,28 +1310,25 @@ protected function substitutePartitionOpExp1
13181310
output DAE.Exp outExp;
13191311
output tuple<list<BackendDAE.Equation>,list<BackendDAE.Var>, Integer, BackendDAE.Shared> outTpl;
13201312
protected
1313+
Absyn.Path path;
1314+
BackendDAE.Shared shared;
1315+
DAE.CallAttributes attr;
1316+
DAE.ClockKind clk;
1317+
Integer cnt;
13211318
list<BackendDAE.Equation> newEqs;
13221319
list<BackendDAE.Var> newVars;
1323-
Integer cnt;
1324-
BackendDAE.Shared shared;
1320+
list<DAE.Exp> exps;
13251321
algorithm
13261322
(newEqs, newVars, cnt, shared) := inTpl;
13271323
(outExp, outTpl) := match inExp
1328-
local
1329-
Absyn.Path path;
1330-
list<DAE.Exp> exps;
1331-
DAE.CallAttributes attr;
1332-
DAE.ClockKind clk;
1333-
case DAE.CLKCONST(clk)
1334-
equation
1335-
(clk, newEqs, newVars, cnt) = substClock(clk, newEqs, newVars, cnt, shared);
1336-
then
1337-
(DAE.CLKCONST(clk), (newEqs, newVars, cnt, shared));
1338-
case DAE.CALL(path = path, expLst = exps, attr = attr)
1339-
then
1340-
substituteExpsCall(path, exps, attr, newEqs, newVars, cnt, shared);
1341-
else
1342-
(inExp, inTpl);
1324+
case DAE.CLKCONST(clk) equation
1325+
(clk, newEqs, newVars, cnt) = substClock(clk, newEqs, newVars, cnt, shared);
1326+
then (DAE.CLKCONST(clk), (newEqs, newVars, cnt, shared));
1327+
1328+
case DAE.CALL(path=path, expLst=exps, attr=attr)
1329+
then substituteExpsCall(path, exps, attr, newEqs, newVars, cnt, shared);
1330+
1331+
else (inExp, inTpl);
13431332
end match;
13441333
end substitutePartitionOpExp1;
13451334

@@ -1353,32 +1342,28 @@ protected function substClock
13531342
output list<BackendDAE.Equation> outNewEqs;
13541343
output list<BackendDAE.Var> outNewVars;
13551344
output Integer outCnt;
1345+
protected
1346+
DAE.Exp e;
1347+
Integer cnt;
1348+
Integer i;
1349+
Real f;
1350+
list<BackendDAE.Equation> eqs;
1351+
list<BackendDAE.Var> vars;
13561352
algorithm
13571353
(outClk, outNewEqs, outNewVars, outCnt) := match inClk
1358-
local
1359-
DAE.Exp e;
1360-
Integer i;
1361-
Real f;
1362-
list<BackendDAE.Equation> eqs;
1363-
list<BackendDAE.Var> vars;
1364-
Integer cnt;
1365-
case DAE.BOOLEAN_CLOCK(e, f)
1366-
equation
1367-
({e}, eqs, vars, cnt) = substExp({e}, inNewEqs, inNewVars, inCnt);
1368-
then
1369-
(DAE.BOOLEAN_CLOCK(e, f), eqs, vars, cnt);
1370-
case DAE.REAL_CLOCK(e)
1371-
equation
1372-
(e, eqs, vars, cnt) = substClockExp(e, inNewEqs, inNewVars, inCnt, inShared);
1373-
then
1374-
(DAE.REAL_CLOCK(e), eqs, vars, cnt);
1375-
case DAE.INTEGER_CLOCK(e, i)
1376-
equation
1377-
(e, eqs, vars, cnt) = substClockExp(e, inNewEqs, inNewVars, inCnt, inShared);
1378-
then
1379-
(DAE.INTEGER_CLOCK(e, i), eqs, vars, cnt);
1380-
else
1381-
(inClk, inNewEqs, inNewVars, inCnt);
1354+
case DAE.BOOLEAN_CLOCK(e, f) equation
1355+
({e}, eqs, vars, cnt) = substExp({e}, inNewEqs, inNewVars, inCnt);
1356+
then (DAE.BOOLEAN_CLOCK(e, f), eqs, vars, cnt);
1357+
1358+
case DAE.REAL_CLOCK(e) equation
1359+
(e, eqs, vars, cnt) = substClockExp(e, inNewEqs, inNewVars, inCnt, inShared);
1360+
then (DAE.REAL_CLOCK(e), eqs, vars, cnt);
1361+
1362+
case DAE.INTEGER_CLOCK(e, i) equation
1363+
(e, eqs, vars, cnt) = substClockExp(e, inNewEqs, inNewVars, inCnt, inShared);
1364+
then (DAE.INTEGER_CLOCK(e, i), eqs, vars, cnt);
1365+
1366+
else (inClk, inNewEqs, inNewVars, inCnt);
13821367
end match;
13831368
end substClock;
13841369

@@ -1561,23 +1546,6 @@ algorithm
15611546
end matchcontinue;
15621547
end getVarIxs;
15631548

1564-
protected function getVars
1565-
input DAE.ComponentRef inComp;
1566-
input BackendDAE.Variables inVariables;
1567-
output list<BackendDAE.Var> outIntegerLst;
1568-
algorithm
1569-
outIntegerLst := matchcontinue inComp
1570-
local
1571-
list<BackendDAE.Var> vars;
1572-
case _
1573-
equation
1574-
(vars, _) = BackendVariable.getVar(inComp, inVariables);
1575-
then vars;
1576-
else
1577-
then {};
1578-
end matchcontinue;
1579-
end getVars;
1580-
15811549
protected function baseClockPartitioning
15821550
"Do base clock partitioning and detect kind of new partitions(clocked or continuous)."
15831551
input BackendDAE.EqSystem inSyst;
@@ -1762,18 +1730,6 @@ algorithm
17621730
else partitionType;
17631731
end detectEqPartition;
17641732

1765-
protected function reverseBoolOption
1766-
input Option<Boolean> inp;
1767-
output Option<Boolean> out;
1768-
algorithm
1769-
out := match inp
1770-
local
1771-
Boolean v;
1772-
case SOME(v) then SOME(not v);
1773-
else inp;
1774-
end match;
1775-
end reverseBoolOption;
1776-
17771733
protected function printPartitionType
17781734
input Option<Boolean> isClockedPartition;
17791735
output String out;
@@ -1947,7 +1903,7 @@ algorithm
19471903
end for;
19481904
end partitionIndependentBlocks0;
19491905

1950-
public function partitionIndependentBlocksMasked
1906+
protected function partitionIndependentBlocksMasked
19511907
input BackendDAE.IncidenceMatrix m;
19521908
input BackendDAE.IncidenceMatrixT mT;
19531909
input BackendDAE.IncidenceMatrix rm;

Compiler/Template/CodegenC.tpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,10 @@ template functionInitSynchronous(list<ClockedPartition> clockedPartitions, Strin
294294
/* Initializes the clocks of model. */
295295
void <%symbolName(modelNamePrefix,"function_initSynchronous")%>(DATA *data, threadData_t *threadData)
296296
{
297+
TRACE_PUSH
297298
long i=0, j=0;
298299
<%body%>
300+
TRACE_POP
299301
}
300302
>>
301303
end functionInitSynchronous;
@@ -344,6 +346,7 @@ template functionUpdateSynchronous(list<ClockedPartition> clockedPartitions, Str
344346
/* Update the base clock. */
345347
void <%symbolName(modelNamePrefix,"function_updateSynchronous")%>(DATA *data, threadData_t *threadData, long i)
346348
{
349+
TRACE_PUSH
347350
<%varDecls%>
348351
modelica_boolean ret;
349352
switch (i) {
@@ -352,6 +355,7 @@ template functionUpdateSynchronous(list<ClockedPartition> clockedPartitions, Str
352355
throwStreamPrint(NULL, "Internal Error: unknown base partition %ld", i);
353356
break;
354357
}
358+
TRACE_POP
355359
}
356360
>>
357361
end functionUpdateSynchronous;
@@ -397,8 +401,8 @@ template functionSystemsSynchronous(list<SubPartition> subPartitions, String mod
397401
/*Clocked systems equations */
398402
int <%symbolName(modelNamePrefix,"function_equationsSynchronous")%>(DATA *data, threadData_t *threadData, long i)
399403
{
400-
int ret;
401404
TRACE_PUSH
405+
int ret;
402406
403407
switch (i) {
404408
<%cases%>

SimulationRuntime/c/simulation/solver/solver_main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ int solver_main_step(DATA* data, threadData_t *threadData, SOLVER_INFO* solverIn
156156
*/
157157
int initializeSolverData(DATA* data, threadData_t *threadData, SOLVER_INFO* solverInfo)
158158
{
159+
TRACE_PUSH
159160
int retValue = 0;
160161
int i;
161162

@@ -279,6 +280,7 @@ int initializeSolverData(DATA* data, threadData_t *threadData, SOLVER_INFO* solv
279280
#endif
280281
default:
281282
errorStreamPrint(LOG_SOLVER, 0, "Solver %s disabled on this configuration", SOLVER_METHOD_NAME[solverInfo->solverMethod]);
283+
TRACE_POP
282284
return 1;
283285
}
284286

@@ -290,6 +292,7 @@ int initializeSolverData(DATA* data, threadData_t *threadData, SOLVER_INFO* solv
290292
rt_tick(SIM_TIMER_TOTAL);
291293
}
292294

295+
TRACE_POP
293296
return retValue;
294297
}
295298

@@ -389,6 +392,7 @@ int freeSolverData(DATA* data, SOLVER_INFO* solverInfo)
389392
int initializeModel(DATA* data, threadData_t *threadData, const char* init_initMethod,
390393
const char* init_file, double init_time, int lambda_steps)
391394
{
395+
TRACE_PUSH
392396
int retValue = 0;
393397

394398
SIMULATION_INFO *simInfo = &(data->simulationInfo);
@@ -439,6 +443,7 @@ int initializeModel(DATA* data, threadData_t *threadData, const char* init_initM
439443
rt_accumulate( SIM_TIMER_INIT);
440444
}
441445

446+
TRACE_POP
442447
return retValue;
443448
}
444449

SimulationRuntime/c/simulation/solver/stateset.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
*/
4444
void initializeStateSetJacobians(DATA *data, threadData_t *threadData)
4545
{
46+
TRACE_PUSH
4647
long i = 0;
4748
STATE_SET_DATA *set = NULL;
4849

@@ -56,6 +57,7 @@ void initializeStateSetJacobians(DATA *data, threadData_t *threadData)
5657
}
5758
}
5859
initializeStateSetPivoting(data);
60+
TRACE_POP
5961
}
6062

6163
/*! \fn initializeStateSetPivoting
@@ -68,6 +70,7 @@ void initializeStateSetJacobians(DATA *data, threadData_t *threadData)
6870
*/
6971
void initializeStateSetPivoting(DATA *data)
7072
{
73+
TRACE_PUSH
7174
long i = 0;
7275
long n = 0;
7376
STATE_SET_DATA *set = NULL;
@@ -93,6 +96,7 @@ void initializeStateSetPivoting(DATA *data)
9396
for(n=0; n<set->nStates; n++)
9497
A[n*set->nCandidates + n] = 1; /* set A[row, col] */
9598
}
99+
TRACE_POP
96100
}
97101

98102
/*! \fn freeStateSetData
@@ -105,9 +109,10 @@ void initializeStateSetPivoting(DATA *data)
105109
*/
106110
void freeStateSetData(DATA *data)
107111
{
112+
TRACE_PUSH
108113
long i=0;
109114

110-
/* go troug all state sets */
115+
/* go through all state sets */
111116
for(i=0; i<data->modelData.nStateSets; i++)
112117
{
113118
STATE_SET_DATA *set = &(data->simulationInfo.stateSetData[i]);
@@ -117,6 +122,7 @@ void freeStateSetData(DATA *data)
117122
free(set->colPivot);
118123
free(set->J);
119124
}
125+
TRACE_POP
120126
}
121127

122128
/*! \fn getAnalyticalJacobianSet
@@ -130,6 +136,7 @@ void freeStateSetData(DATA *data)
130136
*/
131137
static void getAnalyticalJacobianSet(DATA* data, threadData_t *threadData, unsigned int index)
132138
{
139+
TRACE_PUSH
133140
unsigned int i, j, k, l, ii;
134141
unsigned int jacIndex = data->simulationInfo.stateSetData[index].jacobianIndex;
135142
unsigned int nrows = data->simulationInfo.analyticJacobians[jacIndex].sizeRows;
@@ -198,6 +205,7 @@ static void getAnalyticalJacobianSet(DATA* data, threadData_t *threadData, unsig
198205
RELEASE(LOG_DSS);
199206
}
200207
*/
208+
TRACE_POP
201209
}
202210

203211
/*! \fn setAMatrix
@@ -211,11 +219,10 @@ static void getAnalyticalJacobianSet(DATA* data, threadData_t *threadData, unsig
211219
* \param [ref] [states]
212220
* \param [ref] [statecandidates]
213221
* \param [ref] [data]
214-
*
215-
* \author ???
216222
*/
217223
static void setAMatrix(modelica_integer* newEnable, modelica_integer nCandidates, modelica_integer nStates, VAR_INFO* Ainfo, VAR_INFO** states, VAR_INFO** statecandidates, DATA *data)
218224
{
225+
TRACE_PUSH
219226
modelica_integer col;
220227
modelica_integer row=0;
221228
/* clear old values */
@@ -238,6 +245,7 @@ static void setAMatrix(modelica_integer* newEnable, modelica_integer nCandidates
238245
row++;
239246
}
240247
}
248+
TRACE_POP
241249
}
242250

243251
/*! \fn comparePivot
@@ -254,11 +262,10 @@ static void setAMatrix(modelica_integer* newEnable, modelica_integer nCandidates
254262
* \param [ref] [statecandidates]
255263
* \param [ref] [data]
256264
* \return ???
257-
*
258-
* \author ???
259265
*/
260266
static int comparePivot(modelica_integer *oldPivot, modelica_integer *newPivot, modelica_integer nCandidates, modelica_integer nDummyStates, modelica_integer nStates, VAR_INFO* A, VAR_INFO** states, VAR_INFO** statecandidates, DATA *data, int switchStates)
261267
{
268+
TRACE_PUSH
262269
modelica_integer i;
263270
int ret = 0;
264271
modelica_integer* oldEnable = (modelica_integer*) calloc(nCandidates, sizeof(modelica_integer));
@@ -289,6 +296,7 @@ static int comparePivot(modelica_integer *oldPivot, modelica_integer *newPivot,
289296
free(oldEnable);
290297
free(newEnable);
291298

299+
TRACE_POP
292300
return ret;
293301
}
294302

0 commit comments

Comments
 (0)