13 #include "libmesh/boundary_info.h" 14 #include "libmesh/elem_side_builder.h" 25 "Input mesh the operation will be applied to");
26 params.
addParam<std::vector<BoundaryName>>(
27 "nodesets_to_convert",
28 "If specified, list of nodesets to convert. If not specified, all nodesets are converted");
37 std::unique_ptr<MeshBase>
41 _input->get_boundary_info().build_side_list_from_node_list();
44 const auto & nodeset_names = getParam<std::vector<BoundaryName>>(
"nodesets_to_convert");
45 auto & binfo =
_input->get_boundary_info();
47 std::map<BoundaryName, BoundaryID> new_nodeset_ids;
48 std::set<BoundaryID> nodeset_ids;
50 for (
const auto & nodeset_name : nodeset_names)
54 for (
const auto & [
id,
name] : binfo.get_nodeset_name_map())
55 if (
name == nodeset_name)
58 nodeset_id = std::stoi(nodeset_name);
61 "Nodeset '" + nodeset_name +
"' does not exist in the input mesh");
62 nodeset_ids.insert(nodeset_id);
66 new_nodeset_ids[nodeset_name] = nodeset_id;
67 else if (binfo.get_sideset_name(nodeset_id) == nodeset_name)
68 new_nodeset_ids[nodeset_name] = binfo.get_id_by_name(nodeset_name);
70 new_nodeset_ids[nodeset_name] = nodeset_id;
77 const Elem * side_elem;
78 const auto & boundary_node_ids = binfo.get_nodeset_map();
80 for (
const auto & elem :
_input->active_element_ptr_range())
81 for (
auto side : elem->side_index_range())
83 side_elem = &side_builder(*elem, side);
86 std::map<boundary_id_type, unsigned> nodesets_node_count;
90 for (
const auto & node : side_elem->node_ref_range())
91 for (
const auto & pr :
as_range(boundary_node_ids.equal_range(&node)))
93 if (nodeset_ids.count(pr.second))
94 nodesets_node_count[pr.second]++;
100 for (
const auto & pr : nodesets_node_count)
101 if (pr.second == side_elem->n_nodes())
102 binfo.add_side(elem, side, pr.first);
105 for (
const auto & [nodeset_name, new_nodeset_id] : new_nodeset_ids)
106 binfo.sideset_name(new_nodeset_id) = nodeset_name;
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 ...
MeshGenerator for constructing side Sets from node sets.
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
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.
auto max(const L &left, const R &right)
const std::string & name() const
Get the name of the class.
boundary_id_type BoundaryID
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
static InputParameters validParams()
registerMooseObject("MooseApp", SideSetsFromNodeSetsGenerator)
std::unique_ptr< MeshBase > & _input
Input mesh the operation will be applied to.
static InputParameters validParams()
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
SideSetsFromNodeSetsGenerator(const InputParameters ¶meters)
bool isDigits(const std::string &str)
Courtesy https://stackoverflow.com/a/8889045 and https://en.cppreference.com/w/cpp/string/byte/isdigi...
MeshGenerators are objects that can modify or add to an existing mesh.
for(PetscInt i=0;i< nvars;++i)