Skip to content
Snippets Groups Projects
Commit 178b3888 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

simplify progress handler code

parent d0affdce
No related branches found
No related tags found
1 merge request!1276rm ISimulation::compute
...@@ -14,12 +14,15 @@ ...@@ -14,12 +14,15 @@
#include "Base/Progress/DelayedProgressCounter.h" #include "Base/Progress/DelayedProgressCounter.h"
#include "Base/Progress/ProgressHandler.h" #include "Base/Progress/ProgressHandler.h"
#include <stdexcept>
DelayedProgressCounter::DelayedProgressCounter(ProgressHandler* p_progress, size_t interval) DelayedProgressCounter::DelayedProgressCounter(ProgressHandler* progress, size_t interval)
: m_progress(p_progress) : m_progress(progress)
, m_interval(interval) , m_interval(interval)
, m_count(0) , m_count(0)
{ {
if (!progress->alive())
throw std::runtime_error("dead process (user interrupt?)");
} }
void DelayedProgressCounter::stepProgress() void DelayedProgressCounter::stepProgress()
......
...@@ -26,7 +26,7 @@ class ProgressHandler; ...@@ -26,7 +26,7 @@ class ProgressHandler;
class DelayedProgressCounter { class DelayedProgressCounter {
public: public:
DelayedProgressCounter(ProgressHandler* p_progress, size_t interval); DelayedProgressCounter(ProgressHandler* progress, size_t interval);
~DelayedProgressCounter() = default; ~DelayedProgressCounter() = default;
//! Increments inner counter; at regular intervals updates progress handler. //! Increments inner counter; at regular intervals updates progress handler.
......
...@@ -43,8 +43,6 @@ DWBAComputation::~DWBAComputation() = default; ...@@ -43,8 +43,6 @@ DWBAComputation::~DWBAComputation() = default;
void DWBAComputation::runProtected() void DWBAComputation::runProtected()
{ {
for (auto it = m_begin_it; it != m_end_it; ++it) { for (auto it = m_begin_it; it != m_end_it; ++it) {
if (!m_progress->alive())
break;
DiffuseElement& ele = *it; DiffuseElement& ele = *it;
const Fluxes fluxes_in = m_re_sample.fluxesIn(ele.getKi()); const Fluxes fluxes_in = m_re_sample.fluxesIn(ele.getKi());
......
...@@ -21,29 +21,20 @@ IComputation::IComputation(const ReSample& re_sample, const SimulationOptions& o ...@@ -21,29 +21,20 @@ IComputation::IComputation(const ReSample& re_sample, const SimulationOptions& o
ProgressHandler& progress) ProgressHandler& progress)
: m_re_sample(re_sample) : m_re_sample(re_sample)
, m_options(options) , m_options(options)
, m_progress(&progress) , m_progress_counter(std::make_unique<DelayedProgressCounter>(&progress, 100))
{ {
} }
IComputation::~IComputation() = default; IComputation::~IComputation() = default;
void IComputation::setProgressHandler(ProgressHandler* progress) const
{
m_progress_counter = std::make_unique<DelayedProgressCounter>(progress, 100);
}
void IComputation::stepProgress() const void IComputation::stepProgress() const
{ {
if (m_progress_counter) m_progress_counter->stepProgress();
m_progress_counter->stepProgress();
} }
void IComputation::compute() void IComputation::compute()
{ {
try { try {
if (!m_progress->alive())
return;
setProgressHandler(m_progress);
runProtected(); // <--- here the main work is done runProtected(); // <--- here the main work is done
......
...@@ -44,12 +44,10 @@ public: ...@@ -44,12 +44,10 @@ public:
std::string errorMessage() const { return m_errorMessage; } std::string errorMessage() const { return m_errorMessage; }
protected: protected:
void setProgressHandler(ProgressHandler* progress) const;
void stepProgress() const; void stepProgress() const;
const ReSample& m_re_sample; const ReSample& m_re_sample;
const SimulationOptions& m_options; const SimulationOptions& m_options;
ProgressHandler* m_progress;
private: private:
//! Runs computation. May throw. To be called from runProtected(), which catches exceptions. //! Runs computation. May throw. To be called from runProtected(), which catches exceptions.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment