Skip to content

Commit

Permalink
- fix noEquidistantGrid mode of dassl
Browse files Browse the repository at this point in the history
  • Loading branch information
Willi Braun committed Oct 27, 2015
1 parent a2254ab commit e15a57a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
26 changes: 19 additions & 7 deletions SimulationRuntime/c/simulation/solver/dassl.c
Expand Up @@ -306,6 +306,7 @@ int dassl_initial(DATA* data, threadData_t *threadData, SOLVER_INFO* solverInfo,
if (omc_flag[FLAG_NOEQUIDISTANT_GRID])
{
dasslData->dasslSteps = 1; /* TRUE */
solverInfo->solverNoEquidistantGrid = 1;
}
else
{
Expand Down Expand Up @@ -567,7 +568,14 @@ int dassl_step(DATA* data, threadData_t *threadData, SOLVER_INFO* solverInfo)
/* If dasslsteps is selected, the dassl run to stopTime */
if (dasslData->dasslSteps)
{
tout = data->simulationInfo.stopTime;
if (data->simulationInfo.nextSampleEvent < data->simulationInfo.stopTime)
{
tout = data->simulationInfo.nextSampleEvent;
}
else
{
tout = data->simulationInfo.stopTime;
}
}
else
{
Expand All @@ -586,9 +594,9 @@ int dassl_step(DATA* data, threadData_t *threadData, SOLVER_INFO* solverInfo)
{
sData->realVars[i] = sDataOld->realVars[i] + stateDer[i] * solverInfo->currentStepSize;
}
sData->timeValue = tout;
sData->timeValue = solverInfo->currentTime + solverInfo->currentStepSize;
data->callback->functionODE(data, threadData);
solverInfo->currentTime = tout;
solverInfo->currentTime = sData->timeValue;

TRACE_POP
return 0;
Expand Down Expand Up @@ -662,23 +670,22 @@ int dassl_step(DATA* data, threadData_t *threadData, SOLVER_INFO* solverInfo)
* continuous system with algebraic variables.
*/
RHSFinalFlag = 1;
data->callback->updateContinuousSystem(data, threadData);

if (omc_flag[FLAG_NOEQUIDISTANT_OUT_FREQ]){
/* output every n-th time step */
if (dasslStepsOutputCounter >= dasslData->dasslStepsFreq){
sim_result.emit(&sim_result, data, threadData);
dasslStepsOutputCounter = 0; /* next line set it to one */
break;
}
dasslStepsOutputCounter++;
} else if (omc_flag[FLAG_NOEQUIDISTANT_OUT_TIME]){
/* output when time>=k*timeValue */
if (solverInfo->currentTime > dasslStepsOutputCounter * dasslData->dasslStepsTime){
sim_result.emit(&sim_result, data, threadData);
dasslStepsOutputCounter++;
break;
}
} else {
sim_result.emit(&sim_result, data, threadData);
break;
}
RHSFinalFlag = 0;

Expand Down Expand Up @@ -710,6 +717,11 @@ int dassl_step(DATA* data, threadData_t *threadData, SOLVER_INFO* solverInfo)
/* set ringbuffer time to current time */
data->localData[0]->timeValue = solverInfo->currentTime;
}
else
{
if (data->simulationInfo.sampleActivated && solverInfo->currentTime < data->simulationInfo.nextSampleEvent)
data->simulationInfo.sampleActivated = 0;
}


if(ACTIVE_STREAM(LOG_DASSL))
Expand Down
13 changes: 12 additions & 1 deletion SimulationRuntime/c/simulation/solver/perform_simulation.c
Expand Up @@ -344,9 +344,20 @@ int prefixedName_performSimulation(DATA* data, threadData_t *threadData, SOLVER_
}
else
{
__currStepNo++;
if (solverInfo->solverNoEquidistantGrid)
{
if (solverInfo->currentTime >= solverInfo->lastdesiredStep)
{
__currStepNo++;
}
}
else
{
__currStepNo++;
}
}
solverInfo->currentStepSize = (double)(__currStepNo*(simInfo->stopTime-simInfo->startTime))/(simInfo->numSteps) + simInfo->startTime - solverInfo->currentTime;
solverInfo->lastdesiredStep = solverInfo->currentTime + solverInfo->currentStepSize;

/* if retry reduce stepsize */
if(0 != retry)
Expand Down
2 changes: 2 additions & 0 deletions SimulationRuntime/c/simulation/solver/solver_main.c
Expand Up @@ -174,6 +174,8 @@ int initializeSolverData(DATA* data, threadData_t *threadData, SOLVER_INFO* solv
solverInfo->currentStepSize = simInfo->stepSize;
solverInfo->laststep = 0;
solverInfo->solverRootFinding = 0;
solverInfo->solverNoEquidistantGrid = 0;
solverInfo->lastdesiredStep = solverInfo->currentTime + solverInfo->currentStepSize;
solverInfo->eventLst = allocList(sizeof(long));
solverInfo->didEventStep = 0;
solverInfo->stateEvents = 0;
Expand Down
3 changes: 3 additions & 0 deletions SimulationRuntime/c/simulation/solver/solver_main.h
Expand Up @@ -52,6 +52,9 @@ typedef struct SOLVER_INFO

/* set by solver if an internal root finding method is activated */
modelica_boolean solverRootFinding;
/* set by solver if output points are set by step size control */
modelica_boolean solverNoEquidistantGrid;
double lastdesiredStep;

/* events */
LIST* eventLst;
Expand Down
2 changes: 1 addition & 1 deletion common
Submodule common updated 1 files
+21 −2 m4/qmake.m4

0 comments on commit e15a57a

Please sign in to comment.