44 #ifndef MFEM_USE_PETSC 45 #error This example requires that MFEM is built with MFEM_USE_PETSC=YES 51 int main(
int argc,
char *argv[])
54 Mpi::Init(argc, argv);
55 int num_procs = Mpi::WorldSize();
56 int myid = Mpi::WorldRank();
60 const char *mesh_file =
"../../data/beam-tri.mesh";
62 bool static_cond =
false;
63 bool visualization = 1;
65 bool use_petsc =
true;
66 const char *petscrc_file =
"";
67 bool use_nonoverlapping =
false;
68 int ser_ref_levels = -1, par_ref_levels = 1;
71 args.
AddOption(&mesh_file,
"-m",
"--mesh",
73 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
74 "Number of times to refine the mesh uniformly in serial.");
75 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
76 "Number of times to refine the mesh uniformly in parallel.");
78 "Finite element order (polynomial degree).");
79 args.
AddOption(&amg_elast,
"-elast",
"--amg-for-elasticity",
"-sys",
81 "Use the special AMG elasticity solver (GM/LN approaches), " 82 "or standard AMG for systems (unknown approach).");
83 args.
AddOption(&static_cond,
"-sc",
"--static-condensation",
"-no-sc",
84 "--no-static-condensation",
"Enable static condensation.");
85 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
87 "Enable or disable GLVis visualization.");
88 args.
AddOption(&use_petsc,
"-usepetsc",
"--usepetsc",
"-no-petsc",
90 "Use or not PETSc to solve the linear system.");
91 args.
AddOption(&petscrc_file,
"-petscopts",
"--petscopts",
92 "PetscOptions file to use.");
93 args.
AddOption(&use_nonoverlapping,
"-nonoverlapping",
"--nonoverlapping",
94 "-no-nonoverlapping",
"--no-nonoverlapping",
95 "Use or not the block diagonal PETSc's matrix format " 96 "for non-overlapping domain decomposition.");
117 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
123 cerr <<
"\nInput mesh should have at least two materials and " 124 <<
"two boundary attributes! (See schematic in ex2.cpp)\n" 141 int ref_levels = ser_ref_levels >= 0 ? ser_ref_levels :
142 (int)floor(log(1000./mesh->
GetNE())/log(2.)/
dim);
143 for (
int l = 0; l < ref_levels; l++)
155 for (
int l = 0; l < par_ref_levels; l++)
169 const bool use_nodal_fespace = pmesh->
NURBSext && !amg_elast;
170 if (use_nodal_fespace)
183 cout <<
"Number of finite element unknowns: " << size << endl
184 <<
"Assembling: " << flush;
205 for (
int i = 0; i <
dim-1; i++)
212 pull_force(1) = -1.0e-2;
220 cout <<
"r.h.s. ... " << flush;
235 lambda(0) = lambda(1)*50;
249 if (myid == 0) { cout <<
"matrix ... " << flush; }
250 if (static_cond) {
a->EnableStaticCondensation(); }
254 a->Assemble(use_petsc ? 0 : 1);
260 a->FormLinearSystem(ess_tdof_list, x, *
b, A, X, B);
263 cout <<
"done." << endl;
270 if (amg_elast && !
a->StaticCondensationIsEnabled())
292 a->SetOperatorType(use_nonoverlapping ?
293 Operator::PETSC_MATIS : Operator::PETSC_MATAIJ);
294 a->FormLinearSystem(ess_tdof_list, x, *
b, A, X, B);
297 cout <<
"done." << endl;
298 cout <<
"Size of linear system: " << A.
M() << endl;
307 if (use_nonoverlapping)
338 a->RecoverFEMSolution(X, *
b, x);
347 if (!use_nodal_fespace)
360 ostringstream mesh_name, sol_name;
361 mesh_name <<
"mesh." << setfill(
'0') << setw(6) << myid;
362 sol_name <<
"sol." << setfill(
'0') << setw(6) << myid;
364 ofstream mesh_ofs(mesh_name.str().c_str());
365 mesh_ofs.precision(8);
366 pmesh->
Print(mesh_ofs);
368 ofstream sol_ofs(sol_name.str().c_str());
369 sol_ofs.precision(8);
380 sol_sock <<
"parallel " << num_procs <<
" " << myid <<
"\n";
381 sol_sock.precision(8);
382 sol_sock <<
"solution\n" << *pmesh << x << flush;
void SetPreconditioner(Solver &precond)
void SetPrintLevel(int plev)
virtual void Mult(const Vector &b, Vector &x) const
Application of the solver.
virtual void GetEssentialTrueDofs(const Array< int > &bdr_attr_is_ess, Array< int > &ess_tdof_list, int component=-1)
Vector coefficient defined by an array of scalar coefficients. Coefficients that are not set will eva...
Class for grid function - Vector with associated FE space.
Abstract class for PETSc's preconditioners.
A coefficient that is constant across space and time.
void PrintOptions(std::ostream &out) const
Print the options.
int Dimension() const
Dimension of the reference space used within the elements.
Wrapper for PETSc's matrix class.
void PrintUsage(std::ostream &out) const
Print the usage message.
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Solve Ax=b with hypre's PCG.
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
void SetBlockSize(PetscInt rbs, PetscInt cbs=-1)
Set row and column block sizes of a matrix.
bool Good() const
Return true if the command line options were parsed successfully.
Abstract parallel finite element space.
PetscInt M() const
Returns the global number of rows.
void SetMaxIter(int max_iter)
void SetPrintLevel(int print_lvl)
int main(int argc, char *argv[])
The BoomerAMG solver in hypre.
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Auxiliary class for BDDC customization.
void SetElasticityOptions(ParFiniteElementSpace *fespace)
HYPRE_BigInt GlobalTrueVSize() const
void SetMaxIter(int max_iter)
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...
virtual void Save(std::ostream &out) const
int GetNE() const
Returns number of elements.
NURBSExtension * NURBSext
Optional NURBS mesh extension.
A piecewise constant coefficient with the constants keyed off the element attribute numbers...
void MFEMInitializePetsc()
Convenience functions to initialize/finalize PETSc.
void SetSpace(ParFiniteElementSpace *fe)
void DegreeElevate(int rel_degree, int degree=16)
void SetPreconditioner(HypreSolver &precond)
Set the hypre solver to be used as a preconditioner.
void SetSystemsOptions(int dim, bool order_bynodes=false)
void SetNodalFESpace(FiniteElementSpace *nfes) override
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.
void SetNatBdrDofs(const Array< int > *natdofs, bool loc=false)
Specify dofs on the natural boundary.
Wrapper for hypre's ParCSR matrix class.
Class for parallel meshes.
void SetEssBdrDofs(const Array< int > *essdofs, bool loc=false)
Specify dofs on the essential boundary.
HYPRE_BigInt GetGlobalNumRows() const
Return the global number of rows.
Array< int > attributes
A list of all unique element attributes used by the Mesh.
double f(const Vector &p)