11 #include "CastUniquePointer.h"
14 #include "libmesh/face_tri3.h"
15 #include "libmesh/mesh_modification.h"
16 #include "libmesh/mesh_refinement.h"
17 #include "libmesh/sphere.h"
18 #include "libmesh/unstructured_mesh.h"
19 #include "libmesh/replicated_mesh.h"
27 InputParameters params = validParams<MeshGenerator>();
28 params.addClassDescription(
29 "Generated sphere mesh - a two dimensional manifold embedded in three dimensional space");
30 params.addParam<Real>(
"radius", 1.0,
"Sphere radius");
31 params.addParam<Point>(
"center", Point(0, 0, 0),
"Center of the sphere");
32 params.addParam<
unsigned int>(
33 "depth", 3,
"Iteration steps in the triangle bisection construction");
38 : MeshGenerator(parameters),
39 _radius(getParam<Real>(
"radius")),
40 _center(getParam<Point>(
"center")),
41 _depth(getParam<unsigned int>(
"depth"))
45 std::unique_ptr<MeshBase>
49 auto mesh = _mesh->buildMeshBaseObject();
50 mesh->set_mesh_dimension(2);
51 mesh->set_spatial_dimension(3);
56 const Real phi = (1.0 + std::sqrt(5.0)) / 2.0;
57 const Real X = std::sqrt(1.0 / (phi * phi + 1.0));
58 const Real Z = X * phi;
59 const Point vdata[12] = {{-X, 0.0, Z},
71 for (
unsigned int i = 0; i < 12; ++i)
75 const unsigned int tindices[20][3] = {{0, 4, 1}, {0, 9, 4}, {9, 5, 4}, {4, 5, 8}, {4, 8, 1},
76 {8, 10, 1}, {8, 3, 10}, {5, 3, 8}, {5, 2, 3}, {2, 7, 3},
77 {7, 10, 3}, {7, 6, 10}, {7, 11, 6}, {11, 0, 6}, {0, 1, 6},
78 {6, 1, 10}, {9, 0, 11}, {9, 11, 2}, {9, 2, 5}, {7, 2, 11}};
79 for (
unsigned int i = 0; i < 20; ++i)
81 Elem * elem = mesh->add_elem(
new Tri3);
82 elem->set_node(0) = mesh->node_ptr(tindices[i][0]);
83 elem->set_node(1) = mesh->node_ptr(tindices[i][1]);
84 elem->set_node(2) = mesh->node_ptr(tindices[i][2]);
88 if (!mesh->is_replicated())
89 mesh->prepare_for_use(
false);
94 MeshRefinement mesh_refinement(*mesh);
97 for (
unsigned int r = 0; r <
_depth; ++r)
99 mesh_refinement.uniformly_refine(1);
101 auto it = mesh->active_nodes_begin();
102 const auto end = mesh->active_nodes_end();
104 for (; it != end; ++it)
107 node = sphere.closest_point(node);
112 MeshTools::Modification::flatten(*mesh);
114 return dynamic_pointer_cast<MeshBase>(mesh);