suanPan
Converger.h
Go to the documentation of this file.
1/*******************************************************************************
2 * Copyright (C) 2017-2024 Theodore Chang
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 ******************************************************************************/
37#ifndef CONVERGER_H
38#define CONVERGER_H
39
40#include <Domain/Tag.h>
41
42class DomainBase;
43
44class Converger : public Tag {
45 weak_ptr<DomainBase> database;
47 double tolerance;
49 unsigned max_iteration;
51 const bool print_flag;
53 double error = 0.;
55 bool conv_flag = false;
56protected:
57 [[nodiscard]] vec get_residual() const;
58
59 [[nodiscard]] bool is_print() const;
60
61public:
62 explicit Converger(unsigned = 0, double = 1E-8, unsigned = 10, bool = false);
63 Converger(const Converger&) = default;
64 Converger(Converger&&) = default;
65 Converger& operator=(const Converger&) = delete;
67 ~Converger() override = default;
68
69 virtual int initialize();
70
71 virtual unique_ptr<Converger> get_copy() = 0;
72
73 void set_tolerance(double);
74 [[nodiscard]] double get_tolerance() const;
75
76 void set_max_iteration(unsigned);
77 [[nodiscard]] unsigned get_max_iteration() const;
78
79 void set_domain(const weak_ptr<DomainBase>&);
80 [[nodiscard]] const weak_ptr<DomainBase>& get_domain() const;
81
82 virtual void set_error(double);
83 [[nodiscard]] double get_error() const;
84
85 virtual void set_conv_flag(bool);
86 [[nodiscard]] bool get_conv_flag() const;
87
88 virtual bool is_converged(unsigned) = 0;
89};
90
91#endif
92
The Converger class handles converger test to indicate if the iteration converges according to variou...
Definition: Converger.h:44
bool is_print() const
method to return print_flag.
Definition: Converger.cpp:112
Converger & operator=(Converger &&)=delete
void set_domain(const weak_ptr< DomainBase > &)
method to set DomainBase.
Definition: Converger.cpp:64
double get_tolerance() const
method to return tolerance.
Definition: Converger.cpp:54
const weak_ptr< DomainBase > & get_domain() const
method to return DomainBase.
Definition: Converger.cpp:70
virtual unique_ptr< Converger > get_copy()=0
virtual bool is_converged(unsigned)=0
bool get_conv_flag() const
method to return conv_flag.
Definition: Converger.cpp:94
~Converger() override=default
virtual int initialize()
Definition: Converger.cpp:35
void set_tolerance(double)
method to set tolerance.
Definition: Converger.cpp:48
Converger & operator=(const Converger &)=delete
Converger(unsigned=0, double=1E-8, unsigned=10, bool=false)
the complete constructor.
Definition: Converger.cpp:29
vec get_residual() const
Definition: Converger.cpp:96
virtual void set_error(double)
method to set error.
Definition: Converger.cpp:76
double get_error() const
method to return error.
Definition: Converger.cpp:82
virtual void set_conv_flag(bool)
method to set conv_flag.
Definition: Converger.cpp:88
unsigned get_max_iteration() const
Definition: Converger.cpp:58
Converger(const Converger &)=default
void set_max_iteration(unsigned)
Definition: Converger.cpp:56
Converger(Converger &&)=default
The DomainBase class is a template.
Definition: DomainBase.h:104
A base Tag class.
Definition: Tag.h:38