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;
 
   70   const char *device_config = 
"cpu";
 
   73   args.
AddOption(&mesh_file, 
"-m", 
"--mesh",
 
   75   args.
AddOption(&ser_ref_levels, 
"-rs", 
"--refine-serial",
 
   76                  "Number of times to refine the mesh uniformly in serial.");
 
   77   args.
AddOption(&par_ref_levels, 
"-rp", 
"--refine-parallel",
 
   78                  "Number of times to refine the mesh uniformly in parallel.");
 
   80                  "Finite element order (polynomial degree).");
 
   81   args.
AddOption(&amg_elast, 
"-elast", 
"--amg-for-elasticity", 
"-sys",
 
   83                  "Use the special AMG elasticity solver (GM/LN approaches), " 
   84                  "or standard AMG for systems (unknown approach).");
 
   85   args.
AddOption(&static_cond, 
"-sc", 
"--static-condensation", 
"-no-sc",
 
   86                  "--no-static-condensation", 
"Enable static condensation.");
 
   87   args.
AddOption(&visualization, 
"-vis", 
"--visualization", 
"-no-vis",
 
   89                  "Enable or disable GLVis visualization.");
 
   90   args.
AddOption(&use_petsc, 
"-usepetsc", 
"--usepetsc", 
"-no-petsc",
 
   92                  "Use or not PETSc to solve the linear system.");
 
   93   args.
AddOption(&petscrc_file, 
"-petscopts", 
"--petscopts",
 
   94                  "PetscOptions file to use.");
 
   95   args.
AddOption(&use_nonoverlapping, 
"-nonoverlapping", 
"--nonoverlapping",
 
   96                  "-no-nonoverlapping", 
"--no-nonoverlapping",
 
   97                  "Use or not the block diagonal PETSc's matrix format " 
   98                  "for non-overlapping domain decomposition.");
 
   99   args.
AddOption(&device_config, 
"-d", 
"--device",
 
  100                  "Device configuration string, see Device::Configure().");
 
  117   Device device(device_config);
 
  118   if (myid == 0) { device.
Print(); }
 
  126   Mesh *mesh = 
new Mesh(mesh_file, 1, 1);
 
  132         cerr << 
"\nInput mesh should have at least two materials and " 
  133              << 
"two boundary attributes! (See schematic in ex2.cpp)\n" 
  150      int ref_levels = ser_ref_levels >= 0 ? ser_ref_levels :
 
  151                       (int)floor(log(1000./mesh->
GetNE())/log(2.)/
dim);
 
  152      for (
int l = 0; l < ref_levels; l++)
 
  164      for (
int l = 0; l < par_ref_levels; l++)
 
  178   const bool use_nodal_fespace = pmesh->
NURBSext && !amg_elast;
 
  179   if (use_nodal_fespace)
 
  192      cout << 
"Number of finite element unknowns: " << size << endl
 
  193           << 
"Assembling: " << flush;
 
  214   for (
int i = 0; i < 
dim-1; i++)
 
  221      pull_force(1) = -1.0e-2;
 
  229      cout << 
"r.h.s. ... " << flush;
 
  244   lambda(0) = lambda(1)*50;
 
  258   if (myid == 0) { cout << 
"matrix ... " << flush; }
 
  259   if (static_cond) { 
a->EnableStaticCondensation(); }
 
  263   a->Assemble(use_petsc ? 0 : 1);
 
  272         cout << 
"done." << endl;
 
  279      if (amg_elast && !
a->StaticCondensationIsEnabled())
 
  301      a->SetOperatorType(use_nonoverlapping ?
 
  306         cout << 
"done." << endl;
 
  307         cout << 
"Size of linear system: " << A.
M() << endl;
 
  316      if (use_nonoverlapping) 
 
  356   if (!use_nodal_fespace)
 
  369      ostringstream mesh_name, sol_name;
 
  370      mesh_name << 
"mesh." << setfill(
'0') << setw(6) << myid;
 
  371      sol_name << 
"sol." << setfill(
'0') << setw(6) << myid;
 
  373      ofstream mesh_ofs(mesh_name.str().c_str());
 
  374      mesh_ofs.precision(8);
 
  375      pmesh->
Print(mesh_ofs);
 
  377      ofstream sol_ofs(sol_name.str().c_str());
 
  378      sol_ofs.precision(8);
 
  389      sol_sock << 
"parallel " << num_procs << 
" " << myid << 
"\n";
 
  390      sol_sock.precision(8);
 
  391      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.
 
The MFEM Device class abstracts hardware devices such as GPUs, as well as programming models such as ...
 
void Print(std::ostream &out=mfem::out)
Print the configuration of the MFEM virtual device object.
 
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 Mult(const HypreParVector &b, HypreParVector &x) const override
Solve Ax=b with hypre's PCG.
 
void SetPrintLevel(int print_lvl)
 
void SetPreconditioner(HypreSolver &precond)
Set the hypre solver to be used as a preconditioner.
 
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)
 
void Mult(const Vector &b, Vector &x) const override
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)
 
std::array< int, NCMesh::MaxFaceNodes > nodes