hp-FEM
Adaptive hp-FEM suite for nano-optics
Loading...
Searching...
No Matches
progress.hpp
Go to the documentation of this file.
1#pragma once
8#include <chrono>
9#include <functional>
10#include <map>
11#include <string>
12#include <vector>
13
14#include "hpfem/core/error.hpp"
15
16namespace hpfem {
17
20 std::string phase;
21 int step = 0;
22 int num_steps = 0;
23 double seconds = 0;
24};
25
28using ProgressCallback = std::function<bool(const ProgressEvent&)>;
29
31using Timing = std::map<std::string, double>;
32
34class Cancelled : public Error {
35 public:
36 using Error::Error;
37};
38
43 public:
44 ProgressReporter(ProgressCallback callback, std::vector<std::string> phases);
46 void begin(int step);
48 [[nodiscard]] Timing finish();
49
50 private:
51 using Clock = std::chrono::steady_clock;
52 [[nodiscard]] double elapsed() const;
53 void close_current();
54 ProgressCallback callback_;
55 std::vector<std::string> phases_;
56 Clock::time_point start_ = Clock::now();
57 Clock::time_point phase_start_ = Clock::now();
58 int current_ = -1;
59 Timing timing_;
60};
61
62} // namespace hpfem
Thrown by a solve whose progress callback returned false.
Definition progress.hpp:34
Definition error.hpp:10
Definition progress.hpp:42
void begin(int step)
ProgressReporter(ProgressCallback callback, std::vector< std::string > phases)
Definition axisymmetric_estimator.hpp:39
std::map< std::string, double > Timing
Wall-clock seconds per phase by name, plus "total".
Definition progress.hpp:31
std::function< bool(const ProgressEvent &)> ProgressCallback
Definition progress.hpp:28
A phase of a solve starting (or, with step == num_steps, the solve being done).
Definition progress.hpp:19
int num_steps
phases of this solve
Definition progress.hpp:22
std::string phase
"assembly", "constraints", "factorisation", "solve", "post", "done"
Definition progress.hpp:20
double seconds
wall-clock seconds since the solve began
Definition progress.hpp:23
int step
index of the phase, 0-based; num_steps when done
Definition progress.hpp:21