36 #ifndef MFEM_USE_PETSC
37 #error This example requires that MFEM is built with MFEM_USE_PETSC=YES
56 if (!it || it > 5) {
return; }
60 a->RecoverFEMSolution(X, *
b, x);
66 MPI_Comm_size(mesh->
GetComm(),&num_procs);
67 MPI_Comm_rank(mesh->
GetComm(),&myid);
69 sol_sock <<
"parallel " << num_procs <<
" " << myid <<
"\n";
70 sol_sock.precision(8);
71 sol_sock <<
"solution\n" << *mesh << x
72 <<
"window_title 'Iteration no " << it <<
"'" << flush;
76 int main(
int argc,
char *argv[])
80 MPI_Init(&argc, &argv);
81 MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
82 MPI_Comm_rank(MPI_COMM_WORLD, &myid);
85 const char *mesh_file =
"../../data/star.mesh";
87 bool static_cond =
false;
89 bool visualization =
false;
90 const char *device_config =
"cpu";
91 bool use_petsc =
true;
92 const char *petscrc_file =
"";
93 bool petscmonitor =
false;
94 bool forcewrap =
false;
98 args.
AddOption(&mesh_file,
"-m",
"--mesh",
101 "Finite element order (polynomial degree) or -1 for"
102 " isoparametric space.");
103 args.
AddOption(&static_cond,
"-sc",
"--static-condensation",
"-no-sc",
104 "--no-static-condensation",
"Enable static condensation.");
105 args.
AddOption(&pa,
"-pa",
"--partial-assembly",
"-no-pa",
106 "--no-partial-assembly",
"Enable Partial Assembly.");
107 args.
AddOption(&device_config,
"-d",
"--device",
108 "Device configuration string, see Device::Configure().");
109 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
110 "--no-visualization",
111 "Enable or disable GLVis visualization.");
112 args.
AddOption(&use_petsc,
"-usepetsc",
"--usepetsc",
"-no-petsc",
114 "Use or not PETSc to solve the linear system.");
115 args.
AddOption(&petscrc_file,
"-petscopts",
"--petscopts",
116 "PetscOptions file to use.");
117 args.
AddOption(&petscmonitor,
"-petscmonitor",
"--petscmonitor",
118 "-no-petscmonitor",
"--no-petscmonitor",
119 "Enable or disable GLVis visualization of residual.");
120 args.
AddOption(&forcewrap,
"-forcewrap",
"--forcewrap",
121 "-noforce-wrap",
"--noforce-wrap",
122 "Force matrix-free.");
123 args.
AddOption(&useh2,
"-useh2",
"--useh2",
"-no-h2",
125 "Use or not the H2 matrix solver.");
143 Device device(device_config);
144 if (myid == 0) { device.
Print(); }
152 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
161 (int)floor(log(10000./mesh->
GetNE())/log(2.)/
dim);
162 for (
int l = 0; l < ref_levels; l++)
174 int par_ref_levels = 2;
175 for (
int l = 0; l < par_ref_levels; l++)
197 cout <<
"Using isoparametric FEs: " << fec->
Name() << endl;
209 cout <<
"Number of finite element unknowns: " << size << endl;
293 bool wrap = forcewrap ?
true : (pa ?
true : !strlen(petscrc_file));
327 UserMonitor mymon(a,b);
328 if (visualization && petscmonitor)
345 ostringstream mesh_name, sol_name;
346 mesh_name <<
"mesh." << setfill(
'0') << setw(6) << myid;
347 sol_name <<
"sol." << setfill(
'0') << setw(6) << myid;
349 ofstream mesh_ofs(mesh_name.str().c_str());
350 mesh_ofs.precision(8);
351 pmesh->
Print(mesh_ofs);
353 ofstream sol_ofs(sol_name.str().c_str());
354 sol_ofs.precision(8);
361 char vishost[] =
"localhost";
364 sol_sock <<
"parallel " << num_procs <<
" " << myid <<
"\n";
365 sol_sock.precision(8);
366 sol_sock <<
"solution\n" << *pmesh << x << flush;
int Size() const
Return the logical size of the array.
void SetPreconditioner(Solver &precond)
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)
Conjugate gradient method.
OpType * As() const
Return the Operator pointer statically cast to a specified OpType. Similar to the method Get()...
ParMesh * GetParMesh() const
virtual void SetOperator(const Operator &op)
A coefficient that is constant across space and time.
virtual void Mult(const Vector &b, Vector &x) const
Operator application: y=A(x).
Pointer to an Operator of a specified type.
HYPRE_BigInt GlobalTrueVSize() const
int GetNE() const
Returns number of elements.
virtual void Save(std::ostream &out) const
void Print(std::ostream &out=mfem::out)
Print the configuration of the MFEM virtual device object.
Abstract parallel finite element space.
void SetRelTol(double tol)
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.
bool UsesTensorBasis(const FiniteElementSpace &fes)
void SetMonitor(PetscSolverMonitor *ctx)
Sets user-defined monitoring routine.
void SetMaxIter(int max_iter)
The BoomerAMG solver in hypre.
void SetPrintLevel(int print_lvl)
Abstract class for monitoring PETSc's solvers.
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
Jacobi smoothing for a given bilinear form (no matrix necessary).
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
void SetMaxIter(int max_it)
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
virtual void Print(std::ostream &out=mfem::out) const
void PrintUsage(std::ostream &out) const
Print the usage message.
Operator * Ptr() const
Access the underlying Operator pointer.
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
void SetRelTol(double rtol)
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 const char * Name() const
void MFEMInitializePetsc()
Convenience functions to initialize/finalize PETSc.
void SetAbsTol(double tol)
void PrintOptions(std::ostream &out) const
Print the options.
virtual void SetOperator(const Operator &op)
Also calls SetOperator for the preconditioner if there is one.
void GetNodes(Vector &node_coord) const
virtual void SetPreconditioner(Solver &pr)
This should be called before SetOperator.
Arbitrary order H1-conforming (continuous) finite elements.
Class for parallel grid function.
The MFEM Device class abstracts hardware devices such as GPUs, as well as programming models such as ...
Wrapper for hypre's ParCSR matrix class.
virtual void Mult(const Vector &b, Vector &x) const
Application of the solver.
Class for parallel meshes.
bool Good() const
Return true if the command line options were parsed successfully.