https://mooseframework.inl.gov
SphereMeshGenerator.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "SphereMeshGenerator.h"
11 #include "CastUniquePointer.h"
12 
13 #include "libmesh/mesh_generation.h"
14 #include "libmesh/string_to_enum.h"
15 
17 
20 {
22  params.addClassDescription("Generate a 3-D sphere mesh centered on the origin");
23  params.addRequiredRangeCheckedParam<Real>("radius", "radius > 0.0", "Sphere radius");
24  params.addRequiredRangeCheckedParam<unsigned int>("nr", "nr > 0", "Number of radial elements");
25 
26  MooseEnum types("HEX8 HEX27", "HEX8");
27  params.addParam<MooseEnum>("elem_type", types, "The type of element to generate");
28  params.addParam<unsigned int>("n_smooth", 0, "Number of smoothing operations");
29  return params;
30 }
31 
33  : MeshGenerator(parameters),
34  _radius(getParam<Real>("radius")),
35  _nr(getParam<unsigned int>("nr")),
36  _elem_type(getParam<MooseEnum>("elem_type")),
37  _n_smooth(getParam<unsigned int>("n_smooth"))
38 {
39 }
40 
41 std::unique_ptr<MeshBase>
43 {
44  auto mesh = buildMeshBaseObject();
45  mesh->set_mesh_dimension(3);
46  mesh->set_spatial_dimension(3);
47 
48  ElemType et = Utility::string_to_enum<ElemType>(_elem_type);
49 
50  MeshTools::Generation::build_sphere(static_cast<UnstructuredMesh &>(*mesh),
51  _radius,
52  _nr,
53  et,
54  _n_smooth,
55  false /* dummy value; not used for 3-D meshes */);
56 
57  return dynamic_pointer_cast<MeshBase>(mesh);
58 }
ElemType
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
These methods add an range checked parameters.
const MooseEnum _elem_type
element type
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)
These are reworked from https://stackoverflow.com/a/11003103.
static InputParameters validParams()
registerMooseObject("MooseApp", SphereMeshGenerator)
const unsigned int & _n_smooth
number of smoothing operations
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
static InputParameters validParams()
Definition: MeshGenerator.C:23
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
const unsigned int & _nr
number of radial elements
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
SphereMeshGenerator(const InputParameters &parameters)
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
Create a sphere volume mesh.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
std::unique_ptr< MeshBase > buildMeshBaseObject(unsigned int dim=libMesh::invalid_uint)
Build a MeshBase object whose underlying type will be determined by the Mesh input file block...
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:32
void ErrorVector unsigned int
const Real & _radius
sphere radius