www.mooseframework.org
Public Member Functions | Protected Attributes | List of all members
SphereSurfaceMeshGenerator Class Reference

Create a sphere surface mesh based on the recursive subdivision of the faces of a regular icosahedron. More...

#include <SphereSurfaceMeshGenerator.h>

Inheritance diagram for SphereSurfaceMeshGenerator:
[legend]

Public Member Functions

 SphereSurfaceMeshGenerator (const InputParameters &parameters)
 
std::unique_ptr< MeshBase > generate () override
 

Protected Attributes

const Real _radius
 sphere radius More...
 
const Point _center
 
const unsigned int _depth
 recursion levels for triangle subdivision More...
 

Detailed Description

Create a sphere surface mesh based on the recursive subdivision of the faces of a regular icosahedron.

Definition at line 25 of file SphereSurfaceMeshGenerator.h.

Constructor & Destructor Documentation

◆ SphereSurfaceMeshGenerator()

SphereSurfaceMeshGenerator::SphereSurfaceMeshGenerator ( const InputParameters &  parameters)

Definition at line 37 of file SphereSurfaceMeshGenerator.C.

38  : MeshGenerator(parameters),
39  _radius(getParam<Real>("radius")),
40  _center(getParam<Point>("center")),
41  _depth(getParam<unsigned int>("depth"))
42 {
43 }
const Real _radius
sphere radius
const unsigned int _depth
recursion levels for triangle subdivision

Member Function Documentation

◆ generate()

std::unique_ptr< MeshBase > SphereSurfaceMeshGenerator::generate ( )
override

Definition at line 46 of file SphereSurfaceMeshGenerator.C.

47 {
48  // Have MOOSE construct the correct libMesh::Mesh object using Mesh block and CLI parameters.
49  auto mesh = _mesh->buildMeshBaseObject();
50  mesh->set_mesh_dimension(2);
51  mesh->set_spatial_dimension(3);
52 
53  const Sphere sphere(_center, _radius);
54 
55  // icosahedron points (using golden ratio rectangle construction)
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},
60  {X, 0.0, Z},
61  {-X, 0.0, -Z},
62  {X, 0.0, -Z},
63  {0.0, Z, X},
64  {0.0, Z, -X},
65  {0.0, -Z, X},
66  {0.0, -Z, -X},
67  {Z, X, 0.0},
68  {-Z, X, 0.0},
69  {Z, -X, 0.0},
70  {-Z, -X, 0.0}};
71  for (unsigned int i = 0; i < 12; ++i)
72  mesh->add_point(vdata[i] * _radius + _center, i);
73 
74  // icosahedron faces
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)
80  {
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]);
85  }
86 
87  // we need to prepare distributed meshes before using refinement
88  if (!mesh->is_replicated())
89  mesh->prepare_for_use(/*skip_renumber =*/false);
90 
91  // Now we have the beginnings of a sphere.
92  // Add some more elements by doing uniform refinements and
93  // popping nodes to the boundary.
94  MeshRefinement mesh_refinement(*mesh);
95 
96  // Loop over the elements, refine, pop nodes to boundary.
97  for (unsigned int r = 0; r < _depth; ++r)
98  {
99  mesh_refinement.uniformly_refine(1);
100 
101  auto it = mesh->active_nodes_begin();
102  const auto end = mesh->active_nodes_end();
103 
104  for (; it != end; ++it)
105  {
106  Node & node = **it;
107  node = sphere.closest_point(node);
108  }
109  }
110 
111  // Flatten the AMR mesh to get rid of inactive elements
112  MeshTools::Modification::flatten(*mesh);
113 
114  return dynamic_pointer_cast<MeshBase>(mesh);
115 }
const Real _radius
sphere radius
const unsigned int _depth
recursion levels for triangle subdivision

Member Data Documentation

◆ _center

const Point SphereSurfaceMeshGenerator::_center
protected

Definition at line 37 of file SphereSurfaceMeshGenerator.h.

Referenced by generate().

◆ _depth

const unsigned int SphereSurfaceMeshGenerator::_depth
protected

recursion levels for triangle subdivision

Definition at line 40 of file SphereSurfaceMeshGenerator.h.

Referenced by generate().

◆ _radius

const Real SphereSurfaceMeshGenerator::_radius
protected

sphere radius

Definition at line 34 of file SphereSurfaceMeshGenerator.h.

Referenced by generate().


The documentation for this class was generated from the following files: