14 #include "libmesh/mesh_modification.h"
15 #include "libmesh/distributed_mesh.h"
16 #include "libmesh/elem.h"
29 params.
addRequiredParam<MeshGeneratorName>(
"input",
"The mesh we want to modify");
30 params.
addClassDescription(
"Add lower dimensional elements along the faces contained in a side "
31 "set to set up mixed dimensional problems");
33 "The name of the boundary to mesh");
35 "block_id",
"Subdomain id to set for the new elements along the boundary");
37 "block_name",
"Subdomain name to set for the new elements along the boundary (optional)");
44 _input(getMesh(
"input")),
45 _block_id(parameters.get<subdomain_id_type>(
"block_id"))
47 if (
typeid(
_input).
name() ==
typeid(std::unique_ptr<DistributedMesh>).
name())
48 mooseError(
"MeshSideSetGenerator only works with ReplicatedMesh");
51 std::unique_ptr<MeshBase>
54 std::unique_ptr<MeshBase> mesh = std::move(
_input);
56 auto & boundary_info = mesh->get_boundary_info();
59 std::set<boundary_id_type> mesh_boundary_ids;
62 auto & boundary_names = getParam<std::vector<BoundaryName>>(
"boundaries");
63 for (
auto & boundary_name : boundary_names)
64 mesh_boundary_ids.insert(boundary_info.get_id_by_name(boundary_name));
67 mesh_boundary_ids = boundary_info.get_boundary_ids();
70 auto bc_tuples = boundary_info.build_active_side_list();
71 int n = bc_tuples.size();
72 std::vector<std::unique_ptr<BndElement>> bnd_elems;
73 std::map<boundary_id_type, std::set<dof_id_type>> bnd_elem_ids;
75 for (
const auto & t : bc_tuples)
77 auto elem_id = std::get<0>(t);
78 auto side_id = std::get<1>(t);
79 auto bc_id = std::get<2>(t);
81 std::unique_ptr<BndElement> bndElem =
82 libmesh_make_unique<BndElement>(mesh->elem_ptr(elem_id), side_id, bc_id);
83 bnd_elems.push_back(std::move(bndElem));
84 bnd_elem_ids[bc_id].insert(elem_id);
87 for (
auto it = bnd_elems.begin(); it != bnd_elems.end(); ++it)
88 if (mesh_boundary_ids.count((*it)->_bnd_id) > 0)
90 Elem * elem = (*it)->_elem;
91 auto s = (*it)->_side;
94 std::unique_ptr<Elem> side(elem->build_side_ptr(s,
false));
95 side->processor_id() = elem->processor_id();
98 Elem * new_elem = mesh->add_elem(side.release());
104 mesh->subdomain_name(
_block_id) = getParam<SubdomainName>(
"block_name");
106 return dynamic_pointer_cast<MeshBase>(mesh);