https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
41std::unique_ptr<MeshBase>
43{
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}
registerMooseObject("MooseApp", SphereMeshGenerator)
void ErrorVector unsigned int
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
These methods add an range checked parameters.
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.
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.
MeshGenerators are objects that can modify or add to an existing mesh.
static InputParameters validParams()
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.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
static MooseEnum elemTypes()
returns MooseMesh element type options
Definition MooseMesh.C:4027
Create a sphere volume mesh.
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
const unsigned int & _n_smooth
number of smoothing operations
const Real & _radius
sphere radius
SphereMeshGenerator(const InputParameters &parameters)
MooseEnum _elem_type
element type
static InputParameters validParams()
const unsigned int & _nr
number of radial elements
MeshBase & mesh