Skip to content

Commit 15c8679

Browse files
authored
[C] Remove unused variables in solver info (OpenModelica#13856)
1 parent b21fd2b commit 15c8679

File tree

11 files changed

+53
-75
lines changed

11 files changed

+53
-75
lines changed

OMCompiler/SimulationRuntime/c/Makefile.common

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ RUNTIMESIMSOLVER_HEADERS = ./simulation/solver/cvode_solver.h \
113113
./simulation/solver/stateset.h \
114114
./simulation/solver/sundials_error.h \
115115
./simulation/solver/sundials_util.h \
116+
./simulation/solver/sym_solver_ssc.h \
116117
./simulation/solver/synchronous.h
117118

118119
RUNTIMEMETA_HEADERS = ./meta/meta_modelica_builtin_boxptr.h \

OMCompiler/SimulationRuntime/c/simulation/solver/dassl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ int dassl_initial(DATA* data, threadData_t *threadData,
283283
if (omc_flag[FLAG_NOEQUIDISTANT_GRID])
284284
{
285285
dasslData->dasslSteps = 1; /* TRUE */
286-
solverInfo->solverNoEquidistantGrid = 1;
286+
solverInfo->solverNoEquidistantGrid = TRUE;
287287
}
288288
else
289289
{

OMCompiler/SimulationRuntime/c/simulation/solver/gbode_main.c

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,16 @@
5454
#include <string.h>
5555

5656
#include "external_input.h"
57-
#include "jacobianSymbolical.h"
5857
#include "kinsolSolver.h"
59-
#include "model_help.h"
6058
#include "newtonIteration.h"
6159
#include "nonlinearSystem.h"
6260
#include "omc_math.h"
63-
#include "simulation/options.h"
64-
#include "simulation/results/simulation_result.h"
65-
#include "simulation/jacobian_util.h"
66-
#include "util/omc_error.h"
67-
#include "util/omc_file.h"
68-
#include "util/simulation_options.h"
69-
#include "util/varinfo.h"
61+
#include "../options.h"
62+
#include "../results/simulation_result.h"
63+
#include "../jacobian_util.h"
64+
#include "../../util/omc_error.h"
65+
#include "../../util/omc_file.h"
66+
#include "../../util/simulation_options.h"
7067
#include "epsilon.h"
7168

7269
extern void communicateStatus(const char *phase, double completionPercent, double currentTime, double currentStepSize);
@@ -87,8 +84,6 @@ void gbode_fODE(DATA *data, threadData_t *threadData, unsigned int* counter)
8784
externalInputUpdate(data);
8885
data->callback->input_function(data, threadData);
8986
data->callback->functionODE(data, threadData);
90-
91-
return;
9287
}
9388

9489
/**
@@ -271,7 +266,7 @@ int gbodef_allocateData(DATA *data, threadData_t *threadData, SOLVER_INFO *solve
271266
snprintf(filename, bufSize, "%s_ActiveStates.txt", data->modelData->modelFilePrefix);
272267
gbfData->fastStatesDebugFile = omc_fopen(filename, "w");
273268
warningStreamPrint(OMC_LOG_STDOUT, 0, "LOG_GBODE_STATES sets -noEquidistantTimeGrid for emitting results!");
274-
solverInfo->integratorSteps = TRUE;
269+
solverInfo->solverNoEquidistantGrid = TRUE;
275270
} else {
276271
gbfData->fastStatesDebugFile = NULL;
277272
}
@@ -1027,8 +1022,8 @@ int gbodef_main(DATA *data, threadData_t *threadData, SOLVER_INFO *solverInfo, d
10271022
dumpFastStates_gbf(gbData, gbfData->time, 0);
10281023
}
10291024

1030-
/* emit step, if integratorSteps is selected */
1031-
if (solverInfo->integratorSteps) {
1025+
/* emit step, if solverNoEquidistantGrid is selected */
1026+
if (solverInfo->solverNoEquidistantGrid) {
10321027
sData->timeValue = gbfData->time;
10331028
solverInfo->currentTime = sData->timeValue;
10341029
memcpy(sData->realVars, gbfData->y, nStates * sizeof(double));
@@ -1055,7 +1050,7 @@ int gbodef_main(DATA *data, threadData_t *threadData, SOLVER_INFO *solverInfo, d
10551050
// copy error and values of the fast states to the outer integrator routine if outer integration time is reached
10561051
//gbData->err_fast = gbfData->errValues[0];
10571052

1058-
if (!solverInfo->integratorSteps && gbfData->time >= targetTime) {
1053+
if (!solverInfo->solverNoEquidistantGrid && gbfData->time >= targetTime) {
10591054
/* Integrator does large steps and needs to interpolate results with respect to the output grid */
10601055
/* Here, only the fast states get updated */
10611056
sData->timeValue = solverInfo->currentTime + solverInfo->currentStepSize;
@@ -1115,7 +1110,7 @@ int gbode_birate(DATA *data, threadData_t *threadData, SOLVER_INFO *solverInfo)
11151110

11161111
/* Calculate steps until targetTime is reached */
11171112
// 1 => emit result at integrator step points; 0 => equidistant grid
1118-
if (solverInfo->integratorSteps) {
1113+
if (solverInfo->solverNoEquidistantGrid) {
11191114
if (data->simulationInfo->nextSampleEvent < data->simulationInfo->stopTime) {
11201115
targetTime = data->simulationInfo->nextSampleEvent;
11211116
} else {
@@ -1360,7 +1355,7 @@ int gbode_birate(DATA *data, threadData_t *threadData, SOLVER_INFO *solverInfo)
13601355
messageClose(OMC_LOG_GBODE_V);
13611356
}
13621357
if (gbData->ctrl_method != GB_CTRL_CNST && ((gbData->interpolation == GB_INTERPOL_HERMITE_ERRCTRL) || (gbData->interpolation == GB_DENSE_OUTPUT_ERRCTRL))) {
1363-
if (gbData->err_int> err) {
1358+
if (gbData->err_int > err) {
13641359
gbData->errValues[0] = gbData->err_int;
13651360
gbData->stepSize = gbData->lastStepSize * gbData->stepSize_control(gbData->errValues, gbData->stepSizeValues, gbData->tableau->error_order);
13661361
if (gbData->maxStepSize > 0 && gbData->maxStepSize < gbData->stepSize)
@@ -1517,8 +1512,8 @@ int gbode_birate(DATA *data, threadData_t *threadData, SOLVER_INFO *solverInfo)
15171512
dumpFastStates_gb(gbData, FALSE, gbData->time, 0);
15181513
}
15191514

1520-
/* emit step, if integratorSteps is selected */
1521-
if (solverInfo->integratorSteps && gbData->gbfData->time<gbData->time) {
1515+
/* emit step, if solverNoEquidistantGrid is selected */
1516+
if (solverInfo->solverNoEquidistantGrid && gbData->gbfData->time<gbData->time) {
15221517
sData->timeValue = gbData->time;
15231518
solverInfo->currentTime = sData->timeValue;
15241519
memcpy(sData->realVars, gbData->y, nStates * sizeof(double));
@@ -1546,7 +1541,7 @@ int gbode_birate(DATA *data, threadData_t *threadData, SOLVER_INFO *solverInfo)
15461541
}
15471542
// end of while-loop (gbData->time < targetTime)
15481543

1549-
if (!solverInfo->integratorSteps) {
1544+
if (!solverInfo->solverNoEquidistantGrid) {
15501545
/* Integrator does large steps and needs to interpolate results with respect to the output grid */
15511546
sData->timeValue = solverInfo->currentTime + solverInfo->currentStepSize;
15521547
solverInfo->currentTime = sData->timeValue;
@@ -1634,7 +1629,7 @@ int gbode_singlerate(DATA *data, threadData_t *threadData, SOLVER_INFO *solverIn
16341629

16351630
/* Calculate steps until targetTime is reached */
16361631
// 1 => emit result at integrator step points; 0 => equidistant grid
1637-
if (solverInfo->integratorSteps) {
1632+
if (solverInfo->solverNoEquidistantGrid) {
16381633
if (data->simulationInfo->nextSampleEvent < data->simulationInfo->stopTime) {
16391634
targetTime = data->simulationInfo->nextSampleEvent;
16401635
} else {
@@ -1912,8 +1907,8 @@ int gbode_singlerate(DATA *data, threadData_t *threadData, SOLVER_INFO *solverIn
19121907
infoStreamPrint(OMC_LOG_SOLVER, 0, "Accept step from %10g to %10g, error %10g interpolation error %10g, new stepsize %10g",
19131908
gbData->timeLeft, gbData->timeRight, err, gbData->err_int, gbData->stepSize);
19141909

1915-
/* emit step, if integratorSteps is selected */
1916-
if (solverInfo->integratorSteps) {
1910+
/* emit step, if solverNoEquidistantGrid is selected */
1911+
if (solverInfo->solverNoEquidistantGrid) {
19171912
solverInfo->currentTime = sData->timeValue;
19181913
/*
19191914
* to emit consistent value we need to update the whole
@@ -1938,7 +1933,7 @@ int gbode_singlerate(DATA *data, threadData_t *threadData, SOLVER_INFO *solverIn
19381933
// reduce step size with respect to the simulation stop time, if necessary
19391934
gbData->stepSize = fmin(gbData->stepSize, stopTime - gbData->time);
19401935

1941-
if (omc_flag[FLAG_PORT] && solverInfo->integratorSteps) {
1936+
if (omc_flag[FLAG_PORT] && solverInfo->solverNoEquidistantGrid) {
19421937
if (0 != strcmp("ia", data->simulationInfo->outputFormat)) {
19431938
communicateStatus("Running", (solverInfo->currentTime - data->simulationInfo->startTime)/(data->simulationInfo->stopTime - data->simulationInfo->startTime), solverInfo->currentTime, solverInfo->currentStepSize);
19441939
}
@@ -1947,7 +1942,7 @@ int gbode_singlerate(DATA *data, threadData_t *threadData, SOLVER_INFO *solverIn
19471942
}
19481943
// end of while-loop (gbData->time < targetTime)
19491944

1950-
if (!solverInfo->integratorSteps) {
1945+
if (!solverInfo->solverNoEquidistantGrid) {
19511946
/* Integrator does large steps and needs to interpolate results with respect to the output grid */
19521947
sData->timeValue = solverInfo->currentTime + solverInfo->currentStepSize;
19531948
solverInfo->currentTime = sData->timeValue;

OMCompiler/SimulationRuntime/c/simulation/solver/ida_solver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ int ida_solver_initial(DATA* data, threadData_t *threadData,
297297
/* if FLAG_NOEQUIDISTANT_GRID is set, choose ida step method */
298298
if (omc_flag[FLAG_NOEQUIDISTANT_GRID]) {
299299
idaData->internalSteps = 1; /* TRUE */
300-
solverInfo->solverNoEquidistantGrid = 1;
300+
solverInfo->solverNoEquidistantGrid = TRUE;
301301
} else {
302302
idaData->internalSteps = 0; /* FALSE */
303303
}

OMCompiler/SimulationRuntime/c/simulation/solver/irksco.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ int irksco_midpoint_rule(DATA* data, threadData_t* threadData, SOLVER_INFO* solv
421421

422422

423423
/* Calculate steps until targetTime is reached */
424-
if (solverInfo->integratorSteps)
424+
if (solverInfo->solverNoEquidistantGrid)
425425
{
426426
if (data->simulationInfo->nextSampleEvent < data->simulationInfo->stopTime)
427427
{
@@ -528,8 +528,8 @@ int irksco_midpoint_rule(DATA* data, threadData_t* threadData, SOLVER_INFO* solv
528528
memcpy(userdata->radauVarsOld, userdata->radauVars, data->modelData->nStates*sizeof(double));
529529
memcpy(userdata->radauVars, userdata->y2, data->modelData->nStates*sizeof(double));
530530

531-
/* emit step, if integratorSteps is selected */
532-
if (solverInfo->integratorSteps)
531+
/* emit step, if solverNoEquidistantGrid is selected */
532+
if (solverInfo->solverNoEquidistantGrid)
533533
{
534534
sData->timeValue = userdata->radauTime;
535535
memcpy(sData->realVars, userdata->radauVars, data->modelData->nStates*sizeof(double));
@@ -543,7 +543,7 @@ int irksco_midpoint_rule(DATA* data, threadData_t* threadData, SOLVER_INFO* solv
543543
messageClose(OMC_LOG_SOLVER);
544544
}
545545

546-
if (!solverInfo->integratorSteps)
546+
if (!solverInfo->solverNoEquidistantGrid)
547547
{
548548
solverInfo->currentTime = sDataOld->timeValue + solverInfo->currentStepSize;
549549
sData->timeValue = solverInfo->currentTime;

OMCompiler/SimulationRuntime/c/simulation/solver/perform_simulation.c.inc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "solver_main.h"
3232
#include "events.h"
3333
#include "dassl.h"
34+
#include "sym_solver_ssc.h"
3435

3536
#include "../simulation_runtime.h"
3637
#include "../results/simulation_result.h"
@@ -99,7 +100,8 @@ static fire_timer_t simulationUpdate(DATA* data, threadData_t *threadData, SOLVE
99100
prefixedName_updateContinuousSystem(data, threadData);
100101

101102
if (solverInfo->solverMethod == S_SYM_SOLVER_SSC) {
102-
data->simulationInfo->inlineData->dt = solverInfo->solverStepSize;
103+
DATA_SYM_SOLVER_SSC* solverData = (DATA_SYM_SOLVER_SSC*) solverInfo->solverData;
104+
data->simulationInfo->inlineData->dt = solverData->solverStepSize;
103105
//data->callback->symbolicInlineSystems(data, threadData);
104106
}
105107

OMCompiler/SimulationRuntime/c/simulation/solver/solver_main.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ int initializeSolverData(DATA* data, threadData_t *threadData, SOLVER_INFO* solv
219219
solverInfo->currentStepSize = simInfo->stepSize;
220220
solverInfo->laststep = 0;
221221
solverInfo->solverRootFinding = 0;
222-
solverInfo->solverNoEquidistantGrid = 0;
222+
solverInfo->solverNoEquidistantGrid = omc_flag[FLAG_NOEQUIDISTANT_GRID];
223223
solverInfo->lastdesiredStep = solverInfo->currentTime + solverInfo->currentStepSize;
224224
solverInfo->eventLst = allocList(eventListAlloc, eventListFree, eventListCopy);
225225
solverInfo->didEventStep = 0;
@@ -228,16 +228,6 @@ int initializeSolverData(DATA* data, threadData_t *threadData, SOLVER_INFO* solv
228228
resetSolverStats(&solverInfo->solverStats);
229229
resetSolverStats(&solverInfo->solverStatsTmp);
230230

231-
/* if FLAG_NOEQUIDISTANT_GRID is set, choose integrator step method */
232-
if (omc_flag[FLAG_NOEQUIDISTANT_GRID])
233-
{
234-
solverInfo->integratorSteps = 1; /* TRUE */
235-
}
236-
else
237-
{
238-
solverInfo->integratorSteps = 0;
239-
}
240-
241231
/* Deprecation warnings */
242232
deprecationWarningGBODE(solverInfo->solverMethod);
243233

OMCompiler/SimulationRuntime/c/simulation/solver/solver_main.h

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@
4646
* @brief Solver statistics.
4747
*/
4848
typedef struct SOLVERSTATS {
49-
unsigned int nStepsTaken; /* Number of steps taken by the solver */
50-
unsigned int nCallsODE; /* Number of calls on functionODE */
51-
unsigned int nCallsJacobian; /* Number of evaluations of Jacobian */
52-
unsigned int nErrorTestFailures; /* Number of error test failures */
53-
unsigned int nConvergenveTestFailures; /* Number of convergence test failures */
49+
unsigned int nStepsTaken; /* Number of steps taken by the solver */
50+
unsigned int nCallsODE; /* Number of calls on functionODE */
51+
unsigned int nCallsJacobian; /* Number of evaluations of Jacobian */
52+
unsigned int nErrorTestFailures; /* Number of error test failures */
53+
unsigned int nConvergenveTestFailures; /* Number of convergence test failures */
5454
} SOLVERSTATS;
5555

5656
/**
@@ -61,31 +61,25 @@ typedef struct SOLVER_INFO
6161
double currentTime;
6262
double currentStepSize;
6363
double laststep;
64-
enum SOLVER_METHOD solverMethod; /* ODE/DAE solver method */
65-
double solverStepSize; /* used by implicit radau solver */
66-
// TODO: This should be in radau solverData
64+
enum SOLVER_METHOD solverMethod; /* ODE/DAE solver method */
6765

68-
modelica_boolean solverRootFinding; /* Set by solver if an internal root finding method is activated */
69-
modelica_boolean solverNoEquidistantGrid; /* Set by solver if output points are set by step size control */
66+
modelica_boolean solverRootFinding; /* Set by solver if an internal root finding method is activated */
67+
modelica_boolean solverNoEquidistantGrid; /* Set by solver if output points are set by step size control */
7068
double lastdesiredStep;
7169

7270
/* events */
73-
LIST* eventLst; /* List with long indices from data->simulationInfo->zeroCrossingIndex */
74-
int didEventStep; /* Boolean stating if during the last step an event was encountered,
75-
* Used to reinitialize ODE/DAE solver after event iteration */
71+
LIST* eventLst; /* List with long indices from data->simulationInfo->zeroCrossingIndex */
72+
int didEventStep; /* Boolean stating if during the last step an event was encountered,
73+
* Used to reinitialize ODE/DAE solver after event iteration */
7674

7775
/* stats */
7876
unsigned long stateEvents;
7977
unsigned long sampleEvents;
8078
/* integrator stats */
81-
SOLVERSTATS solverStats; /* Statistic for integrator */
82-
SOLVERSTATS solverStatsTmp; /* tmp solver stats to update solverStats with */
79+
SOLVERSTATS solverStats; /* Statistic for integrator */
80+
SOLVERSTATS solverStatsTmp; /* tmp solver stats to update solverStats with */
8381

84-
/* further options */
85-
int integratorSteps; /* 1 => stepSizeControl; 0 => equidistant grid */
86-
// TODO: This is a duplicate of solverNoEquidistantGrid set in DASSL/IDA/...
87-
88-
void* solverData; /* ODE/DAE solver data */
82+
void* solverData; /* ODE/DAE solver data */
8983
}SOLVER_INFO;
9084

9185
#ifdef __cplusplus

OMCompiler/SimulationRuntime/c/simulation/solver/sym_solver_ssc.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,14 @@
3232
*/
3333

3434
#include <string.h>
35-
#include <float.h>
3635

37-
#include "simulation/simulation_info_json.h"
38-
#include "util/omc_error.h"
39-
#include "util/varinfo.h"
36+
#include "../../util/omc_error.h"
4037
#include "model_help.h"
41-
#include "newtonIteration.h"
42-
4338

4439
#include "sym_solver_ssc.h"
4540
#include "external_input.h"
4641

42+
4743
int first_step(DATA* data, threadData_t *threadData, SOLVER_INFO* solverInfo);
4844
int generateTwoApproximationsOfDifferentOrder(DATA* data, threadData_t *threadData, SOLVER_INFO* solverInfo);
4945

@@ -236,8 +232,8 @@ int sym_solver_ssc_step(DATA* data, threadData_t *threadData, SOLVER_INFO* solve
236232

237233
/* update step size */
238234
data->simulationInfo->inlineData->dt = userdata->radauStepSize;
239-
solverInfo->solverStepSize = userdata->radauStepSizeOld;
240-
infoStreamPrint(OMC_LOG_SOLVER,0, "Step done to %f with step size = %e", sData->timeValue, solverInfo->solverStepSize);
235+
userdata->solverStepSize = userdata->radauStepSizeOld;
236+
infoStreamPrint(OMC_LOG_SOLVER,0, "Step done to %f with step size = %e", sData->timeValue, userdata->solverStepSize);
241237

242238

243239
return retVal;

OMCompiler/SimulationRuntime/c/simulation/solver/sym_solver_ssc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@
3434
#ifndef _SYM_SOLVER_SSC_H_
3535
#define _SYM_SOLVER_SSC_H_
3636

37-
#include "simulation_data.h"
37+
#include "../../simulation_data.h"
3838
#include "solver_main.h"
39-
#include "omc_config.h"
4039

4140
#include <math.h>
4241

@@ -48,10 +47,11 @@ typedef struct DATA_SYM_SOLVER_SSC{
4847
double radauTime;
4948
double radauTimeOld;
5049
double radauStepSize, radauStepSizeOld;
50+
double solverStepSize;
5151
int firstStep;
5252
unsigned int stepsDone;
5353
unsigned int evalFunctionODE;
54-
}DATA_SYM_SOLVER_SSC;
54+
} DATA_SYM_SOLVER_SSC;
5555

5656

5757
int allocateSymSolverSsc(SOLVER_INFO* solverInfo, int size);

0 commit comments

Comments
 (0)