15 #include "libmesh/mesh_generation.h" 16 #include "libmesh/mesh.h" 17 #include "libmesh/elem.h" 23 params.
addRequiredParam<MeshGeneratorName>(
"input",
"The mesh we want to modify");
25 "The list of nodeset names to create.");
29 "If true, replace the old nodesets. If false, the current nodesets (if " 30 "any) will be preserved.");
32 params.
addParam<std::vector<BoundaryName>>(
34 "A set of nodeset names or ids whose nodes will be included in the new nodesets. A node " 35 "is only added if it also belongs to one of these nodesets.");
36 params.
addParam<std::vector<BoundaryName>>(
38 "A set of nodeset names or ids whose nodes will be excluded from the new nodesets. A node " 39 "is only added if does not belong to any of these nodesets.");
40 params.
addParam<std::vector<SubdomainName>>(
41 "included_subdomains",
42 "A set of subdomain names or ids whose nodes will be included in the new nodesets. A node " 43 "is only added if the subdomain id of the corresponding element is in this set.");
44 params.
addParam<std::vector<SubdomainName>>(
45 "excluded_subdomains",
46 "A set of subdomain names or ids whose nodes will be excluded in the new nodesets. A node " 47 "is only added if the subdomain id of the corresponding element is not in this set.");
50 "include_only_external_nodes",
52 "Whether to only include external nodes when considering nodes to add to the nodeset");
56 "include_only_external_nodes",
57 "Nodeset restrictions");
64 _input(getMesh(
"input")),
65 _nodeset_names(
std::vector<BoundaryName>()),
66 _replace(getParam<bool>(
"replace")),
67 _check_included_nodesets(isParamValid(
"included_nodesets")),
68 _check_excluded_nodesets(isParamValid(
"excluded_nodesets")),
69 _check_included_subdomains(isParamValid(
"included_subdomains")),
70 _check_excluded_subdomains(isParamValid(
"excluded_subdomains")),
75 _include_only_external_nodes(getParam<bool>(
"include_only_external_nodes"))
78 _nodeset_names = getParam<std::vector<BoundaryName>>(
"new_nodeset");
87 const auto & included_nodesets = getParam<std::vector<BoundaryName>>(
"included_nodesets");
89 if (std::find(included_nodesets.begin(), included_nodesets.end(), nodeset_name) !=
90 included_nodesets.end())
93 "A nodeset cannot be both the new nodeset and be included in the list of included " 94 "nodesets. If you are trying to restrict an existing nodeset, you must use a " 95 "different name for 'new_nodeset', delete the old nodeset, and then rename the " 96 "new nodeset to the old nodeset.");
105 included_nodesets[i],
106 "' was not found within the mesh");
111 const auto & excluded_nodesets = getParam<std::vector<BoundaryName>>(
"excluded_nodesets");
113 if (std::find(excluded_nodesets.begin(), excluded_nodesets.end(), nodeset_name) !=
114 excluded_nodesets.end())
117 "A nodeset cannot be both the new nodeset and be excluded in the list of excluded " 126 excluded_nodesets[i],
127 "' was not found within the mesh");
136 "'included_nodesets' and 'excluded_nodesets' lists should not overlap");
144 const auto subdomains = getParam<std::vector<SubdomainName>>(
"included_subdomains");
145 for (
const auto &
name : subdomains)
147 paramError(
"included_subdomains",
"The block '",
name,
"' was not found in the mesh");
155 const auto subdomains = getParam<std::vector<SubdomainName>>(
"excluded_subdomains");
156 for (
const auto &
name : subdomains)
158 paramError(
"excluded_subdomains",
"The block '",
name,
"' was not found in the mesh");
170 "'included_subdomains' and 'excluded_subdomains' lists should not overlap");
176 for (
const auto & elem :
mesh.active_element_ptr_range())
177 for (
unsigned int n = 0; n < elem->n_nodes(); n++)
183 const std::vector<dof_id_type> & node_elems,
184 const MeshBase & mesh)
const 187 for (
const auto elem_id : node_elems)
189 const auto elem =
mesh.elem_ptr(elem_id);
190 for (
const auto side_i :
make_range(elem->n_sides()))
196 if (!elem->neighbor_ptr(side_i))
206 const MeshBase & mesh)
const 208 for (
const auto elem_id : node_elems)
221 const MeshBase & mesh)
const 223 for (
const auto elem_id : node_elems)
237 for (
const auto bid : node_nodesets)
247 for (
const auto bid : node_nodesets)
256 const std::vector<BoundaryID> & node_nodesets,
257 const std::vector<dof_id_type> & node_elems,
258 const MeshBase & mesh)
const const bool _check_excluded_nodesets
whether to check nodeset ids against the excluded nodeset list when adding nodes or not ...
const bool _check_excluded_subdomains
whether to check subdomain ids of the element that excluded this node
const bool _check_included_subdomains
whether to check subdomain ids of the element that included this node
const unsigned int invalid_uint
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 ...
std::vector< subdomain_id_type > _excluded_subdomain_ids
A list of included subdomain ids that the node must not be part of, extracted from the excluded_subdo...
const BoundaryID INVALID_BOUNDARY_ID
bool nodeSatisfiesRequirements(const Node *node, const std::vector< BoundaryID > &node_nodesets, const std::vector< dof_id_type > &node_elems, const MeshBase &mesh) const
Determines whether the given node satisfies the user-specified constraints.
const bool _check_included_nodesets
whether to check nodeset ids against the included nodeset list when adding nodes or not ...
bool nodeInExcludedNodesets(const std::vector< BoundaryID > &node_nodesets) const
Determines whether the given node of an element belongs to any nodesets in the excluded_nodesets para...
std::vector< subdomain_id_type > getSubdomainIDs(const libMesh::MeshBase &mesh, const std::vector< SubdomainName > &subdomain_name)
Get the associated subdomainIDs for the subdomain names that are passed in.
std::vector< BoundaryName > _nodeset_names
The list of new nodeset names.
const std::string & name() const
Get the name of the class.
bool nodeInIncludedNodesets(const std::vector< BoundaryID > &node_nodesets) const
Determines whether the given node belongs to any nodesets in the included_nodesets parameter...
bool nodeOnMeshExteriorBoundary(const Node *node, const std::vector< dof_id_type > &node_elems, const MeshBase &mesh) const
Determines whether the node is on the exterior of the mesh.
std::vector< BoundaryID > getBoundaryIDs(const libMesh::MeshBase &mesh, const std::vector< BoundaryName > &boundary_name, bool generate_unknown, const std::set< BoundaryID > &mesh_boundary_ids)
Gets the boundary IDs with their names.
static InputParameters validParams()
bool hasSubdomainName(const MeshBase &input_mesh, const SubdomainName &name)
Whether a particular subdomain name exists in the mesh.
std::vector< boundary_id_type > _excluded_nodeset_ids
A list of nodeset ids that the node must not be a part of, extracted from the excluded_nodesets param...
const bool _include_only_external_nodes
Whether to only include external node when considering nodes to add to the nodeset.
bool nodeElementsInExcludedSubdomains(const std::vector< dof_id_type > node_elems, const MeshBase &mesh) const
Determines whether any neighbor element of the node has a subdomain id in the given excluded_subdomai...
IntRange< T > make_range(T beg, T end)
std::unordered_map< dof_id_type, std::vector< dof_id_type > > _node_to_elem_map
A map from nodes (ids) to local elements (ids) which comprise the node.
void setup(MeshBase &mesh)
This method prepares a few attributes which are commonly needed for nodeset generation such as a map ...
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
NodeSetsGeneratorBase(const InputParameters ¶meters)
static InputParameters validParams()
MeshGenerators are objects that can modify or add to an existing mesh.
auto index_range(const T &sizable)
std::vector< boundary_id_type > _included_nodeset_ids
A list of nodeset ids that the node has to be part of, extracted from the included_nodesets parameter...
bool nodeElementsInIncludedSubdomains(const std::vector< dof_id_type > node_elems, const MeshBase &mesh) const
Determines whether any neighbor element of the node has a subdomain id in the given included_subdomai...
std::vector< subdomain_id_type > _included_subdomain_ids
A list of included subdomain ids that the node has to be part of, extracted from the included_subdoma...