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 sphere (ball) mesh centered on the origin");
23  params.addRequiredRangeCheckedParam<Real>("radius", "radius > 0.0", "Sphere (ball) radius");
24  params.addRequiredRangeCheckedParam<unsigned int>("nr", "nr >= 0", "Number of refinements");
25 
26  params.addParam<MooseEnum>(
27  "elem_type", MooseMesh::elemTypes(), "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 
46  if (!isParamValid("elem_type"))
47  _elem_type = "HEX8";
48 
49  // libMesh will determine sphere dimension based on ElemType, and
50  // will throw an error with error message if the ElemType is not yet
51  // implemented (prisms and pyramids, currently)
52  ElemType et = Utility::string_to_enum<ElemType>(_elem_type);
53 
54  MeshTools::Generation::build_sphere(
55  cast_ref<UnstructuredMesh &>(*mesh), _radius, _nr, et, _n_smooth);
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.
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:54
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
MooseEnum _elem_type
element type
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...
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseBase.h:209
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:33
void ErrorVector unsigned int
static MooseEnum elemTypes()
returns MooseMesh element type options
Definition: MooseMesh.C:4026
const Real & _radius
sphere radius