95 _nx(declareMeshProperty(
"num_elements_x", getParam<unsigned
int>(
"nx"))),
96 _ny(declareMeshProperty(
"num_elements_y", getParam<unsigned
int>(
"ny"))),
97 _nz(declareMeshProperty(
"num_elements_z", getParam<unsigned
int>(
"nz"))),
98 _xmin(declareMeshProperty(
"xmin", getParam<Real>(
"xmin"))),
99 _xmax(declareMeshProperty(
"xmax", getParam<Real>(
"xmax"))),
100 _ymin(declareMeshProperty(
"ymin", getParam<Real>(
"ymin"))),
101 _ymax(declareMeshProperty(
"ymax", getParam<Real>(
"ymax"))),
102 _zmin(declareMeshProperty(
"zmin", getParam<Real>(
"zmin"))),
103 _zmax(declareMeshProperty(
"zmax", getParam<Real>(
"zmax"))),
104 _has_subdomain_ids(isParamValid(
"subdomain_ids")),
105 _gauss_lobatto_grid(getParam<bool>(
"gauss_lobatto_grid")),
106 _bias_x(getParam<Real>(
"bias_x")),
107 _bias_y(getParam<Real>(
"bias_y")),
108 _bias_z(getParam<Real>(
"bias_z")),
109 _boundary_name_prefix(isParamValid(
"boundary_name_prefix")
110 ? getParam<
std::string>(
"boundary_name_prefix") +
"_"
112 _boundary_id_offset(getParam<boundary_id_type>(
"boundary_id_offset"))
115 mooseError(
"Cannot apply both Gauss-Lobatto mesh grading and biasing at the same time.");
117 paramError(
"xmax",
"xmax must be larger than xmin.");
119 paramError(
"ymax",
"ymax must be larger than ymin.");
121 paramError(
"zmax",
"zmax must be larger than zmin.");
132 for (
auto &
name : getParam<std::vector<ExtraElementIDName>>(
"extra_element_integers"))
136 MooseEnum elem_type_enum = getParam<MooseEnum>(
"elem_type");
144 elem_type_enum =
"EDGE2";
147 elem_type_enum =
"QUAD4";
150 elem_type_enum =
"HEX8";
155 ElemType elem_type = Utility::string_to_enum<ElemType>(elem_type_enum);
163 MeshTools::Generation::build_line(
167 MeshTools::Generation::build_square(cast_ref<UnstructuredMesh &>(*
mesh),
178 MeshTools::Generation::build_cube(cast_ref<UnstructuredMesh &>(*
mesh),
195 auto & bids = getParam<std::vector<SubdomainID>>(
"subdomain_ids");
196 if (bids.size() !=
_nx *
_ny *
_nz && bids.size() != 1)
198 "Size must equal to the product of number of elements in all directions, or one.");
199 for (
auto & elem :
mesh->element_ptr_range())
201 const Point p = elem->vertex_average();
205 unsigned int i = iz *
_nx *
_ny + iy *
_nx + ix;
206 if (bids.size() == 1)
207 elem->subdomain_id() = bids[0];
209 elem->subdomain_id() = bids[i];
214 mesh->unset_has_cached_elem_data();
215 mesh->unset_is_partitioned();
220 const auto & subdomain_name = getParam<SubdomainName>(
"subdomain_name");
223 const auto & bids = getParam<std::vector<SubdomainID>>(
"subdomain_ids");
227 "Specifying a subdomain_name is only supported for a single entry in subdomain_ids");
229 mesh->set_subdomain_name(bids[0], subdomain_name,
true);
232 mesh->set_subdomain_name(0, subdomain_name,
true);
236 BoundaryInfo & boundary_info =
mesh->get_boundary_info();
239 const auto mesh_boundary_ids = boundary_info.get_global_boundary_ids();
240 for (
auto rit = mesh_boundary_ids.rbegin(); rit != mesh_boundary_ids.rend(); ++rit)
242 const std::string old_sideset_name = boundary_info.sideset_name(*rit);
243 const std::string old_nodeset_name = boundary_info.nodeset_name(*rit);
255 mesh->unset_has_boundary_id_sets();
260 const auto MIN = std::numeric_limits<Real>::max();
263 std::array<Real, LIBMESH_DIM> bias = {
267 std::array<Real, LIBMESH_DIM> width = {
274 std::array<unsigned int, LIBMESH_DIM> nelem = {{
_nx,
_dim > 1 ?
_ny : 1,
_dim > 2 ?
_nz : 1}};
278 std::array<std::vector<Real>, LIBMESH_DIM> pows;
279 for (
unsigned int dir = 0; dir < LIBMESH_DIM; ++dir)
281 pows[dir].resize(nelem[dir] + 1);
283 for (
unsigned int i = 1; i < pows[dir].size(); ++i)
284 pows[dir][i] = pows[dir][i - 1] * bias[dir];
288 for (
auto & node_ptr :
mesh->node_ptr_range())
290 Node & node = *node_ptr;
292 for (
unsigned int dir = 0; dir < LIBMESH_DIM; ++dir)
294 if (width[dir] != 0. && bias[dir] != 1.)
299 Real float_index = (node(dir) - mins[dir]) * nelem[dir] / width[dir];
301 Real integer_part = 0;
302 Real fractional_part = std::modf(float_index, &integer_part);
305 if (std::abs(fractional_part) < TOLERANCE || std::abs(fractional_part - 1.0) < TOLERANCE)
314 int index = round(float_index);
316 mooseAssert(index >=
static_cast<int>(0) && index <
static_cast<int>(pows[dir].size()),
317 "Scaled \"index\" out of range");
321 mins[dir] + width[dir] * (1. - pows[dir][index]) / (1. - pows[dir][nelem[dir]]);
323 else if (std::abs(fractional_part - 0.5) < TOLERANCE)
334 node(dir) = mins[dir] +
336 (1. - 0.5 * (pows[dir][integer_part] + pows[dir][integer_part + 1])) /
337 (1. - pows[dir][nelem[dir]]);
342 mooseError(
"Unable to bias node at node(", dir,
")=", node(dir));
359 mesh->clear_point_locator();
360 mesh->clear_stored_ranges();
361 mesh->unset_has_reinit_ghosting_functors();
362 mesh->unset_is_partitioned();
365 return dynamic_pointer_cast<MeshBase>(
mesh);