Skip to content

Commit

Permalink
Simulation support: properly handle the generation of elapsed time (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed May 1, 2018
1 parent ae46194 commit a6b822a
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/plugins/miscellaneous/Core/src/centralwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ void CentralWidget::reloadFile(int pIndex, bool pForce)
// that the corresponding simulation, if any, has been stopped

if (mSimulationInterface)
mSimulationInterface->stop(fileName);
mSimulationInterface->stop(fileName, false);

// Actually redownload the file, if it is a remote one

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3123,16 +3123,9 @@ void SimulationExperimentViewSimulationWidget::simulationPaused()

void SimulationExperimentViewSimulationWidget::simulationStopped(qint64 pElapsedTime)
{
// Output the given elapsed time, if our simulation's runtime is still valid
// and if its elapsed time is valid
// Note: to check whether our simulation's runtime is still valid is needed
// in case we, for example, ran a SED-ML file and then modified its
// corresponding CellML file (and made it invalid), resulting in the
// simulation being stopped and the SED-ML file being reloaded.
// However, because the simulation's runtime won't be valid anymore,
// we don't need (and don't want) to output the simulation time...

if (mSimulation->runtime()->isValid() && (pElapsedTime != -1)) {
// Output the given elapsed time, if valid

if (pElapsedTime != -1) {
QString solversInformation = mSimulation->data()->odeSolverName();

if (!mSimulation->data()->nlaSolverName().isEmpty())
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/simulationinterface.inl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// Note: make sure to update simulationInterfaceVersion() whenever you
// update this interface...

virtual void stop(const QString &pFileName) PURE;
virtual void stop(const QString &pFileName, bool pElapsedTime) PURE;

#undef PURE

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/support/SimulationSupport/src/simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1117,11 +1117,11 @@ bool Simulation::resume()

//==============================================================================

bool Simulation::stop()
bool Simulation::stop(bool pElapsedTime)
{
// Stop our worker

return mWorker?mWorker->stop():false;
return mWorker?mWorker->stop(pElapsedTime):false;
}

//==============================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/support/SimulationSupport/src/simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class SIMULATIONSUPPORT_EXPORT Simulation : public QObject
bool run();
bool pause();
bool resume();
bool stop();
bool stop(bool pElapsedTime = true);

bool reset();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ void SimulationManager::unmanage(const QString &pFileName)

//==============================================================================

void SimulationManager::stop(const QString &pFileName)
void SimulationManager::stop(const QString &pFileName, bool pElapsedTime)
{
// Check whether we are already managing the corresponding simulation and,
// if so, stop it

Simulation *crtSimulation = simulation(pFileName);

if (crtSimulation)
crtSimulation->stop();
crtSimulation->stop(pElapsedTime);
}

//==============================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class SIMULATIONSUPPORT_EXPORT SimulationManager : public QObject
void manage(const QString &pFileName);
void unmanage(const QString &pFileName);

void stop(const QString &pFileName);
void stop(const QString &pFileName, bool pElapsedTime);

void save(const QString &pFileName);
void reload(const QString &pFileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ void SimulationSupportPlugin::retranslateUi()
// Simulation interface
//==============================================================================

void SimulationSupportPlugin::stop(const QString &pFileName)
void SimulationSupportPlugin::stop(const QString &pFileName, bool pElapsedTime)
{
// Stop the simulation for the given file

SimulationManager::instance()->stop(pFileName);
SimulationManager::instance()->stop(pFileName, pElapsedTime);
}

//==============================================================================
Expand Down
21 changes: 14 additions & 7 deletions src/plugins/support/SimulationSupport/src/simulationworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ SimulationWorker::SimulationWorker(Simulation *pSimulation,
mRuntime(pSimulation->runtime()),
mCurrentPoint(0.0),
mPaused(false),
mStopped(false),
mStoppedWithElapsedTime(false),
mStoppedWithNoElapsedTime(false),
mReset(false),
mError(false),
mSelf(pSelf)
Expand Down Expand Up @@ -152,14 +153,17 @@ bool SimulationWorker::resume()

//==============================================================================

bool SimulationWorker::stop()
bool SimulationWorker::stop(bool pElapsedTime)
{
// Check that we are either running or paused

if (isRunning() || isPaused()) {
// Ask our thread to stop

mStopped = true;
if (pElapsedTime)
mStoppedWithElapsedTime = true;
else
mStoppedWithNoElapsedTime = true;

// Resume our thread, if needed

Expand Down Expand Up @@ -219,7 +223,9 @@ void SimulationWorker::started()

// Keep track of any error that might be reported by any of our solvers

mStopped = false;
mStoppedWithElapsedTime = false;
mStoppedWithNoElapsedTime = false;

mError = false;

connect(odeSolver, &Solver::OdeSolver::error,
Expand Down Expand Up @@ -318,7 +324,8 @@ void SimulationWorker::started()

// Some post-processing, if needed

if ((mCurrentPoint == endingPoint) || mStopped) {
if ( (mCurrentPoint == endingPoint)
|| mStoppedWithElapsedTime|| mStoppedWithNoElapsedTime) {
// We have reached our ending point or we have been asked to
// stop, so leave our main work loop

Expand Down Expand Up @@ -364,7 +371,7 @@ void SimulationWorker::started()

// Retrieve the total elapsed time, should no error have occurred

if (!mError)
if (!mError && !mStoppedWithNoElapsedTime)
elapsedTime += timer.elapsed();
}

Expand All @@ -387,7 +394,7 @@ void SimulationWorker::started()

// Let people know that we are done and give them the elapsed time

emit finished(mError?-1:elapsedTime);
emit finished((mError || mStoppedWithNoElapsedTime)?-1:elapsedTime);
}

//==============================================================================
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/support/SimulationSupport/src/simulationworker.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class SimulationWorker : public QObject
bool run();
bool pause();
bool resume();
bool stop();
bool stop(bool pReloaded);

bool reset();

Expand All @@ -78,7 +78,9 @@ class SimulationWorker : public QObject
double mCurrentPoint;

bool mPaused;
bool mStopped;

bool mStoppedWithElapsedTime;
bool mStoppedWithNoElapsedTime;

bool mReset;

Expand Down

0 comments on commit a6b822a

Please sign in to comment.