FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
iterative.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8// includes, FEAT
9#include <kernel/solver/base.hpp>
10#include <kernel/util/dist.hpp>
11#include <kernel/util/property_map.hpp>
12#include <kernel/util/statistics.hpp>
13
14namespace FEAT
15{
16 namespace Solver
17 {
19 namespace Intern
20 {
22 template<typename Matrix_>
23 const Dist::Comm* get_mat_comm(const Matrix_& mat, typename Matrix_::GateRowType*)
24 {
25 return mat.get_comm();
26 }
27
28 template<typename Matrix_>
29 const Dist::Comm* get_mat_comm(const Matrix_&, ...)
30 {
31 return nullptr;
32 }
33
35 template<typename Vector_>
36 const Dist::Comm* get_vec_comm(const Vector_& vec, typename Vector_::GateType*)
37 {
38 return vec.get_comm();
39 }
40
41 template<typename Vector_>
42 const Dist::Comm* get_vec_comm(const Vector_&, ...)
43 {
44 return nullptr;
45 }
46 } // namespace Intern
48
53 enum class PlotMode
54 {
56 none = 0,
58 iter,
60 summary,
62 all
63 };
64
66 inline std::ostream& operator<<(std::ostream& os, PlotMode mode)
67 {
68 switch(mode)
69 {
70 case PlotMode::none:
71 return os << "none";
72 case PlotMode::iter:
73 return os << "iter";
75 return os << "summary";
76 case PlotMode::all:
77 return os << "all";
78 default:
79 return os << "-unknown-";
80 }
81 }
82
83 inline std::istream& operator>>(std::istream& is, PlotMode& mode)
84 {
85 String s;
86 if((is >> s).fail())
87 return is;
88
89 if(s.compare_no_case("none") == 0)
90 mode = PlotMode::none;
91 else if(s.compare_no_case("iter") == 0)
92 mode = PlotMode::iter;
93 else if(s.compare_no_case("summary") == 0)
94 mode = PlotMode::summary;
95 else if(s.compare_no_case("all") == 0)
96 mode = PlotMode::all;
97 else
98 is.setstate(std::ios_base::failbit);
99
100 return is;
101 }
103
195 template<typename Vector_>
197 public SolverBase<Vector_>
198 {
199 public:
201 typedef Vector_ VectorType;
203 typedef typename VectorType::DataType DataType;
206
207 protected:
250
270 explicit IterativeSolver(const String& plot_name) :
271 BaseClass(),
272 _comm(nullptr),
273 _plot_name(plot_name),
275 _tol_rel(Math::sqrt(Math::eps<DataType>())),
276 _tol_abs(DataType(1) / Math::sqr(Math::eps<DataType>())),
278 _div_rel(DataType(1) / Math::eps<DataType>()),
279 _div_abs(DataType(1) / Math::sqr(Math::eps<DataType>())),
280 _stag_rate(DataType(0.95)),
281 _min_iter(0),
282 _max_iter(100),
283 _num_iter(0),
286 _def_init(0),
287 _def_cur(0),
288 _def_prev(0),
289 _iter_digits(Math::ilog10(_max_iter)),
293 {
294 }
295
311 explicit IterativeSolver(const String& plot_name, const String& section_name, const PropertyMap* section) :
312 IterativeSolver(plot_name)
313 {
314 auto plot_mode_p = section->get_entry("plot_mode");
315 if (plot_mode_p.second && !plot_mode_p.first.parse(this->_plot_mode))
316 throw ParseError(section_name + ".plot_mode", plot_mode_p.first, "one of: none, iter, summary, all");
317
318 auto plot_name_p = section->get_entry("plot_name");
319 if (plot_name_p.second)
320 this->_plot_name = plot_name_p.first;
321
322 auto plot_interval_p = section->get_entry("plot_interval");
323 if (plot_interval_p.second && !plot_interval_p.first.parse(this->_plot_interval))
324 throw ParseError(section_name + ".plot_interval", plot_interval_p.first, "an integer >= 0");
325
326 auto tol_abs_p = section->get_entry("tol_abs");
327 if (tol_abs_p.second && !tol_abs_p.first.parse(this->_tol_abs))
328 throw ParseError(section_name + ".tol_abs", tol_abs_p.first, "a floating point number");
329
330 auto tol_rel_p = section->get_entry("tol_rel");
331 if (tol_rel_p.second && !tol_rel_p.first.parse(this->_tol_rel))
332 throw ParseError(section_name + ".tol_rel", tol_rel_p.first, "a floating point number");
333
334 auto tol_abs_low_p = section->get_entry("tol_abs_low");
335 if (tol_abs_low_p.second && !tol_abs_low_p.first.parse(this->_tol_abs_low))
336 throw ParseError(section_name + ".tol_abs_low", tol_abs_low_p.first, "a floating point number");
337
338 auto div_abs_p = section->get_entry("div_abs");
339 if (div_abs_p.second && !div_abs_p.first.parse(this->_div_abs))
340 throw ParseError(section_name + ".div_abs", div_abs_p.first, "a floating point number");
341
342 auto div_rel_p = section->get_entry("div_rel");
343 if (div_rel_p.second && !div_rel_p.first.parse(this->_div_rel))
344 throw ParseError(section_name + ".div_rel", div_rel_p.first, "a floating point number");
345
346 auto stag_rate_p = section->get_entry("stag_rate");
347 if (stag_rate_p.second && !stag_rate_p.first.parse(this->_stag_rate))
348 throw ParseError(section_name + ".stag_rate", stag_rate_p.first, "a floating point number in range [0,1)");
349
350 auto max_iter_p = section->get_entry("max_iter");
351 if (max_iter_p.second && !max_iter_p.first.parse(this->_max_iter))
352 throw ParseError(section_name + ".max_iter", max_iter_p.first, "an integer >= 0");
353
354 auto min_iter_p = section->get_entry("min_iter");
355 if (min_iter_p.second && !min_iter_p.first.parse(this->_min_iter))
356 throw ParseError(section_name + ".min_iter", min_iter_p.first, "an integer >= 0");
357
358 auto min_stag_iter_p = section->get_entry("min_stag_iter");
359 if (min_stag_iter_p.second && !min_stag_iter_p.first.parse(this->_min_stag_iter))
360 throw ParseError(section_name + ".min_stag_iter", min_stag_iter_p.first, "an integer >= 0");
361 }
362
363 public:
365 void set_tol_rel(DataType tol_rel)
366 {
367 _tol_rel = tol_rel;
368 }
369
371 void set_tol_abs(DataType tol_abs)
372 {
373 _tol_abs = tol_abs;
374 }
375
377 void set_tol_abs_low(DataType tol_abs_low)
378 {
379 _tol_abs_low = tol_abs_low;
380 }
381
384 {
385 return _tol_rel;
386 }
387
390 {
391 return _tol_abs;
392 }
393
396 {
397 return _tol_abs_low;
398 }
399
401 void set_div_rel(DataType div_rel)
402 {
403 _div_rel = div_rel;
404 }
405
407 void set_div_abs(DataType div_abs)
408 {
409 _div_abs = div_abs;
410 }
411
414 {
415 return _div_rel;
416 }
417
420 {
421 return _div_abs;
422 }
423
426 {
427 _stag_rate = rate;
428 }
429
432 {
433 return _stag_rate;
434 }
435
438 {
439 _min_stag_iter = min_iter;
440 }
441
444 {
445 return _min_stag_iter;
446 }
447
449 void set_min_iter(Index min_iter)
450 {
451 _min_iter = min_iter;
452 }
453
456 {
459 }
460
463 {
464 return _num_iter;
465 }
466
469 {
470 return _min_iter;
471 }
472
475 {
476 return _max_iter;
477 }
478
490 virtual void force_defect_norm_calc(bool force)
491 {
492 _force_def_norm_calc = force;
493 }
494
501 void set_plot_mode(const PlotMode plot_mode)
502 {
503 _plot_mode = plot_mode;
504 }
505
511 void set_plot_interval(const Index plot_interval)
512 {
513 _plot_interval = plot_interval;
514 }
515
517 void set_plot_name(const String& plot_name)
518 {
519 _plot_name = plot_name;
520 }
521
524 {
525 return _plot_name;
526 }
527
533 bool is_converged() const
534 {
535 return is_converged(_def_cur);
536 }
537
546 bool is_converged(const DataType def_cur) const
547 {
548 return (def_cur <= _tol_abs) && ((def_cur <= (_tol_rel * _def_init)) || (def_cur <= _tol_abs_low));
549 }
550
552 bool is_diverged() const
553 {
554 return is_diverged(_def_cur);
555 }
556
558 bool is_diverged(const DataType def_cur) const
559 {
560 return (def_cur > _div_abs) || (def_cur > (_div_rel * _def_init));
561 }
562
565 {
566 return _def_init;
567 }
568
571 {
572 return _def_cur;
573 }
574
577 {
578 return _status;
579 }
580
583 {
584 // no iterations performed?
585 if(_num_iter <= Index(0))
586 return DataType(0);
587
588 // initial defect zero?
589 if(_def_init < Math::eps<DataType>())
590 return DataType(0);
591
592 // compute convergence rate: (def_final / def_initial) ^ (1 / #iter)
594 }
595
598 {
599 // avoid division by zero
600 if(this->_def_init <= Math::abs(this->_def_cur * Math::eps<DataType>()))
601 return DataType(0);
602
603 // compute defect reduction (def_final / def_inital)
604 return this->_def_cur / this->_def_init;
605 }
606
610 virtual String get_summary() const
611 {
612 String msg;
613 msg += String( "Name............: ") + this->get_plot_name();
614 msg += String("\nStatus..........: ") + stringify(this->get_status());
615 msg += String("\nIterations......: ") + stringify(this->get_num_iter());
616 msg += String("\nInitial Defect..: ") + stringify_fp_sci(this->get_def_initial());
617 msg += String("\nFinal Defect....: ") + stringify_fp_sci(this->get_def_final());
618 msg += String("\nDefect Reduction: ") + stringify_fp_sci(this->calc_defect_reduction());
619 msg += String("\nConvergence Rate: ") + stringify_fp_fix(this->calc_convergence_rate());
620
621 return msg;
622 }
623
627 virtual void plot_summary() const
628 {
629 // Print solver summary
630 if(!_plot_summary())
631 return;
632
633 this->_print_line(this->get_summary());
634 }
635
658 virtual Status correct(VectorType& vec_sol, const VectorType& vec_rhs) = 0;
659
660 protected:
667 void _set_comm(const Dist::Comm* comm)
668 {
669 this->_comm = comm;
670 }
671
679 template<typename Matrix_>
680 void _set_comm_by_matrix(const Matrix_& matrix)
681 {
682 this->_comm = Intern::get_mat_comm(matrix, nullptr);
683 }
684
692 void _set_comm_by_vector(const Vector_& vector)
693 {
694 this->_comm = Intern::get_vec_comm(vector, nullptr);
695 }
696
706 virtual DataType _calc_def_norm(const VectorType& vec_def, const VectorType& DOXY(vec_sol))
707 {
708 return vec_def.norm2();
709 }
710
721 {
722 return ((_num_iter % _plot_interval == 0) || (st != Status::progress))
724 }
725
731 bool _plot_summary() const
732 {
734 }
735
741 bool _progress() const
742 {
743 return this->_status == Status::progress;
744 }
745
752 void _print_line(const String& line) const
753 {
754 // print message line via comm (if available)
755 if(_comm != nullptr)
756 _comm->print(line);
757 else
758 std::cout << line << "\n";
759 }
760
773 virtual void _plot_iter_line(Index num_iter, DataType def_cur, DataType def_prev)
774 {
775 // compose message line
776 String msg = this->_plot_name
777 + ": " + stringify(num_iter).pad_front(this->_iter_digits)
778 + " : " + stringify_fp_sci(def_cur);
779
780 // not first iteration?
781 if(num_iter > Index(0))
782 {
783 msg += " / " + stringify_fp_sci(def_cur / this->_def_init);
784 msg += " / " + stringify_fp_fix(def_cur / def_prev);
785 }
786
787 this->_print_line(msg);
788 }
789
802 virtual Status _set_initial_defect(const VectorType& vec_def, const VectorType& vec_sol)
803 {
804 // reset iteration variables
805 this->_def_init = this->_def_prev = this->_def_cur = DataType(0);
806 this->_num_iter = Index(0);
807 this->_num_stag_iter = Index(0);
808
809 // first, let's see if we have to compute the defect at all
810 bool calc_def = _force_def_norm_calc
811 || (this->_min_iter < this->_max_iter)
812 || (this->_plot_iter() || this->_plot_summary())
813 || (this->_min_stag_iter > Index(0));
814
815 // if we don't have to compute the initial defect, we can exit here
816 if(!calc_def)
817 return Status::progress;
818
819 // compute new initial defect
820 this->_def_init = this->_def_cur = this->_def_prev = this->_calc_def_norm(vec_def, vec_sol);
821 Statistics::add_solver_expression(std::make_shared<ExpressionDefect>(this->name(), this->_def_init, this->get_num_iter()));
822
823 // plot iteration line?
824 if(this->_plot_iter())
825 this->_plot_iter_line(Index(0), this->_def_init, this->_def_init);
826
827 // ensure that the defect is neither NaN nor infinity
828 if(!Math::isfinite(this->_def_init))
829 return Status::aborted;
830
831 // check against low absolute tolerance; this may be fulfilled if we have only a handful of dofs
832 if(this->_def_init < this->_tol_abs_low)
833 return Status::success;
834
835 // check if the initial defect is zero; we test against eps^2 here
836 if(this->_def_init <= Math::sqr(Math::eps<DataType>()))
837 return Status::success;
838
839 // continue iterating
840 return Status::progress;
841 }
842
866 virtual Status _analyze_defect(Index num_iter, DataType def_cur, DataType def_prev, bool check_stag)
867 {
868 // ensure that the defect is neither NaN nor infinity
869 if(!Math::isfinite(def_cur))
870 return Status::aborted;
871
872 // is diverged?
873 if(this->is_diverged(def_cur))
874 return Status::diverged;
875
876 // maximum number of iterations performed?
877 if(num_iter >= this->_max_iter)
878 return Status::max_iter;
879
880 // minimum number of iterations performed?
881 if(num_iter < this->_min_iter)
882 return Status::progress;
883
884 // is converged?
885 if(this->is_converged(def_cur))
886 return Status::success;
887
888 // check for stagnation?
889 if(check_stag && (this->_min_stag_iter > Index(0)))
890 {
891 // did this iteration stagnate?
892 if(def_cur >= this->_stag_rate * def_prev)
893 {
894 // increment stagnation count
895 if(++this->_num_stag_iter >= this->_min_stag_iter)
896 return Status::stagnated;
897 }
898 else
899 {
900 // this iteration did not stagnate
901 this->_num_stag_iter = Index(0);
902 }
903 }
904
905 // continue iterating
906 return Status::progress;
907 }
908
924 virtual Status _set_new_defect(const VectorType& vec_def, const VectorType& vec_sol)
925 {
926 // increase iteration count
927 ++this->_num_iter;
928
929 // store previous defect
930 this->_def_prev = this->_def_cur;
931
932 // first, let's see if we have to compute the defect at all
933 bool calc_def = _force_def_norm_calc
934 || (this->_min_iter < this->_max_iter)
935 || (this->_plot_iter() || this->_plot_summary())
936 || (this->_min_stag_iter > Index(0));
937
938 // compute new defect
939 if(calc_def)
940 {
941 this->_def_cur = this->_calc_def_norm(vec_def, vec_sol);
942 Statistics::add_solver_expression(std::make_shared<ExpressionDefect>(this->name(), this->_def_cur, this->get_num_iter()));
943 }
944
945 // analyze defect
946 Status status = this->_analyze_defect(this->_num_iter, this->_def_cur, this->_def_prev, true);
947
948 // plot defect?
949 if(this->_plot_iter(status))
950 this->_plot_iter_line(this->_num_iter, this->_def_cur, this->_def_prev);
951
952 // return status
953 return status;
954 }
955
970 virtual Status _update_defect(const DataType def_cur_norm)
971 {
972 // increase iteration count
973 ++this->_num_iter;
974
975 // store previous defect
976 this->_def_prev = this->_def_cur;
977
978 // update current defect
979 this->_def_cur = def_cur_norm;
980 Statistics::add_solver_expression(std::make_shared<ExpressionDefect>(this->name(), this->_def_cur, this->get_num_iter()));
981
982 // analyze defect
983 Status status = this->_analyze_defect(this->_num_iter, this->_def_cur, this->_def_prev, true);
984
985 // plot defect?
986 if(this->_plot_iter(status))
987 this->_plot_iter_line(this->_num_iter, this->_def_cur, this->_def_prev);
988
989 // return status
990 return status;
991 }
992 }; // class IterativeSolver
993
997 template<
998 typename Vector_,
999 typename Matrix_,
1000 typename Filter_>
1003 Vector_& vec_sol,
1004 const Vector_& vec_rhs,
1005 const Matrix_& DOXY(matrix),
1006 const Filter_& DOXY(filter))
1007 {
1008 // simply call the 'correct' method
1009 return solver.correct(vec_sol, vec_rhs);
1010 }
1011
1024 template<typename Vector_>
1026 public IterativeSolver<Vector_>
1027 {
1028 public:
1030 typedef Vector_ VectorType;
1032 typedef typename VectorType::DataType DataType;
1037
1038 protected:
1040 std::shared_ptr<PrecondType> _precond;
1041
1051 explicit PreconditionedIterativeSolver(const String& plot_name,std::shared_ptr<PrecondType> precond = nullptr) :
1052 BaseClass(plot_name),
1053 _precond(precond)
1054 {
1055 }
1056
1072 explicit PreconditionedIterativeSolver(const String& plot_name, const String& section_name,
1073 const PropertyMap* section, std::shared_ptr<PrecondType> precond = nullptr) :
1074 BaseClass(plot_name, section_name, section),
1075 _precond(precond)
1076 {
1077 }
1078
1079 public:
1082 {
1083 }
1084
1086 virtual void init_symbolic() override
1087 {
1089 if(_precond)
1090 _precond->init_symbolic();
1091 }
1092
1094 virtual void init_numeric() override
1095 {
1097 if(_precond)
1098 _precond->init_numeric();
1099 }
1100
1102 virtual void done_numeric() override
1103 {
1104 if(_precond)
1105 _precond->done_numeric();
1107 }
1108
1110 virtual void done_symbolic() override
1111 {
1112 if(_precond)
1113 _precond->done_symbolic();
1115 }
1116
1117 protected:
1139 template<typename Filter_>
1140 bool _apply_precond(VectorType& vec_cor, const VectorType& vec_def, const Filter_& filter)
1141 {
1142 XASSERTM(&vec_cor != &vec_def, "vec_cor and vec_def must not refer to the same object");
1143 if(this->_precond)
1144 {
1145 Statistics::add_solver_expression(std::make_shared<ExpressionCallPrecond>(this->name(), this->_precond->name()));
1146 return status_success(this->_precond->apply(vec_cor, vec_def));
1147 }
1148 else
1149 {
1150 vec_cor.copy(vec_def);
1151 filter.filter_cor(vec_cor);
1152 return true;
1153 }
1154 }
1155 }; // class PreconditionedIterativeSolver<...>
1156 } // namespace Solver
1157} // namespace FEAT
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
Communicator class.
Definition: dist.hpp:1349
void print(std::ostream &os, const String &msg, int root=0) const
Prints a message line to an output stream.
Definition: dist.cpp:782
Class for parser related errors.
Definition: exception.hpp:132
A class organizing a tree of key-value pairs.
std::pair< String, bool > get_entry(String key) const
Retrieves a value by its key.
Abstract base-class for iterative solvers.
Definition: iterative.hpp:198
DataType get_div_abs() const
Returns the absolute divergence.
Definition: iterative.hpp:419
bool _force_def_norm_calc
whether skipping of defect computation is allowed or not
Definition: iterative.hpp:249
void set_plot_name(const String &plot_name)
Sets the plot name of the solver.
Definition: iterative.hpp:517
virtual void force_defect_norm_calc(bool force)
Forces the calculation of defect norms in every iteration.
Definition: iterative.hpp:490
IterativeSolver(const String &plot_name)
Protected constructor.
Definition: iterative.hpp:270
bool _plot_summary() const
Plot summary?
Definition: iterative.hpp:731
DataType _stag_rate
stagnation rate
Definition: iterative.hpp:225
virtual Status correct(VectorType &vec_sol, const VectorType &vec_rhs)=0
Solver correction method.
DataType _def_init
initial defect
Definition: iterative.hpp:237
Status get_status() const
Returns the status.
Definition: iterative.hpp:576
void set_plot_interval(const Index plot_interval)
Sets the interval between two plot outputs, if any.
Definition: iterative.hpp:511
String get_plot_name() const
Returns the plot name of the solver.
Definition: iterative.hpp:523
Index get_min_iter() const
Returns the minimal number of iterations.
Definition: iterative.hpp:468
Index _min_iter
minimum number of iterations
Definition: iterative.hpp:227
DataType get_tol_abs() const
Returns the absolute tolerance.
Definition: iterative.hpp:389
Index get_max_iter() const
Returns the maximum number of iterations.
Definition: iterative.hpp:474
void set_max_iter(Index max_iter)
Sets the maximum iteration count for the solver.
Definition: iterative.hpp:455
VectorType::DataType DataType
Floating point type.
Definition: iterative.hpp:203
Index _iter_digits
iteration count digits for plotting
Definition: iterative.hpp:243
Index get_num_iter() const
Returns number of performed iterations.
Definition: iterative.hpp:462
bool is_converged(const DataType def_cur) const
checks for convergence
Definition: iterative.hpp:546
void _set_comm(const Dist::Comm *comm)
Sets the communicator for the solver directly.
Definition: iterative.hpp:667
void set_tol_abs(DataType tol_abs)
Sets the absolute tolerance for the solver.
Definition: iterative.hpp:371
Status _status
current status of the solver
Definition: iterative.hpp:213
void set_stag_rate(DataType rate)
Sets the stagnation rate for the solver.
Definition: iterative.hpp:425
virtual Status _analyze_defect(Index num_iter, DataType def_cur, DataType def_prev, bool check_stag)
Internal function: analyze the current defect.
Definition: iterative.hpp:866
void _set_comm_by_matrix(const Matrix_ &matrix)
Sets the communicator for the solver from a matrix.
Definition: iterative.hpp:680
void _print_line(const String &line) const
Prints a line.
Definition: iterative.hpp:752
SolverBase< VectorType > BaseClass
The base class.
Definition: iterative.hpp:205
bool is_diverged() const
checks for divergence
Definition: iterative.hpp:552
String _plot_name
name of the solver in plots
Definition: iterative.hpp:211
const Dist::Comm * _comm
Communicator of the solver.
Definition: iterative.hpp:209
DataType get_tol_abs_low() const
Returns the lower absolute tolerance.
Definition: iterative.hpp:395
void set_min_iter(Index min_iter)
Sets the minimum iteration count for the solver.
Definition: iterative.hpp:449
DataType _div_rel
relative divergence parameter
Definition: iterative.hpp:221
bool _progress() const
Progress iteration?
Definition: iterative.hpp:741
DataType _def_prev
previous iteration defect
Definition: iterative.hpp:241
virtual void _plot_iter_line(Index num_iter, DataType def_cur, DataType def_prev)
Plots an iteration line.
Definition: iterative.hpp:773
DataType get_div_rel() const
Returns the relative divergence.
Definition: iterative.hpp:413
Vector_ VectorType
The vector type this solver can be applied to.
Definition: iterative.hpp:201
Index _plot_interval
plot output interval
Definition: iterative.hpp:247
virtual Status _update_defect(const DataType def_cur_norm)
Internal function: sets the new (next) defect norm.
Definition: iterative.hpp:970
Index get_min_stag_iter() const
Returns the minimum stagnation iteration count.
Definition: iterative.hpp:443
DataType _div_abs
absolute divergence parameter
Definition: iterative.hpp:223
virtual DataType _calc_def_norm(const VectorType &vec_def, const VectorType &vec_sol)
Computes the defect norm.
Definition: iterative.hpp:706
virtual Status _set_new_defect(const VectorType &vec_def, const VectorType &vec_sol)
Internal function: sets the new (next) defect vector.
Definition: iterative.hpp:924
Index _num_iter
number of performed iterations
Definition: iterative.hpp:231
bool _plot_iter(Status st=Status::progress) const
Plot the current iteration?
Definition: iterative.hpp:720
bool is_diverged(const DataType def_cur) const
checks for divergence
Definition: iterative.hpp:558
DataType _tol_rel
relative tolerance parameter
Definition: iterative.hpp:215
void set_plot_mode(const PlotMode plot_mode)
Sets the plot mode of the solver.
Definition: iterative.hpp:501
void set_div_abs(DataType div_abs)
Sets the absolute divergence for the solver.
Definition: iterative.hpp:407
void set_tol_abs_low(DataType tol_abs_low)
Sets the lower absolute tolerance for the solver.
Definition: iterative.hpp:377
Index _num_stag_iter
number of consecutive stagnated iterations
Definition: iterative.hpp:235
DataType _def_cur
current defect
Definition: iterative.hpp:239
virtual void plot_summary() const
Plot a summary of the last solver run.
Definition: iterative.hpp:627
Index _max_iter
maximum number of iterations
Definition: iterative.hpp:229
DataType get_def_final() const
Returns the final defect.
Definition: iterative.hpp:570
DataType calc_defect_reduction() const
Computes the overall defect reduction factor: (defect_final / defect_inital)
Definition: iterative.hpp:597
DataType _tol_abs_low
absolute low tolerance parameter
Definition: iterative.hpp:219
virtual Status _set_initial_defect(const VectorType &vec_def, const VectorType &vec_sol)
Internal function: sets the initial defect vector.
Definition: iterative.hpp:802
DataType calc_convergence_rate() const
Computes the overall convergence rate: (defect_final / defect_initial) ^ (1 / number of iterations)
Definition: iterative.hpp:582
bool is_converged() const
checks for convergence
Definition: iterative.hpp:533
void set_tol_rel(DataType tol_rel)
Sets the relative tolerance for the solver.
Definition: iterative.hpp:365
IterativeSolver(const String &plot_name, const String &section_name, const PropertyMap *section)
Constructor using a PropertyMap.
Definition: iterative.hpp:311
void set_div_rel(DataType div_rel)
Sets the relative divergence for the solver.
Definition: iterative.hpp:401
virtual String get_summary() const
Returns a summary string.
Definition: iterative.hpp:610
void _set_comm_by_vector(const Vector_ &vector)
Sets the communicator for the solver from a vector.
Definition: iterative.hpp:692
DataType get_tol_rel() const
Returns the relative tolerance.
Definition: iterative.hpp:383
void set_min_stag_iter(Index min_iter)
Sets the minimum stagnate iteration count for the solver.
Definition: iterative.hpp:437
DataType _tol_abs
absolute tolerance parameter
Definition: iterative.hpp:217
DataType get_def_initial() const
Returns the initial defect.
Definition: iterative.hpp:564
DataType get_stag_rate() const
Returns the stagnation rate.
Definition: iterative.hpp:431
PlotMode _plot_mode
whether to plot something
Definition: iterative.hpp:245
Index _min_stag_iter
minimum number of stagnation iterations
Definition: iterative.hpp:233
Abstract base-class for preconditioned iterative solvers.
Definition: iterative.hpp:1027
VectorType::DataType DataType
Floating point data type.
Definition: iterative.hpp:1032
PreconditionedIterativeSolver(const String &plot_name, const String &section_name, const PropertyMap *section, std::shared_ptr< PrecondType > precond=nullptr)
Constructor using a PropertyMap.
Definition: iterative.hpp:1072
SolverBase< VectorType > PrecondType
the interface for the preconditioner
Definition: iterative.hpp:1036
virtual void init_symbolic() override
Symbolic initialization method.
Definition: iterative.hpp:1086
virtual void done_numeric() override
Numeric finalization method.
Definition: iterative.hpp:1102
virtual ~PreconditionedIterativeSolver()
virtual destructor
Definition: iterative.hpp:1081
IterativeSolver< VectorType > BaseClass
Our base class.
Definition: iterative.hpp:1034
Vector_ VectorType
The vector type this solver can be applied to.
Definition: iterative.hpp:1030
virtual void init_numeric() override
Numeric initialization method.
Definition: iterative.hpp:1094
PreconditionedIterativeSolver(const String &plot_name, std::shared_ptr< PrecondType > precond=nullptr)
Constructor.
Definition: iterative.hpp:1051
std::shared_ptr< PrecondType > _precond
the pointer to the preconditioner
Definition: iterative.hpp:1040
bool _apply_precond(VectorType &vec_cor, const VectorType &vec_def, const Filter_ &filter)
Applies the preconditioner onto a defect vector.
Definition: iterative.hpp:1140
virtual void done_symbolic() override
Symbolic finalization method.
Definition: iterative.hpp:1110
Polymorphic solver interface.
Definition: base.hpp:183
virtual void init_symbolic()
Symbolic initialization method.
Definition: base.hpp:227
virtual void init_numeric()
Numeric initialization method.
Definition: base.hpp:237
virtual void done_symbolic()
Symbolic finalization method.
Definition: base.hpp:255
virtual String name() const =0
Returns a descriptive string.
virtual void done_numeric()
Numeric finalization method.
Definition: base.hpp:246
String class implementation.
Definition: string.hpp:46
String pad_front(size_type len, char c=' ') const
Pads the front of the string up to a desired length.
Definition: string.hpp:392
T_ abs(T_ x)
Returns the absolute value.
Definition: math.hpp:275
T_ pow(T_ x, T_ y)
Returns x raised to the power of y.
Definition: math.hpp:643
T_ sqr(T_ x)
Returns the square of a value.
Definition: math.hpp:95
T_ ilog10(T_ x)
Computes the integral base-10 logarithm of an integer, i.e. its number of non-zero decimal digits.
Definition: math.hpp:231
bool isfinite(T_ x)
Checks whether a value is finite.
std::istream & operator>>(std::istream &is, Pack::Type &t)
stream input operator for Pack::Type
Definition: pack.hpp:189
bool status_success(Status status)
Status success check function.
Definition: base.hpp:108
PlotMode
Solver plot modes enumeration.
Definition: iterative.hpp:54
@ none
No plotting whatsoever.
@ iter
Plot every iteration (if applicable)
@ all
Plot every iteration (if applicable) and a summary.
@ summary
Plot a summary after each solver run.
Status
Solver status return codes enumeration.
Definition: base.hpp:47
@ success
solving successful (convergence criterion fulfilled)
@ progress
continue iteration (internal use only)
@ undefined
undefined status
@ stagnated
solver stagnated (stagnation criterion fulfilled)
@ max_iter
solver reached maximum iterations
@ diverged
solver diverged (divergence criterion fulfilled)
@ aborted
premature abort (solver aborted due to internal errors or preconditioner failure)
Status solve(SolverBase< Vector_ > &solver, Vector_ &vec_sol, const Vector_ &vec_rhs, const Matrix_ &matrix, const Filter_ &filter)
Solve linear system with initial solution guess.
Definition: base.hpp:347
FEAT namespace.
Definition: adjactor.hpp:12
String stringify_fp_fix(DataType_ value, int precision=0, int width=0, bool sign=false)
Prints a floating point value to a string in fixed-point notation.
Definition: string.hpp:1142
String stringify(const T_ &item)
Converts an item into a String.
Definition: string.hpp:944
String stringify_fp_sci(DataType_ value, int precision=0, int width=0, bool sign=false)
Prints a floating point value to a string in scientific notation.
Definition: string.hpp:1088
std::uint64_t Index
Index data type.