13 #include "libmesh/enum_point_locator_type.h" 14 #include "libmesh/elem.h" 15 #include "libmesh/mesh_serializer.h" 26 "input",
"Name of an existing mesh generator to which we assign coarse element IDs");
28 "coarse_mesh",
"Name of an existing mesh generator as the coarse mesh");
30 "extra_element_id_name",
"Name for the extra element ID that is added to the input mesh");
32 "coarse_mesh_extra_element_id",
33 "Name for the extra element ID that is copied from the coarse mesh (default to element ID)");
34 params.
addParam<std::vector<SubdomainName>>(
35 "subdomains", std::vector<SubdomainName>(),
"Subdomains to apply extra element IDs to.");
36 params.
addParam<
bool>(
"enforce_mesh_embedding",
38 "True to error out when the input mesh is not embedded in the coarse mesh");
41 "mesh based on a coarse mesh.");
48 _coarse_mesh(
getMesh(
"coarse_mesh")),
49 _coarse_id_name(getParam<
std::string>(
"extra_element_id_name")),
50 _using_coarse_element_id(isParamValid(
"coarse_mesh_extra_element_id")),
51 _embedding_necessary(getParam<bool>(
"enforce_mesh_embedding"))
55 std::unique_ptr<MeshBase>
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);
91 if (elem_id != DofObject::invalid_id && elem_id > id_offset)
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);
void add_scaled(const TypeVector< T2 > &, const Real &)
T & getMesh(MooseMesh &mesh)
function to cast mesh
unsigned int add_elem_integer(std::string name, bool allocate_data=true, dof_id_type default_value=DofObject::invalid_id)
bool has_elem_integer(std::string_view name) const
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
SubdomainID getSubdomainID(const SubdomainName &subdomain_name, const MeshBase &mesh)
bool hasSubdomainID(const MeshBase &input_mesh, const SubdomainID &id)
unsigned int get_elem_integer_index(std::string_view name) const
const T & getParam(const std::string &name) const
void paramError(const std::string ¶m, Args... args) const
static InputParameters validParams()
std::string stringify(const T &t)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
subdomain_id_type subdomain_id() const
void mooseError(Args &&... args) const
virtual SimpleRange< element_iterator > active_subdomain_set_elements_ptr_range(std::set< subdomain_id_type > ss)=0
dof_id_type get_extra_integer(const unsigned int index) const