LCOV - code coverage report
Current view: top level - src/meshgenerators - BoundaryDeletionGenerator.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 32 32 100.0 %
Date: 2025-08-08 20:01:16 Functions: 3 3 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 "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       14445 : BoundaryDeletionGenerator::validParams()
      21             : {
      22       14445 :   InputParameters params = MeshGenerator::validParams();
      23             : 
      24       14445 :   params.addClassDescription("Mesh generator which removes side sets");
      25       14445 :   params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
      26       14445 :   params.addRequiredParam<std::vector<BoundaryName>>("boundary_names",
      27             :                                                      "The boundaries to be deleted / kept");
      28       14445 :   MooseEnum opt("keep remove", "remove");
      29       14445 :   params.addParam<MooseEnum>("operation", opt, "Whether to remove or keep the listed boundaries");
      30             : 
      31       28890 :   return params;
      32       14445 : }
      33             : 
      34          90 : BoundaryDeletionGenerator::BoundaryDeletionGenerator(const InputParameters & parameters)
      35             :   : MeshGenerator(parameters),
      36          90 :     _input(getMesh("input")),
      37         180 :     _boundary_names(getParam<std::vector<BoundaryName>>("boundary_names"))
      38             : {
      39          90 : }
      40             : 
      41             : std::unique_ptr<MeshBase>
      42          89 : BoundaryDeletionGenerator::generate()
      43             : {
      44          89 :   std::unique_ptr<MeshBase> mesh = std::move(_input);
      45             : 
      46             :   // Gather the boundary ids of interest from the names
      47          89 :   std::set<boundary_id_type> ids;
      48         280 :   for (const auto & name : _boundary_names)
      49             :   {
      50         195 :     auto bid = MooseMeshUtils::getBoundaryID(name, *mesh);
      51         195 :     if (bid == BoundaryInfo::invalid_id)
      52           4 :       paramError("boundary_names", "The boundary '", name, "' was not found in the mesh");
      53             : 
      54         191 :     ids.insert(bid);
      55             :   }
      56             : 
      57          85 :   std::set<boundary_id_type> ids_to_remove;
      58          85 :   if (getParam<MooseEnum>("operation") == "keep")
      59             :   {
      60          11 :     ids_to_remove = mesh->get_boundary_info().get_boundary_ids();
      61          33 :     for (const auto & id : ids)
      62          22 :       ids_to_remove.erase(id);
      63             :   }
      64             :   else
      65          74 :     ids_to_remove = ids;
      66             : 
      67         276 :   for (const auto & id : ids_to_remove)
      68         191 :     mesh->get_boundary_info().remove_id(id);
      69             : 
      70          85 :   mesh->set_isnt_prepared();
      71         170 :   return dynamic_pointer_cast<MeshBase>(mesh);
      72          85 : }

Generated by: LCOV version 1.14