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[])
45 Mpi::Init(argc, argv);
46 int num_procs = Mpi::WorldSize();
47 int myid = Mpi::WorldRank();
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;
124 Device device(device_config);
125 if (myid == 0) { device.
Print(); }
133 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
139 for (
int lev = 0; lev < ser_ref_levels; lev++)
150 for (
int lev = 0; lev < par_ref_levels; lev++)
175 cout <<
"Number of unknowns: " << size << endl;
203 a->EliminateEssentialBCDiag(ess_bdr, 1.0);
216 !use_slepc ? Operator::Hypre_ParCSR : Operator::PETSC_MATAIJ;
219 a->ParallelAssemble(Ah);
220 if (!use_slepc) { Ah.Get(A); }
222 Ah.SetOperatorOwner(
false);
225 if (!use_slepc) {Mh.
Get(M); }
229 #if defined(MFEM_USE_SUPERLU) || defined(MFEM_USE_STRUMPACK) 231 #ifdef MFEM_USE_SUPERLU 237 #ifdef MFEM_USE_STRUMPACK 254 if (!slu_solver && !sp_solver)
262 #ifdef MFEM_USE_SUPERLU 273 #ifdef MFEM_USE_STRUMPACK 277 strumpack->SetPrintFactorStatistics(
true);
278 strumpack->SetPrintSolveStatistics(
false);
279 strumpack->SetKrylovSolver(strumpack::KrylovSolver::DIRECT);
280 strumpack->SetReorderingStrategy(strumpack::ReorderingStrategy::METIS);
329 for (
int i=0; i<nev; i++)
340 ostringstream mesh_name, mode_name;
341 mesh_name <<
"mesh." << setfill(
'0') << setw(6) << myid;
343 ofstream mesh_ofs(mesh_name.str().c_str());
344 mesh_ofs.precision(8);
345 pmesh->
Print(mesh_ofs);
347 for (
int i=0; i<nev; i++)
360 mode_name <<
"mode_" << setfill(
'0') << setw(2) << i <<
"." 361 << setfill(
'0') << setw(6) << myid;
363 ofstream mode_ofs(mode_name.str().c_str());
364 mode_ofs.precision(8);
376 mode_sock.precision(8);
378 for (
int i=0; i<nev; i++)
382 cout <<
"Eigenmode " << i+1 <<
'/' << nev
383 <<
", Lambda = " << eigenvalues[i] << endl;
397 mode_sock <<
"parallel " << num_procs <<
" " << myid <<
"\n" 398 <<
"solution\n" << *pmesh << x << flush
399 <<
"window_title 'Eigenmode " << i+1 <<
'/' << nev
400 <<
", Lambda = " << eigenvalues[i] <<
"'" << endl;
405 cout <<
"press (q)uit or (c)ontinue --> " << flush;
408 MPI_Bcast(&c, 1, MPI_CHAR, 0, MPI_COMM_WORLD);
426 #if defined(MFEM_USE_SUPERLU) || defined(MFEM_USE_STRUMPACK) void GetEigenvalues(Array< double > &eigenvalues) const
Collect the converged eigenvalues.
A coefficient that is constant across space and time.
void PrintOptions(std::ostream &out) const
Print the options.
void MFEMInitializeSlepc()
int Dimension() const
Dimension of the reference space used within the elements.
Wrapper for PETSc's matrix class.
const HypreParVector & GetEigenvector(unsigned int i) const
Extract a single eigenvector.
void GetEigenvalue(unsigned int i, double &lr) const
Get the corresponding eigenvalue.
void PrintUsage(std::ostream &out) const
Print the usage message.
Pointer to an Operator of a specified type.
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
void SetPreconditioner(Solver &precond)
void GetEigenvector(unsigned int i, Vector &vr) const
Get the corresponding eigenvector.
void Print(std::ostream &out=mfem::out)
Print the configuration of the MFEM virtual device object.
void SetMassMatrix(Operator &M)
bool Good() const
Return true if the command line options were parsed successfully.
Abstract parallel finite element space.
void Get(OpType *&A) const
Return the Operator pointer statically cast to a given OpType.
void SetPrintLevel(int logging)
void SetTarget(double target)
void SetSymmetricPattern(bool sym)
int close()
Close the socketstream.
void SetOperator(const Operator &op)
Set/update the solver for the given operator.
The BoomerAMG solver in hypre.
void SetSpectralTransformation(SpectralTransformation transformation)
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)
void SetNumModes(int num_eigs)
Set the number of required eigenmodes.
void SetPrintStatistics(bool print_stat)
void Solve()
Solve the eigenvalue problem for the specified number of eigenvalues.
HYPRE_BigInt GlobalTrueVSize() const
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)
virtual int GetTrueVSize() const
Return the number of local vector true dofs.
void SetOperatorOwner(bool own=true)
Set the ownership flag for the held Operator.
void SetWhichEigenpairs(Which which)
void SetOperator(Operator &A)
int Size() const
Return the logical size of the array.
void SetPrecondUsageMode(int pcg_mode)
Arbitrary order H1-conforming (continuous) finite elements.
void GetNodes(Vector &node_coord) const
void Print(std::ostream &out=mfem::out) const override
Class for parallel grid function.
int main(int argc, char *argv[])
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.