13 #include "libmesh/elem.h" 17 ElementSubdomainIDGenerator,
26 params.
addRequiredParam<MeshGeneratorName>(
"input",
"The mesh we want to modify");
28 "New subdomain IDs of all elements");
29 params.
addParam<std::vector<dof_id_type>>(
"element_ids",
"New element IDs of all elements");
31 "Allows the user to assign each element the subdomain ID of their choice");
40 std::unique_ptr<MeshBase>
43 std::unique_ptr<MeshBase>
mesh = std::move(
_input);
45 std::vector<SubdomainID> bids = getParam<std::vector<SubdomainID>>(
"subdomain_ids");
48 std::vector<Elem *> elements;
51 std::vector<dof_id_type> elemids = getParam<std::vector<dof_id_type>>(
"element_ids");
52 for (
const auto & dof : elemids)
54 Elem * elem =
mesh->query_elem_ptr(dof);
64 mooseError(
"invalid element ID is in element_ids");
66 elements.push_back(elem);
72 bool has_warned_remapping =
false;
99 Elem * elem =
mesh->query_elem_ptr(e);
100 bool someone_has_elem = elem;
101 if (!
mesh->is_replicated())
102 this->
comm().
max(someone_has_elem);
104 if (elem && elem->id() != e && (!has_warned_remapping))
106 mooseWarning(
"AssignElementSubdomainID will ignore the element remapping");
107 has_warned_remapping =
true;
110 if (someone_has_elem)
111 elements.push_back(elem);
115 if (bids.size() != elements.size())
116 mooseError(
" Size of subdomain_ids is not consistent with the number of elements");
120 std::map<ElemType, std::set<SubdomainID>> type2blocks;
125 Elem * elem = elements[e];
132 bool has_type =
false;
133 for (
auto & it : type2blocks)
135 if (it.first ==
type)
138 it.second.insert(newid);
140 else if (it.second.count(newid) > 0)
141 mooseError(
"trying to assign elements with different types with the same subdomain ID");
146 std::set<SubdomainID>
blocks;
148 type2blocks.insert(std::make_pair(
type,
blocks));
151 elem->subdomain_id() = newid;
154 mesh->set_isnt_prepared();
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
std::unique_ptr< MeshBase > & _input
mesh to modify
const Parallel::Communicator & comm() const
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.
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
registerMooseObjectRenamed("MooseApp", ElementSubdomainIDGenerator, "05/18/2024 24:00", SubdomainPerElementGenerator)
registerMooseObject("MooseApp", SubdomainPerElementGenerator)
const std::string & type() const
Get the type of this class.
MeshGenerator for assigning subdomain IDs of all elements.
static InputParameters validParams()
void max(const T &r, T &o, Request &req) const
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
static InputParameters validParams()
MeshGenerators are objects that can modify or add to an existing mesh.
SubdomainPerElementGenerator(const InputParameters ¶meters)