GooseFEM 1.4.1.dev2+g78f16df
Loading...
Searching...
No Matches
Iterate.h
Go to the documentation of this file.
1
9#ifndef GOOSEFEM_ITERATE_H
10#define GOOSEFEM_ITERATE_H
11
12#include "config.h"
13
14namespace GooseFEM {
15
19namespace Iterate {
20
27class StopList {
28public:
34 StopList(size_t n = 1)
35 {
36 m_res.resize(n);
37 reset();
38 }
39
43 void reset()
44 {
45 std::fill(m_res.begin(), m_res.end(), std::numeric_limits<double>::infinity());
46 }
47
53 void reset(size_t n)
54 {
55 m_res.resize(n);
56 reset();
57 }
58
69 void roll_insert(double res)
70 {
71 std::rotate(m_res.begin(), m_res.begin() + 1, m_res.end());
72 m_res.back() = res;
73 }
74
80 bool descending() const
81 {
82 return std::is_sorted(m_res.cbegin(), m_res.cend(), std::greater<double>());
83 }
84
91 bool all_less(double tol) const
92 {
93 return !std::any_of(m_res.cbegin(), m_res.cend(), [=](const auto& i) { return i >= tol; });
94 }
95
99 const std::vector<double>& data() const
100 {
101 return m_res;
102 }
103
107 [[deprecated]]
108 const std::vector<double>& get() const
109 {
110 return m_res;
111 }
112
113private:
114 std::vector<double> m_res;
115};
116
117} // namespace Iterate
118} // namespace GooseFEM
119
120#endif
Class to perform a residual check based on the last "n" iterations.
Definition Iterate.h:27
void roll_insert(double res)
Roll the list with the residuals, and add a new residual to the end.
Definition Iterate.h:69
bool all_less(double tol) const
Check of the sequence of n residuals are all below a tolerance.
Definition Iterate.h:91
const std::vector< double > & get() const
Get the historic residuals.
Definition Iterate.h:108
bool descending() const
Check of the sequence of n residuals is in descending order.
Definition Iterate.h:80
StopList(size_t n=1)
Constructor.
Definition Iterate.h:34
void reset(size_t n)
Reset all residuals to infinity, and change the number of residuals to check.
Definition Iterate.h:53
void reset()
Reset all residuals to infinity.
Definition Iterate.h:43
const std::vector< double > & data() const
Get the historic residuals.
Definition Iterate.h:99
Basic configuration:
Toolbox to perform finite element computations.
Definition Allocate.h:14
auto AsTensor(const T &arg, const S &shape)
"Broadcast" a scalar stored in an array (e.g.
Definition Allocate.h:167