35 return int(std::abs(1.0e5 * sin(seed * 1.1234 * M_PI)));
40int main(
int argc,
char *argv[])
43 const char *mesh_file =
"";
45 const char *device_config =
"cpu";
46 bool visualization =
true;
49 bool deterministic =
true;
50 bool projectSolution =
false;
51 bool onlyPref =
false;
54 args.
AddOption(&mesh_file,
"-m",
"--mesh",
57 "Finite element order (polynomial degree) or -1 for"
58 " isoparametric space.");
59 args.
AddOption(&device_config,
"-d",
"--device",
60 "Device configuration string, see Device::Configure().");
61 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
63 "Enable or disable GLVis visualization.");
64 args.
AddOption(&numIter,
"-n",
"--num-iter",
"Number of hp-ref iterations");
65 args.
AddOption(&
dim,
"-dim",
"--dim",
"Mesh dimension (2 or 3)");
66 args.
AddOption(&deterministic,
"-det",
"--deterministic",
"-not-det",
67 "--not-deterministic",
68 "Use deterministic random refinements");
69 args.
AddOption(&projectSolution,
"-proj",
"--project-solution",
"-no-proj",
71 "Project a coefficient to solution");
72 args.
AddOption(&onlyPref,
"-pref",
"--only-p-refinement",
"-no-pref",
74 "Use only p-refinement");
85 Device device(device_config);
89 std::string mesh_filename(mesh_file);
91 if (!mesh_filename.empty())
121 cout <<
"Using isoparametric FEs: " << fec->
Name() << endl;
129 const int fespaceDim = projectSolution ?
dim : 1;
137 const std::vector<char> hp_char = {
'h',
'p'};
139 for (
int iter=0; iter<numIter; ++iter)
141 const int r1 = deterministic ?
DetRand(seed) : rand();
142 const int r2 = deterministic ?
DetRand(seed) : rand();
143 const int elem = r1 % mesh.
GetNE();
144 const int hp = onlyPref ? 1 : r2 % 2;
146 cout <<
"hp-refinement iteration " << iter <<
": "
147 << hp_char[hp] <<
"-refinement" << endl;
169 cout <<
"Number of finite element unknowns: " << size << endl;
172 cout <<
"Total number of h-refinements: " << numH
173 <<
"\nTotal number of p-refinements: " << numP
174 <<
"\nMaximum order " << maxP <<
"\n";
191 cout <<
"\n|| E_h - E ||_{L^2} = " << error <<
'\n' << endl;
234 a.FormLinearSystem(ess_tdof_list, x,
b, A, X, B);
238#ifndef MFEM_USE_SUITESPARSE
241 PCG(*A, M, B, X, 1, 200, 1e-12, 0.0);
245 umf_solver.
Control[UMFPACK_ORDERING] = UMFPACK_ORDERING_METIS;
247 umf_solver.
Mult(B, X);
252 a.RecoverFEMSolution(X,
b, x);
258 cout <<
"H1 continuity error " << h1error << endl;
259 MFEM_VERIFY(h1error < 1.0e-12,
"H1 continuity is not satisfied");
267 for (
int e=0; e<mesh.
GetNE(); ++e)
272 MFEM_VERIFY(dofs.
Size() == 1,
"");
273 xo[dofs[0]] = p_elem;
279 ofstream mesh_ofs(
"refined.mesh");
280 mesh_ofs.precision(8);
281 mesh.
Print(mesh_ofs);
282 ofstream sol_ofs(
"sol.gf");
283 sol_ofs.precision(8);
284 vis_x->Save(sol_ofs);
285 ofstream order_ofs(
"order.gf");
286 order_ofs.precision(8);
295 sol_sock.precision(8);
296 sol_sock <<
"solution\n" << mesh << *vis_x << flush;
322 int Inf1, Inf2, NCFace;
329 auto &int_rule =
IntRules.
Get(FT->FaceGeom, 2 * faceOrder);
337 bool isNCSlave = FT->Elem2No >= 0 && NCFace >= 0;
338 bool isConforming = FT->Elem2No >= 0 && NCFace == -1;
339 if ((FT->Elem1No < FT->Elem2No && isConforming) || isNCSlave)
341 for (
int i = 0; i < nip; i++)
343 const auto &fip = int_rule.IntPoint(i);
346 FT->Loc1.Transform(fip, ip);
349 FT->Loc2.Transform(fip, ip);
352 const real_t err_i = std::abs(v1 - v2);
353 errorMax = std::max(errorMax, err_i);
377 if (x.
Size() == 3) {
f(2) = 0.0; }
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
int Size() const
Return the logical size of the array.
int Append(const T &el)
Append element 'el' to array, resize if necessary.
A coefficient that is constant across space and time.
The MFEM Device class abstracts hardware devices such as GPUs, as well as programming models such as ...
void Print(std::ostream &os=mfem::out)
Print the configuration of the MFEM virtual device object.
Class for domain integration .
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
virtual const char * Name() const
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
virtual int GetTrueVSize() const
Return the number of vector true (conforming) dofs.
DofTransformation * GetElementDofs(int elem, Array< int > &dofs) const
Returns indices of degrees of freedom of element 'elem'. The returned indices are offsets into an ldo...
int GetEdgeOrder(int edge, int variant=0) const
int GetFaceOrder(int face, int variant=0) const
Returns the polynomial degree of the i'th face finite element.
virtual void GetEssentialTrueDofs(const Array< int > &bdr_attr_is_ess, Array< int > &ess_tdof_list, int component=-1) const
Get a list of essential true dofs, ess_tdof_list, corresponding to the boundary attributes marked in ...
virtual const Operator * GetProlongationMatrix() const
virtual void Update(bool want_transform=true)
Reflect changes in the mesh: update number of DOFs, etc. Also, calculate GridFunction transformation ...
int GetElementOrder(int i) const
Returns the order of the i'th finite element.
Mesh * GetMesh() const
Returns the mesh.
virtual void PRefineAndUpdate(const Array< pRefinement > &refs, bool want_transfer=true)
virtual const SparseMatrix * GetHpRestrictionMatrix() const
The returned SparseMatrix is owned by the FiniteElementSpace.
virtual int GetMaxElementOrder() const
Return the maximum polynomial order over all elements.
Data type for Gauss-Seidel smoother of sparse matrix.
Class for grid function - Vector with associated FE space.
virtual real_t GetValue(int i, const IntegrationPoint &ip, int vdim=1) const
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
virtual real_t ComputeL2Error(Coefficient *exsol[], const IntegrationRule *irs[]=NULL, const Array< int > *elems=NULL) const
Returns ||exsol - u_h||_L2 for scalar or vector H1 or L2 elements.
FiniteElementSpace * FESpace()
virtual void ProjectCoefficient(Coefficient &coeff)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
std::unique_ptr< GridFunction > ProlongateToMaxOrder() const
Return a GridFunction with the values of this, prolongated to the maximum order of all elements in th...
Arbitrary order H1-conforming (continuous) finite elements.
Class for integration point with weight.
int GetNPoints() const
Returns the number of the points in the integration rule.
const IntegrationRule & Get(int GeomType, int Order)
Returns an integration rule for given GeomType and Order.
Arbitrary order "L2-conforming" discontinuous finite elements.
virtual FaceElementTransformations * GetFaceElementTransformations(int FaceNo, int mask=31)
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
void GetFaceInfos(int Face, int *Inf1, int *Inf2) const
int GetNumFaces() const
Return the number of faces (3D), edges (2D) or vertices (1D).
void GeneralRefinement(const Array< Refinement > &refinements, int nonconforming=-1, int nc_limit=0)
virtual void Print(std::ostream &os=mfem::out, const std::string &comments="") const
Print the mesh to the given stream using the default MFEM mesh format.
int GetNE() const
Returns number of elements.
int Dimension() const
Dimension of the reference space used within the elements.
bool FaceIsInterior(int FaceNo) const
Return true if the given face is interior.
static Mesh MakeCartesian3D(int nx, int ny, int nz, Element::Type type, real_t sx=1.0, real_t sy=1.0, real_t sz=1.0, bool sfc_ordering=true)
Creates a mesh for the parallelepiped [0,sx]x[0,sy]x[0,sz], divided into nx*ny*nz hexahedra if type =...
void GetNodes(Vector &node_coord) const
static Mesh LoadFromFile(const std::string &filename, int generate_edges=0, int refine=1, bool fix_orientation=true)
void EnsureNCMesh(bool simplices_nonconforming=false)
static Mesh MakeCartesian2D(int nx, int ny, Element::Type type, bool generate_edges=false, real_t sx=1.0, real_t sy=1.0, bool sfc_ordering=true)
Creates mesh for the rectangle [0,sx]x[0,sy], divided into nx*ny quadrilaterals if type = QUADRILATER...
Pointer to an Operator of a specified type.
virtual void Mult(const Vector &x, Vector &y) const =0
Operator application: y=A(x).
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
void PrintUsage(std::ostream &out) const
Print the usage message.
void PrintOptions(std::ostream &out) const
Print the options.
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...
bool Good() const
Return true if the command line options were parsed successfully.
void Mult(const Vector &x, Vector &y) const override
Matrix vector multiplication.
Direct sparse solver using UMFPACK.
real_t Control[UMFPACK_CONTROL]
void SetOperator(const Operator &op) override
Factorize the given Operator op which must be a SparseMatrix.
void Mult(const Vector &b, Vector &x) const override
Direct solution of the linear system using UMFPACK.
A general vector function coefficient.
int Size() const
Returns the size of the vector.
void SetSize(int s)
Resize the vector to size s.
real_t CheckH1Continuity(GridFunction &x)
void f_exact(const Vector &x, Vector &f)
void PCG(const Operator &A, Solver &B, const Vector &b, Vector &x, int print_iter, int max_num_iter, real_t RTOLERANCE, real_t ATOLERANCE)
Preconditioned conjugate gradient method. (tolerances are squared)
std::function< real_t(const Vector &)> f(real_t mass_coeff)
IntegrationRules IntRules(0, Quadrature1D::GaussLegendre)
A global object with all integration rules (defined in intrules.cpp)