12 #include "../config/config.hpp" 22 static PetscErrorCode ierr;
45 ierr = PetscOptionsSetValue(NULL,
"-cuda_device",
47 MFEM_VERIFY(!ierr,
"Unable to set initial option value to PETSc");
49 ierr = SlepcInitialize(argc,argv,rc_file,help);
50 MFEM_VERIFY(!ierr,
"Unable to initialize SLEPc");
55 ierr = SlepcFinalize();
56 MFEM_VERIFY(!ierr,
"Unable to finalize SLEPc");
60 SlepcEigenSolver::SlepcEigenSolver(MPI_Comm comm,
const std::string &prefix)
66 ierr = EPSCreate(comm,&eps); CCHKERRQ(comm,ierr);
67 ierr = EPSSetOptionsPrefix(eps, prefix.c_str()); PCHKERRQ(eps, ierr);
70 SlepcEigenSolver::~SlepcEigenSolver()
76 ierr = PetscObjectGetComm((
PetscObject)eps,&comm); PCHKERRQ(eps,ierr);
77 ierr = EPSDestroy(&eps); CCHKERRQ(comm,ierr);
87 ierr = EPSSetOperators(eps,op,NULL); PCHKERRQ(eps, ierr);
100 ierr = EPSSetOperators(eps,op,opB); PCHKERRQ(eps,ierr);
106 void SlepcEigenSolver::SetTol(
double tol)
110 ierr = EPSGetTolerances(eps,NULL,&max_its); PCHKERRQ(eps,ierr);
112 if (max_its==0) { max_its = PETSC_DECIDE; }
113 ierr = EPSSetTolerances(eps,tol,max_its); PCHKERRQ(eps,ierr);
116 void SlepcEigenSolver::SetMaxIter(
int max_its)
120 ierr = EPSGetTolerances(eps,&tol,NULL); PCHKERRQ(eps,ierr);
121 ierr = EPSSetTolerances(eps,tol,max_its); PCHKERRQ(eps,ierr);
124 void SlepcEigenSolver::SetNumModes(
int num_eigs)
126 ierr = EPSSetDimensions(eps,num_eigs,PETSC_DECIDE,PETSC_DECIDE);
130 void SlepcEigenSolver::Solve()
134 ierr = EPSSolve(eps); PCHKERRQ(eps,ierr);
137 void SlepcEigenSolver::Customize(
bool customize)
const 139 if (!customize) {clcustom =
true; }
142 ierr = EPSSetFromOptions(eps); PCHKERRQ(eps,ierr);
147 void SlepcEigenSolver::GetEigenvalue(
unsigned int i,
double & lr)
const 149 ierr = EPSGetEigenvalue(eps,i,&lr,NULL); PCHKERRQ(eps,ierr);
152 void SlepcEigenSolver::GetEigenvalue(
unsigned int i,
double & lr,
155 ierr = EPSGetEigenvalue(eps,i,&lr,&lc); PCHKERRQ(eps,ierr);
158 void SlepcEigenSolver::GetEigenvector(
unsigned int i,
Vector & vr)
const 160 MFEM_VERIFY(VR,
"Missing real vector");
162 MFEM_ASSERT(vr.
Size() == VR->Size(),
"invalid vr.Size() = " << vr.
Size()
163 <<
", expected size = " << VR->Size());
166 ierr = EPSGetEigenvector(eps,i,*VR,NULL); PCHKERRQ(eps,ierr);
171 void SlepcEigenSolver::GetEigenvector(
unsigned int i,
Vector & vr,
174 MFEM_VERIFY(VR,
"Missing real vector");
175 MFEM_VERIFY(VC,
"Missing imaginary vector");
176 MFEM_ASSERT(vr.
Size() == VR->Size(),
"invalid vr.Size() = " << vr.
Size()
177 <<
", expected size = " << VR->Size());
178 MFEM_ASSERT(vc.
Size() == VC->Size(),
"invalid vc.Size() = " << vc.
Size()
179 <<
", expected size = " << VC->Size());
183 ierr = EPSGetEigenvector(eps,i,*VR,*VC); PCHKERRQ(eps,ierr);
188 int SlepcEigenSolver::GetNumConverged()
191 ierr = EPSGetConverged(eps,&num_conv); PCHKERRQ(eps,ierr);
192 return static_cast<int>(num_conv);
199 case SlepcEigenSolver::LARGEST_MAGNITUDE:
200 ierr = EPSSetWhichEigenpairs(eps,EPS_LARGEST_MAGNITUDE); PCHKERRQ(eps,ierr);
202 case SlepcEigenSolver::SMALLEST_MAGNITUDE:
203 ierr = EPSSetWhichEigenpairs(eps,EPS_SMALLEST_MAGNITUDE); PCHKERRQ(eps,ierr);
205 case SlepcEigenSolver::LARGEST_REAL:
206 ierr = EPSSetWhichEigenpairs(eps,EPS_LARGEST_REAL); PCHKERRQ(eps,ierr);
208 case SlepcEigenSolver::SMALLEST_REAL:
209 ierr = EPSSetWhichEigenpairs(eps,EPS_SMALLEST_REAL); PCHKERRQ(eps,ierr);
211 case SlepcEigenSolver::LARGEST_IMAGINARY:
212 ierr = EPSSetWhichEigenpairs(eps,EPS_LARGEST_IMAGINARY); PCHKERRQ(eps,ierr);
214 case SlepcEigenSolver::SMALLEST_IMAGINARY:
215 ierr = EPSSetWhichEigenpairs(eps,EPS_SMALLEST_IMAGINARY); PCHKERRQ(eps,ierr);
217 case SlepcEigenSolver::TARGET_MAGNITUDE:
218 ierr = EPSSetWhichEigenpairs(eps,EPS_TARGET_MAGNITUDE); PCHKERRQ(eps,ierr);
220 case SlepcEigenSolver::TARGET_REAL:
221 ierr = EPSSetWhichEigenpairs(eps,EPS_TARGET_REAL); PCHKERRQ(eps,ierr);
224 MFEM_ABORT(
"Which eigenpair not implemented!");
229 void SlepcEigenSolver::SetTarget(
double target)
231 ierr = EPSSetTarget(eps,target); PCHKERRQ(eps,ierr);
234 void SlepcEigenSolver::SetSpectralTransformation(
238 ierr = EPSGetST(eps,&st); PCHKERRQ(eps,ierr);
241 case SlepcEigenSolver::SHIFT:
242 ierr = STSetType(st,STSHIFT); PCHKERRQ(eps,ierr);
244 case SlepcEigenSolver::SHIFT_INVERT:
245 ierr = STSetType(st,STSINVERT); PCHKERRQ(eps,ierr);
248 MFEM_ABORT(
"Spectral transformation not implemented!");
255 #endif // MFEM_USE_SLEPC 256 #endif // MFEM_USE_PETSC 257 #endif // MFEM_USE_MPI static int GetId()
Get the device id of the configured device.
Wrapper for PETSc's matrix class.
int Size() const
Returns the size of the vector.
Memory< double > & GetMemory()
Return a reference to the Memory object used by the Vector.
void MFEMInitializeSlepc(int *argc, char ***argv, const char rc_file[], const char help[])
void transformation(const Vector &p, Vector &v)
Biwise-OR of all CUDA backends.
static bool Allows(unsigned long b_mask)
Return true if any of the backends in the backend mask, b_mask, are allowed.
struct _p_PetscObject * PetscObject