Commit 395f1b3c by Praetorius, Simon

### cleanup for updated dune-* modules

parent 3c2194bd
Pipeline #142 failed with stage
 // Software License for MTL // // Copyright (c) 2007 The Trustees of Indiana University. // 2008 Dresden University of Technology and the Trustees of Indiana University. // 2010 SimuNova UG (haftungsbeschränkt), www.simunova.com. // All rights reserved. // Authors: Peter Gottschling and Andrew Lumsdaine // // This file is part of the Matrix Template Library // // See also license.mtl.txt in the distribution. #ifndef ITL_BASIC_ITERATION_INCLUDE #define ITL_BASIC_ITERATION_INCLUDE #include #include #include namespace itl { template class basic_iteration { public: typedef basic_iteration self; typedef Real real; template basic_iteration(const Vector& r0, int max_iter_, Real t, Real a = Real(0)) : error(0), i(0), norm_r0(std::abs(two_norm(r0))), max_iter(max_iter_), rtol_(t), atol_(a), is_finished(false), my_quite(false), my_suppress(false) { } basic_iteration(Real nb, int max_iter_, Real t, Real a = Real(0)) : error(0), i(0), norm_r0(nb), max_iter(max_iter_), rtol_(t), atol_(a), is_finished(false), my_quite(false), my_suppress(false) {} virtual ~basic_iteration() {} bool check_max() { if (i >= max_iter) error= 1, is_finished= true, err_msg= "Too many iterations."; return is_finished; } template bool finished(const Vector& r) { if (converged(two_norm(r))) return is_finished= true; return check_max(); } bool finished(const Real& r) { if (converged(r)) return is_finished= true; return check_max(); } template bool finished(const std::complex& r) { if (converged(std::abs(r))) return is_finished= true; return check_max(); } bool finished() const { return is_finished; } template int terminate(const T& r) { finished(r); return error; } bool converged(const Real& r) { resid_= r; return converged(); } bool converged() const { if (norm_r0 == 0) return resid_ <= atol_; // ignore relative tolerance if |r0| is zero return resid_ <= rtol_ * norm_r0 || resid_ <= atol_; } self& operator++() { ++i; return *this; } self& operator+=(int n) { i+= n; return *this; } bool first() const { return i <= 1; } virtual operator int() const { return error; } virtual int error_code() const { return error; } bool is_converged() const { return is_finished && error == 0; } int iterations() const { return i; } int max_iterations() const { return max_iter; } void set_max_iterations(int m) { max_iter= m; } Real resid() const { return resid_; } Real relresid() const { return resid_ / norm_r0; } Real normb() const { return norm_r0; } Real tol() const { return rtol_; } Real atol() const { return atol_; } int fail(int err_code) { error = err_code; return error_code(); } int fail(int err_code, const std::string& msg) { error = err_code; err_msg = msg; return error_code(); } void set(Real v) { norm_r0 = v; } void set_quite(bool q) { my_quite= q; } bool is_quite() const { return my_quite; } void suppress_resume(bool s) { my_suppress= s; } bool resume_suppressed() const { return my_suppress; } void update_progress(const basic_iteration& that) { i= that.i; resid_= that.resid_; if (that.error > 1) { // copy error except too many iterations error= that.error; err_msg= that.err_msg; is_finished= true; } else finished(resid_); } protected: int error, i; Real norm_r0; int max_iter; Real rtol_, atol_, resid_; std::string err_msg; bool is_finished, my_quite, my_suppress; }; } // namespace itl #endif // ITL_BASIC_ITERATION_INCLUDE
 // Software License for MTL // // Copyright (c) 2007 The Trustees of Indiana University. // 2008 Dresden University of Technology and the Trustees of Indiana University. // 2010 SimuNova UG (haftungsbeschränkt), www.simunova.com. // All rights reserved. // Authors: Peter Gottschling and Andrew Lumsdaine // // This file is part of the Matrix Template Library2 // // See also license.mtl.txt in the distribution. #ifndef ITL_CYCLIC_ITERATION_INCLUDE #define ITL_CYCLIC_ITERATION_INCLUDE #include #include namespace itl { /// Class for iteration control that cyclically prints residual template class cyclic_iteration : public basic_iteration { typedef basic_iteration super; typedef cyclic_iteration self; void print_resid() { if (!this->my_quite && this->i % cycle == 0) if (multi_print || this->i != last_print) { // Avoid multiple print-outs in same iteration out << "iteration " << this->i << ": resid " << this->resid() // << " / " << this->norm_r0 << " = " << this->resid() / this->norm_r0 << " (rel. error)" << std::endl; last_print= this->i; } } public: template cyclic_iteration(const Vector& r0, int max_iter_, Real tol_, Real atol_ = Real(0), int cycle_ = 100, OStream& out = std::cout) : super(r0, max_iter_, tol_, atol_), cycle(cycle_), last_print(-1), multi_print(false), out(out) {} cyclic_iteration(Real r0, int max_iter_, Real tol_, Real atol_ = Real(0), int cycle_ = 100, OStream& out = std::cout) : super(r0, max_iter_, tol_, atol_), cycle(cycle_), last_print(-1), multi_print(false), out(out) {} bool finished() { return super::finished(); } template bool finished(const T& r) { bool ret= super::finished(r); print_resid(); return ret; } inline self& operator++() { ++this->i; return *this; } inline self& operator+=(int n) { this->i+= n; return *this; } operator int() const { return error_code(); } /// Whether the residual is printed multiple times in iteration bool is_multi_print() const { return multi_print; } /// Set whether the residual is printed multiple times in iteration void set_multi_print(bool m) { multi_print= m; } int error_code() const { if (!this->my_suppress) out << "finished! error code = " << this->error << '\n' << this->iterations() << " iterations\n" << this->resid() << " is actual final residual. \n" << this->relresid() << " is actual relative tolerance achieved. \n" << "Relative tol: " << this->rtol_ << " Absolute tol: " << this->atol_ << '\n' << "Convergence: " << pow(this->relresid(), 1.0 / double(this->iterations())) << std::endl; return this->error; } protected: int cycle, last_print; bool multi_print; OStream& out; }; } // namespace itl #endif // ITL_CYCLIC_ITERATION_INCLUDE
 // Software License for MTL // // Copyright (c) 2007 The Trustees of Indiana University. // 2008 Dresden University of Technology and the Trustees of Indiana University. // 2010 SimuNova UG (haftungsbeschränkt), www.simunova.com. // All rights reserved. // Authors: Peter Gottschling and Andrew Lumsdaine // // This file is part of the Matrix Template Library // // See also license.mtl.txt in the distribution. #ifndef ITL_NOISY_ITERATION_INCLUDE #define ITL_NOISY_ITERATION_INCLUDE #include #include namespace itl { template class noisy_iteration : public cyclic_iteration { public: template noisy_iteration(const Vector& r0, int max_iter_, Real tol_, Real atol_ = Real(0), OStream& out = std::cout) : cyclic_iteration(r0, max_iter_, tol_, atol_, 1, out) {} }; } // namespace itl #endif // ITL_NOISY_ITERATION_INCLUDE
 // Software License for MTL // // Copyright (c) 2007 The Trustees of Indiana University. // 2008 Dresden University of Technology and the Trustees of Indiana University. // 2010 SimuNova UG (haftungsbeschränkt), www.simunova.com. // All rights reserved. // Authors: Peter Gottschling and Andrew Lumsdaine // // This file is part of the Matrix Template Library // // See also license.mtl.txt in the distribution. #ifndef ITL_ITL_INCLUDE #define ITL_ITL_INCLUDE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #endif // ITL_ITL_INCLUDE