32 #include "mfem-performance.hpp"
63 int main(
int argc,
char *argv[])
67 MPI_Init(&argc, &argv);
68 MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
69 MPI_Comm_rank(MPI_COMM_WORLD, &myid);
72 const char *mesh_file =
"../../data/fichera.mesh";
73 int ser_ref_levels = -1;
74 int par_ref_levels = 1;
76 const char *basis_type =
"G";
77 bool static_cond =
false;
78 const char *pc =
"lor";
80 bool matrix_free =
true;
81 bool visualization = 1;
84 args.
AddOption(&mesh_file,
"-m",
"--mesh",
86 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
87 "Number of times to refine the mesh uniformly in serial;"
88 " -1 = auto: <= 10,000 elements.");
89 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
90 "Number of times to refine the mesh uniformly in parallel.");
92 "Finite element order (polynomial degree) or -1 for"
93 " isoparametric space.");
94 args.
AddOption(&basis_type,
"-b",
"--basis-type",
95 "Basis: G - Gauss-Lobatto, P - Positive, U - Uniform");
96 args.
AddOption(&perf,
"-perf",
"--hpc-version",
"-std",
"--standard-version",
97 "Enable high-performance, tensor-based, assembly/evaluation.");
98 args.
AddOption(&matrix_free,
"-mf",
"--matrix-free",
"-asm",
"--assembly",
99 "Use matrix-free evaluation or efficient matrix assembly in "
100 "the high-performance version.");
101 args.
AddOption(&pc,
"-pc",
"--preconditioner",
102 "Preconditioner: lor - low-order-refined (matrix-free) AMG, "
103 "ho - high-order (assembled) AMG, none.");
104 args.
AddOption(&static_cond,
"-sc",
"--static-condensation",
"-no-sc",
105 "--no-static-condensation",
"Enable static condensation.");
106 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
107 "--no-visualization",
108 "Enable or disable GLVis visualization.");
119 if (static_cond && perf && matrix_free)
123 cout <<
"\nStatic condensation can not be used with matrix-free"
124 " evaluation!\n" << endl;
129 MFEM_VERIFY(perf || !matrix_free,
130 "--standard-version is not compatible with --matrix-free");
136 enum PCType {
NONE, LOR, HO };
138 if (!strcmp(pc,
"ho")) { pc_choice = HO; }
139 else if (!strcmp(pc,
"lor")) { pc_choice = LOR; }
140 else if (!strcmp(pc,
"none")) { pc_choice =
NONE; }
143 mfem_error(
"Invalid Preconditioner specified");
148 int basis = BasisType::GetType(basis_type[0]);
151 cout <<
"Using " << BasisType::Name(basis) <<
" basis ..." << endl;
157 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
165 cout <<
"High-performance version using integration rule with "
166 << int_rule_t::qpts <<
" points ..." << endl;
168 if (!mesh_t::MatchesGeometry(*mesh))
172 cout <<
"The given mesh does not match the optimized 'geom' parameter.\n"
173 <<
"Recompile with suitable 'geom' value." << endl;
179 else if (!mesh_t::MatchesNodes(*mesh))
183 cout <<
"Switching the mesh curvature to match the "
184 <<
"optimized value (order " <<
mesh_p <<
") ..." << endl;
196 int ref_levels = (ser_ref_levels != -1) ? ser_ref_levels :
197 (
int)floor(log(10000./mesh->
GetNE())/log(2.)/
dim);
198 for (
int l = 0; l < ref_levels; l++)
208 cout <<
"NURBS mesh: switching the mesh curvature to be "
209 <<
"min(sol_p, mesh_p) = " << new_mesh_p <<
" ..." << endl;
211 mesh->
SetCurvature(new_mesh_p,
false, -1, Ordering::byNODES);
220 for (
int l = 0; l < par_ref_levels; l++)
227 MFEM_VERIFY(pc_choice != LOR,
"triangle and tet meshes do not support"
228 " the LOR preconditioner yet");
244 cout <<
"Using isoparametric FEs: " << fec->
Name() << endl;
255 cout <<
"Number of finite element unknowns: " << size << endl;
261 if (pc_choice == LOR)
263 int basis_lor = basis;
264 if (basis == BasisType::Positive) { basis_lor=BasisType::ClosedUniform; }
265 pmesh_lor =
new ParMesh(pmesh, order, basis_lor);
271 if (perf && !sol_fes_t::Matches(*fespace))
275 cout <<
"The given order does not match the optimized parameter.\n"
276 <<
"Recompile with suitable 'sol_p' value." << endl;
325 MFEM_VERIFY(pc_choice != LOR,
326 "cannot use LOR preconditioner with static condensation");
331 cout <<
"Assembling the matrix ..." << flush;
372 if (perf && matrix_free)
378 cout <<
"Size of linear system: " << glob_size << endl;
387 cout <<
"Size of linear system: " << glob_size << endl;
395 cout <<
"Assembling the preconditioning matrix ..." << flush;
401 if (pc_choice == LOR)
409 else if (pc_choice == HO)
438 if (pc_choice !=
NONE)
456 cout <<
"Time per CG step: "
462 if (perf && matrix_free)
474 ostringstream mesh_name, sol_name;
475 mesh_name <<
"mesh." << setfill(
'0') << setw(6) << myid;
476 sol_name <<
"sol." << setfill(
'0') << setw(6) << myid;
478 ofstream mesh_ofs(mesh_name.str().c_str());
479 mesh_ofs.precision(8);
480 pmesh->
Print(mesh_ofs);
482 ofstream sol_ofs(sol_name.str().c_str());
483 sol_ofs.precision(8);
490 char vishost[] =
"localhost";
493 sol_sock <<
"parallel " << num_procs <<
" " << myid <<
"\n";
494 sol_sock.precision(8);
495 sol_sock <<
"solution\n" << *pmesh << x << flush;
501 if (a_oper != &A) {
delete a_oper; }
508 if (order > 0) {
delete fec; }
int Size() const
Logical size of the array.
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.
int GetNumIterations() const
Subclass constant coefficient.
virtual void Mult(const Vector &b, Vector &x) const
Operator application: y=A(x).
void MakeRef(const HypreParMatrix &master)
Make this HypreParMatrix a reference to 'master'.
int GetNE() const
Returns number of elements.
virtual void Save(std::ostream &out) const
Abstract parallel finite element space.
int main(int argc, char *argv[])
The BoomerAMG solver in hypre.
HYPRE_Int GetGlobalNumRows() const
Return the global number of rows.
void SetPrintLevel(int print_lvl)
void mfem_error(const char *msg)
Function called when an error is encountered. Used by the macros MFEM_ABORT, MFEM_ASSERT, MFEM_VERIFY.
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
void SetMaxIter(int max_it)
virtual void SetCurvature(int order, bool discont=false, int space_dim=-1, int ordering=1)
int MeshGenerator()
Get the mesh generator/type.
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
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
void SetRelTol(double rtol)
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)
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.
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...
NURBSExtension * NURBSext
Optional NURBS mesh extension.
virtual const char * Name() const
void PrintOptions(std::ostream &out) const
Abstract class for hypre's solvers and preconditioners.
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.
Wrapper for hypre's ParCSR matrix class.
Class for parallel meshes.