12 #include "libmesh/elem.h" 20 params.
addRequiredParam<MeshGeneratorName>(
"input",
"The mesh we want to modify");
22 "The extra element ID to be copied");
23 params.
addRequiredParam<std::vector<std::string>>(
"target_extra_element_ids",
24 "The target extra element IDs");
34 std::unique_ptr<MeshBase>
37 std::unique_ptr<MeshBase>
mesh = std::move(
_input);
39 auto src_id_name = getParam<std::string>(
"source_extra_element_id");
40 bool copy_subdomain_id = (src_id_name ==
"subdomain_id");
41 bool copy_element_id = (src_id_name ==
"element_id");
42 unsigned int src_id = 0;
43 if (!copy_subdomain_id && !copy_element_id)
45 if (!
mesh->has_elem_integer(src_id_name))
46 mooseError(
"The source element ID does not exist on the input mesh");
47 src_id =
mesh->get_elem_integer_index(src_id_name);
50 auto target_id_names = getParam<std::vector<std::string>>(
"target_extra_element_ids");
52 std::vector<unsigned int> target_ids;
53 for (
auto &
name : target_id_names)
58 target_ids.push_back(
mesh->get_elem_integer_index(
name));
61 for (
auto & elem :
mesh->element_ptr_range())
64 if (copy_subdomain_id)
65 id = elem->subdomain_id();
66 else if (copy_element_id)
69 id = elem->get_extra_integer(src_id);
71 for (
auto & target_id : target_ids)
72 elem->set_extra_integer(target_id,
id);
T & getMesh(MooseMesh &mesh)
function to cast mesh
virtual const std::string & name() const
static InputParameters validParams()
void mooseError(Args &&... args) const