MFEM  v4.4.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-2022, 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 declaration of SLEPc's internal struct _p_EPS:
23 struct _p_EPS;
24 
25 namespace mfem
26 {
27 
28 // Declare an alias of SLEPc's EPS type, mfem::slepc::EPS:
29 namespace slepc { typedef struct ::_p_EPS *EPS; }
30 
31 void MFEMInitializeSlepc();
32 void MFEMInitializeSlepc(int*,char***);
33 void MFEMInitializeSlepc(int*,char***,const char[],const char[]);
34 void MFEMFinalizeSlepc();
35 
37 {
38 private:
39  /// Boolean to handle SetFromOptions calls
40  mutable bool clcustom;
41 
42  /// SLEPc linear eigensolver object
43  slepc::EPS eps;
44 
45  /// Real and imaginary part of eigenvector
46  mutable PetscParVector *VR, *VC;
47 
48 public:
49  /// Constructors
50  SlepcEigenSolver(MPI_Comm comm, const std::string &prefix = std::string());
51 
52  virtual ~SlepcEigenSolver();
53 
54  /// Set solver tolerance
55  void SetTol(double tol);
56 
57  /// Set maximum number of iterations
58  void SetMaxIter(int max_iter);
59  /// Set the number of required eigenmodes
60  void SetNumModes(int num_eigs);
61  /// Set operator for standard eigenvalue problem
62  void SetOperator(const PetscParMatrix &op);
63  /// Set operator for generalized eigenvalue problem
64  void SetOperators(const PetscParMatrix &op, const PetscParMatrix &opB);
65 
66  /// Customize object with options set
67  void Customize(bool customize = true) const;
68 
69  /// Solve the eigenvalue problem for the specified number of eigenvalues
70  void Solve();
71 
72  /// Get the number of converged eigenvalues
73  int GetNumConverged();
74 
75  /// Get the corresponding eigenvalue
76  void GetEigenvalue(unsigned int i, double & lr) const;
77  void GetEigenvalue(unsigned int i, double & lr, double & lc) const;
78 
79  /// Get the corresponding eigenvector
80  void GetEigenvector(unsigned int i, Vector & vr) const;
81  void GetEigenvector(unsigned int i, Vector & vr, Vector & vc) const;
82 
83  /// Target spectrum for the eigensolver. Target imaginary is not supported
84  /// without complex support in SLEPc, and intervals are not implemented.
85  enum Which
86  {
95  };
96 
98  {
101  };
102 
103  void SetWhichEigenpairs(Which which);
104  void SetTarget(double target);
106 
107  /// Conversion function to SLEPc's EPS type.
108  operator slepc::EPS() const { return eps; }
109 
110  /// Conversion function to PetscObject
111  operator PetscObject() const {return (PetscObject)eps; }
112 };
113 
114 }
115 
116 #endif // MFEM_USE_MPI
117 #endif // MFEM_USE_SLEPC
118 
119 #endif // MFEM_SLEPC
void SetOperator(const PetscParMatrix &op)
Set operator for standard eigenvalue problem.
Definition: slepc.cpp:81
void Customize(bool customize=true) const
Customize object with options set.
Definition: slepc.cpp:137
void MFEMInitializeSlepc()
Definition: slepc.cpp:29
Wrapper for PETSc's matrix class.
Definition: petsc.hpp:307
void GetEigenvalue(unsigned int i, double &lr) const
Get the corresponding eigenvalue.
Definition: slepc.cpp:147
void SetTarget(double target)
Definition: slepc.cpp:229
void SetSpectralTransformation(SpectralTransformation transformation)
Definition: slepc.cpp:234
virtual ~SlepcEigenSolver()
Definition: slepc.cpp:70
void transformation(const Vector &p, Vector &v)
void SetMaxIter(int max_iter)
Set maximum number of iterations.
Definition: slepc.cpp:116
void SetNumModes(int num_eigs)
Set the number of required eigenmodes.
Definition: slepc.cpp:124
void Solve()
Solve the eigenvalue problem for the specified number of eigenvalues.
Definition: slepc.cpp:130
void MFEMFinalizeSlepc()
Definition: slepc.cpp:53
void SetTol(double tol)
Set solver tolerance.
Definition: slepc.cpp:106
SlepcEigenSolver(MPI_Comm comm, const std::string &prefix=std::string())
Constructors.
Definition: slepc.cpp:60
int GetNumConverged()
Get the number of converged eigenvalues.
Definition: slepc.cpp:188
void SetWhichEigenpairs(Which which)
Definition: slepc.cpp:195
struct _p_PetscObject * PetscObject
Definition: petsc.hpp:51
Vector data type.
Definition: vector.hpp:60
void GetEigenvector(unsigned int i, Vector &vr) const
Get the corresponding eigenvector.
Definition: slepc.cpp:158
struct::_p_EPS * EPS
Definition: slepc.hpp:29
void SetOperators(const PetscParMatrix &op, const PetscParMatrix &opB)
Set operator for generalized eigenvalue problem.
Definition: slepc.cpp:93