Line data Source code
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 : 10 : #include "BoundaryDeletionGenerator.h" 11 : 12 : #include "MooseMeshUtils.h" 13 : #include "CastUniquePointer.h" 14 : 15 : #include "libmesh/boundary_info.h" 16 : 17 : registerMooseObject("MooseApp", BoundaryDeletionGenerator); 18 : 19 : InputParameters 20 3219 : BoundaryDeletionGenerator::validParams() 21 : { 22 3219 : InputParameters params = MeshGenerator::validParams(); 23 : 24 6438 : params.addClassDescription("Mesh generator which removes side sets"); 25 12876 : params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify"); 26 12876 : params.addRequiredParam<std::vector<BoundaryName>>("boundary_names", 27 : "The boundaries to be deleted / kept"); 28 12876 : MooseEnum opt("keep remove", "remove"); 29 9657 : params.addParam<MooseEnum>("operation", opt, "Whether to remove or keep the listed boundaries"); 30 : 31 6438 : return params; 32 3219 : } 33 : 34 79 : BoundaryDeletionGenerator::BoundaryDeletionGenerator(const InputParameters & parameters) 35 : : MeshGenerator(parameters), 36 79 : _input(getMesh("input")), 37 237 : _boundary_names(getParam<std::vector<BoundaryName>>("boundary_names")) 38 : { 39 79 : } 40 : 41 : std::unique_ptr<MeshBase> 42 78 : BoundaryDeletionGenerator::generate() 43 : { 44 78 : std::unique_ptr<MeshBase> mesh = std::move(_input); 45 : 46 : // We need prepared boundary id sets here 47 78 : if (!mesh->preparation().has_boundary_id_sets) 48 78 : mesh->get_boundary_info().regenerate_id_sets(); 49 : 50 : // Gather the boundary ids of interest from the names 51 78 : std::set<boundary_id_type> ids; 52 246 : for (const auto & name : _boundary_names) 53 : { 54 171 : auto bid = MooseMeshUtils::getBoundaryID(name, *mesh); 55 171 : if (bid == BoundaryInfo::invalid_id) 56 6 : paramError("boundary_names", "The boundary '", name, "' was not found in the mesh"); 57 : 58 168 : ids.insert(bid); 59 : } 60 : 61 75 : std::set<boundary_id_type> ids_to_remove; 62 225 : if (getParam<MooseEnum>("operation") == "keep") 63 : { 64 10 : ids_to_remove = mesh->get_boundary_info().get_boundary_ids(); 65 30 : for (const auto & id : ids) 66 20 : ids_to_remove.erase(id); 67 : } 68 : else 69 65 : ids_to_remove = ids; 70 : 71 243 : for (const auto & id : ids_to_remove) 72 168 : mesh->get_boundary_info().remove_id(id); 73 : 74 75 : mesh->unset_is_prepared(); 75 150 : return dynamic_pointer_cast<MeshBase>(mesh); 76 75 : }