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 =
"";
62 const char *device_config =
"cpu";
65 args.
AddOption(&mesh_file,
"-m",
"--mesh",
67 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
68 "Number of times to refine the mesh uniformly in serial.");
69 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
70 "Number of times to refine the mesh uniformly in parallel.");
72 "Finite element order (polynomial degree) or -1 for"
73 " isoparametric space.");
75 "Number of desired eigenmodes.");
77 "Random seed used to initialize LOBPCG.");
78 #ifdef MFEM_USE_SUPERLU
79 args.
AddOption(&slu_solver,
"-slu",
"--superlu",
"-no-slu",
80 "--no-superlu",
"Use the SuperLU Solver.");
82 #ifdef MFEM_USE_STRUMPACK
83 args.
AddOption(&sp_solver,
"-sp",
"--strumpack",
"-no-sp",
84 "--no-strumpack",
"Use the STRUMPACK Solver.");
86 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
88 "Enable or disable GLVis visualization.");
89 args.
AddOption(&use_slepc,
"-useslepc",
"--useslepc",
"-no-slepc",
90 "--no-slepc",
"Use or not SLEPc to solve the eigenvalue problem");
91 args.
AddOption(&slepcrc_file,
"-slepcopts",
"--slepcopts",
92 "SlepcOptions file to use.");
93 args.
AddOption(&device_config,
"-d",
"--device",
94 "Device configuration string, see Device::Configure().");
96 if (slu_solver && sp_solver)
99 cout <<
"WARNING: Both SuperLU and STRUMPACK have been selected,"
100 <<
" please choose either one." << endl
101 <<
" Defaulting to SuperLU." << endl;
125 Device device(device_config);
126 if (myid == 0) { device.
Print(); }
134 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
140 for (
int lev = 0; lev < ser_ref_levels; lev++)
151 for (
int lev = 0; lev < par_ref_levels; lev++)
176 cout <<
"Number of unknowns: " << size << endl;
217 !use_slepc ? Operator::Hypre_ParCSR : Operator::PETSC_MATAIJ;
221 if (!use_slepc) { Ah.Get(A); }
223 Ah.SetOperatorOwner(
false);
226 if (!use_slepc) {Mh.
Get(M); }
230 #if defined(MFEM_USE_SUPERLU) || defined(MFEM_USE_STRUMPACK)
232 #ifdef MFEM_USE_SUPERLU
238 #ifdef MFEM_USE_STRUMPACK
255 if (!slu_solver && !sp_solver)
263 #ifdef MFEM_USE_SUPERLU
274 #ifdef MFEM_USE_STRUMPACK
330 for (
int i=0; i<nev; i++)
341 ostringstream mesh_name, mode_name;
342 mesh_name <<
"mesh." << setfill(
'0') << setw(6) << myid;
344 ofstream mesh_ofs(mesh_name.str().c_str());
345 mesh_ofs.precision(8);
346 pmesh->
Print(mesh_ofs);
348 for (
int i=0; i<nev; i++)
361 mode_name <<
"mode_" << setfill(
'0') << setw(2) << i <<
"."
362 << setfill(
'0') << setw(6) << myid;
364 ofstream mode_ofs(mode_name.str().c_str());
365 mode_ofs.precision(8);
377 mode_sock.precision(8);
379 for (
int i=0; i<nev; i++)
383 cout <<
"Eigenmode " << i+1 <<
'/' << nev
384 <<
", Lambda = " << eigenvalues[i] << endl;
398 mode_sock <<
"parallel " << num_procs <<
" " << myid <<
"\n"
399 <<
"solution\n" << *pmesh << x << flush
400 <<
"window_title 'Eigenmode " << i+1 <<
'/' << nev
401 <<
", Lambda = " << eigenvalues[i] <<
"'" << endl;
406 cout <<
"press (q)uit or (c)ontinue --> " << flush;
409 MPI_Bcast(&c, 1, MPI_CHAR, 0, MPI_COMM_WORLD);
427 #if defined(MFEM_USE_SUPERLU) || defined(MFEM_USE_STRUMPACK)
int Size() const
Return the logical size of the array.
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.
HYPRE_BigInt GlobalTrueVSize() const
void SetFromCommandLine()
void SetPreconditioner(Solver &precond)
void Print(std::ostream &out=mfem::out)
Print the configuration of the MFEM virtual device object.
void SetMassMatrix(Operator &M)
Abstract parallel finite element space.
void SetPrintLevel(int logging)
void SetTarget(double target)
void SetSymmetricPattern(bool sym)
void GetEigenvalues(Array< double > &eigenvalues) const
Collect the converged eigenvalues.
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.
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.
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.
const HypreParVector & GetEigenvector(unsigned int i) const
Extract a single eigenvector.
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.
The MFEM Device class abstracts hardware devices such as GPUs, as well as programming models such as ...
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.