BubbleProfiler  0.3.0
by Peter Athron, Csaba Balazs, Michael Bardsley, Andrew Fowlie, Dylan Harries & Graham White
relative_convergence_tester.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of BubbleProfiler.
3  *
4  * BubbleProfiler 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  * BubbleProfiler 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 BubbleProfiler. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef BUBBLEPROFILER_RELATIVE_CONVERGENCE_TESTER_HPP_INCLUDED
19 #define BUBBLEPROFILER_RELATIVE_CONVERGENCE_TESTER_HPP_INCLUDED
20 
21 #include "basic_logger.hpp"
23 
24 #include <Eigen/Core>
25 
26 #include <vector>
27 
28 namespace BubbleProfiler {
29 
41 public:
45  Relative_convergence_tester() = default;
46 
59  explicit Relative_convergence_tester(double tol);
60 
74  Relative_convergence_tester(double action_tol, double fields_tol);
77  virtual ~Relative_convergence_tester() = default;
80 
91  virtual bool is_converged(
92  const Potential& potential, const Field_profiles& profiles) override;
93 
103  virtual int get_max_iterations() const override { return max_iterations; }
104 
108  virtual void restart() override;
109 
114  void set_max_iterations(int it) { max_iterations = it; }
115 
116 private:
118  int max_iterations{10};
119  double action_relative_tol{1.e-4};
120  double field_vals_relative_tol{1.e-4};
121  double old_action{0.};
122  Eigen::VectorXd old_field_vals{};
124 
125  int calculate_max_iterations() const;
126  double relative_difference(double, double) const;
127  bool check_action_converged(double) const;
128  bool check_fields_converged(double, const Eigen::VectorXd&) const;
129 };
130 
131 } // namespace BubbleProfiler
132 
133 #endif
virtual bool is_converged(const Potential &potential, const Field_profiles &profiles) override
Check whether the candidate bubble solution has converged.
bool check_fields_converged(double, const Eigen::VectorXd &) const
virtual void restart() override
Restart the convergence tester to the start of the iteration.
Relative_convergence_tester()=default
Construct relative convergence tester with default tolerances.
virtual int get_max_iterations() const override
Return the maximum number of iterations allowed.
Relative_convergence_tester & operator=(const Relative_convergence_tester &)=default
void set_max_iterations(int it)
Set the maximum number of iterations allowed.
Abstract base class for a generic potential.
Definition: potential.hpp:36
Discretized set of field profiles.