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");
115 "subdomain_id must be in the size of product of sizes of dx, dy and dz. Sizes are '" +
117 std::to_string(
_dx.size() *
_dy.size() *
_dz.size()) +
"' respectively");
123 "subdomain_id must be in the size of product of sizes of dx and dy. Sizes are '" +
125 std::to_string(
_dx.size() *
_dy.size()) +
"' respectively");
130 mooseError(
"subdomain_id must be in the size of product of sizes of dx. Sizes are '" +
131 std::to_string(
_subdomain_id.size()) +
"' and '" + std::to_string(
_dx.size()) +
151 for (
unsigned int i = 0; i <
_dx.size(); ++i)
156 std::vector<unsigned int> new_id;
157 for (
unsigned int i = 0; i <
_dx.size(); ++i)
158 for (
unsigned int ii = 0; ii <
_ix[i]; ++ii)
176 for (
unsigned int i = 0; i <
_dx.size(); ++i)
179 for (
unsigned int i = 0; i <
_dy.size(); ++i)
183 std::vector<unsigned int> new_id;
184 for (
unsigned int j = 0; j <
_dy.size(); ++j)
185 for (
unsigned int jj = 0; jj <
_iy[j]; ++jj)
186 for (
unsigned int i = 0; i <
_dx.size(); ++i)
187 for (
unsigned int ii = 0; ii <
_ix[i]; ++ii)
203 for (
unsigned int i = 0; i <
_dx.size(); ++i)
206 for (
unsigned int i = 0; i <
_dy.size(); ++i)
209 for (
unsigned int i = 0; i <
_dz.size(); ++i)
212 std::vector<unsigned int> new_id;
213 for (
unsigned int k = 0; k <
_dz.size(); ++k)
214 for (
unsigned int kk = 0; kk <
_iz[k]; ++kk)
215 for (
unsigned int j = 0; j <
_dy.size(); ++j)
216 for (
unsigned int jj = 0; jj <
_iy[j]; ++jj)
217 for (
unsigned int i = 0; i <
_dx.size(); ++i)
218 for (
unsigned int ii = 0; ii <
_ix[i]; ++ii)
232 std::unique_ptr<MeshBase>
242 MeshTools::Generation::build_line(static_cast<UnstructuredMesh &>(*
mesh),
_nx, 0,
_nx,
EDGE2);
245 MeshTools::Generation::build_square(
249 MeshTools::Generation::build_cube(
250 static_cast<UnstructuredMesh &>(*
mesh),
_nx,
_ny,
_nz, 0,
_nx, 0,
_ny, 0,
_nz,
HEX8);
255 MeshBase::element_iterator el =
mesh->active_elements_begin();
256 MeshBase::element_iterator el_end =
mesh->active_elements_end();
257 for (; el != el_end; ++el)
259 const Point p = (*el)->vertex_average();
260 unsigned int ix = std::floor(p(0));
261 unsigned int iy = std::floor(p(1));
262 unsigned int iz = std::floor(p(2));
263 unsigned int i = iz *
_nx *
_ny + iy *
_nx + ix;
274 std::vector<Real> mapx;
277 mapx.push_back(base);
278 for (
unsigned int i = 0; i <
_dx.size(); ++i)
280 for (
unsigned int j = 1; j <=
_ix[i]; ++j)
281 mapx.push_back(base +
_dx[i] /
_ix[i] * j);
285 MeshBase::node_iterator node =
mesh->active_nodes_begin();
286 MeshBase::node_iterator node_end =
mesh->active_nodes_end();
287 for (; node != node_end; ++node)
289 unsigned int i = (*(*node))(0) + 0.5;
290 (*(*node))(0) = mapx.at(i);
298 std::vector<Real> mapx;
300 mapx.push_back(base);
301 for (
unsigned int i = 0; i <
_dx.size(); ++i)
303 for (
unsigned int j = 1; j <=
_ix[i]; ++j)
304 mapx.push_back(base +
_dx[i] /
_ix[i] * j);
308 std::vector<Real> mapy;
310 mapy.push_back(base);
311 for (
unsigned int i = 0; i <
_dy.size(); ++i)
313 for (
unsigned int j = 1; j <=
_iy[i]; ++j)
314 mapy.push_back(base +
_dy[i] /
_iy[i] * j);
318 MeshBase::node_iterator node =
mesh->active_nodes_begin();
319 MeshBase::node_iterator node_end =
mesh->active_nodes_end();
320 for (; node != node_end; ++node)
322 unsigned int i = (*(*node))(0) + 0.5;
323 (*(*node))(0) = mapx.at(i);
324 unsigned int j = (*(*node))(1) + 0.5;
325 (*(*node))(1) = mapy.at(j);
333 std::vector<Real> mapx;
335 mapx.push_back(base);
336 for (
unsigned int i = 0; i <
_dx.size(); ++i)
338 for (
unsigned int j = 1; j <=
_ix[i]; ++j)
339 mapx.push_back(base +
_dx[i] /
_ix[i] * j);
343 std::vector<Real> mapy;
345 mapy.push_back(base);
346 for (
unsigned int i = 0; i <
_dy.size(); ++i)
348 for (
unsigned int j = 1; j <=
_iy[i]; ++j)
349 mapy.push_back(base +
_dy[i] /
_iy[i] * j);
353 std::vector<Real> mapz;
355 mapz.push_back(base);
356 for (
unsigned int i = 0; i <
_dz.size(); ++i)
358 for (
unsigned int j = 1; j <=
_iz[i]; ++j)
359 mapz.push_back(base +
_dz[i] /
_iz[i] * j);
363 MeshBase::node_iterator node =
mesh->active_nodes_begin();
364 MeshBase::node_iterator node_end =
mesh->active_nodes_end();
365 for (; node != node_end; ++node)
367 unsigned int i = (*(*node))(0) + 0.5;
368 (*(*node))(0) = mapx.at(i);
369 unsigned int j = (*(*node))(1) + 0.5;
370 (*(*node))(1) = mapy.at(j);
371 unsigned int k = (*(*node))(2) + 0.5;
372 (*(*node))(2) = mapz.at(k);
378 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::string stringify(const T &t)
conversion to string
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()