https://mooseframework.inl.gov
BoundaryDeletionGenerator.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 "MooseMeshUtils.h"
13 #include "CastUniquePointer.h"
14 
15 #include "libmesh/boundary_info.h"
16 
18 
21 {
23 
24  params.addClassDescription("Mesh generator which removes side sets");
25  params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
26  params.addRequiredParam<std::vector<BoundaryName>>("boundary_names",
27  "The boundaries to be deleted / kept");
28  MooseEnum opt("keep remove", "remove");
29  params.addParam<MooseEnum>("operation", opt, "Whether to remove or keep the listed boundaries");
30 
31  return params;
32 }
33 
35  : MeshGenerator(parameters),
36  _input(getMesh("input")),
37  _boundary_names(getParam<std::vector<BoundaryName>>("boundary_names"))
38 {
39 }
40 
41 std::unique_ptr<MeshBase>
43 {
44  std::unique_ptr<MeshBase> mesh = std::move(_input);
45 
46  // Gather the boundary ids of interest from the names
47  std::set<boundary_id_type> ids;
48  for (const auto & name : _boundary_names)
49  {
51  if (bid == BoundaryInfo::invalid_id)
52  paramError("boundary_names", "The boundary '", name, "' was not found in the mesh");
53 
54  ids.insert(bid);
55  }
56 
57  std::set<boundary_id_type> ids_to_remove;
58  if (getParam<MooseEnum>("operation") == "keep")
59  {
60  ids_to_remove = mesh->get_boundary_info().get_boundary_ids();
61  for (const auto & id : ids)
62  ids_to_remove.erase(id);
63  }
64  else
65  ids_to_remove = ids;
66 
67  for (const auto & id : ids_to_remove)
68  mesh->get_boundary_info().remove_id(id);
69 
70  mesh->set_isnt_prepared();
71  return dynamic_pointer_cast<MeshBase>(mesh);
72 }
static InputParameters validParams()
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:435
registerMooseObject("MooseApp", BoundaryDeletionGenerator)
std::string opt
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
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.
virtual std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
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...
BoundaryID getBoundaryID(const BoundaryName &boundary_name, const MeshBase &mesh)
Gets the boundary ID associated with the given BoundaryName.
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:99
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
static InputParameters validParams()
Definition: MeshGenerator.C:23
const std::vector< BoundaryName > _boundary_names
The boundaries to be removed.
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...
std::unique_ptr< MeshBase > & _input
The input mesh.
BoundaryDeletionGenerator(const InputParameters &parameters)
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:32