58 std::unique_ptr<MeshBase>
mesh = std::move(
_input);
60 unsigned int coarse_id;
68 std::set<SubdomainID> included_subdomains;
69 std::set<SubdomainName> bad_subdomains;
70 for (
const auto & snm : getParam<std::vector<SubdomainName>>(
"subdomains"))
74 bad_subdomains.insert(snm);
76 included_subdomains.insert(sid);
78 if (!bad_subdomains.empty())
80 "The requested subdomains do not exist on the fine mesh: ",
86 if (already_has_id && !included_subdomains.empty())
88 for (
auto & elem :
mesh->active_element_ptr_range())
90 dof_id_type elem_id = elem->get_extra_integer(coarse_id);
97 std::unique_ptr<MeshBase> coarse_mesh = std::move(
_coarse_mesh);
99 bool using_subdomain_id =
false;
100 unsigned int id_for_assignment = 0;
103 const auto & id_name = getParam<std::string>(
"coarse_mesh_extra_element_id");
104 if (id_name ==
"subdomain_id")
105 using_subdomain_id =
true;
108 using_subdomain_id =
false;
109 if (!coarse_mesh->has_elem_integer(id_name))
111 "The extra element ID does not exist on the coarse mesh");
113 id_for_assignment = coarse_mesh->get_elem_integer_index(id_name);
125 std::unique_ptr<PointLocatorBase> point_locator =
127 point_locator->enable_out_of_mesh_mode();
130 auto elem_range = included_subdomains.empty()
131 ?
mesh->active_element_ptr_range()
133 for (
auto & elem : elem_range)
136 Point centroid = elem->true_centroid();
139 const Elem * coarse_elem = (*point_locator)(centroid);
141 mooseError(
"Could not find a coarse element containing a fine element with centroid ",
148 if (using_subdomain_id)
154 elem_id = coarse_elem->
id();
155 elem_id += id_offset;
158 for (
unsigned int n = 0; n < elem->n_nodes(); n++)
162 Point current_node = elem->point(n);
169 const Elem * node_elem = (*point_locator)(current_node);
171 mooseError(
"Could not find a coarse element containing a node of fine element at ",
178 if (using_subdomain_id)
184 node_elem_id = node_elem->
id();
186 if (node_elem_id != elem_id)
189 "Input mesh is not nested in the coarse mesh in CoarseMeshExtraElementIDGenerator.");
192 elem->set_extra_integer(coarse_id, elem_id);