14 #include "libmesh/mesh_generation.h" 15 #include "libmesh/string_to_enum.h" 16 #include "libmesh/periodic_boundaries.h" 17 #include "libmesh/periodic_boundary_base.h" 18 #include "libmesh/unstructured_mesh.h" 19 #include "libmesh/node.h" 36 "dim", dims,
"The dimension of the mesh to be generated");
38 params.
addParam<
unsigned int>(
"nx", 1,
"Number of elements in the X direction");
39 params.
addParam<
unsigned int>(
"ny", 1,
"Number of elements in the Y direction");
40 params.
addParam<
unsigned int>(
"nz", 1,
"Number of elements in the Z direction");
41 params.
addParam<
Real>(
"xmin", 0.0,
"Lower X Coordinate of the generated mesh");
42 params.
addParam<
Real>(
"ymin", 0.0,
"Lower Y Coordinate of the generated mesh");
43 params.
addParam<
Real>(
"zmin", 0.0,
"Lower Z Coordinate of the generated mesh");
44 params.
addParam<
Real>(
"xmax", 1.0,
"Upper X Coordinate of the generated mesh");
45 params.
addParam<
Real>(
"ymax", 1.0,
"Upper Y Coordinate of the generated mesh");
46 params.
addParam<
Real>(
"zmax", 1.0,
"Upper Z Coordinate of the generated mesh");
49 "The type of element from libMesh to " 50 "generate (default: linear element for " 51 "requested dimension)");
55 "Grade mesh into boundaries according to Gauss-Lobatto quadrature spacing.");
59 "bias_x>=0.5 & bias_x<=2",
60 "The amount by which to grow (or shrink) the cells in the x-direction.");
64 "bias_y>=0.5 & bias_y<=2",
65 "The amount by which to grow (or shrink) the cells in the y-direction.");
69 "bias_z>=0.5 & bias_z<=2",
70 "The amount by which to grow (or shrink) the cells in the z-direction.");
75 "Create a line, square, or cube mesh with uniformly spaced or biased elements.");
82 _nx(getParam<unsigned
int>(
"nx")),
83 _ny(getParam<unsigned
int>(
"ny")),
84 _nz(getParam<unsigned
int>(
"nz")),
85 _xmin(getParam<
Real>(
"xmin")),
86 _xmax(getParam<
Real>(
"xmax")),
87 _ymin(getParam<
Real>(
"ymin")),
88 _ymax(getParam<
Real>(
"ymax")),
89 _zmin(getParam<
Real>(
"zmin")),
90 _zmax(getParam<
Real>(
"zmax")),
91 _gauss_lobatto_grid(getParam<bool>(
"gauss_lobatto_grid")),
92 _bias_x(getParam<
Real>(
"bias_x")),
93 _bias_y(getParam<
Real>(
"bias_y")),
94 _bias_z(getParam<
Real>(
"bias_z")),
95 _dims_may_have_changed(false)
98 mooseError(
"Cannot apply both Gauss-Lobatto mesh grading and biasing at the same time.");
152 std::unique_ptr<MooseMesh>
161 MooseEnum elem_type_enum = getParam<MooseEnum>(
"elem_type");
169 elem_type_enum =
"EDGE2";
172 elem_type_enum =
"QUAD4";
175 elem_type_enum =
"HEX8";
180 ElemType elem_type = Utility::string_to_enum<ElemType>(elem_type_enum);
188 MeshTools::Generation::build_line(dynamic_cast<UnstructuredMesh &>(
getMesh()),
196 MeshTools::Generation::build_square(dynamic_cast<UnstructuredMesh &>(
getMesh()),
207 MeshTools::Generation::build_cube(dynamic_cast<UnstructuredMesh &>(
getMesh()),
229 std::array<Real, LIBMESH_DIM> bias = {
233 std::array<Real, LIBMESH_DIM> width = {
237 std::array<Real, LIBMESH_DIM> mins = {
241 std::array<unsigned int, LIBMESH_DIM> nelem = {{
_nx,
_dim > 1 ?
_ny : 1,
_dim > 2 ?
_nz : 1}};
245 std::array<std::vector<Real>, LIBMESH_DIM> pows;
246 for (
unsigned int dir = 0; dir < LIBMESH_DIM; ++dir)
248 pows[dir].resize(nelem[dir] + 1);
249 for (
unsigned int i = 0; i < pows[dir].size(); ++i)
250 pows[dir][i] =
std::pow(bias[dir], static_cast<int>(i));
254 for (
auto & node_ptr :
mesh.node_ptr_range())
256 Node &
node = *node_ptr;
258 for (
unsigned int dir = 0; dir < LIBMESH_DIM; ++dir)
260 if (width[dir] != 0. && bias[dir] != 1.)
265 Real float_index = (
node(dir) - mins[dir]) * nelem[dir] / width[dir];
267 Real integer_part = 0;
268 Real fractional_part = std::modf(float_index, &integer_part);
271 if (
std::abs(fractional_part) < TOLERANCE ||
std::abs(fractional_part - 1.0) < TOLERANCE)
280 int index =
round(float_index);
282 mooseAssert(index >= static_cast<int>(0) && index < static_cast<int>(pows[dir].size()),
283 "Scaled \"index\" out of range");
287 mins[dir] + width[dir] * (1. - pows[dir][index]) / (1. - pows[dir][nelem[dir]]);
289 else if (
std::abs(fractional_part - 0.5) < TOLERANCE)
300 node(dir) = mins[dir] +
302 (1. - 0.5 * (pows[dir][integer_part] + pows[dir][integer_part + 1])) /
303 (1. - pows[dir][nelem[dir]]);
static InputParameters validParams()
Typical "Moose-style" constructor and copy constructor.
virtual Real getMaxInDimension(unsigned int component) const
virtual Real getMinInDimension(unsigned int component) const
Returns the min or max of the requested dimension respectively.
bool prepared() const
Setter/getter for whether the mesh is prepared.
const std::string LIST_GEOM_ELEM
virtual std::unique_ptr< MooseMesh > safeClone() const override
A safer version of the clone() method that hands back an allocated object wrapped in a smart pointer...
MooseEnum _dim
The dimension of the mesh.
virtual Real getMaxInDimension(unsigned int component) const override
bool _dims_may_have_changed
Boolean to indicate that dimensions may have changed.
virtual Real getMinInDimension(unsigned int component) const override
Returns the min or max of the requested dimension respectively.
std::unique_ptr< T > copyConstruct(const T &object)
Copy constructs the object object.
virtual void buildMesh() override
Must be overridden by child classes.
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
Mesh generated from parameters.
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Real _xmin
The min/max values for x,y,z component.
GeneratedMesh(const InputParameters ¶meters)
MooseApp & _app
The MOOSE application this is associated with.
registerMooseObject("MooseApp", GeneratedMesh)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
bool _gauss_lobatto_grid
All of the libmesh build_line/square/cube routines support an option to grade the mesh into the bound...
virtual const Node & node(const dof_id_type i) const
Various accessors (pointers/references) for Node "i".
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
unsigned int _nx
Number of elements in x, y, z direction.
Real _bias_x
The amount by which to bias the cells in the x,y,z directions.
MooseUnits pow(const MooseUnits &, int)
void ErrorVector unsigned int
bool _regular_orthogonal_mesh
Boolean indicating whether this mesh was detected to be regular and orthogonal.
static InputParameters validParams()