40 #ifndef MFEM_USE_PETSC
41 #error This example requires that MFEM is built with MFEM_USE_PETSC=YES
47 int main(
int argc,
char *argv[])
51 MPI_Init(&argc, &argv);
52 MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
53 MPI_Comm_rank(MPI_COMM_WORLD, &myid);
56 const char *mesh_file =
"../../data/beam-tri.mesh";
58 bool static_cond =
false;
59 bool visualization = 1;
61 bool use_petsc =
true;
62 const char *petscrc_file =
"";
63 bool use_nonoverlapping =
false;
66 args.
AddOption(&mesh_file,
"-m",
"--mesh",
69 "Finite element order (polynomial degree).");
70 args.
AddOption(&amg_elast,
"-elast",
"--amg-for-elasticity",
"-sys",
72 "Use the special AMG elasticity solver (GM/LN approaches), "
73 "or standard AMG for systems (unknown approach).");
74 args.
AddOption(&static_cond,
"-sc",
"--static-condensation",
"-no-sc",
75 "--no-static-condensation",
"Enable static condensation.");
76 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
78 "Enable or disable GLVis visualization.");
79 args.
AddOption(&use_petsc,
"-usepetsc",
"--usepetsc",
"-no-petsc",
81 "Use or not PETSc to solve the linear system.");
82 args.
AddOption(&petscrc_file,
"-petscopts",
"--petscopts",
83 "PetscOptions file to use.");
84 args.
AddOption(&use_nonoverlapping,
"-nonoverlapping",
"--nonoverlapping",
85 "-no-nonoverlapping",
"--no-nonoverlapping",
86 "Use or not the block diagonal PETSc's matrix format "
87 "for non-overlapping domain decomposition.");
104 if (use_petsc) { PetscInitialize(NULL,NULL,petscrc_file,NULL); }
109 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
115 cerr <<
"\nInput mesh should have at least two materials and "
116 <<
"two boundary attributes! (See schematic in ex2.cpp)\n"
135 (int)floor(log(1000./mesh->
GetNE())/log(2.)/
dim);
136 for (
int l = 0; l < ref_levels; l++)
148 int par_ref_levels = 1;
149 for (
int l = 0; l < par_ref_levels; l++)
163 const bool use_nodal_fespace = pmesh->
NURBSext && !amg_elast;
164 if (use_nodal_fespace)
177 cout <<
"Number of finite element unknowns: " << size << endl
178 <<
"Assembling: " << flush;
199 for (
int i = 0; i < dim-1; i++)
206 pull_force(1) = -1.0e-2;
214 cout <<
"r.h.s. ... " << flush;
229 lambda(0) = lambda(1)*50;
243 if (myid == 0) { cout <<
"matrix ... " << flush; }
254 cout <<
"done." << endl;
284 Operator::PETSC_MATIS : Operator::PETSC_MATAIJ);
288 cout <<
"done." << endl;
289 cout <<
"Size of linear system: " << A.
M() << endl;
313 if (!use_nodal_fespace)
326 ostringstream mesh_name, sol_name;
327 mesh_name <<
"mesh." << setfill(
'0') << setw(6) << myid;
328 sol_name <<
"sol." << setfill(
'0') << setw(6) << myid;
330 ofstream mesh_ofs(mesh_name.str().c_str());
331 mesh_ofs.precision(8);
332 pmesh->
Print(mesh_ofs);
334 ofstream sol_ofs(sol_name.str().c_str());
335 sol_ofs.precision(8);
343 char vishost[] =
"localhost";
346 sol_sock <<
"parallel " << num_procs <<
" " << myid <<
"\n";
347 sol_sock.precision(8);
348 sol_sock <<
"solution\n" << *pmesh << x << flush;
362 if (use_petsc) { PetscFinalize(); }
void SetPrintLevel(int plev)
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.
Class for grid function - Vector with associated FE space.
Subclass constant coefficient.
Wrapper for PETSc's matrix class.
int GetNE() const
Returns number of elements.
virtual void Save(std::ostream &out) const
Abstract parallel finite element space.
void SetMaxIter(int max_iter)
int main(int argc, char *argv[])
void SetPrintLevel(int print_lvl)
PetscInt M() const
Returns the global number of rows.
void SetSystemsOptions(int dim)
The BoomerAMG solver in hypre.
HYPRE_Int GetGlobalNumRows() const
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
HYPRE_Int GlobalTrueVSize() const
virtual void Print(std::ostream &out=mfem::out) const
void SetElasticityOptions(ParFiniteElementSpace *fespace)
void SetNodalFESpace(FiniteElementSpace *nfes)
void PrintUsage(std::ostream &out) const
void SetMaxIter(int max_iter)
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
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)
NURBSExtension * NURBSext
Optional NURBS mesh extension.
class for piecewise constant coefficient
void DegreeElevate(int rel_degree, int degree=16)
void SetPreconditioner(HypreSolver &precond)
Set the hypre solver to be used as a preconditioner.
void PrintOptions(std::ostream &out) const
void GetNodes(Vector &node_coord) const
Arbitrary order H1-conforming (continuous) finite elements.
Class for parallel grid function.
Wrapper for hypre's ParCSR matrix class.
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Solve Ax=b with hypre's PCG.
virtual void Mult(const Vector &b, Vector &x) const
Application of the solver.
Class for parallel meshes.
void Set(int i, Coefficient *c)
Sets coefficient in the vector.
Array< int > attributes
A list of all unique element attributes used by the Mesh.