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 14437 : BoundaryDeletionGenerator::validParams() 21 : { 22 14437 : InputParameters params = MeshGenerator::validParams(); 23 : 24 14437 : params.addClassDescription("Mesh generator which removes side sets"); 25 14437 : params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify"); 26 14437 : params.addRequiredParam<std::vector<BoundaryName>>("boundary_names", 27 : "The boundaries to be deleted / kept"); 28 14437 : MooseEnum opt("keep remove", "remove"); 29 14437 : params.addParam<MooseEnum>("operation", opt, "Whether to remove or keep the listed boundaries"); 30 : 31 28874 : return params; 32 14437 : } 33 : 34 86 : BoundaryDeletionGenerator::BoundaryDeletionGenerator(const InputParameters & parameters) 35 : : MeshGenerator(parameters), 36 86 : _input(getMesh("input")), 37 172 : _boundary_names(getParam<std::vector<BoundaryName>>("boundary_names")) 38 : { 39 86 : } 40 : 41 : std::unique_ptr<MeshBase> 42 85 : BoundaryDeletionGenerator::generate() 43 : { 44 85 : std::unique_ptr<MeshBase> mesh = std::move(_input); 45 : 46 : // Gather the boundary ids of interest from the names 47 85 : std::set<boundary_id_type> ids; 48 265 : for (const auto & name : _boundary_names) 49 : { 50 184 : auto bid = MooseMeshUtils::getBoundaryID(name, *mesh); 51 184 : if (bid == BoundaryInfo::invalid_id) 52 4 : paramError("boundary_names", "The boundary '", name, "' was not found in the mesh"); 53 : 54 180 : ids.insert(bid); 55 : } 56 : 57 81 : std::set<boundary_id_type> ids_to_remove; 58 81 : if (getParam<MooseEnum>("operation") == "keep") 59 : { 60 10 : ids_to_remove = mesh->get_boundary_info().get_boundary_ids(); 61 30 : for (const auto & id : ids) 62 20 : ids_to_remove.erase(id); 63 : } 64 : else 65 71 : ids_to_remove = ids; 66 : 67 261 : for (const auto & id : ids_to_remove) 68 180 : mesh->get_boundary_info().remove_id(id); 69 : 70 81 : mesh->set_isnt_prepared(); 71 162 : return dynamic_pointer_cast<MeshBase>(mesh); 72 81 : }