Skip to content

Commit

Permalink
- rename sample event to time event
Browse files Browse the repository at this point in the history
- revise some DEBUG dumps


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@16261 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
lochel committed Jun 9, 2013
1 parent 0b01973 commit 58ac55d
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 95 deletions.
20 changes: 10 additions & 10 deletions SimulationRuntime/c/simulation/solver/events.c
Expand Up @@ -93,11 +93,11 @@ void initSample(DATA* data, double startTime, double stopTime)
*
* \param [ref] [data]
* \param [ref] [solverInfo]
* \return indicates if a sample event is occuered or not.
* \return indicates if a time event is occuered or not.
*
* Function check if a sample expression should be activated
* before next step and sets then the next step size to the
* sample event.
* time event.
*
*/
void checkForSampleEvent(DATA *data, SOLVER_INFO* solverInfo)
Expand Down Expand Up @@ -157,11 +157,11 @@ int checkForStateEvent(DATA* data, LIST *eventList)
* \param [in] [eventTime]
* \param [ref] [solverInfo]
*
* This function check if a sample event or a state event should
* This function check if a time event or a state event should
* processed. If sample and state event have the same event-time
* then sample events are prioritize, since they handle also
* state event. It returns 1 if state event is before sample event
* then it de-activate the sample events.
* then time events are prioritize, since they handle also
* state event. It returns 1 if state event is before time event
* then it de-activate the time events.
*/
int checkEvents(DATA* data, LIST* eventLst, double *eventTime, SOLVER_INFO* solverInfo)
{
Expand Down Expand Up @@ -193,12 +193,12 @@ void handleEvents(DATA* data, LIST* eventLst, double *eventTime, SOLVER_INFO* so

sim_result.emit(&sim_result,data);

/* sample event */
/* time event */
if(data->simulationInfo.sampleActivated)
{
storePreValues(data);

/* activate sample event */
/* activate time event */
for(i=0; i<data->modelData.nSamples; ++i)
if(data->simulationInfo.nextSampleTimes[i] <= time + eps)
{
Expand All @@ -225,10 +225,10 @@ void handleEvents(DATA* data, LIST* eventLst, double *eventTime, SOLVER_INFO* so
saveZeroCrossingsAfterEvent(data);
/*sim_result_emit(data);*/

/* sample event */
/* time event */
if(data->simulationInfo.sampleActivated)
{
/* deactivate sample events */
/* deactivate time events */
for(i=0; i<data->modelData.nSamples; ++i)
{
if(data->simulationInfo.samples[i])
Expand Down
131 changes: 63 additions & 68 deletions SimulationRuntime/c/simulation/solver/model_help.c
Expand Up @@ -61,14 +61,14 @@ void updateDiscreteSystem(DATA *data)
storeRelations(data);
updateHysteresis(data);

if(ACTIVE_STREAM(LOG_EVENTS_V))
printRelations(data);
/* should we print the relations before functionDAE?
* printRelations(data, LOG_EVENTS_V);
*/

functionDAE(data);
DEBUG(LOG_EVENTS_V, "updated discrete System");

if(ACTIVE_STREAM(LOG_EVENTS_V))
printRelations(data);
printRelations(data, LOG_EVENTS_V);

relationChanged = checkRelations(data);
discreteChanged = checkForDiscreteChanges(data);
Expand All @@ -83,8 +83,8 @@ void updateDiscreteSystem(DATA *data)

storePreValues(data);
storeRelations(data);
if(ACTIVE_STREAM(LOG_EVENTS_V))
printRelations(data);

printRelations(data, LOG_EVENTS_V);

functionDAE(data);

Expand Down Expand Up @@ -179,49 +179,37 @@ void printAllVars(DATA *data, int ringSegment, int stream)
INFO(stream, "states variables");
INDENT(stream);
for(i=0; i<mData->nStates; ++i)
{
INFO4(stream, "%ld: %s = %g (pre: %g)", i+1, mData->realVarsData[i].info.name, data->localData[ringSegment]->realVars[i], sInfo->realVarsPre[i]);
}
RELEASE(stream);

INFO(stream, "derivatives variables");
INDENT(stream);
for(i=mData->nStates; i<2*mData->nStates; ++i)
{
INFO4(stream, "%ld: %s = %g (pre: %g)", i+1, mData->realVarsData[i].info.name, data->localData[ringSegment]->realVars[i], sInfo->realVarsPre[i]);
}
RELEASE(stream);

INFO(stream, "other real values");
INDENT(stream);
for(i=2*mData->nStates; i<mData->nVariablesReal; ++i)
{
INFO4(stream, "%ld: %s = %g (pre: %g)", i+1, mData->realVarsData[i].info.name, data->localData[ringSegment]->realVars[i], sInfo->realVarsPre[i]);
}
RELEASE(stream);

INFO(stream, "integer variables");
INDENT(stream);
for(i=0; i<mData->nVariablesInteger; ++i)
{
INFO4(stream, "%ld: %s = %ld (pre: %ld)", i+1, mData->integerVarsData[i].info.name, data->localData[ringSegment]->integerVars[i], sInfo->integerVarsPre[i]);
}
RELEASE(stream);

INFO(stream, "boolean variables");
INDENT(stream);
for(i=0; i<mData->nVariablesBoolean; ++i)
{
INFO4(stream, "%ld: %s = %s (pre: %s)", i+1, mData->booleanVarsData[i].info.name, data->localData[ringSegment]->booleanVars[i] ? "true" : "false", sInfo->booleanVarsPre[i] ? "true" : "false");
}
RELEASE(stream);

INFO(stream, "string variables");
INDENT(stream);
for(i=0; i<mData->nVariablesString; ++i)
{
INFO4(stream, "%ld: %s = %s (pre: %s)", i+1, mData->stringVarsData[i].info.name, data->localData[ringSegment]->stringVars[i], sInfo->stringVarsPre[i]);
}
RELEASE(stream);

RELEASE(stream);
Expand All @@ -235,68 +223,55 @@ void printAllVars(DATA *data, int ringSegment, int stream)
* \param [in] [data]
* \param [in] [ringSegment]
*/
void printAllVarsDebug(DATA *data, int ringSegment)
void printAllVarsDebug(DATA *data, int ringSegment, int stream)
{
long i;
MODEL_DATA *mData = &(data->modelData);
SIMULATION_INFO *sInfo = &(data->simulationInfo);

DEBUG2(LOG_DEBUG, "Print values for buffer segment %d regarding point in time : %e", ringSegment, data->localData[ringSegment]->timeValue);
INDENT(LOG_DEBUG);
DEBUG2(stream, "Print values for buffer segment %d regarding point in time : %e", ringSegment, data->localData[ringSegment]->timeValue);
INDENT(stream);

DEBUG(LOG_DEBUG, "states variables");
INDENT(LOG_DEBUG);
DEBUG(stream, "states variables");
INDENT(stream);
for(i=0; i<mData->nStates; ++i)
{
DEBUG4(LOG_DEBUG, "%ld: %s = %g (pre: %g)", i+1, mData->realVarsData[i].info.name, data->localData[ringSegment]->realVars[i], sInfo->realVarsPre[i]);
}
RELEASE(LOG_DEBUG);
DEBUG4(stream, "%ld: %s = %g (pre: %g)", i+1, mData->realVarsData[i].info.name, data->localData[ringSegment]->realVars[i], sInfo->realVarsPre[i]);
RELEASE(stream);

DEBUG(LOG_DEBUG, "derivatives variables");
INDENT(LOG_DEBUG);
DEBUG(stream, "derivatives variables");
INDENT(stream);
for(i=mData->nStates; i<2*mData->nStates; ++i)
{
DEBUG4(LOG_DEBUG, "%ld: %s = %g (pre: %g)", i+1, mData->realVarsData[i].info.name, data->localData[ringSegment]->realVars[i], sInfo->realVarsPre[i]);
}
RELEASE(LOG_DEBUG);
DEBUG4(stream, "%ld: %s = %g (pre: %g)", i+1, mData->realVarsData[i].info.name, data->localData[ringSegment]->realVars[i], sInfo->realVarsPre[i]);
RELEASE(stream);

DEBUG(LOG_DEBUG, "other real values");
INDENT(LOG_DEBUG);
DEBUG(stream, "other real values");
INDENT(stream);
for(i=2*mData->nStates; i<mData->nVariablesReal; ++i)
{
DEBUG4(LOG_DEBUG, "%ld: %s = %g (pre: %g)", i+1, mData->realVarsData[i].info.name, data->localData[ringSegment]->realVars[i], sInfo->realVarsPre[i]);
}
RELEASE(LOG_DEBUG);
DEBUG4(stream, "%ld: %s = %g (pre: %g)", i+1, mData->realVarsData[i].info.name, data->localData[ringSegment]->realVars[i], sInfo->realVarsPre[i]);
RELEASE(stream);

DEBUG(LOG_DEBUG, "integer variables");
INDENT(LOG_DEBUG);
DEBUG(stream, "integer variables");
INDENT(stream);
for(i=0; i<mData->nVariablesInteger; ++i)
{
DEBUG4(LOG_DEBUG, "%ld: %s = %ld (pre: %ld)", i+1, mData->integerVarsData[i].info.name, data->localData[ringSegment]->integerVars[i], sInfo->integerVarsPre[i]);
}
RELEASE(LOG_DEBUG);
DEBUG4(stream, "%ld: %s = %ld (pre: %ld)", i+1, mData->integerVarsData[i].info.name, data->localData[ringSegment]->integerVars[i], sInfo->integerVarsPre[i]);
RELEASE(stream);

DEBUG(LOG_DEBUG, "boolean variables");
INDENT(LOG_DEBUG);
DEBUG(stream, "boolean variables");
INDENT(stream);
for(i=0; i<mData->nVariablesBoolean; ++i)
{
DEBUG4(LOG_DEBUG, "%ld: %s = %s (pre: %s)", i+1, mData->booleanVarsData[i].info.name, data->localData[ringSegment]->booleanVars[i] ? "true" : "false", sInfo->booleanVarsPre[i] ? "true" : "false");
}
RELEASE(LOG_DEBUG);
DEBUG4(stream, "%ld: %s = %s (pre: %s)", i+1, mData->booleanVarsData[i].info.name, data->localData[ringSegment]->booleanVars[i] ? "true" : "false", sInfo->booleanVarsPre[i] ? "true" : "false");
RELEASE(stream);

DEBUG(LOG_DEBUG, "string variables");
INDENT(LOG_DEBUG);
DEBUG(stream, "string variables");
INDENT(stream);
for(i=0; i<mData->nVariablesString; ++i)
{
DEBUG4(LOG_DEBUG, "%ld: %s = %s (pre: %s)", i+1, mData->stringVarsData[i].info.name, data->localData[ringSegment]->stringVars[i], sInfo->stringVarsPre[i]);
}
RELEASE(LOG_DEBUG);
DEBUG4(stream, "%ld: %s = %s (pre: %s)", i+1, mData->stringVarsData[i].info.name, data->localData[ringSegment]->stringVars[i], sInfo->stringVarsPre[i]);
RELEASE(stream);

RELEASE(LOG_DEBUG);
RELEASE(stream);
}
#endif


/*! \fn printParameters
*
* prints all parameter values
Expand Down Expand Up @@ -341,25 +316,46 @@ void printParameters(DATA *data, int stream)
RELEASE(stream);
}

/*! \fn printRelations
#ifdef USE_DEBUG_OUTPUT
/*! \fn printRelationsDebug
*
* print all relations
*
* \param [ref] [data]
* \param [in] [data]
* \param [in] [stream]
*/
void printRelationsDebug(DATA *data, int stream)
{
long i;

DEBUG(stream, "status of relations");
INDENT(stream);

for(i=0; i<data->modelData.nRelations; i++)
DEBUG5(stream, "[%ld] %s = %c | pre(%s) = %c", i, relationDescription[i], data->simulationInfo.relations[i] ? 'T' : 'F', relationDescription[i], data->simulationInfo.relationsPre[i] ? 'T' : 'F');

RELEASE(stream);
}
#endif

/*! \fn printRelations
*
* \author wbraun
* print all relations
*
* \param [in] [data]
* \param [in] [stream]
*/
void printRelations(DATA *data)
void printRelations(DATA *data, int stream)
{
long i;

DEBUG(LOG_EVENTS, "status of relations");
INDENT(LOG_EVENTS);
INFO(stream, "status of relations");
INDENT(stream);

for(i=0; i<data->modelData.nRelations; i++)
DEBUG5(LOG_EVENTS, "[%ld] %s = %c | pre(%s) = %c", i, relationDescription[i], data->simulationInfo.relations[i] ? 'T' : 'F', relationDescription[i], data->simulationInfo.relationsPre[i] ? 'T' : 'F');
INFO5(stream, "[%ld] %s = %c | pre(%s) = %c", i, relationDescription[i], data->simulationInfo.relations[i] ? 'T' : 'F', relationDescription[i], data->simulationInfo.relationsPre[i] ? 'T' : 'F');

RELEASE(LOG_EVENTS);
RELEASE(stream);
}

/*! \fn overwriteOldSimulationData
Expand Down Expand Up @@ -641,7 +637,6 @@ double getNextSampleTimeFMU(DATA *data)
return data->simulationInfo.nextSampleEvent;
}


return -1;
}

Expand Down
10 changes: 8 additions & 2 deletions SimulationRuntime/c/simulation/solver/model_help.h
Expand Up @@ -92,12 +92,18 @@ void saveZeroCrossings(DATA *data);

void copyStartValuestoInitValues(DATA *data);

/* functions that are only used in USE_DEBUG_OUTPUT mode */
#ifdef USE_DEBUG_OUTPUT
void printAllVarsDebug(DATA *data, int ringSegment);
void printAllVarsDebug(DATA *data, int ringSegment, int stream);
void printRelationsDebug(DATA *data, int stream);
#else
#define printAllVarsDebug(data, ringSegment, stream) {}
#define printRelationsDebug(data, stream) {}
#endif

void printAllVars(DATA *data, int ringSegment, int stream);
void printRelations(DATA *data, int stream);
void printParameters(DATA *data, int stream);
void printRelations(DATA *data);

void overwriteOldSimulationData(DATA *data);

Expand Down
10 changes: 3 additions & 7 deletions SimulationRuntime/c/simulation/solver/omp_perform_simulation.c
Expand Up @@ -112,9 +112,7 @@ int performSimulation(DATA* data, SOLVER_INFO* solverInfo)
free(filename);
}

#ifdef USE_DEBUG_OUTPUT
printAllVarsDebug(data, 0);
#endif
printAllVarsDebug(data, 0, LOG_DEBUG); /* ??? */

omp_set_num_threads(4);

Expand Down Expand Up @@ -156,7 +154,7 @@ int performSimulation(DATA* data, SOLVER_INFO* solverInfo)
solverInfo->currentStepSize = simInfo->stopTime - solverInfo->currentTime;
/***** End calculation next step size *****/

/* check for next sample event */
/* check for next time event */
checkForSampleEvent(data, solverInfo);
INFO3(LOG_SOLVER, "call solver from %g to %g (stepSize: %g)", solverInfo->currentTime, solverInfo->currentTime + solverInfo->currentStepSize, solverInfo->currentStepSize);

Expand Down Expand Up @@ -247,9 +245,7 @@ int performSimulation(DATA* data, SOLVER_INFO* solverInfo)
}
sim_result.emit(&sim_result,data);

#ifdef USE_DEBUG_OUTPUT
printAllVarsDebug(data, 0);
#endif
printAllVarsDebug(data, 0, LOG_DEBUG); /* ??? */

/***** end of Emit this time step *****/

Expand Down
10 changes: 3 additions & 7 deletions SimulationRuntime/c/simulation/solver/perform_simulation.c
Expand Up @@ -106,9 +106,7 @@ int performSimulation(DATA* data, SOLVER_INFO* solverInfo)
free(filename);
}

#ifdef USE_DEBUG_OUTPUT
printAllVarsDebug(data, 0);
#endif
printAllVarsDebug(data, 0, LOG_DEBUG); /* ??? */

/***** Start main simulation loop *****/
while(solverInfo->currentTime < simInfo->stopTime)
Expand Down Expand Up @@ -141,7 +139,7 @@ int performSimulation(DATA* data, SOLVER_INFO* solverInfo)
solverInfo->currentStepSize = simInfo->stopTime - solverInfo->currentTime;
/***** End calculation next step size *****/

/* check for next sample event */
/* check for next time event */
checkForSampleEvent(data, solverInfo);
INFO3(LOG_SOLVER, "call solver from %g to %g (stepSize: %g)", solverInfo->currentTime, solverInfo->currentTime + solverInfo->currentStepSize, solverInfo->currentStepSize);

Expand Down Expand Up @@ -226,9 +224,7 @@ int performSimulation(DATA* data, SOLVER_INFO* solverInfo)
}
sim_result.emit(&sim_result,data);

#ifdef USE_DEBUG_OUTPUT
printAllVarsDebug(data, 0);
#endif
printAllVarsDebug(data, 0, LOG_DEBUG); /* ??? */

/***** end of Emit this time step *****/

Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/c/simulation/solver/solver_main.c
Expand Up @@ -433,7 +433,7 @@ int finishSimulation(DATA* data, SOLVER_INFO* solverInfo, const char* outputVari
INFO(LOG_STATS, "events");
INDENT(LOG_STATS);
INFO1(LOG_STATS, "%5ld state events", solverInfo->stateEvents);
INFO1(LOG_STATS, "%5ld sample events", solverInfo->sampleEvents);
INFO1(LOG_STATS, "%5ld time events", solverInfo->sampleEvents);
RELEASE(LOG_STATS);

INFO(LOG_STATS, "solver");
Expand Down

0 comments on commit 58ac55d

Please sign in to comment.