32 #include "mfem-performance.hpp"
63 int main(
int argc,
char *argv[])
66 const char *mesh_file =
"../../data/fichera.mesh";
69 const char *basis_type =
"G";
70 bool static_cond =
false;
71 const char *pc =
"none";
73 bool matrix_free =
true;
74 bool visualization = 1;
77 args.
AddOption(&mesh_file,
"-m",
"--mesh",
79 args.
AddOption(&ref_levels,
"-r",
"--refine",
80 "Number of times to refine the mesh uniformly;"
81 " -1 = auto: <= 50,000 elements.");
83 "Finite element order (polynomial degree) or -1 for"
84 " isoparametric space.");
85 args.
AddOption(&basis_type,
"-b",
"--basis-type",
86 "Basis: G - Gauss-Lobatto, P - Positive, U - Uniform");
87 args.
AddOption(&perf,
"-perf",
"--hpc-version",
"-std",
"--standard-version",
88 "Enable high-performance, tensor-based, assembly/evaluation.");
89 args.
AddOption(&matrix_free,
"-mf",
"--matrix-free",
"-asm",
"--assembly",
90 "Use matrix-free evaluation or efficient matrix assembly in "
91 "the high-performance version.");
92 args.
AddOption(&pc,
"-pc",
"--preconditioner",
93 "Preconditioner: lor - low-order-refined (matrix-free) GS, "
94 "ho - high-order (assembled) GS, none.");
95 args.
AddOption(&static_cond,
"-sc",
"--static-condensation",
"-no-sc",
96 "--no-static-condensation",
"Enable static condensation.");
97 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
99 "Enable or disable GLVis visualization.");
106 if (static_cond && perf && matrix_free)
108 cout <<
"\nStatic condensation can not be used with matrix-free"
109 " evaluation!\n" << endl;
112 MFEM_VERIFY(perf || !matrix_free,
113 "--standard-version is not compatible with --matrix-free");
116 enum PCType {
NONE, LOR, HO };
118 if (!strcmp(pc,
"ho")) { pc_choice = HO; }
119 else if (!strcmp(pc,
"lor")) { pc_choice = LOR; }
120 else if (!strcmp(pc,
"none")) { pc_choice =
NONE; }
123 mfem_error(
"Invalid Preconditioner specified");
128 int basis = BasisType::GetType(basis_type[0]);
129 cout <<
"Using " << BasisType::Name(basis) <<
" basis ..." << endl;
134 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
140 cout <<
"High-performance version using integration rule with "
141 << int_rule_t::qpts <<
" points ..." << endl;
142 if (!mesh_t::MatchesGeometry(*mesh))
144 cout <<
"The given mesh does not match the optimized 'geom' parameter.\n"
145 <<
"Recompile with suitable 'geom' value." << endl;
149 else if (!mesh_t::MatchesNodes(*mesh))
151 cout <<
"Switching the mesh curvature to match the "
152 <<
"optimized value (order " <<
mesh_p <<
") ..." << endl;
163 ref_levels = (ref_levels != -1) ? ref_levels :
164 (
int)floor(log(50000./mesh->
GetNE())/log(2.)/
dim);
165 for (
int l = 0; l < ref_levels; l++)
172 MFEM_VERIFY(pc_choice != LOR,
"triangle and tet meshes do not support"
173 " the LOR preconditioner yet");
187 cout <<
"Using isoparametric FEs: " << fec->
Name() << endl;
194 cout <<
"Number of finite element unknowns: "
199 Mesh *mesh_lor = NULL;
202 if (pc_choice == LOR)
204 int basis_lor = basis;
205 if (basis == BasisType::Positive) { basis_lor=BasisType::ClosedUniform; }
206 mesh_lor =
new Mesh(mesh, order, basis_lor);
212 if (perf && !sol_fes_t::Matches(*fespace))
214 cout <<
"The given order does not match the optimized parameter.\n"
215 <<
"Recompile with suitable 'sol_p' value." << endl;
253 if (pc_choice == LOR) { a_pc =
new BilinearForm(fespace_lor); }
254 if (pc_choice == HO) { a_pc =
new BilinearForm(fespace); }
263 MFEM_VERIFY(pc_choice != LOR,
264 "cannot use LOR preconditioner with static condensation");
267 cout <<
"Assembling the bilinear form ..." << flush;
304 if (perf && matrix_free)
307 cout <<
"Size of linear system: " << a_hpc->
Height() << endl;
312 cout <<
"Size of linear system: " << A.
Height() << endl;
317 cout <<
"Assembling the preconditioning matrix ..." << flush;
322 if (pc_choice == LOR)
330 else if (pc_choice == HO)
348 if (pc_choice !=
NONE)
351 PCG(*a_oper, M, B, X, 1, 500, 1e-12, 0.0);
355 CG(*a_oper, B, X, 1, 500, 1e-12, 0.0);
359 if (perf && matrix_free)
370 ofstream mesh_ofs(
"refined.mesh");
371 mesh_ofs.precision(8);
372 mesh->
Print(mesh_ofs);
373 ofstream sol_ofs(
"sol.gf");
374 sol_ofs.precision(8);
380 char vishost[] =
"localhost";
383 sol_sock.precision(8);
384 sol_sock <<
"solution\n" << *mesh << x << flush;
390 if (a_oper != &A) {
delete a_oper; }
397 if (order > 0) {
delete fec; }
int Size() const
Logical size of the array.
Class for domain integration L(v) := (f, v)
virtual void Print(std::ostream &out=mfem::out) const
Class for grid function - Vector with associated FE space.
Subclass constant coefficient.
void MakeRef(const SparseMatrix &master)
Clear the contents of the SparseMatrix and make it a reference to master.
virtual void GetEssentialTrueDofs(const Array< int > &bdr_attr_is_ess, Array< int > &ess_tdof_list, int component=-1)
int GetNE() const
Returns number of elements.
int main(int argc, char *argv[])
Data type for Gauss-Seidel smoother of sparse matrix.
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
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 *)
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.
void CG(const Operator &A, const Vector &b, Vector &x, int print_iter, int max_num_iter, double RTOLERANCE, double ATOLERANCE)
Conjugate gradient method. (tolerances are squared)
void PCG(const Operator &A, Solver &B, const Vector &b, Vector &x, int print_iter, int max_num_iter, double RTOLERANCE, double ATOLERANCE)
Preconditioned conjugate gradient method. (tolerances are squared)
virtual int GetTrueVSize() const
Return the number of vector true (conforming) dofs.
void PrintUsage(std::ostream &out) const
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
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...
virtual const char * Name() const
void PrintOptions(std::ostream &out) const
void GetNodes(Vector &node_coord) const
Arbitrary order H1-conforming (continuous) finite elements.