34 #ifndef MFEM_USE_PETSC
35 #error This example requires that MFEM is built with MFEM_USE_PETSC=YES
51 void MonitorSolution(PetscInt it, PetscReal norm,
const Vector &X)
54 if (!it || it > 5) {
return; }
58 _a->RecoverFEMSolution(X, *_b, _x);
60 char vishost[] =
"localhost";
64 MPI_Comm_size(mesh->
GetComm(),&num_procs);
65 MPI_Comm_rank(mesh->
GetComm(),&myid);
67 sol_sock <<
"parallel " << num_procs <<
" " << myid <<
"\n";
68 sol_sock.precision(8);
69 sol_sock <<
"solution\n" << *mesh << _x
70 <<
"window_title 'Iteration no " << it <<
"'" << flush;
74 int main(
int argc,
char *argv[])
78 MPI_Init(&argc, &argv);
79 MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
80 MPI_Comm_rank(MPI_COMM_WORLD, &myid);
83 const char *mesh_file =
"../../data/star.mesh";
85 bool static_cond =
false;
86 bool visualization =
false;
87 bool use_petsc =
true;
88 const char *petscrc_file =
"";
89 bool petscmonitor =
false;
92 args.
AddOption(&mesh_file,
"-m",
"--mesh",
95 "Finite element order (polynomial degree) or -1 for"
96 " isoparametric space.");
97 args.
AddOption(&static_cond,
"-sc",
"--static-condensation",
"-no-sc",
98 "--no-static-condensation",
"Enable static condensation.");
99 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
100 "--no-visualization",
101 "Enable or disable GLVis visualization.");
102 args.
AddOption(&use_petsc,
"-usepetsc",
"--usepetsc",
"-no-petsc",
104 "Use or not PETSc to solve the linear system.");
105 args.
AddOption(&petscrc_file,
"-petscopts",
"--petscopts",
106 "PetscOptions file to use.");
107 args.
AddOption(&petscmonitor,
"-petscmonitor",
"--petscmonitor",
108 "-no-petscmonitor",
"--no-petscmonitor",
109 "Enable or disable GLVis visualization of residual.");
126 PetscInitialize(NULL,NULL,petscrc_file,NULL);
131 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
140 (int)floor(log(10000./mesh->
GetNE())/log(2.)/
dim);
141 for (
int l = 0; l < ref_levels; l++)
153 int par_ref_levels = 2;
154 for (
int l = 0; l < par_ref_levels; l++)
173 cout <<
"Using isoparametric FEs: " << fec->
Name() << endl;
184 cout <<
"Number of finite element unknowns: " << size << endl;
254 bool wrap = !strlen(petscrc_file);
265 UserMonitor mymon(a,b);
266 if (visualization && petscmonitor)
284 ostringstream mesh_name, sol_name;
285 mesh_name <<
"mesh." << setfill(
'0') << setw(6) << myid;
286 sol_name <<
"sol." << setfill(
'0') << setw(6) << myid;
288 ofstream mesh_ofs(mesh_name.str().c_str());
289 mesh_ofs.precision(8);
290 pmesh->
Print(mesh_ofs);
292 ofstream sol_ofs(sol_name.str().c_str());
293 sol_ofs.precision(8);
300 char vishost[] =
"localhost";
303 sol_sock <<
"parallel " << num_procs <<
" " << myid <<
"\n";
304 sol_sock.precision(8);
305 sol_sock <<
"solution\n" << *pmesh << x << flush;
313 if (order > 0) {
delete fec; }
int Size() const
Logical size of the array.
void SetPreconditioner(Solver &precond)
Sets the solver to perform preconditioning.
void SetPrintLevel(int plev)
Class for domain integration L(v) := (f, v)
virtual void GetEssentialTrueDofs(const Array< int > &bdr_attr_is_ess, Array< int > &ess_tdof_list, int component=-1)
Subclass constant coefficient.
int GetNE() const
Returns number of elements.
virtual void Save(std::ostream &out) const
Abstract parallel finite element space.
bool iterative_mode
If true, use the second argument of Mult() as an initial guess.
void Randomize(int seed=0)
Set random values in the vector.
void SetMonitor(PetscSolverMonitor *ctx)
Sets user-defined monitoring routine.
void SetMaxIter(int max_iter)
void SetPrintLevel(int print_lvl)
The BoomerAMG solver in hypre.
HYPRE_Int GetGlobalNumRows() const
Abstract class for monitoring PETSc's solvers.
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 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)
virtual const char * Name() const
void SetPreconditioner(HypreSolver &precond)
Set the hypre solver to be used as a preconditioner.
void SetAbsTol(double tol)
void PrintOptions(std::ostream &out) const
Abstract class for hypre's solvers and preconditioners.
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.