Class documentation of Concepts

Loading...
Searching...
No Matches
easyArpackpp.hh
Go to the documentation of this file.
1
8#ifndef EASYARPACKPP_HH_
9#define EASYARPACKPP_HH_
10
11#include "arpackpp.hh"
12#include "basics/exceptions.hh"
13
14namespace eigensolver {
15
16 /*** struct to compute the type of the operator for the EasyArpack classes ***/
17 template<typename F, typename G>
18 struct OperatorType {
19 typedef concepts::Cmplx type;
20 };
21
22 template<>
24 typedef concepts::Real type;
25 };
26
28 template<class T>
30
31 public:
34 }
35 ;
36
38 virtual ~EasyArPackpp() {
39 }
40 ;
41
43 virtual EigenSolver<T>* getSolver() = 0;
44
45 protected:
47 int dim_;
48 };
49
51 template<class F = Cmplx, class G = Real,
52 class H = typename eigensolver::OperatorType<F, G>::type>
53 class EasyArPackppStd: public EasyArPackpp<concepts::Cmplx> {
54 public:
55
67
68 //set dimension
69 dim_ = A.dimX();
70
71 //calculate shifted matrix: shifted = A - shift*I
73 A.addInto(shifted, 1.);
75 for (int i = 0; i < dim_; ++i)
76 eye(i, i) = 1;
77 eye.addInto(shifted, -shift);
78
79 //set operator
80#ifdef HAS_MUMPS
81 OP_ = new concepts::Mumps<H>(shifted);
82#else
83#ifdef HAS_SuperLU
84 OP_ = new concepts::SuperLU<H>(shifted);
85#else
86 throw conceptsException(concepts::ExceptionBase("No valid solver was defined"));
87#endif
88#endif
89
90 //set solver
91 solver_ = new ArPackppStd<H> (*OP_, std::min(std::max(kmax, 1), dim_ - 2), shift);
92 }
93 ;
94
104 EasyArPackppStd(concepts::SparseMatrix<F> &A, int kmax = 1, char* which =
105 (char*) "LM") {
106
107 //ensure we're not calling with SM
108 if ( strcmp(which,"SM")==0 )
109 throw(concepts::MissingFeature("SM mode is not allowed. Use the shift and invert method instead."));
110
111 //set dimension
112 dim_ = A.dimX();
113
114 //set empty operator
115 OP_ = 0;
116
117 //set solver
118 solver_ = new ArPackppStd<H> (A, std::min(std::max(kmax, 1), dim_ - 2), which);
119
120 }
121 ;
122
125 if (OP_ != 0)
126 delete OP_;
127 delete solver_;
128 }
129 ;
130
137 return solver_;
138 }
139 ;
140
141 private:
145 ArPackppStd<H>* solver_;
146 };
147
149 template<class F, class G = concepts::Real,
150 class H = typename eigensolver::OperatorType<F, G>::type>
151 class EasyArPackppGen: public EasyArPackpp<concepts::Cmplx> {
152 public:
153
167 concepts::Real> &B, int kmax, G shift) {
168 //set dimension
169 dim_ = A.dimX();
170
171 //calculate shifted matrix: shifted = A - shift*B
173 A.addInto(shifted, 1.);
174 B.addInto(shifted, -shift);
175
176 //set operator
177#ifdef HAS_MUMPS
178 OP_ = new concepts::Mumps<H>(shifted);
179#else
180#ifdef HAS_SuperLU
181 OP_ = new concepts::SuperLU<H>(shifted);
182#else
183 throw conceptsException(concepts::ExceptionBase("No valid solver was defined"));
184#endif
185#endif
186
187 //set solver
188 solver_ = new ArPackppGen<H, F, concepts::Real> (*OP_, A, B,
189 std::min(std::max(kmax, 1), dim_ - 2), (concepts::Cmplx) shift);
190 }
191
204 concepts::Real> &B, int kmax = 1, char* which = (char*) "LM") {
205
206 //ensure we're not calling with SM
207 if ( strcmp(which,"SM")==0 )
208 throw(concepts::MissingFeature("SM mode is not allowed. Use the shift and invert method instead."));
209
210 //set dimension
211 dim_ = A.dimX();
212
213 /********************UNSECURE CAST**************************
214 *
215 * In The case H = concepts::Real the cast is well defined.
216 * If H = concepts::Cmplx the cast is not well defined and it can occur many problems.
217 * But if H = concepts::Cmplx the only method we use from concepts::SuperLU<concepts::Real> is
218 * operator()(vector<concepts::Cmplx> v1, vector<concepts::Cmplx> v2) and that is well defined for
219 * an instance of concepts::SuperLU<concepts::Real>. Never Use
220 * operator()(vector<concepts::Real> v1, vector<concepts::Cmplx> v2) cause this method is not implemented in
221 * instances of Operators<concepts::Real>.
222 * The class member OP_ is private, so nobody can kid around with it (exept in the class).
223 *
224 */
225
226 //set operator
227#ifdef HAS_MUMPS
229#else
230#ifdef HAS_SuperLU
232#else
233 throw conceptsException(concepts::ExceptionBase("No valid solver was defined"));
234#endif
235#endif
236
237 //set solver
238 solver_ = new ArPackppGen<H, F, concepts::Real> (*OP_, A, B,
239 std::min(std::max(kmax, 1), dim_ - 2), which);
240 }
241 ;
242
245 if (OP_ != 0)
246 delete OP_;
247 delete solver_;
248
249 }
250 ;
251
258 return solver_;
259 }
260 ;
261
262 private:
267 };
268
270 class EasyArPackppSymGen: public EasyArPackpp<concepts::Real> {
271 public:
272
286 concepts::Real shift);
287
300 EasyArPackppSymGen(char invertType,
302 concepts::Real> &B, int kmax, concepts::Real shift);
303
304 /******************* Not working yet ******************************/
305 // /**Regular mode constructor. Builds an eigenvalue solver
306 // * that solves the given eigenvalue problem using arpack++ with the
307 // * regular mode.
308 // *@param A symmetric matrix of the left hand side
309 // *@param B symmetric matrix of the right hand side; it has to be symmetric positive definite
310 // *@param kmax number of eigenvalues that should be calculated
311 // *@param which defines which eigenvalue should be calculated (default "LM")
312 // */
313 // EasyArPackppSymGen(concepts::SparseMatrix<concepts::Real> &A,
314 // concepts::SparseMatrix<concepts::Real> &B, int kmax,
315 // char* which = (char*)("LM"));
316
319
322
323 private:
327 ArPackppSymGen* solver_;
328 };
329
330}//end namespace eigensolver
331
332#endif /* EASYARPACKPP_HH_ */
#define conceptsException(exc)
void addInto(Matrix< H > &dest, const I fact)
Definition diagonal.hh:127
virtual const uint dimX() const
void addInto(Matrix< H > &dest, const I fact, const uint rowoffset=0, const uint coloffset=0) const
Tool to easily solve general eigenvalue problems.
virtual ~EasyArPackppGen()
Destructor that deletes the solver and the operator.
virtual ArPackppGen< H, F, concepts::Real > * getSolver()
EasyArPackppGen(concepts::SparseMatrix< F > &A, concepts::SparseMatrix< concepts::Real > &B, int kmax, G shift)
EasyArPackppGen(concepts::SparseMatrix< F > &A, concepts::SparseMatrix< concepts::Real > &B, int kmax=1, char *which=(char *) "LM")
Tool to easily solve standard eigenvalue problems.
EasyArPackppStd(concepts::SparseMatrix< F > &A, int kmax=1, char *which=(char *) "LM")
virtual ArPackppStd< H > * getSolver()
EasyArPackppStd(concepts::SparseMatrix< F > &A, int kmax, G shift)
virtual ~EasyArPackppStd()
Destructor that deletes the solver and the operator.
Tool to easily solve general eigenvalue problems for symmetric matrices.
virtual ~EasyArPackppSymGen()
Destructor that deletes the solver and the operator.
EasyArPackppSymGen(concepts::SparseMatrix< concepts::Real > &A, concepts::SparseMatrix< concepts::Real > &B, int kmax, concepts::Real shift)
EasyArPackppSymGen(char invertType, concepts::SparseMatrix< concepts::Real > &A, concepts::SparseMatrix< concepts::Real > &B, int kmax, concepts::Real shift)
virtual ArPackppSymGen * getSolver()
Getter for the generated solver.
Purely virtual class providing methods and instances for its child classes EasyArPackppStd,...
EasyArPackpp()
Default constructor.
virtual ~EasyArPackpp()
Empty destructor.
int dim_
Dimension of the space.
virtual EigenSolver< T > * getSolver()=0
Pure virtual method for getting the generated solver.
double Real
Definition typedefs.hh:39
Set< F > makeSet(uint n, const F &first,...)
Definition set.hh:320
std::complex< Real > Cmplx
Type for a complex number. It also depends on the setting of Real.
Definition typedefs.hh:42