https://mooseframework.inl.gov
SideSetsFromNodeSetsGenerator.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
11 
12 #include "CastUniquePointer.h"
13 #include "libmesh/boundary_info.h"
14 #include "libmesh/elem_side_builder.h"
15 
17 
20 {
22 
23  params.addClassDescription("Mesh generator which constructs side sets from node sets");
24  params.addRequiredParam<MeshGeneratorName>("input",
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");
29  return params;
30 }
31 
33  : MeshGenerator(parameters), _input(getMesh("input"))
34 {
35 }
36 
37 std::unique_ptr<MeshBase>
39 {
40  if (!isParamValid("nodesets_to_convert"))
41  _input->get_boundary_info().build_side_list_from_node_list();
42  else
43  {
44  const auto & nodeset_names = getParam<std::vector<BoundaryName>>("nodesets_to_convert");
45  auto & binfo = _input->get_boundary_info();
46 
47  std::set<BoundaryID> nodeset_ids;
48  for (const auto & nodeset_name : nodeset_names)
49  {
50  // Look through the nodeset map.
52  for (const auto & [id, name] : binfo.get_nodeset_name_map())
53  if (name == nodeset_name)
54  nodeset_id = id;
55  if (MooseUtils::isDigits(nodeset_name))
56  nodeset_id = std::stoi(nodeset_name);
57  if (nodeset_id == std::numeric_limits<BoundaryID>::max())
58  paramError("nodesets_to_convert",
59  "Nodeset '" + nodeset_name + "' does not exist in the input mesh");
60  nodeset_ids.insert(nodeset_id);
61  }
62  _input->get_boundary_info().build_side_list_from_node_list(nodeset_ids);
63  }
64 
65  return dynamic_pointer_cast<MeshBase>(_input);
66 }
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:439
MeshGenerator for constructing side Sets from node sets.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
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.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
auto max(const L &left, const R &right)
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
boundary_id_type BoundaryID
static InputParameters validParams()
Definition: MeshGenerator.C:23
registerMooseObject("MooseApp", SideSetsFromNodeSetsGenerator)
std::unique_ptr< MeshBase > & _input
Input mesh the operation will be applied to.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseBase.h:199
SideSetsFromNodeSetsGenerator(const InputParameters &parameters)
bool isDigits(const std::string &str)
Courtesy https://stackoverflow.com/a/8889045 and https://en.cppreference.com/w/cpp/string/byte/isdigi...
Definition: MooseUtils.h:1188
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:33