35 int main(
int argc,
char *argv[])
39 MPI_Init(&argc, &argv);
40 MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
41 MPI_Comm_rank(MPI_COMM_WORLD, &myid);
48 bool always_snap =
false;
49 bool visualization = 1;
52 args.
AddOption(&elem_type,
"-e",
"--elem",
53 "Type of elements to use: 0 - triangles, 1 - quads.");
55 "Finite element order (polynomial degree).");
56 args.
AddOption(&ref_levels,
"-r",
"--refine",
57 "Number of times to refine the mesh uniformly.");
58 args.
AddOption(&amr,
"-amr",
"--refine-locally",
59 "Additional local (non-conforming) refinement:"
60 " 1 = refine around north pole, 2 = refine randomly.");
61 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
63 "Enable or disable GLVis visualization.");
64 args.
AddOption(&always_snap,
"-snap",
"--always-snap",
"-no-snap",
66 "If true, snap nodes to the sphere initially and after each refinement "
67 "otherwise, snap only after the last refinement");
87 int Nvert = 8, Nelem = 6;
93 Mesh *mesh =
new Mesh(2, Nvert, Nelem, 0, 3);
97 const double tri_v[6][3] =
99 { 1, 0, 0}, { 0, 1, 0}, {-1, 0, 0},
100 { 0, -1, 0}, { 0, 0, 1}, { 0, 0, -1}
102 const int tri_e[8][3] =
104 {0, 1, 4}, {1, 2, 4}, {2, 3, 4}, {3, 0, 4},
105 {1, 0, 5}, {2, 1, 5}, {3, 2, 5}, {0, 3, 5}
108 for (
int j = 0; j < Nvert; j++)
112 for (
int j = 0; j < Nelem; j++)
114 int attribute = j + 1;
121 const double quad_v[8][3] =
123 {-1, -1, -1}, {+1, -1, -1}, {+1, +1, -1}, {-1, +1, -1},
124 {-1, -1, +1}, {+1, -1, +1}, {+1, +1, +1}, {-1, +1, +1}
126 const int quad_e[6][4] =
128 {3, 2, 1, 0}, {0, 1, 5, 4}, {1, 2, 6, 5},
129 {2, 3, 7, 6}, {3, 0, 4, 7}, {4, 5, 6, 7}
132 for (
int j = 0; j < Nvert; j++)
136 for (
int j = 0; j < Nelem; j++)
138 int attribute = j + 1;
139 mesh->
AddQuad(quad_e[j], attribute);
151 for (
int l = 0; l <= ref_levels; l++)
179 int par_ref_levels = 2;
180 for (
int l = 0; l < par_ref_levels; l++)
190 if (!always_snap || par_ref_levels < 1)
213 cout <<
"Number of unknowns: " << size << endl;
266 cout <<
"\nL2 norm of error: " << err << endl;
272 ostringstream mesh_name, sol_name;
273 mesh_name <<
"sphere_refined." << setfill(
'0') << setw(6) << myid;
274 sol_name <<
"sol." << setfill(
'0') << setw(6) << myid;
276 ofstream mesh_ofs(mesh_name.str().c_str());
277 mesh_ofs.precision(8);
278 pmesh->
Print(mesh_ofs);
280 ofstream sol_ofs(sol_name.str().c_str());
281 sol_ofs.precision(8);
288 char vishost[] =
"localhost";
291 sol_sock <<
"parallel " << num_procs <<
" " << myid <<
"\n";
292 sol_sock.precision(8);
293 sol_sock <<
"solution\n" << *pmesh << x << flush;
309 double l2 = x(0)*x(0) + x(1)*x(1) + x(2)*x(2);
315 double l2 = x(0)*x(0) + x(1)*x(1) + x(2)*x(2);
316 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.
int DofToVDof(int dof, int vd, int ndofs=-1) const
double ComputeL2Error(Coefficient *exsol[], const IntegrationRule *irs[]=NULL) const
Subclass constant coefficient.
double Norml2() const
Returns the l2 norm of the vector.
HYPRE_Int GlobalTrueVSize()
virtual void Save(std::ostream &out) const
Abstract parallel finite element space.
void SetPrintLevel(int print_lvl)
void RefineAtVertex(const Vertex &vert, int levels, double eps=0.0, int nonconforming=-1)
Refine elements sharing the specified vertex, 'levels' times.
void AddVertex(const double *)
The BoomerAMG solver in hypre.
void FinalizeTriMesh(int generate_edges=0, int refine=0, bool fix_orientation=true)
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
double analytic_solution(const Vector &x)
void SetNodalFESpace(FiniteElementSpace *nfes)
FiniteElementSpace * FESpace()
void PrintUsage(std::ostream &out) const
void SetMaxIter(int max_iter)
double analytic_rhs(const Vector &x)
int SpaceDimension() const
int main(int argc, char *argv[])
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 RandomRefinement(int levels, int frac=2, bool aniso=false, int nonconforming=-1, int nc_limit=-1, int seed=0)
Refine each element with 1/frac probability, repeat 'levels' times.
void AddTriangle(const int *vi, int attr=1)
void FinalizeQuadMesh(int generate_edges=0, int refine=0, bool fix_orientation=true)
void SetPreconditioner(HypreSolver &precond)
Set the hypre solver to be used as a preconditioner.
void PrintOptions(std::ostream &out) const
void SnapNodes(Mesh &mesh)
Abstract class for hypre's solvers and preconditioners.
class for C-function coefficient
void GetNodes(Vector &node_coord) const
Arbitrary order H1-conforming (continuous) finite elements.
Class for parallel grid function.
Wrapper for hypre's ParCSR matrix class.
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Solve Ax=b with hypre's PCG.
Class for parallel meshes.
virtual void Print(std::ostream &out=std::cout) const