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 "BlockDeletionGenerator.h" 11 : #include "MooseMeshUtils.h" 12 : #include "MooseEnum.h" 13 : 14 : #include "libmesh/elem.h" 15 : 16 : registerMooseObject("MooseApp", BlockDeletionGenerator); 17 : 18 : InputParameters 19 3598 : BlockDeletionGenerator::validParams() 20 : { 21 3598 : InputParameters params = ElementDeletionGeneratorBase::validParams(); 22 : 23 14392 : MooseEnum operation("remove keep", "remove"); 24 14392 : params.addParam<MooseEnum>("operation", 25 : operation, 26 : "Whether to remove or keep the listed blocks. If keep, all blocks not " 27 : "in the list will be removed."); 28 : 29 7196 : params.addClassDescription("Mesh generator which removes elements from the specified subdomains"); 30 14392 : params.addParam<std::vector<SubdomainName>>( 31 : "block", "The list of blocks to be processed (deleted or kept)"); 32 17990 : params.addDeprecatedParam<SubdomainID>( 33 : "block_id", "The block to be deleted.", "Use block instead"); 34 : 35 7196 : return params; 36 3598 : } 37 : 38 267 : BlockDeletionGenerator::BlockDeletionGenerator(const InputParameters & parameters) 39 801 : : ElementDeletionGeneratorBase(parameters), _operation(getParam<MooseEnum>("operation")) 40 : { 41 : // Handle deprecated parameter 42 801 : if (isParamValid("block_id")) 43 0 : _block_ids.push_back(getParam<SubdomainID>("block_id")); 44 1335 : if (!isParamValid("block_id") && !isParamValid("block")) 45 0 : mooseError("Must provide the blocks to be processed in the 'block' parameter"); 46 801 : if (isParamValid("block_id") && isParamValid("block")) 47 0 : paramError("block_id", "Cannot use with the parameter 'block'. Please use just 'block'."); 48 267 : } 49 : 50 : std::unique_ptr<MeshBase> 51 251 : BlockDeletionGenerator::generate() 52 : { 53 : // We're querying subdomain id caches from our input mesh 54 251 : if (!_input->preparation().has_cached_elem_data) 55 209 : _input->cache_elem_data(); 56 : 57 753 : if (isParamValid("block")) 58 : // Get the list of block ids from the block names 59 : _block_ids = 60 753 : MooseMeshUtils::getSubdomainIDs(*_input, getParam<std::vector<SubdomainName>>("block")); 61 : 62 : // Check that the block ids/names exist in the mesh 63 529 : for (std::size_t i = 0; i < _block_ids.size(); ++i) 64 281 : if (!MooseMeshUtils::hasSubdomainID(*_input, _block_ids[i])) 65 : { 66 9 : if (isParamValid("block")) 67 6 : paramError("block", 68 : "The block '", 69 6 : getParam<std::vector<SubdomainName>>("block")[i], 70 : "' was not found within the mesh"); 71 : else 72 0 : paramError("block_id", 73 : "The block '", 74 0 : getParam<SubdomainID>("block_id"), 75 : "' was not found within the mesh"); 76 : } 77 : 78 248 : return ElementDeletionGeneratorBase::generate(); 79 : } 80 : 81 : bool 82 172681 : BlockDeletionGenerator::shouldDelete(const Elem * elem) 83 : { 84 : bool in_list = 85 172681 : std::find(_block_ids.begin(), _block_ids.end(), elem->subdomain_id()) != _block_ids.end(); 86 : 87 172681 : if ((int)_operation == 0) 88 172529 : return in_list; 89 : else 90 152 : return !in_list; 91 : }