14 #include "libmesh/replicated_mesh.h" 15 #include "libmesh/boundary_info.h" 16 #include "libmesh/elem.h" 25 params.
addRequiredParam<MeshGeneratorName>(
"input",
"the mesh we want to extrude");
26 params.
addClassDescription(
"Takes a 1D or 2D mesh and extrudes the entire structure along the " 27 "specified axis increasing the dimensionality of the mesh.");
29 "The direction and length of the extrusion");
30 params.
addParam<
unsigned int>(
"num_layers", 1,
"The number of layers in the extruded mesh");
31 params.
addParam<std::vector<BoundaryName>>(
32 "bottom_sideset",
"The boundary that will be applied to the bottom of the extruded mesh");
33 params.
addParam<std::vector<BoundaryName>>(
34 "top_sideset",
"The boundary that will be to the top of the extruded mesh");
36 params.
addParam<std::vector<SubdomainID>>(
37 "existing_subdomains",
38 std::vector<SubdomainID>(),
39 "The subdomains that will be remapped for specific layers");
40 params.
addParam<std::vector<unsigned int>>(
42 std::vector<unsigned int>(),
43 "The layers where the \"existing_subdomain\" will be remapped to new ids");
44 params.
addParam<std::vector<unsigned int>>(
46 std::vector<unsigned int>(),
47 "The list of new ids, This list should be either length \"existing_subdomains\" or " 48 "\"existing_subdomains\" * layers");
55 _input(getMesh(
"input")),
57 _num_layers(getParam<unsigned
int>(
"num_layers")),
58 _existing_subdomains(getParam<
std::vector<
SubdomainID>>(
"existing_subdomains")),
59 _layers(getParam<
std::vector<unsigned
int>>(
"layers")),
60 _new_ids(getParam<
std::vector<unsigned
int>>(
"new_ids"))
66 "The length of the \"existing_subdomains\", \"layers\", and \"new_ids\" are not valid");
69 std::unique_ptr<MeshBase>
72 std::unique_ptr<MeshBase> source_mesh = std::move(
_input);
79 paramError(
"existing_subdomains",
"The block ID '",
id,
"' was not found in the mesh");
81 if (source_mesh->mesh_dimension() == 3)
84 std::unique_ptr<QueryElemSubdomainID> elem_subdomain_id;
86 elem_subdomain_id = std::make_unique<QueryElemSubdomainID>(
89 MeshTools::Generation::build_extrusion(dynamic_cast<libMesh::UnstructuredMesh &>(*dest_mesh),
93 elem_subdomain_id.get());
96 std::set<boundary_id_type> side_ids = dest_mesh->get_boundary_info().get_side_boundary_ids();
101 std::set<boundary_id_type>::reverse_iterator last_side_it = side_ids.rbegin();
104 mooseAssert(last_side_it != side_ids.rend(),
"Error in generating sidesets for extruded mesh");
109 changeID(*dest_mesh,
getParam<std::vector<BoundaryName>>(
"bottom_sideset"), old_bottom);
111 changeID(*dest_mesh,
getParam<std::vector<BoundaryName>>(
"top_sideset"), old_top);
113 dest_mesh->set_isnt_prepared();
119 const std::vector<BoundaryName> & names,
124 if (std::find(boundary_ids.begin(), boundary_ids.end(), old_id) == boundary_ids.end())
127 for (
unsigned int i = 0; i < boundary_ids.size(); ++i)
129 mesh.get_boundary_info().sideset_name(boundary_ids[i]) = names[i];
130 mesh.get_boundary_info().nodeset_name(boundary_ids[i]) = names[i];
135 const std::vector<SubdomainID> & existing_subdomains,
136 std::vector<unsigned int> layers,
137 const std::vector<unsigned int> & new_ids,
138 unsigned int num_layers)
139 : QueryElemSubdomainIDBase(), _num_layers(num_layers)
143 const unsigned int stride =
144 existing_subdomains.size() == new_ids.size() ? 0 : existing_subdomains.size();
146 if (layers.size() == 0)
151 for (
unsigned int i = 0; i < layers.size(); ++i)
152 for (
unsigned int j = 0; j < existing_subdomains.size(); ++j)
153 _layer_data[layers[i]][existing_subdomains[j]] = new_ids[i * stride + j];
160 mooseAssert(layer <
_num_layers,
"Access out of bounds: " << layer);
163 std::map<unsigned int, std::map<SubdomainID, unsigned int>>::const_iterator layer_it =
164 _layer_data.find(layer);
166 if (layer_it == _layer_data.end())
168 return old_elem->subdomain_id();
171 std::map<SubdomainID, unsigned int>::const_iterator sub_id_it =
172 layer_it->second.find(old_elem->subdomain_id());
174 if (sub_id_it == layer_it->second.end())
177 return old_elem->subdomain_id();
180 return sub_id_it->second;
Extrude a 1D or 2D mesh to a 2D or 3D mesh respectively.
QueryElemSubdomainID(const std::vector< SubdomainID > &existing_subdomains, std::vector< unsigned int > layers, const std::vector< unsigned int > &new_ids, unsigned int num_layers)
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
virtual subdomain_id_type get_subdomain_for_layer(const Elem *old_elem, unsigned int layer)
The override from the base class for obtaining a new id based on the old (original) element and the s...
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.
const Parallel::Communicator & _communicator
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
bool hasSubdomainID(const MeshBase &input_mesh, const SubdomainID &id)
Whether a particular subdomain ID exists in the mesh.
static InputParameters validParams()
boundary_id_type BoundaryID
void changeID(MeshBase &mesh, const std::vector< BoundaryName > &names, BoundaryID old_id)
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
std::vector< unsigned int > _layers
std::vector< BoundaryID > getBoundaryIDs(const libMesh::MeshBase &mesh, const std::vector< BoundaryName > &boundary_name, bool generate_unknown, const std::set< BoundaryID > &mesh_boundary_ids)
Gets the boundary IDs with their names.
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
static InputParameters validParams()
std::unique_ptr< MeshBase > & _input
Mesh that comes from another generator.
std::map< unsigned int, std::map< SubdomainID, unsigned int > > _layer_data
Data structure for holding the old -> new id mapping based on the layer number.
const RealVectorValue _extrusion_vector
std::vector< SubdomainID > _existing_subdomains
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...
void changeBoundaryId(MeshBase &mesh, const libMesh::boundary_id_type old_id, const libMesh::boundary_id_type new_id, bool delete_prev)
Changes the old boundary ID to a new ID in the mesh.
MeshExtruderGenerator(const InputParameters ¶meters)
MeshGenerators are objects that can modify or add to an existing mesh.
void ErrorVector unsigned int
std::vector< unsigned int > _new_ids
registerMooseObjectDeprecated("MooseApp", MeshExtruderGenerator, "12/31/2025 24:00")
unsigned int _num_layers
The total number of layers in the extrusion.
void set_union(T &data, const unsigned int root_id) const