Class documentation of Concepts

Loading...
Searching...
No Matches
cg.hh
Go to the documentation of this file.
1
6#ifndef cg_hh
7#define cg_hh
8
9#include <string>
10
11#include "basics/typedefs.hh"
12#include "basics/parallel.hh"
13#include "compositions.hh"
14
15#ifdef HAS_MPI
16#include <mpi.h>
17#endif
18
19namespace concepts {
20
21 // ******************************************************************* CG **
22
38 template<class F>
39 class CG : public VecOperator<F> {
40 public:
49 CG(Operator<F>& A, Real maxeps, int maxit = 0, uint relres = false,
50 bool throwing = true )
51 : VecOperator<F>(A.dimY(), A.dimX()), W_(0), A_(A)
52 , maxeps_(maxeps*maxeps), maxit_(maxit), eps_(1.0), it_(0)
53 , relres_(relres), throwing_(throwing) {
54#ifdef HAS_MPI
55 // Parallel compiled environment
56 if (isParallelRunning ())
57 {
58 // Parallel running environment
61 parallel_ = (N_>1);
62 if (parallel_) J_ = create_index_vector();
63 }
64 else
65 {
66 // Sequential running environment
67 N_ = 1; rank_ = 0;
68 parallel_ = false;
69 }
70#else
71 // Sequential compiled environment
72 N_ = 1; rank_ = 0;
73 parallel_=false;
74#endif
75 }
76
88 bool relres = 0, bool throwing = true)
89 : VecOperator<F>(A.dimY(), A.dimX()), W_(&Minv), A_(A)
90 , maxeps_(maxeps*maxeps), maxit_(maxit), eps_(1.0), it_(0)
91 , relres_(relres), throwing_(throwing) {
92#ifdef HAS_MPI
93 // Parallel compiled environment
94 if (isParallelRunning ())
95 {
96 // Parallel running environment
99 parallel_ = (N_>1);
100 if (parallel_) J_ = create_index_vector();
101 }
102 else
103 {
104 // Sequential running environment
105 N_ = 1; rank_ = 0;
106 parallel_ = false;
107 }
108#else
109 // Sequential compiled environment
110 N_ = 1; rank_ = 0;
111 parallel_=false;
112#endif
113 }
114
118 uint iterations() const { return it_; }
119
123 Real epsilon() const { return eps_; }
124 protected:
125 std::ostream& info(std::ostream& os) const;
126
127 private:
129 Operator<F>* W_;
131 Operator<F>& A_;
132
134 Real maxeps_;
136 uint maxit_;
138 Real eps_;
140 uint it_;
142 bool relres_;
146 bool throwing_;
147
149 int N_;
150
152 int rank_;
153
155 bool parallel_;
156
158 Vector<Real> J_;
159
160 virtual void apply_(const Vector<F>& fncY, Vector<F>& fncX);
161 virtual void apply_();
162
164 Vector<Real> create_index_vector();
165
166#ifdef HAS_MPI
168 Real parallel_l2_2(const std::map<int,Vector<F>> &K_ij, const Vector<F>& r_i,std::map<int,Vector<F>> &map_tilde_r_ji);
169#endif
170 };
171
172} // namespace concepts
173
174#endif // cg_hh
std::ostream & info(std::ostream &os) const
Returns information in an output stream.
CG(Operator< F > &A, Operator< F > &Minv, Real maxeps, int maxit=0, bool relres=0, bool throwing=true)
Definition cg.hh:87
CG(Operator< F > &A, Real maxeps, int maxit=0, uint relres=false, bool throwing=true)
Definition cg.hh:49
uint iterations() const
Definition cg.hh:118
Real epsilon() const
Definition cg.hh:123
virtual const uint dimY() const
virtual const uint dimX() const
double Real
Definition typedefs.hh:39
bool isParallelRunning()
Set< F > makeSet(uint n, const F &first,...)
Definition set.hh:320