Line data Source code
1 : //* This file is part of the MOOSE framework
2 : //* https://mooseframework.inl.gov
3 : //*
4 : //* All rights reserved, see COPYRIGHT for full restrictions
5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 : //*
7 : //* Licensed under LGPL 2.1, please see LICENSE for details
8 : //* https://www.gnu.org/licenses/lgpl-2.1.html
9 :
10 : #include "TiledMeshGenerator.h"
11 : #include "CastUniquePointer.h"
12 :
13 : #include "libmesh/replicated_mesh.h"
14 : #include "libmesh/distributed_mesh.h"
15 : #include "libmesh/boundary_info.h"
16 : #include "libmesh/mesh_modification.h"
17 : #include "libmesh/bounding_box.h"
18 : #include "libmesh/mesh_tools.h"
19 : #include "libmesh/point.h"
20 :
21 : #include <typeinfo>
22 :
23 : registerMooseObject("MooseApp", TiledMeshGenerator);
24 :
25 : InputParameters
26 14281 : TiledMeshGenerator::validParams()
27 : {
28 14281 : InputParameters params = MeshGenerator::validParams();
29 :
30 14281 : params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to repeat");
31 :
32 : // x boundary names
33 14281 : params.addParam<BoundaryName>("left_boundary", "left", "name of the left (x) boundary");
34 14281 : params.addParam<BoundaryName>("right_boundary", "right", "name of the right (x) boundary");
35 :
36 : // y boundary names
37 14281 : params.addParam<BoundaryName>("top_boundary", "top", "name of the top (y) boundary");
38 14281 : params.addParam<BoundaryName>("bottom_boundary", "bottom", "name of the bottom (y) boundary");
39 :
40 : // z boundary names
41 14281 : params.addParam<BoundaryName>("front_boundary", "front", "name of the front (z) boundary");
42 14281 : params.addParam<BoundaryName>("back_boundary", "back", "name of the back (z) boundary");
43 :
44 : // The number of tiles is 1 in each direction unless otherwise specified.
45 : // An x_tiles value of 1 means do not stitch any extra meshes together in
46 : // the x-direction.
47 42843 : params.addParam<unsigned int>(
48 28562 : "x_tiles", 1, "Number of tiles to stitch together (left to right) in the x-direction");
49 42843 : params.addParam<unsigned int>(
50 28562 : "y_tiles", 1, "Number of tiles to stitch together (top to bottom) in the y-direction");
51 42843 : params.addParam<unsigned int>(
52 28562 : "z_tiles", 1, "Number of tiles to stitch together (front to back) in the z-direction");
53 :
54 14281 : params.addClassDescription("Use the supplied mesh and create a tiled grid by repeating this mesh "
55 : "in the x, y, and z directions.");
56 :
57 14281 : return params;
58 0 : }
59 :
60 8 : TiledMeshGenerator::TiledMeshGenerator(const InputParameters & parameters)
61 8 : : MeshGenerator(parameters), _input(getMesh("input"))
62 : {
63 8 : }
64 :
65 : std::unique_ptr<MeshBase>
66 8 : TiledMeshGenerator::generate()
67 : {
68 8 : std::unique_ptr<MeshBase> initial_mesh = std::move(_input);
69 8 : if (!initial_mesh->is_replicated())
70 0 : mooseError("This MeshGenerator is not implemented for distributed meshes");
71 8 : std::unique_ptr<ReplicatedMesh> mesh = dynamic_pointer_cast<ReplicatedMesh>(initial_mesh);
72 :
73 : // Getting the x,y,z widths
74 8 : std::set<subdomain_id_type> sub_ids;
75 8 : mesh->subdomain_ids(sub_ids);
76 8 : BoundingBox bbox;
77 16 : for (auto id : sub_ids)
78 : {
79 8 : BoundingBox sub_bbox = MeshTools::create_subdomain_bounding_box(*mesh, id);
80 8 : bbox.union_with(sub_bbox);
81 : }
82 :
83 8 : _x_width = bbox.max()(0) - bbox.min()(0);
84 8 : _y_width = bbox.max()(1) - bbox.min()(1);
85 8 : _z_width = bbox.max()(2) - bbox.min()(2);
86 :
87 : boundary_id_type left =
88 8 : mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>("left_boundary"));
89 : boundary_id_type right =
90 8 : mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>("right_boundary"));
91 : boundary_id_type top =
92 8 : mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>("top_boundary"));
93 : boundary_id_type bottom =
94 8 : mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>("bottom_boundary"));
95 : boundary_id_type front =
96 8 : mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>("front_boundary"));
97 : boundary_id_type back =
98 8 : mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>("back_boundary"));
99 :
100 : {
101 8 : std::unique_ptr<MeshBase> clone = mesh->clone();
102 :
103 : // Build X Tiles
104 16 : for (unsigned int i = 1; i < getParam<unsigned int>("x_tiles"); ++i)
105 : {
106 8 : MeshTools::Modification::translate(*clone, _x_width, 0, 0);
107 8 : mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
108 : right,
109 : left,
110 : TOLERANCE,
111 : /*clear_stitched_boundary_ids=*/true);
112 : }
113 8 : }
114 :
115 : {
116 8 : std::unique_ptr<MeshBase> clone = mesh->clone();
117 :
118 : // Build Y Tiles
119 16 : for (unsigned int i = 1; i < getParam<unsigned int>("y_tiles"); ++i)
120 : {
121 8 : MeshTools::Modification::translate(*clone, 0, _y_width, 0);
122 8 : mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
123 : top,
124 : bottom,
125 : TOLERANCE,
126 : /*clear_stitched_boundary_ids=*/true);
127 : }
128 8 : }
129 :
130 : {
131 8 : std::unique_ptr<MeshBase> clone = mesh->clone();
132 :
133 : // Build Z Tiles
134 16 : for (unsigned int i = 1; i < getParam<unsigned int>("z_tiles"); ++i)
135 : {
136 8 : MeshTools::Modification::translate(*clone, 0, 0, _z_width);
137 8 : mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
138 : front,
139 : back,
140 : TOLERANCE,
141 : /*clear_stitched_boundary_ids=*/true);
142 : }
143 8 : }
144 :
145 16 : return dynamic_pointer_cast<MeshBase>(mesh);
146 8 : }
|