99 _nx(declareMeshProperty(
"num_elements_x", getParam<unsigned
int>(
"nx"))),
100 _ny(declareMeshProperty(
"num_elements_y", getParam<unsigned
int>(
"ny"))),
101 _nz(declareMeshProperty(
"num_elements_z", getParam<unsigned
int>(
"nz"))),
102 _xmin(declareMeshProperty(
"xmin", getParam<Real>(
"xmin"))),
103 _xmax(declareMeshProperty(
"xmax", getParam<Real>(
"xmax"))),
104 _ymin(declareMeshProperty(
"ymin", getParam<Real>(
"ymin"))),
105 _ymax(declareMeshProperty(
"ymax", getParam<Real>(
"ymax"))),
106 _zmin(declareMeshProperty(
"zmin", getParam<Real>(
"zmin"))),
107 _zmax(declareMeshProperty(
"zmax", getParam<Real>(
"zmax"))),
108 _has_subdomain_ids(isParamValid(
"subdomain_ids")),
109 _gauss_lobatto_grid(getParam<bool>(
"gauss_lobatto_grid")),
110 _bias_x(getParam<Real>(
"bias_x")),
111 _bias_y(getParam<Real>(
"bias_y")),
112 _bias_z(getParam<Real>(
"bias_z")),
113 _boundary_name_prefix(isParamValid(
"boundary_name_prefix")
114 ? getParam<
std::string>(
"boundary_name_prefix") +
"_"
116 _boundary_id_offset(getParam<boundary_id_type>(
"boundary_id_offset"))
119 mooseError(
"Cannot apply both Gauss-Lobatto mesh grading and biasing at the same time.");
121 paramError(
"xmax",
"xmax must be larger than xmin.");
123 paramError(
"ymax",
"ymax must be larger than ymin.");
125 paramError(
"zmax",
"zmax must be larger than zmin.");
128 const auto & bdy_names = getParam<std::vector<BoundaryName>>(
"boundary_names");
129 if ((
_dim == 1 && bdy_names.size() != 2) || (
_dim == 2 && bdy_names.size() != 4) ||
130 (
_dim == 3 && bdy_names.size() != 6))
132 "Should be of size '" + std::to_string(2 *
_dim) +
133 "', currently of size: " + std::to_string(bdy_names.size()));
145 for (
auto &
name : getParam<std::vector<ExtraElementIDName>>(
"extra_element_integers"))
149 MooseEnum elem_type_enum = getParam<MooseEnum>(
"elem_type");
157 elem_type_enum =
"EDGE2";
160 elem_type_enum =
"QUAD4";
163 elem_type_enum =
"HEX8";
168 ElemType elem_type = Utility::string_to_enum<ElemType>(elem_type_enum);
176 MeshTools::Generation::build_line(
180 MeshTools::Generation::build_square(cast_ref<UnstructuredMesh &>(*
mesh),
191 MeshTools::Generation::build_cube(cast_ref<UnstructuredMesh &>(*
mesh),
208 auto & bids = getParam<std::vector<SubdomainID>>(
"subdomain_ids");
209 if (bids.size() !=
_nx *
_ny *
_nz && bids.size() != 1)
211 "Size must equal to the product of number of elements in all directions, or one.");
212 for (
auto & elem :
mesh->element_ptr_range())
214 const Point p = elem->vertex_average();
218 unsigned int i = iz *
_nx *
_ny + iy *
_nx + ix;
219 if (bids.size() == 1)
220 elem->subdomain_id() = bids[0];
222 elem->subdomain_id() = bids[i];
227 mesh->unset_has_cached_elem_data();
228 mesh->unset_is_partitioned();
233 const auto & subdomain_name = getParam<SubdomainName>(
"subdomain_name");
236 const auto & bids = getParam<std::vector<SubdomainID>>(
"subdomain_ids");
240 "Specifying a subdomain_name is only supported for a single entry in subdomain_ids");
242 mesh->set_subdomain_name(bids[0], subdomain_name,
true);
245 mesh->set_subdomain_name(0, subdomain_name,
true);
249 BoundaryInfo & boundary_info =
mesh->get_boundary_info();
252 const auto mesh_boundary_ids = boundary_info.get_global_boundary_ids();
253 for (
auto rit = mesh_boundary_ids.rbegin(); rit != mesh_boundary_ids.rend(); ++rit)
255 const std::string old_sideset_name = boundary_info.sideset_name(*rit);
256 const std::string old_nodeset_name = boundary_info.nodeset_name(*rit);
270 const auto & bdy_name = getParam<std::vector<BoundaryName>>(
271 "boundary_names")[std::distance(rit, mesh_boundary_ids.rend()) - 1];
279 mesh->unset_has_boundary_id_sets();
284 const auto MIN = std::numeric_limits<Real>::max();
287 std::array<Real, LIBMESH_DIM> bias = {
291 std::array<Real, LIBMESH_DIM> width = {
298 std::array<unsigned int, LIBMESH_DIM> nelem = {{
_nx,
_dim > 1 ?
_ny : 1,
_dim > 2 ?
_nz : 1}};
302 std::array<std::vector<Real>, LIBMESH_DIM> pows;
303 for (
unsigned int dir = 0; dir < LIBMESH_DIM; ++dir)
305 pows[dir].resize(nelem[dir] + 1);
307 for (
unsigned int i = 1; i < pows[dir].size(); ++i)
308 pows[dir][i] = pows[dir][i - 1] * bias[dir];
312 for (
auto & node_ptr :
mesh->node_ptr_range())
314 Node & node = *node_ptr;
316 for (
unsigned int dir = 0; dir < LIBMESH_DIM; ++dir)
318 if (width[dir] != 0. && bias[dir] != 1.)
323 Real float_index = (node(dir) - mins[dir]) * nelem[dir] / width[dir];
325 Real integer_part = 0;
326 Real fractional_part = std::modf(float_index, &integer_part);
329 if (std::abs(fractional_part) < TOLERANCE || std::abs(fractional_part - 1.0) < TOLERANCE)
338 int index = round(float_index);
340 mooseAssert(index >=
static_cast<int>(0) && index <
static_cast<int>(pows[dir].size()),
341 "Scaled \"index\" out of range");
345 mins[dir] + width[dir] * (1. - pows[dir][index]) / (1. - pows[dir][nelem[dir]]);
347 else if (std::abs(fractional_part - 0.5) < TOLERANCE)
358 node(dir) = mins[dir] +
360 (1. - 0.5 * (pows[dir][integer_part] + pows[dir][integer_part + 1])) /
361 (1. - pows[dir][nelem[dir]]);
366 mooseError(
"Unable to bias node at node(", dir,
")=", node(dir));
383 mesh->clear_point_locator();
384 mesh->clear_stored_ranges();
385 mesh->unset_has_reinit_ghosting_functors();
386 mesh->unset_is_partitioned();
389 return dynamic_pointer_cast<MeshBase>(
mesh);