Skip to content

Commit

Permalink
fix: reinitialization after stopSimulation
Browse files Browse the repository at this point in the history
fix: wrong references on ssdArray
update: setResultData and getResultData
update: resetSSDArrayWithNullSSD
update: initializeSSD_AND_SRDF

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9071 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Parham Vasaiely authored and Parham Vasaiely committed May 22, 2011
1 parent 6ff0245 commit b57d7e4
Show file tree
Hide file tree
Showing 5 changed files with 437 additions and 416 deletions.
25 changes: 5 additions & 20 deletions c_runtime/interactive/omi_Calculation.cpp
Expand Up @@ -89,12 +89,6 @@ int calculate() {
if (simulationStatus == SimulationStatus::SHUTDOWN) {
// If the simulation should stop, unlock and break out of the loop.
mutexSimulationStatus->Unlock();
if (debugCalculation) {
cout
<< "Calculation:\tFunct.: calculate\tMessage: Simulation Stopped set forZero = true"
<< endl;
fflush( stdout);
}
break;
}

Expand All @@ -116,28 +110,20 @@ int calculate() {
forZero = false;
} else {
//TODO 20100210 pv testing rungekutter...
if (method == std::string("euler") || method == std::string(
"rungekutta") || method == std::string("dassl")) {
if (method == std::string("euler") || method == std::string("rungekutta") || method == std::string("dassl")) {
stop = get_timeValue() + stepSize;
start = get_timeValue();
if (debugCalculation) {
cout
<< "Calculation:\tFunct.: calculate\tData 2: p_SimStepData_from_Calculation->forTimeStep: "
<< p_SimStepData_from_Calculation->forTimeStep
<< " --------------------" << endl;
fflush( stdout);
cout << "Calculation:\tFunct.: calculate\tData 3: start "
<< start << " stop: " << stop << endl;
fflush(stdout);
cout << "Calculation:\tFunct.: calculate\tData 2: p_SimStepData_from_Calculation->forTimeStep: " << p_SimStepData_from_Calculation->forTimeStep << " ------" << endl; fflush( stdout);
cout << "Calculation:\tFunct.: calculate\tData 3: start " << start << " stop: " << stop << endl; fflush(stdout);
}
} else {
stop = get_lastEmittedTime() + stepSize;
start = get_lastEmittedTime();
}
}

retVal = callSolverFromOM(method, outputFormat, start, stop, stepSize,
outputSteps, tolerance);
retVal = callSolverFromOM(method, outputFormat, start, stop, stepSize, outputSteps, tolerance);

if (retVal != 0) {
cout << "Calculation:\tFunct.: calculate\tMessage: omi_Calculation: error occurred while calculating" << endl; fflush( stdout);
Expand All @@ -163,8 +149,7 @@ int calculate() {
* Asks the ServiceInterface for the last simulation results to put into the simulation step data structure
*/
void createSSDEntry(string method) {
fillSimulationStepDataWithValuesFromGlobalData(method,
p_SimStepData_from_Calculation);
fillSimulationStepDataWithValuesFromGlobalData(method, p_SimStepData_from_Calculation);

p_sdnMutex->Lock();
long nStates = p_simdatanumbers->nStates;
Expand Down
12 changes: 10 additions & 2 deletions c_runtime/interactive/omi_Control.cpp
Expand Up @@ -58,7 +58,7 @@ bool initDone = false; //True if initialization is done
bool clientDone = false; //True if client ip and port was configured
bool transferDone = false; //True if transfer ip and port was configured

SimulationStatus::type simulationStatus = SimulationStatus::PAUSED;
SimulationStatus::type simulationStatus = SimulationStatus::STOPPED;
Mutex mutexSimulationStatus_;
Mutex* mutexSimulationStatus = &mutexSimulationStatus_;
Semaphore waitForResume_(0, NUMBER_PRODUCER + NUMBER_CONSUMER);
Expand Down Expand Up @@ -291,7 +291,7 @@ void reInitAll() {
}
setGlobalSimulationValuesFromSimulationStepData(p_ssdAtSimulationTime);
resetSRDFAfterChangetime(); //Resets the SRDF Array and the producer and consumer semaphores
resetSSDArrayWithNullSSD(); //overrides all SSD Slots with nullSSD elements
resetSSDArrayWithNullSSD(nStates, nAlgebraic, nParameters); //overrides all SSD Slots with nullSSD elements
if (debugLevelControl > 0)
{
cout << "Control:\tFunct.: reInitAll\tData: globalData->lastEmittedTime: " << get_lastEmittedTime() << endl; fflush(stdout);
Expand Down Expand Up @@ -478,11 +478,19 @@ void stopSimulation(void) {
{
pauseSimulation();

// Is this necessary anymore?
lockMutexSSD();
denied_work_on_GD();

reInitAll();

mutexSimulationStatus->Lock();
simulationStatus = SimulationStatus::STOPPED;
mutexSimulationStatus->Unlock();

allow_work_on_GD();
releaseMutexSSD();

status = "stop";

cout << "Control:\tFunct.: stopSimulation\tMessage: stop done" << endl; fflush(stdout);
Expand Down

0 comments on commit b57d7e4

Please sign in to comment.