Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F65735202
Iterate.hpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Jun 5, 21:09
Size
1 KB
Mime Type
text/x-c
Expires
Fri, Jun 7, 21:09 (2 d)
Engine
blob
Format
Raw Data
Handle
17893081
Attached To
rGOOSEFEM GooseFEM
Iterate.hpp
View Options
/*
(c - GPLv3) T.W.J. de Geus (Tom) | tom@geus.me | www.geus.me | github.com/tdegeus/GooseFEM
*/
#ifndef GOOSEFEM_ITERATE_HPP
#define GOOSEFEM_ITERATE_HPP
#include "Iterate.h"
namespace GooseFEM {
namespace Iterate {
inline StopList::StopList(size_t n)
{
m_res.resize(n);
reset();
}
inline void StopList::reset()
{
for (auto& i : m_res) {
i = std::numeric_limits<double>::infinity();
}
}
inline void StopList::reset(size_t n)
{
m_res.resize(n);
reset();
}
inline bool StopList::stop(double res, double tol)
{
// move residual one place back (forgetting the first)
for (size_t i = 1; i < m_res.size(); ++i) {
m_res[i - 1] = m_res[i];
}
// add new residual to the end
m_res[m_res.size() - 1] = res;
// check for convergence: all residuals should be below the tolerance
for (size_t i = 0; i < m_res.size(); ++i) {
if (m_res[i] > tol) {
return false;
}
}
// check for convergence: all residuals should be decreasing
for (size_t i = 1; i < m_res.size(); ++i) {
if (m_res[i] > m_res[i - 1]) {
return false;
}
}
// all checks passed: signal convergence
return true;
}
} // namespace Iterate
} // namespace GooseFEM
#endif
Event Timeline
Log In to Comment