14 #include "libmesh/mesh_generation.h" 15 #include "libmesh/unstructured_mesh.h" 16 #include "libmesh/replicated_mesh.h" 17 #include "libmesh/point.h" 18 #include "libmesh/elem.h" 19 #include "libmesh/node.h" 30 params.
addRequiredParam<std::vector<Real>>(
"dx",
"Intervals in the X direction");
31 params.
addParam<std::vector<unsigned int>>(
32 "ix",
"Number of grids in all intervals in the X direction (default to all one)");
34 "dy",
"Intervals in the Y direction (required when dim>1 otherwise ignored)");
35 params.
addParam<std::vector<unsigned int>>(
36 "iy",
"Number of grids in all intervals in the Y direction (default to all one)");
38 "dz",
"Intervals in the Z direction (required when dim>2 otherwise ignored)");
39 params.
addParam<std::vector<unsigned int>>(
40 "iz",
"Number of grids in all intervals in the Z direction (default to all one)");
41 params.
addParam<std::vector<unsigned int>>(
"subdomain_id",
"Block IDs (default to all zero)");
42 params.
addClassDescription(
"This CartesianMeshGenerator creates a non-uniform Cartesian mesh.");
49 _dx(getParam<
std::vector<
Real>>(
"dx"))
54 _ix = getParam<std::vector<unsigned int>>(
"ix");
55 if (
_ix.size() !=
_dx.size())
56 mooseError(
"ix must be in the same size of dx");
57 for (
unsigned int i = 0; i <
_ix.size(); ++i)
62 _ix = std::vector<unsigned int>(
_dx.size(), 1);
64 for (
unsigned int i = 0; i <
_dx.size(); ++i)
70 _dy = getParam<std::vector<Real>>(
"dy");
71 for (
unsigned int i = 0; i <
_dy.size(); ++i)
78 _iy = getParam<std::vector<unsigned int>>(
"iy");
79 if (
_iy.size() !=
_dy.size())
80 mooseError(
"iy must be in the same size of dy");
81 for (
unsigned int i = 0; i <
_iy.size(); ++i)
86 _iy = std::vector<unsigned int>(
_dy.size(), 1);
90 _dz = getParam<std::vector<Real>>(
"dz");
91 for (
unsigned int i = 0; i <
_dz.size(); ++i)
98 _iz = getParam<std::vector<unsigned int>>(
"iz");
99 if (
_iz.size() !=
_dz.size())
100 mooseError(
"iz must be in the same size of dz");
101 for (
unsigned int i = 0; i <
_iz.size(); ++i)
106 _iz = std::vector<unsigned int>(
_dz.size(), 1);
110 _subdomain_id = getParam<std::vector<unsigned int>>(
"subdomain_id");
114 mooseError(
"subdomain_id must be in the size of product of sizes of dx, dy and dz");
119 mooseError(
"subdomain_id must be in the size of product of sizes of dx and dy");
124 mooseError(
"subdomain_id must be in the size of product of sizes of dx");
143 for (
unsigned int i = 0; i <
_dx.size(); ++i)
148 std::vector<unsigned int> new_id;
149 for (
unsigned int i = 0; i <
_dx.size(); ++i)
150 for (
unsigned int ii = 0; ii <
_ix[i]; ++ii)
168 for (
unsigned int i = 0; i <
_dx.size(); ++i)
171 for (
unsigned int i = 0; i <
_dy.size(); ++i)
175 std::vector<unsigned int> new_id;
176 for (
unsigned int j = 0; j <
_dy.size(); ++j)
177 for (
unsigned int jj = 0; jj <
_iy[j]; ++jj)
178 for (
unsigned int i = 0; i <
_dx.size(); ++i)
179 for (
unsigned int ii = 0; ii <
_ix[i]; ++ii)
195 for (
unsigned int i = 0; i <
_dx.size(); ++i)
198 for (
unsigned int i = 0; i <
_dy.size(); ++i)
201 for (
unsigned int i = 0; i <
_dz.size(); ++i)
204 std::vector<unsigned int> new_id;
205 for (
unsigned int k = 0; k <
_dz.size(); ++k)
206 for (
unsigned int kk = 0; kk <
_iz[k]; ++kk)
207 for (
unsigned int j = 0; j <
_dy.size(); ++j)
208 for (
unsigned int jj = 0; jj <
_iy[j]; ++jj)
209 for (
unsigned int i = 0; i <
_dx.size(); ++i)
210 for (
unsigned int ii = 0; ii <
_ix[i]; ++ii)
224 std::unique_ptr<MeshBase>
234 MeshTools::Generation::build_line(static_cast<UnstructuredMesh &>(*
mesh),
_nx, 0,
_nx,
EDGE2);
237 MeshTools::Generation::build_square(
241 MeshTools::Generation::build_cube(
242 static_cast<UnstructuredMesh &>(*
mesh),
_nx,
_ny,
_nz, 0,
_nx, 0,
_ny, 0,
_nz,
HEX8);
247 MeshBase::element_iterator el =
mesh->active_elements_begin();
248 MeshBase::element_iterator el_end =
mesh->active_elements_end();
249 for (; el != el_end; ++el)
251 const Point p = (*el)->vertex_average();
252 unsigned int ix = std::floor(p(0));
253 unsigned int iy = std::floor(p(1));
254 unsigned int iz = std::floor(p(2));
255 unsigned int i = iz *
_nx *
_ny + iy *
_nx + ix;
266 std::vector<Real> mapx;
269 mapx.push_back(base);
270 for (
unsigned int i = 0; i <
_dx.size(); ++i)
272 for (
unsigned int j = 1; j <=
_ix[i]; ++j)
273 mapx.push_back(base +
_dx[i] /
_ix[i] * j);
277 MeshBase::node_iterator node =
mesh->active_nodes_begin();
278 MeshBase::node_iterator node_end =
mesh->active_nodes_end();
279 for (; node != node_end; ++node)
281 unsigned int i = (*(*node))(0) + 0.5;
282 (*(*node))(0) = mapx.at(i);
290 std::vector<Real> mapx;
292 mapx.push_back(base);
293 for (
unsigned int i = 0; i <
_dx.size(); ++i)
295 for (
unsigned int j = 1; j <=
_ix[i]; ++j)
296 mapx.push_back(base +
_dx[i] /
_ix[i] * j);
300 std::vector<Real> mapy;
302 mapy.push_back(base);
303 for (
unsigned int i = 0; i <
_dy.size(); ++i)
305 for (
unsigned int j = 1; j <=
_iy[i]; ++j)
306 mapy.push_back(base +
_dy[i] /
_iy[i] * j);
310 MeshBase::node_iterator node =
mesh->active_nodes_begin();
311 MeshBase::node_iterator node_end =
mesh->active_nodes_end();
312 for (; node != node_end; ++node)
314 unsigned int i = (*(*node))(0) + 0.5;
315 (*(*node))(0) = mapx.at(i);
316 unsigned int j = (*(*node))(1) + 0.5;
317 (*(*node))(1) = mapy.at(j);
325 std::vector<Real> mapx;
327 mapx.push_back(base);
328 for (
unsigned int i = 0; i <
_dx.size(); ++i)
330 for (
unsigned int j = 1; j <=
_ix[i]; ++j)
331 mapx.push_back(base +
_dx[i] /
_ix[i] * j);
335 std::vector<Real> mapy;
337 mapy.push_back(base);
338 for (
unsigned int i = 0; i <
_dy.size(); ++i)
340 for (
unsigned int j = 1; j <=
_iy[i]; ++j)
341 mapy.push_back(base +
_dy[i] /
_iy[i] * j);
345 std::vector<Real> mapz;
347 mapz.push_back(base);
348 for (
unsigned int i = 0; i <
_dz.size(); ++i)
350 for (
unsigned int j = 1; j <=
_iz[i]; ++j)
351 mapz.push_back(base +
_dz[i] /
_iz[i] * j);
355 MeshBase::node_iterator node =
mesh->active_nodes_begin();
356 MeshBase::node_iterator node_end =
mesh->active_nodes_end();
357 for (; node != node_end; ++node)
359 unsigned int i = (*(*node))(0) + 0.5;
360 (*(*node))(0) = mapx.at(i);
361 unsigned int j = (*(*node))(1) + 0.5;
362 (*(*node))(1) = mapy.at(j);
363 unsigned int k = (*(*node))(2) + 0.5;
364 (*(*node))(2) = mapz.at(k);
370 mesh->prepare_for_use();
MooseEnum _dim
The dimension of the mesh.
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
CartesianMeshGenerator(const InputParameters ¶meters)
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.
int _nx
Number of elements in x, y, z direction.
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
std::vector< Real > _dy
Intervals in y direction.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
std::vector< unsigned int > _ix
Number of grids in all intervals in x direction.
std::vector< unsigned int > _subdomain_id
Block IDs.
registerMooseObject("MooseApp", CartesianMeshGenerator)
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
std::vector< unsigned int > _iy
Number of grids in all intervals in y direction.
static InputParameters validParams()
std::vector< Real > _dx
Intervals in x direction.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< unsigned int > _iz
Number of grids in all intervals in z direction.
std::vector< Real > _dz
Intervals in z direction.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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.
static InputParameters validParams()