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 
14 namespace eigensolver {
15 
16  /*** struct to compute the type of the operator for the EasyArpack classes ***/
17  template<typename F, typename G>
18  struct OperatorType {
20  };
21 
22  template<>
25  };
26 
28  template<class T>
29  class EasyArPackpp {
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 
66  EasyArPackppStd(concepts::SparseMatrix<F> &A, int kmax, G shift) {
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 
124  virtual ~EasyArPackppStd() {
125  if (OP_ != 0)
126  delete OP_;
127  delete solver_;
128  }
129  ;
130 
137  return solver_;
138  }
139  ;
140 
141  private:
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
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
239  std::min(std::max(kmax, 1), dim_ - 2), which);
240  }
241  ;
242 
244  virtual ~EasyArPackppGen() {
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:
328  };
329 
330 }//end namespace eigensolver
331 
332 #endif /* EASYARPACKPP_HH_ */
Interafce for eigenvalue solvers.
Definition: eigens.hh:23
virtual ArPackppSymGen * getSolver()
Getter for the generated solver.
virtual ~EasyArPackppStd()
Destructor that deletes the solver and the operator.
EasyArPackppStd(concepts::SparseMatrix< F > &A, int kmax, G shift)
Shift and invert mode constructor.
Definition: easyArpackpp.hh:66
virtual ~EasyArPackppSymGen()
Destructor that deletes the solver and the operator.
Direct sparse solver for unsymmetric matrices.
Definition: superLU.hh:70
virtual ArPackppGen< H, F, concepts::Real > * getSolver()
Getter for the generated solver.
EigenSolver for complex, standard eigenproblems.
Definition: arpackpp.hh:161
#define conceptsException(exc)
Prepares an exception for throwing.
Definition: exceptions.hh:344
Base class for exceptions.
Definition: exceptions.hh:86
Tool to easily solve standard eigenvalue problems.
Definition: easyArpackpp.hh:53
ArPackppStd< H > * solver_
pointer to the builded solver
ArPackppSymGen * solver_
pointer to the builded solver
concepts::Operator< H > * OP_
stores the operator inv(A-shift*B) in shift and invert mode inv(B) otherwise
EasyArPackppGen(concepts::SparseMatrix< F > &A, concepts::SparseMatrix< concepts::Real > &B, int kmax, G shift)
Shift and invert mode constructor.
void addInto(Matrix< H > &dest, const I fact, const uint rowoffset=0, const uint coloffset=0) const
This matrix is added as block to the given matrix dest.
EasyArPackppSymGen(char invertType, concepts::SparseMatrix< concepts::Real > &A, concepts::SparseMatrix< concepts::Real > &B, int kmax, concepts::Real shift)
Buckling mode constructor.
Tool to easily solve general eigenvalue problems.
EasyArPackppSymGen(concepts::SparseMatrix< concepts::Real > &A, concepts::SparseMatrix< concepts::Real > &B, int kmax, concepts::Real shift)
Cayley mode constructor.
virtual ArPackppStd< H > * getSolver()
Getter for the generated solver.
int dim_
Dimension of the space.
Definition: easyArpackpp.hh:47
concepts::Operator< concepts::Real > * OP_
stores the operator inv(A-shift*B) in shift and invert mode inv(B) otherwise
Abstract class for an operator.
Definition: ARPACK.hh:16
EasyArPackpp()
Default constructor.
Definition: easyArpackpp.hh:33
F min(const concepts::Array< F > &a)
Returns the minimal value in array a.
Definition: arrayOp.hh:67
std::complex< Real > Cmplx
Type for a complex number. It also depends on the setting of Real.
Definition: typedefs.hh:39
virtual ~EasyArPackpp()
Empty destructor.
Definition: easyArpackpp.hh:38
EigenSolver for symmetric, real-valued, general eigenproblems.
Definition: arpackpp.hh:349
Diagonal matrix.
Definition: diagonal.hh:24
Tool to easily solve general eigenvalue problems for symmetric matrices.
EasyArPackppStd(concepts::SparseMatrix< F > &A, int kmax=1, char *which=(char *) "LM")
Regular mode constructor.
void addInto(Matrix< H > &dest, const I fact)
This matrix is added to the given matrix dest.
Definition: diagonal.hh:127
MUMPS : MUltifrontal Massively Parallel sparse direct Solver.
Definition: mumps.hh:72
Exception class to express a missing feature.
Definition: exceptions.hh:206
concepts::Operator< H > * OP_
stores the empty operator
EasyArPackppGen(concepts::SparseMatrix< F > &A, concepts::SparseMatrix< concepts::Real > &B, int kmax=1, char *which=(char *) "LM")
Regular mode constructor.
ArPackppGen< H, F, concepts::Real > * solver_
pointer to the builded solver
Eigenvalue solvers.
Definition: ARPACK.hh:19
virtual EigenSolver< T > * getSolver()=0
Pure virtual method for getting the generated solver.
EigenSolver for complex, general eigenproblems.
Definition: arpackpp.hh:541
virtual ~EasyArPackppGen()
Destructor that deletes the solver and the operator.
double Real
Type normally used for a floating point number.
Definition: typedefs.hh:36
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
Purely virtual class providing methods and instances for its child classes EasyArPackppStd,...
Definition: easyArpackpp.hh:29
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich