33 int main(
int argc,
char *argv[])
37 MPI_Init(&argc, &argv);
38 MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
39 MPI_Comm_rank(MPI_COMM_WORLD, &myid);
45 bool always_snap =
false;
46 bool visualization = 1;
49 args.
AddOption(&elem_type,
"-e",
"--elem",
50 "Type of elements to use: 0 - triangles, 1 - quads.");
52 "Finite element order (polynomial degree).");
53 args.
AddOption(&ref_levels,
"-r",
"--refine",
54 "Number of times to refine the mesh uniformly.");
55 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
57 "Enable or disable GLVis visualization.");
58 args.
AddOption(&always_snap,
"-snap",
"--always-snap",
"-no-snap",
60 "If true, snap nodes to the sphere initially and after each refinement "
61 "otherwise, snap only after the last refinement");
77 int Nvert = 8, Nelem = 6;
83 Mesh *mesh =
new Mesh(2, Nvert, Nelem, 0, 3);
87 const double tri_v[6][3] =
88 {{ 1, 0, 0}, { 0, 1, 0}, {-1, 0, 0},
89 { 0, -1, 0}, { 0, 0, 1}, { 0, 0, -1}};
90 const int tri_e[8][3] =
91 {{0, 1, 4}, {1, 2, 4}, {2, 3, 4}, {3, 0, 4},
92 {1, 0, 5}, {2, 1, 5}, {3, 2, 5}, {0, 3, 5}};
94 for (
int j = 0; j < Nvert; j++)
98 for (
int j = 0; j < Nelem; j++)
100 int attribute = j + 1;
107 const double quad_v[8][3] =
108 {{-1, -1, -1}, {+1, -1, -1}, {+1, +1, -1}, {-1, +1, -1},
109 {-1, -1, +1}, {+1, -1, +1}, {+1, +1, +1}, {-1, +1, +1}};
110 const int quad_e[6][4] =
111 {{3, 2, 1, 0}, {0, 1, 5, 4}, {1, 2, 6, 5},
112 {2, 3, 7, 6}, {3, 0, 4, 7}, {4, 5, 6, 7}};
114 for (
int j = 0; j < Nvert; j++)
118 for (
int j = 0; j < Nelem; j++)
120 int attribute = j + 1;
121 mesh->
AddQuad(quad_e[j], attribute);
133 for (
int l = 0; l <= ref_levels; l++)
146 int par_ref_levels = 2;
147 for (
int l = 0; l < par_ref_levels; l++)
155 if (!always_snap || par_ref_levels < 1)
164 cout <<
"Number of unknowns: " << size << endl;
218 cout <<
"\nL2 norm of error: " << err << endl;
223 ostringstream mesh_name, sol_name;
224 mesh_name <<
"sphere_refined." << setfill(
'0') << setw(6) << myid;
225 sol_name <<
"sol." << setfill(
'0') << setw(6) << myid;
227 ofstream mesh_ofs(mesh_name.str().c_str());
228 mesh_ofs.precision(8);
229 pmesh->
Print(mesh_ofs);
231 ofstream sol_ofs(sol_name.str().c_str());
232 sol_ofs.precision(8);
239 char vishost[] =
"localhost";
242 sol_sock <<
"parallel " << num_procs <<
" " << myid <<
"\n";
243 sol_sock.precision(8);
244 sol_sock <<
"solution\n" << *pmesh << x << flush;
263 double l2 = x(0)*x(0) + x(1)*x(1) + x(2)*x(2);
269 double l2 = x(0)*x(0) + x(1)*x(1) + x(2)*x(2);
270 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.
double ComputeL2Error(Coefficient *exsol[], const IntegrationRule *irs[]=NULL) const
Subclass constant coefficient.
double Norml2() const
Returns the l2 norm of the vector.
virtual void Save(std::ostream &out) const
Abstract parallel finite element space.
void SetPrintLevel(int print_lvl)
void AddVertex(const double *)
double analytic_rhs(Vector &x)
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(Vector &x)
void SetNodalFESpace(FiniteElementSpace *nfes)
FiniteElementSpace * FESpace()
void PrintUsage(std::ostream &out) const
void SetMaxIter(int max_iter)
int SpaceDimension() const
Wrapper for hypre's parallel vector class.
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 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
int DofToVDof(int dof, int vd) const
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.
void ParallelAverage(Vector &tv) const
Returns the vector averaged on the true dofs.
virtual void Print(std::ostream &out=std::cout) const