Skip to content

Commit

Permalink
- removed rounding step-size work-a-round
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@18697 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Willi Braun committed Jan 20, 2014
1 parent 095936b commit 30ef637
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 46 deletions.
11 changes: 1 addition & 10 deletions SimulationRuntime/c/simulation/solver/dassl.c
Expand Up @@ -269,16 +269,7 @@ int dasrt_step(DATA* simData, SOLVER_INFO* solverInfo)

/* Calculate time steps until TOUT is reached
* (DASSL calculates beyond TOUT unless info[6] is set to 1!) */

/* adjust next time step by rounding. No rounding,
* when time event is activated, since then currectStepSize is exact */
if (simData->simulationInfo.sampleActivated){
tout = solverInfo->currentTime + solverInfo->currentStepSize;
} else {
tout = _omc_round(solverInfo->currentTime + solverInfo->currentStepSize, solverInfo->stepPrecision);
solverInfo->currentStepSize = tout - solverInfo->currentTime;
}

tout = solverInfo->currentTime + solverInfo->currentStepSize;
/* Check that tout is not less than timeValue
* else will dassl get in trouble. If that is the case we skip the current step. */
if(solverInfo->currentTime - tout >= -1e-13)
Expand Down
17 changes: 0 additions & 17 deletions SimulationRuntime/c/simulation/solver/model_help.c
Expand Up @@ -1198,20 +1198,3 @@ modelica_real _event_div_real(modelica_real x1, modelica_real x2, modelica_integ
#endif
}


/*! \fn _omc_round
*
* \param [in] [x]
* \param [in] [precision]
*
* Returns a round value of x with a certain precision.
*/
modelica_real _omc_round(modelica_real x, modelica_integer precision)
{
double p, trunc;
assertStreamPrint(precision < 20, "_omc_round fails with precision > 19");
p = (double) pow(10, precision);
trunc = round(x * p);
return (modelica_real) (trunc / p);
}

1 change: 0 additions & 1 deletion SimulationRuntime/c/simulation/solver/model_help.h
Expand Up @@ -138,7 +138,6 @@ modelica_real _event_div_real(modelica_real x1, modelica_real x2, modelica_integ
modelica_integer _event_mod_integer(modelica_integer x1, modelica_integer x2, modelica_integer index, DATA *data);
modelica_integer _event_rem_integer(modelica_integer x1, modelica_integer x2, modelica_integer index, DATA *data);

modelica_real _omc_round(modelica_real x, modelica_integer prec);
/* functions used for relation which
* are not used as zero-crossings
*/
Expand Down
19 changes: 2 additions & 17 deletions SimulationRuntime/c/simulation/solver/solver_main.c
Expand Up @@ -147,7 +147,6 @@ int initializeSolverData(DATA* data, SOLVER_INFO* solverInfo)
solverInfo->didEventStep = 0;
solverInfo->stateEvents = 0;
solverInfo->sampleEvents = 0;
solverInfo->stepPrecision = fmin(15,abs(log10(simInfo->stepSize)+fmax(log10(simInfo->startTime),-4)+log10(simInfo->tolerance)));

if(solverInfo->solverMethod == 2)
{
Expand Down Expand Up @@ -597,14 +596,7 @@ static int euler_ex_step(DATA* data, SOLVER_INFO* solverInfo)
SIMULATION_DATA *sDataOld = (SIMULATION_DATA*)data->localData[1];
modelica_real* stateDer = sDataOld->realVars + data->modelData.nStates;

/* adjust next time step by rounding. No rounding,
* when time event is activated, since then currectStepSize is exact */
if (data->simulationInfo.sampleActivated){
solverInfo->currentTime = sDataOld->timeValue + solverInfo->currentStepSize;
} else {
solverInfo->currentTime = _omc_round(sDataOld->timeValue + solverInfo->currentStepSize, solverInfo->stepPrecision);
solverInfo->currentStepSize = solverInfo->currentTime - sDataOld->timeValue;
}
solverInfo->currentTime = sDataOld->timeValue + solverInfo->currentStepSize;

for(i = 0; i < data->modelData.nStates; i++)
{
Expand All @@ -625,14 +617,7 @@ static int rungekutta_step(DATA* data, SOLVER_INFO* solverInfo)
modelica_real* stateDer = sData->realVars + data->modelData.nStates;
modelica_real* stateDerOld = sDataOld->realVars + data->modelData.nStates;

/* adjust next time step by rounding. No rounding,
* when time event is activated, since then currectStepSize is exact */
if (data->simulationInfo.sampleActivated){
solverInfo->currentTime = sDataOld->timeValue + solverInfo->currentStepSize;
} else {
solverInfo->currentTime = _omc_round(sDataOld->timeValue + solverInfo->currentStepSize, solverInfo->stepPrecision);
solverInfo->currentStepSize = solverInfo->currentTime - sDataOld->timeValue;
}
solverInfo->currentTime = sDataOld->timeValue + solverInfo->currentStepSize;

/* We calculate k[0] before returning from this function.
* We only want to calculate f() 4 times per call */
Expand Down
1 change: 0 additions & 1 deletion SimulationRuntime/c/simulation/solver/solver_main.h
Expand Up @@ -48,7 +48,6 @@ typedef struct SOLVER_INFO
double currentStepSize;
double laststep;
int solverMethod;
int stepPrecision;

/* set by solver if an internal root finding method is activated */
modelica_boolean solverRootFinding;
Expand Down

0 comments on commit 30ef637

Please sign in to comment.