LCOV - code coverage report
Current view: top level - src/meshgenerators - BlockDeletionGenerator.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 23 29 79.3 %
Date: 2025-07-17 01:28:37 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          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             : 
      13             : #include "libmesh/elem.h"
      14             : 
      15             : registerMooseObject("MooseApp", BlockDeletionGenerator);
      16             : 
      17             : InputParameters
      18       14741 : BlockDeletionGenerator::validParams()
      19             : {
      20       14741 :   InputParameters params = ElementDeletionGeneratorBase::validParams();
      21             : 
      22       14741 :   params.addClassDescription("Mesh generator which removes elements from the specified subdomains");
      23       14741 :   params.addParam<std::vector<SubdomainName>>("block", "The list of blocks to be deleted");
      24       14741 :   params.addDeprecatedParam<SubdomainID>(
      25             :       "block_id", "The block to be deleted.", "Use block instead");
      26             : 
      27       14741 :   return params;
      28           0 : }
      29             : 
      30         236 : BlockDeletionGenerator::BlockDeletionGenerator(const InputParameters & parameters)
      31         236 :   : ElementDeletionGeneratorBase(parameters)
      32             : {
      33             :   // Handle deprecated parameter
      34         236 :   if (isParamValid("block_id"))
      35           0 :     _block_ids.push_back(getParam<SubdomainID>("block_id"));
      36         236 :   if (!isParamValid("block_id") && !isParamValid("block"))
      37           0 :     mooseError("Must provide the blocks to be deleted in the 'block' parameter");
      38         236 :   if (isParamValid("block_id") && isParamValid("block"))
      39           0 :     paramError("block_id", "Cannot use with the parameter 'block'. Please use just 'block'.");
      40         236 : }
      41             : 
      42             : std::unique_ptr<MeshBase>
      43         223 : BlockDeletionGenerator::generate()
      44             : {
      45         223 :   if (isParamValid("block"))
      46             :     // Get the list of block ids from the block names
      47             :     _block_ids =
      48         223 :         MooseMeshUtils::getSubdomainIDs(*_input, getParam<std::vector<SubdomainName>>("block"));
      49             : 
      50             :   // Check that the block ids/names exist in the mesh
      51         462 :   for (std::size_t i = 0; i < _block_ids.size(); ++i)
      52         243 :     if (!MooseMeshUtils::hasSubdomainID(*_input, _block_ids[i]))
      53             :     {
      54           4 :       if (isParamValid("block"))
      55           4 :         paramError("block",
      56             :                    "The block '",
      57           4 :                    getParam<std::vector<SubdomainName>>("block")[i],
      58             :                    "' was not found within the mesh");
      59             :       else
      60           0 :         paramError("block_id",
      61             :                    "The block '",
      62           0 :                    getParam<SubdomainID>("block_id"),
      63             :                    "' was not found within the mesh");
      64             :     }
      65             : 
      66         219 :   return ElementDeletionGeneratorBase::generate();
      67             : }
      68             : 
      69             : bool
      70      164129 : BlockDeletionGenerator::shouldDelete(const Elem * elem)
      71             : {
      72      164129 :   return std::find(_block_ids.begin(), _block_ids.end(), elem->subdomain_id()) != _block_ids.end();
      73             : }

Generated by: LCOV version 1.14