MFEM  v4.2.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
slepc.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2020, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-806117.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability visit https://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
11 
12 #ifndef MFEM_SLEPC
13 #define MFEM_SLEPC
14 
15 #include "../config/config.hpp"
16 
17 #ifdef MFEM_USE_SLEPC
18 #ifdef MFEM_USE_MPI
19 
20 #include "petsc.hpp"
21 
22 // Forward declarations
23 typedef struct _p_EPS *EPS;
24 
25 namespace mfem
26 {
27 
28 void MFEMInitializeSlepc();
29 void MFEMInitializeSlepc(int*,char***);
30 void MFEMInitializeSlepc(int*,char***,const char[],const char[]);
31 void MFEMFinalizeSlepc();
32 
34 {
35 private:
36  /// Boolean to handle SetFromOptions calls
37  mutable bool clcustom;
38 
39  /// SLEPc linear eigensolver object
40  EPS eps;
41 
42  /// Real and imaginary part of eigenvector
43  mutable PetscParVector *VR, *VC;
44 
45 public:
46  /// Constructors
47  SlepcEigenSolver(MPI_Comm comm, const std::string &prefix = std::string());
48 
49  virtual ~SlepcEigenSolver();
50 
51  /// Set solver tolerance
52  void SetTol(double tol);
53 
54  /// Set maximum number of iterations
55  void SetMaxIter(int max_iter);
56  /// Set the number of required eigenmodes
57  void SetNumModes(int num_eigs);
58  /// Set operator for standard eigenvalue problem
59  void SetOperator(const PetscParMatrix &op);
60  /// Set operator for generalized eigenvalue problem
61  void SetOperators(const PetscParMatrix &op, const PetscParMatrix &opB);
62 
63  /// Customize object with options set
64  void Customize(bool customize = true) const;
65 
66  /// Solve the eigenvalue problem for the specified number of eigenvalues
67  void Solve();
68 
69  /// Get the number of converged eigenvalues
70  int GetNumConverged();
71 
72  /// Get the corresponding eigenvalue
73  void GetEigenvalue(unsigned int i, double & lr) const;
74  void GetEigenvalue(unsigned int i, double & lr, double & lc) const;
75 
76  /// Get the corresponding eigenvector
77  void GetEigenvector(unsigned int i, Vector & vr) const;
78  void GetEigenvector(unsigned int i, Vector & vr, Vector & vc) const;
79 
80  /// Target spectrum for the eigensolver. Target imaginary is not supported
81  /// without complex support in SLEPc, and intervals are not implemented.
82  enum Which
83  {
92  };
93 
95  {
98  };
99 
100  void SetWhichEigenpairs(Which which);
101  void SetTarget(double target);
103 
104  /// Conversion function to SLEPc's EPS type.
105  operator EPS() const { return eps; }
106 
107  /// Conversion function to PetscObject
108  operator PetscObject() const {return (PetscObject)eps; }
109 };
110 
111 }
112 
113 #endif // MFEM_USE_MPI
114 #endif // MFEM_USE_SLEPC
115 
116 #endif // MFEM_SLEPC
void SetOperator(const PetscParMatrix &op)
Set operator for standard eigenvalue problem.
Definition: slepc.cpp:74
void Customize(bool customize=true) const
Customize object with options set.
Definition: slepc.cpp:131
void MFEMInitializeSlepc()
Definition: slepc.cpp:29
Wrapper for PETSc's matrix class.
Definition: petsc.hpp:197
void GetEigenvalue(unsigned int i, double &lr) const
Get the corresponding eigenvalue.
Definition: slepc.cpp:141
struct _p_EPS * EPS
Definition: slepc.hpp:23
void SetTarget(double target)
Definition: slepc.cpp:223
Wrapper for PETSc's vector class.
Definition: petsc.hpp:75
void SetSpectralTransformation(SpectralTransformation transformation)
Definition: slepc.cpp:228
virtual ~SlepcEigenSolver()
Definition: slepc.cpp:63
void transformation(const Vector &p, Vector &v)
void SetMaxIter(int max_iter)
Set maximum number of iterations.
Definition: slepc.cpp:110
void SetNumModes(int num_eigs)
Set the number of required eigenmodes.
Definition: slepc.cpp:118
void Solve()
Solve the eigenvalue problem for the specified number of eigenvalues.
Definition: slepc.cpp:124
void MFEMFinalizeSlepc()
Definition: slepc.cpp:46
void SetTol(double tol)
Set solver tolerance.
Definition: slepc.cpp:100
SlepcEigenSolver(MPI_Comm comm, const std::string &prefix=std::string())
Constructors.
Definition: slepc.cpp:53
int GetNumConverged()
Get the number of converged eigenvalues.
Definition: slepc.cpp:182
void SetWhichEigenpairs(Which which)
Definition: slepc.cpp:189
struct _p_PetscObject * PetscObject
Definition: petsc.hpp:50
Vector data type.
Definition: vector.hpp:51
void GetEigenvector(unsigned int i, Vector &vr) const
Get the corresponding eigenvector.
Definition: slepc.cpp:152
void SetOperators(const PetscParMatrix &op, const PetscParMatrix &opB)
Set operator for generalized eigenvalue problem.
Definition: slepc.cpp:87