56 std::unique_ptr<MeshBase>
mesh = std::move(
_input);
58 unsigned int coarse_id;
66 std::set<SubdomainID> included_subdomains;
67 std::set<SubdomainName> bad_subdomains;
68 for (
const auto & snm : getParam<std::vector<SubdomainName>>(
"subdomains"))
72 bad_subdomains.insert(snm);
74 included_subdomains.insert(sid);
76 if (!bad_subdomains.empty())
78 "The requested subdomains do not exist on the fine mesh: ",
83 dof_id_type id_offset = 0;
84 if (already_has_id && !included_subdomains.empty())
86 for (
auto & elem :
mesh->active_element_ptr_range())
88 dof_id_type elem_id = elem->get_extra_integer(coarse_id);
89 if (elem_id != DofObject::invalid_id && elem_id > id_offset)
95 std::unique_ptr<MeshBase> coarse_mesh = std::move(
_coarse_mesh);
97 bool using_subdomain_id =
false;
98 unsigned int id_for_assignment = 0;
101 const auto & id_name = getParam<std::string>(
"coarse_mesh_extra_element_id");
102 if (id_name ==
"subdomain_id")
103 using_subdomain_id =
true;
106 using_subdomain_id =
false;
107 if (!coarse_mesh->has_elem_integer(id_name))
109 "The extra element ID does not exist on the coarse mesh");
111 id_for_assignment = coarse_mesh->get_elem_integer_index(id_name);
120 MeshSerializer tm(*coarse_mesh);
123 std::unique_ptr<PointLocatorBase> point_locator =
124 PointLocatorBase::build(TREE_ELEMENTS, *coarse_mesh);
125 point_locator->enable_out_of_mesh_mode();
128 auto elem_range = included_subdomains.empty()
129 ?
mesh->active_element_ptr_range()
130 :
mesh->active_subdomain_set_elements_ptr_range(included_subdomains);
131 for (
auto & elem : elem_range)
134 Point centroid = elem->true_centroid();
137 const Elem * coarse_elem = (*point_locator)(centroid);
139 mooseError(
"Could not find a coarse element containing a fine element with centroid ",
146 if (using_subdomain_id)
147 elem_id = coarse_elem->subdomain_id();
149 elem_id = coarse_elem->get_extra_integer(id_for_assignment);
152 elem_id = coarse_elem->id();
153 elem_id += id_offset;
156 for (
unsigned int n = 0; n < elem->n_nodes(); n++)
160 Point current_node = elem->point(n);
161 current_node.add_scaled(current_node, -aeps);
162 current_node.add_scaled(centroid, aeps);
167 const Elem * node_elem = (*point_locator)(current_node);
169 mooseError(
"Could not find a coarse element containing a node of fine element at ",
173 dof_id_type node_elem_id;
176 if (using_subdomain_id)
177 node_elem_id = node_elem->subdomain_id();
179 node_elem_id = node_elem->get_extra_integer(id_for_assignment);
182 node_elem_id = node_elem->id();
184 if (node_elem_id != elem_id)
187 "Input mesh is not nested in the coarse mesh in CoarseMeshExtraElementIDGenerator.");
190 elem->set_extra_integer(coarse_id, elem_id);