33 int main(
int argc,
char *argv[])
39 bool always_snap =
false;
40 bool visualization = 1;
43 args.
AddOption(&elem_type,
"-e",
"--elem",
44 "Type of elements to use: 0 - triangles, 1 - quads.");
46 "Finite element order (polynomial degree).");
47 args.
AddOption(&ref_levels,
"-r",
"--refine",
48 "Number of times to refine the mesh uniformly.");
49 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
51 "Enable or disable GLVis visualization.");
52 args.
AddOption(&always_snap,
"-snap",
"--always-snap",
"-no-snap",
54 "If true, snap nodes to the sphere initially and after each refinement "
55 "otherwise, snap only after the last refinement");
68 int Nvert = 8, Nelem = 6;
74 Mesh *mesh =
new Mesh(2, Nvert, Nelem, 0, 3);
78 const double tri_v[6][3] =
79 {{ 1, 0, 0}, { 0, 1, 0}, {-1, 0, 0},
80 { 0, -1, 0}, { 0, 0, 1}, { 0, 0, -1}};
81 const int tri_e[8][3] =
82 {{0, 1, 4}, {1, 2, 4}, {2, 3, 4}, {3, 0, 4},
83 {1, 0, 5}, {2, 1, 5}, {3, 2, 5}, {0, 3, 5}};
85 for (
int j = 0; j < Nvert; j++)
89 for (
int j = 0; j < Nelem; j++)
91 int attribute = j + 1;
98 const double quad_v[8][3] =
99 {{-1, -1, -1}, {+1, -1, -1}, {+1, +1, -1}, {-1, +1, -1},
100 {-1, -1, +1}, {+1, -1, +1}, {+1, +1, +1}, {-1, +1, +1}};
101 const int quad_e[6][4] =
102 {{3, 2, 1, 0}, {0, 1, 5, 4}, {1, 2, 6, 5},
103 {2, 3, 7, 6}, {3, 0, 4, 7}, {4, 5, 6, 7}};
105 for (
int j = 0; j < Nvert; j++)
109 for (
int j = 0; j < Nelem; j++)
111 int attribute = j + 1;
112 mesh->
AddQuad(quad_e[j], attribute);
123 for (
int l = 0; l <= ref_levels; l++)
129 if (always_snap || l == ref_levels)
136 cout <<
"Number of unknowns: " << fespace->
GetVSize() << endl;
167 #ifndef MFEM_USE_SUITESPARSE
171 PCG(A, M, *b, x, 1, 200, 1e-12, 0.0);
175 umf_solver.
Control[UMFPACK_ORDERING] = UMFPACK_ORDERING_METIS;
177 umf_solver.
Mult(*b, x);
181 cout<<
"\nL2 norm of error: " << x.
ComputeL2Error(sol_coef) << endl;
186 ofstream mesh_ofs(
"sphere_refined.mesh");
187 mesh_ofs.precision(8);
188 mesh->
Print(mesh_ofs);
189 ofstream sol_ofs(
"sol.gf");
190 sol_ofs.precision(8);
197 char vishost[] =
"localhost";
200 sol_sock.precision(8);
201 sol_sock <<
"solution\n" << *mesh << x << flush;
215 double l2 = x(0)*x(0) + x(1)*x(1) + x(2)*x(2);
221 double l2 = x(0)*x(0) + x(1)*x(1) + x(2)*x(2);
222 return 7*x(0)*x(1)/l2;
Class for domain integration L(v) := (f, v)
int GetNDofs() const
Returns number of degrees of freedom.
Class for grid function - Vector with associated FE space.
Subclass constant coefficient.
double Norml2() const
Returns the l2 norm of the vector.
Data type for Gauss-Seidel smoother of sparse matrix.
void AddVertex(const double *)
Direct sparse solver using UMFPACK.
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
double analytic_rhs(Vector &x)
void FinalizeTriMesh(int generate_edges=0, int refine=0, bool fix_orientation=true)
double ComputeL2Error(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
double analytic_solution(Vector &x)
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)
void SetNodalFESpace(FiniteElementSpace *nfes)
FiniteElementSpace * FESpace()
void PrintUsage(std::ostream &out) const
int SpaceDimension() const
virtual void Print(std::ostream &out=std::cout) const
Print the mesh to the given stream using the default MFEM mesh format.
int main(int argc, char *argv[])
double Control[UMFPACK_CONTROL]
Abstract finite element space.
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 AddQuad(const int *vi, int attr=1)
void AddTriangle(const int *vi, int attr=1)
void FinalizeQuadMesh(int generate_edges=0, int refine=0, bool fix_orientation=true)
void PrintOptions(std::ostream &out) const
void SnapNodes(Mesh &mesh)
class for C-function coefficient
int DofToVDof(int dof, int vd) const
void GetNodes(Vector &node_coord) const
Arbitrary order H1-conforming (continuous) finite elements.
virtual void Mult(const Vector &b, Vector &x) const
Operator application.
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.