12 #include "libmesh/elem.h" 21 "input",
"Name of an existing mesh generator to which we assign extra element IDs");
24 "Existing extra integer ID names that is used to generate a new extra integer ID by finding " 25 "unique combinations of their values");
26 params.
addRequiredParam<ExtraElementIDName>(
"new_id_name",
"New extra integer ID name");
27 params.
addParam<std::vector<unsigned int>>(
29 "Vector of unsigned integers to determine new integer ID values by multiplying the provided " 30 "integers to the corresponding existing ID values and then summing the resulting values");
31 params.
addParam<std::vector<SubdomainName>>(
32 "restricted_subdomains",
"Only set new extra element id for elements in given subdomains");
33 params.
addClassDescription(
"Add a new extra element integer ID by finding unique combinations of " 34 "the existing extra element integer ID values");
40 _input(getMesh(
"input")),
41 _extra_ids(getParam<
std::vector<ExtraElementIDName>>(
"id_name")),
42 _use_new_id_rule(isParamValid(
"new_id_rule")),
43 _has_restriction(isParamValid(
"restricted_subdomains"))
48 "This parameter, if provided, must have a length equal to length of id_name.");
51 std::unique_ptr<MeshBase>
54 std::unique_ptr<MeshBase>
mesh = std::move(
_input);
56 std::set<SubdomainID> restricted_ids;
59 auto names = getParam<std::vector<SubdomainName>>(
"restricted_subdomains");
60 for (
auto &
name : names)
64 paramError(
"restricted_subdomains",
"The block '",
name,
"' was not found in the mesh");
77 std::vector<unsigned int> new_id_rule = getParam<std::vector<unsigned int>>(
"new_id_rule");
78 std::vector<unsigned int> existing_extra_id_index;
80 existing_extra_id_index.push_back(
mesh->get_elem_integer_index(id_name));
81 for (
auto & elem :
mesh->active_local_element_ptr_range())
84 for (
unsigned int i = 0; i <
_extra_ids.size(); ++i)
85 new_id_value += new_id_rule[i] * elem->get_extra_integer(existing_extra_id_index[i]);
86 parsed_ids[elem->id()] = new_id_value;
89 auto new_id_name = getParam<ExtraElementIDName>(
"new_id_name");
90 unsigned int extra_id_index;
91 if (!
mesh->has_elem_integer(new_id_name))
92 extra_id_index =
mesh->add_elem_integer(new_id_name);
95 extra_id_index =
mesh->get_elem_integer_index(new_id_name);
97 "new_id_name",
"An element integer with the name '", new_id_name,
"' already exists");
100 for (
auto & elem :
mesh->active_element_ptr_range())
104 elem->set_extra_integer(extra_id_index, parsed_ids.at(elem->id()));
std::unordered_map< dof_id_type, dof_id_type > getExtraIDUniqueCombinationMap(const MeshBase &mesh, const std::set< SubdomainID > &block_ids, std::vector< ExtraElementIDName > extra_ids)
Crate a new set of element-wise IDs by finding unique combinations of existing extra ID values...
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 ...
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
SubdomainID getSubdomainID(const SubdomainName &subdomain_name, const MeshBase &mesh)
Gets the subdomain ID associated with the given SubdomainName.
const std::string & name() const
Get the name of the class.
static InputParameters validParams()
bool hasSubdomainName(const MeshBase &input_mesh, const SubdomainName &name)
Whether a particular subdomain name exists in the mesh.
void paramWarning(const std::string ¶m, Args... args) const
Emits a warning prefixed with the file and line number of the given param (from the input file) along...
MeshGenerators are objects that can modify or add to an existing mesh.