suanPan
Converger.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright (C) 2017-2022 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 
42 class DomainBase;
43 
44 class 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;
56 protected:
57  [[nodiscard]] bool is_print() const;
58 
59 public:
60  explicit Converger(unsigned = 0, double = 1E-8, unsigned = 10, bool = false);
61  Converger(const Converger&) = default;
62  Converger(Converger&&) = default;
63  Converger& operator=(const Converger&) = delete;
65  ~Converger() override = default;
66 
67  virtual int initialize();
68 
69  virtual unique_ptr<Converger> get_copy() = 0;
70 
71  void set_tolerance(double);
72  [[nodiscard]] double get_tolerance() const;
73 
74  void set_max_iteration(unsigned);
75  [[nodiscard]] unsigned get_max_iteration() const;
76 
77  void set_domain(const weak_ptr<DomainBase>&);
78  [[nodiscard]] const weak_ptr<DomainBase>& get_domain() const;
79 
80  virtual void set_error(double);
81  [[nodiscard]] double get_error() const;
82 
83  virtual void set_conv_flag(bool);
84  [[nodiscard]] bool get_conv_flag() const;
85 
86  virtual bool is_converged() = 0;
87 };
88 
89 #endif
90 
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:99
void set_domain(const weak_ptr< DomainBase > &)
method to set DomainBase.
Definition: Converger.cpp:63
double get_tolerance() const
method to return tolerance.
Definition: Converger.cpp:53
const weak_ptr< DomainBase > & get_domain() const
method to return DomainBase.
Definition: Converger.cpp:69
virtual bool is_converged()=0
bool get_conv_flag() const
method to return conv_flag.
Definition: Converger.cpp:93
~Converger() override=default
Converger & operator=(const Converger &)=delete
virtual int initialize()
Definition: Converger.cpp:34
void set_tolerance(double)
method to set tolerance.
Definition: Converger.cpp:47
Converger(unsigned=0, double=1E-8, unsigned=10, bool=false)
the complete constructor.
Definition: Converger.cpp:28
Converger & operator=(Converger &&)=delete
virtual void set_error(double)
method to set error.
Definition: Converger.cpp:75
double get_error() const
method to return error.
Definition: Converger.cpp:81
virtual void set_conv_flag(bool)
method to set conv_flag.
Definition: Converger.cpp:87
unsigned get_max_iteration() const
Definition: Converger.cpp:57
Converger(const Converger &)=default
void set_max_iteration(unsigned)
Definition: Converger.cpp:55
Converger(Converger &&)=default
virtual unique_ptr< Converger > get_copy()=0
The DomainBase class is a template.
Definition: DomainBase.h:90
A base Tag class.
Definition: Tag.h:38