45#error This example requires that MFEM is built with MFEM_USE_PETSC=YES
51int main(
int argc,
char *argv[])
60 const char *mesh_file =
"../../data/beam-tri.mesh";
61 int ser_ref_levels = -1;
62 int par_ref_levels = 1;
64 bool static_cond =
false;
65 bool visualization = 1;
67 bool use_petsc =
true;
68 const char *petscrc_file =
"";
69 bool use_nonoverlapping =
false;
72 args.
AddOption(&mesh_file,
"-m",
"--mesh",
74 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
75 "Number of times to refine the mesh uniformly in serial.");
76 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
77 "Number of times to refine the mesh uniformly in parallel.");
79 "Finite element order (polynomial degree).");
80 args.
AddOption(&amg_elast,
"-elast",
"--amg-for-elasticity",
"-sys",
82 "Use the special AMG elasticity solver (GM/LN approaches), "
83 "or standard AMG for systems (unknown approach).");
84 args.
AddOption(&static_cond,
"-sc",
"--static-condensation",
"-no-sc",
85 "--no-static-condensation",
"Enable static condensation.");
86 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
88 "Enable or disable GLVis visualization.");
89 args.
AddOption(&use_petsc,
"-usepetsc",
"--usepetsc",
"-no-petsc",
91 "Use or not PETSc to solve the linear system.");
92 args.
AddOption(&petscrc_file,
"-petscopts",
"--petscopts",
93 "PetscOptions file to use.");
94 args.
AddOption(&use_nonoverlapping,
"-nonoverlapping",
"--nonoverlapping",
95 "-no-nonoverlapping",
"--no-nonoverlapping",
96 "Use or not the block diagonal PETSc's matrix format "
97 "for non-overlapping domain decomposition.");
118 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
124 cerr <<
"\nInput mesh should have at least two materials and "
125 <<
"two boundary attributes! (See schematic in ex2.cpp)\n"
142 int ref_levels = ser_ref_levels >= 0 ? ser_ref_levels :
143 (int)floor(log(1000./mesh->
GetNE())/log(2.)/
dim);
144 for (
int l = 0; l < ref_levels; l++)
156 for (
int l = 0; l < par_ref_levels; l++)
170 const bool use_nodal_fespace = pmesh->
NURBSext && !amg_elast;
171 if (use_nodal_fespace)
184 cout <<
"Number of finite element unknowns: " << size << endl
185 <<
"Assembling: " << flush;
206 for (
int i = 0; i <
dim-1; i++)
213 pull_force(1) = -1.0e-2;
221 cout <<
"r.h.s. ... " << flush;
236 lambda(0) = lambda(1)*50;
250 if (myid == 0) { cout <<
"matrix ... " << flush; }
251 if (static_cond) {
a->EnableStaticCondensation(); }
255 a->Assemble(use_petsc ? 0 : 1);
264 cout <<
"done." << endl;
271 if (amg_elast && !
a->StaticCondensationIsEnabled())
293 a->SetOperatorType(use_nonoverlapping ?
298 cout <<
"done." << endl;
299 cout <<
"Size of linear system: " << A.
M() << endl;
308 if (use_nonoverlapping)
348 if (!use_nodal_fespace)
361 ostringstream mesh_name, sol_name;
362 mesh_name <<
"mesh." << setfill(
'0') << setw(6) << myid;
363 sol_name <<
"sol." << setfill(
'0') << setw(6) << myid;
365 ofstream mesh_ofs(mesh_name.str().c_str());
366 mesh_ofs.precision(8);
367 pmesh->
Print(mesh_ofs);
369 ofstream sol_ofs(sol_name.str().c_str());
370 sol_ofs.precision(8);
381 sol_sock <<
"parallel " << num_procs <<
" " << myid <<
"\n";
382 sol_sock.precision(8);
383 sol_sock <<
"solution\n" << *pmesh << x << flush;
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
A coefficient that is constant across space and time.
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
Class for grid function - Vector with associated FE space.
Arbitrary order H1-conforming (continuous) finite elements.
The BoomerAMG solver in hypre.
void SetSystemsOptions(int dim, bool order_bynodes=false)
void SetElasticityOptions(ParFiniteElementSpace *fespace, bool interp_refine=true)
void SetPrintLevel(int print_lvl)
void SetPreconditioner(HypreSolver &precond)
Set the hypre solver to be used as a preconditioner.
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Solve Ax=b with hypre's PCG.
void SetMaxIter(int max_iter)
Wrapper for hypre's ParCSR matrix class.
HYPRE_BigInt GetGlobalNumRows() const
Return the global number of rows.
static void Init()
Initialize hypre by calling HYPRE_Init() and set default options. After calling Hypre::Init(),...
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
NURBSExtension * NURBSext
Optional NURBS mesh extension.
int GetNE() const
Returns number of elements.
int Dimension() const
Dimension of the reference space used within the elements.
void GetNodes(Vector &node_coord) const
void DegreeElevate(int rel_degree, int degree=16)
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Array< int > attributes
A list of all unique element attributes used by the Mesh.
static int WorldRank()
Return the MPI rank in MPI_COMM_WORLD.
static int WorldSize()
Return the size of MPI_COMM_WORLD.
static void Init(int &argc, char **&argv, int required=default_thread_required, int *provided=nullptr)
Singleton creation with Mpi::Init(argc, argv).
void FormLinearSystem(const Array< int > &ess_tdof_list, Vector &x, Vector &b, Operator *&A, Vector &X, Vector &B, int copy_interior=0)
Form a constrained linear system using a matrix-free approach.
@ PETSC_MATIS
ID for class PetscParMatrix, MATIS format.
@ PETSC_MATAIJ
ID for class PetscParMatrix, MATAIJ format.
virtual void RecoverFEMSolution(const Vector &X, const Vector &b, Vector &x)
Reconstruct a solution vector x (e.g. a GridFunction) from the solution X of a constrained linear sys...
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
void PrintUsage(std::ostream &out) const
Print the usage message.
void PrintOptions(std::ostream &out) const
Print the options.
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...
bool Good() const
Return true if the command line options were parsed successfully.
A piecewise constant coefficient with the constants keyed off the element attribute numbers.
Abstract parallel finite element space.
void GetEssentialTrueDofs(const Array< int > &bdr_attr_is_ess, Array< int > &ess_tdof_list, int component=-1) const override
HYPRE_BigInt GlobalTrueVSize() const
Class for parallel grid function.
void Save(std::ostream &out) const override
Class for parallel meshes.
void SetNodalFESpace(FiniteElementSpace *nfes) override
void Print(std::ostream &out=mfem::out, const std::string &comments="") const override
Auxiliary class for BDDC customization.
void SetEssBdrDofs(const Array< int > *essdofs, bool loc=false)
Specify dofs on the essential boundary.
void SetSpace(ParFiniteElementSpace *fe)
void SetNatBdrDofs(const Array< int > *natdofs, bool loc=false)
Specify dofs on the natural boundary.
void SetPreconditioner(Solver &precond)
virtual void Mult(const Vector &b, Vector &x) const
Application of the solver.
Wrapper for PETSc's matrix class.
PetscInt M() const
Returns the global number of rows.
void SetBlockSize(PetscInt rbs, PetscInt cbs=-1)
Set row and column block sizes of a matrix.
Abstract class for PETSc's preconditioners.
void SetPrintLevel(int plev)
void SetMaxIter(int max_iter)
Vector coefficient defined by an array of scalar coefficients. Coefficients that are not set will eva...
Vector & Set(const real_t a, const Vector &x)
(*this) = a * x
void MFEMInitializePetsc()
Convenience functions to initialize/finalize PETSc.
std::function< real_t(const Vector &)> f(real_t mass_coeff)