https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
41std::unique_ptr<MeshBase>
43{
44 std::unique_ptr<MeshBase> mesh = std::move(_input);
45
46 // We need prepared boundary id sets here
47 if (!mesh->preparation().has_boundary_id_sets)
48 mesh->get_boundary_info().regenerate_id_sets();
49
50 // Gather the boundary ids of interest from the names
51 std::set<boundary_id_type> ids;
52 for (const auto & name : _boundary_names)
53 {
55 if (bid == BoundaryInfo::invalid_id)
56 paramError("boundary_names", "The boundary '", name, "' was not found in the mesh");
57
58 ids.insert(bid);
59 }
60
61 std::set<boundary_id_type> ids_to_remove;
62 if (getParam<MooseEnum>("operation") == "keep")
63 {
64 ids_to_remove = mesh->get_boundary_info().get_boundary_ids();
65 for (const auto & id : ids)
66 ids_to_remove.erase(id);
67 }
68 else
69 ids_to_remove = ids;
70
71 for (const auto & id : ids_to_remove)
72 mesh->get_boundary_info().remove_id(id);
73
74 mesh->unset_is_prepared();
75 return dynamic_pointer_cast<MeshBase>(mesh);
76}
registerMooseObject("MooseApp", BoundaryDeletionGenerator)
std::string opt
virtual std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
static InputParameters validParams()
BoundaryDeletionGenerator(const InputParameters &parameters)
const std::vector< BoundaryName > _boundary_names
The boundaries to be removed.
std::unique_ptr< MeshBase > & _input
The input mesh.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
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...
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.
MeshGenerators are objects that can modify or add to an existing mesh.
static InputParameters validParams()
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
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:457
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
MeshBase & mesh
BoundaryID getBoundaryID(const BoundaryName &boundary_name, const MeshBase &mesh)
Gets the boundary ID associated with the given BoundaryName.