35 #ifndef MFEM_USE_SLEPC
36 #error This examples requires that MFEM is build with MFEM_USE_SLEPC=YES
42 int main(
int argc,
char *argv[])
46 MPI_Init(&argc, &argv);
47 MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
48 MPI_Comm_rank(MPI_COMM_WORLD, &myid);
51 const char *mesh_file =
"../../data/star.mesh";
52 int ser_ref_levels = 2;
53 int par_ref_levels = 1;
57 bool slu_solver =
false;
58 bool sp_solver =
false;
59 bool visualization = 1;
60 bool use_slepc =
true;
61 const char *slepcrc_file =
"";
64 args.
AddOption(&mesh_file,
"-m",
"--mesh",
66 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
67 "Number of times to refine the mesh uniformly in serial.");
68 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
69 "Number of times to refine the mesh uniformly in parallel.");
71 "Finite element order (polynomial degree) or -1 for"
72 " isoparametric space.");
74 "Number of desired eigenmodes.");
76 "Random seed used to initialize LOBPCG.");
77 #ifdef MFEM_USE_SUPERLU
78 args.
AddOption(&slu_solver,
"-slu",
"--superlu",
"-no-slu",
79 "--no-superlu",
"Use the SuperLU Solver.");
81 #ifdef MFEM_USE_STRUMPACK
82 args.
AddOption(&sp_solver,
"-sp",
"--strumpack",
"-no-sp",
83 "--no-strumpack",
"Use the STRUMPACK Solver.");
85 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
87 "Enable or disable GLVis visualization.");
88 args.
AddOption(&use_slepc,
"-useslepc",
"--useslepc",
"-no-slepc",
89 "--no-slepc",
"Use or not SLEPc to solve the eigenvalue problem");
90 args.
AddOption(&slepcrc_file,
"-slepcopts",
"--slepcopts",
91 "SlepcOptions file to use.");
93 if (slu_solver && sp_solver)
96 cout <<
"WARNING: Both SuperLU and STRUMPACK have been selected,"
97 <<
" please choose either one." << endl
98 <<
" Defaulting to SuperLU." << endl;
126 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
132 for (
int lev = 0; lev < ser_ref_levels; lev++)
143 for (
int lev = 0; lev < par_ref_levels; lev++)
168 cout <<
"Number of unknowns: " << size << endl;
209 !use_slepc ? Operator::Hypre_ParCSR : Operator::PETSC_MATAIJ;
213 if (!use_slepc) { Ah.Get(A); }
215 Ah.SetOperatorOwner(
false);
218 if (!use_slepc) {Mh.
Get(M); }
222 #if defined(MFEM_USE_SUPERLU) || defined(MFEM_USE_STRUMPACK)
224 #ifdef MFEM_USE_SUPERLU
230 #ifdef MFEM_USE_STRUMPACK
247 if (!slu_solver && !sp_solver)
255 #ifdef MFEM_USE_SUPERLU
266 #ifdef MFEM_USE_STRUMPACK
322 for (
int i=0; i<nev; i++)
333 ostringstream mesh_name, mode_name;
334 mesh_name <<
"mesh." << setfill(
'0') << setw(6) << myid;
336 ofstream mesh_ofs(mesh_name.str().c_str());
337 mesh_ofs.precision(8);
338 pmesh->
Print(mesh_ofs);
340 for (
int i=0; i<nev; i++)
354 mode_name <<
"mode_" << setfill(
'0') << setw(2) << i <<
"."
355 << setfill(
'0') << setw(6) << myid;
357 ofstream mode_ofs(mode_name.str().c_str());
358 mode_ofs.precision(8);
370 mode_sock.precision(8);
372 for (
int i=0; i<nev; i++)
376 cout <<
"Eigenmode " << i+1 <<
'/' << nev
377 <<
", Lambda = " << eigenvalues[i] << endl;
391 mode_sock <<
"parallel " << num_procs <<
" " << myid <<
"\n"
392 <<
"solution\n" << *pmesh << x << flush
393 <<
"window_title 'Eigenmode " << i+1 <<
'/' << nev
394 <<
", Lambda = " << eigenvalues[i] <<
"'" << endl;
399 cout <<
"press (q)uit or (c)ontinue --> " << flush;
402 MPI_Bcast(&c, 1, MPI_CHAR, 0, MPI_COMM_WORLD);
420 #if defined(MFEM_USE_SUPERLU) || defined(MFEM_USE_STRUMPACK)
int Size() const
Return the logical size of the array.
HypreParVector & GetEigenvector(unsigned int i)
Extract a single eigenvector.
A coefficient that is constant across space and time.
void MFEMInitializeSlepc()
Wrapper for PETSc's matrix class.
Pointer to an Operator of a specified type.
void GetEigenvalue(unsigned int i, double &lr) const
Get the corresponding eigenvalue.
void SetFromCommandLine()
void SetPreconditioner(Solver &precond)
void SetMassMatrix(Operator &M)
Abstract parallel finite element space.
void SetPrintLevel(int logging)
int main(int argc, char *argv[])
void SetTarget(double target)
void SetSymmetricPattern(bool sym)
int close()
Close the socketstream.
virtual int GetTrueVSize() const
Return the number of local vector true dofs.
void SetOperator(const Operator &op)
Set/update the solver for the given operator.
The BoomerAMG solver in hypre.
void SetSpectralTransformation(SpectralTransformation transformation)
void SetPrintFactorStatistics(bool print_stat)
void SetMaxIter(int max_iter)
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
void SetColumnPermutation(superlu::ColPerm col_perm)
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
void SetPrintLevel(int print_level)
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
HYPRE_Int GlobalTrueVSize() const
void SetNumModes(int num_eigs)
Set the number of required eigenmodes.
virtual void Print(std::ostream &out=mfem::out) const
void SetPrintSolveStatistics(bool print_stat)
void SetPrintStatistics(bool print_stat)
void Solve()
Solve the eigenvalue problem for the specified number of eigenvalues.
void PrintUsage(std::ostream &out) const
Print the usage message.
void SetReorderingStrategy(strumpack::ReorderingStrategy method)
Type
Enumeration defining IDs for some classes derived from Operator.
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
void GetEigenvalues(Array< double > &eigenvalues)
Collect the converged eigenvalues.
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
void AddOption(bool *var, const char *enable_short_name, const char *enable_long_name, const char *disable_short_name, const char *disable_long_name, const char *description, bool required=false)
Add a boolean option and set 'var' to receive the value. Enable/disable tags are used to set the bool...
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
void SetRandomSeed(int s)
void SetOperatorOwner(bool own=true)
Set the ownership flag for the held Operator.
void SetWhichEigenpairs(Which which)
void SetKrylovSolver(strumpack::KrylovSolver method)
void SetOperator(Operator &A)
void PrintOptions(std::ostream &out) const
Print the options.
void SetOperator(const Operator &op)
Set/update the solver for the given operator.
void Get(OpType *&A) const
Return the Operator pointer statically cast to a given OpType.
void GetNodes(Vector &node_coord) const
void SetPrecondUsageMode(int pcg_mode)
Arbitrary order H1-conforming (continuous) finite elements.
Class for parallel grid function.
void GetEigenvector(unsigned int i, Vector &vr) const
Get the corresponding eigenvector.
Wrapper for hypre's ParCSR matrix class.
void SetNumModes(int num_eigs)
Class for parallel meshes.
void Solve()
Solve the eigenproblem.
void SetOperators(const PetscParMatrix &op, const PetscParMatrix &opB)
Set operator for generalized eigenvalue problem.
bool Good() const
Return true if the command line options were parsed successfully.