LCOV - code coverage report
Current view: top level - src/meshgenerators - BoundaryLayerSubdomainGenerator.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 36 43 83.7 %
Date: 2025-07-17 01:28:37 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 "BoundaryLayerSubdomainGenerator.h"
      11             : #include "CastUniquePointer.h"
      12             : #include "MooseMeshUtils.h"
      13             : 
      14             : #include "libmesh/elem.h"
      15             : 
      16             : registerMooseObject("MooseApp", BoundaryLayerSubdomainGenerator);
      17             : 
      18             : InputParameters
      19       14305 : BoundaryLayerSubdomainGenerator::validParams()
      20             : {
      21       14305 :   InputParameters params = MeshGenerator::validParams();
      22             : 
      23       14305 :   params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
      24       14305 :   params.addClassDescription(
      25             :       "Changes the subdomain ID of elements near the specified boundary(ies).");
      26             : 
      27       14305 :   params.addRequiredParam<SubdomainName>(
      28             :       "block_name", "Subdomain name to set for inside/outside the bounding box (optional)");
      29       14305 :   params.addParam<subdomain_id_type>("block_id",
      30             :                                      "Subdomain id to set for inside/outside the bounding box");
      31             : 
      32       42915 :   params.addParam<bool>("include_nodesets",
      33       28610 :                         false,
      34             :                         "Whether to include nodesets in the boundaries. Nodesets are not sided so "
      35             :                         "elements on both sides of the nodesets will be included");
      36       14305 :   params.addRequiredParam<std::vector<BoundaryName>>("boundaries",
      37             :                                                      "Boundaries to add the layer next to");
      38       14305 :   return params;
      39           0 : }
      40             : 
      41          20 : BoundaryLayerSubdomainGenerator::BoundaryLayerSubdomainGenerator(const InputParameters & parameters)
      42             :   : MeshGenerator(parameters),
      43          20 :     _input(getMesh("input")),
      44          20 :     _new_block_name(getParam<SubdomainName>("block_name")),
      45          40 :     _include_nodesets(getParam<bool>("include_nodesets"))
      46             : {
      47          20 : }
      48             : 
      49             : std::unique_ptr<MeshBase>
      50          20 : BoundaryLayerSubdomainGenerator::generate()
      51             : {
      52          20 :   std::unique_ptr<MeshBase> mesh = std::move(_input);
      53             : 
      54             :   // Get the next free block id
      55          20 :   _new_block_id = MooseMeshUtils::getNextFreeSubdomainID(*mesh);
      56             : 
      57             :   // Get the ids for the boundaries
      58             :   const auto boundary_ids = MooseMeshUtils::getBoundaryIDs(
      59          20 :       *mesh, getParam<std::vector<BoundaryName>>("boundaries"), false);
      60             : 
      61             :   // Boundary info
      62          20 :   const auto & boundary_info = mesh->get_boundary_info();
      63             : 
      64             :   // Loop over the elements
      65         502 :   for (const auto & elem : mesh->element_ptr_range())
      66             :   {
      67             :     // Check all the sides for a boundary in the concerned list
      68         241 :     bool next_to_a_boundary = false;
      69        1031 :     for (const auto side : elem->side_index_range())
      70        1975 :       for (const auto bid : boundary_ids)
      71        1185 :         if (boundary_info.has_boundary_id(elem, side, bid))
      72             :         {
      73          88 :           next_to_a_boundary = true;
      74          88 :           goto out_loop_1;
      75             :         }
      76         241 :   out_loop_1:;
      77             : 
      78             :     // Check all the nodes in case the boundary is a nodeset
      79         241 :     if (!next_to_a_boundary && _include_nodesets)
      80             :     {
      81           0 :       for (const auto node_index : elem->node_index_range())
      82           0 :         for (const auto bid : boundary_ids)
      83           0 :           if (boundary_info.has_boundary_id(elem->node_ptr(node_index), bid))
      84             :           {
      85           0 :             next_to_a_boundary = true;
      86           0 :             goto out_loop_2;
      87             :           }
      88           0 :     out_loop_2:;
      89             :     }
      90             : 
      91         241 :     if (next_to_a_boundary)
      92          88 :       elem->subdomain_id() = _new_block_id;
      93          20 :   }
      94             : 
      95             :   // Assign block name
      96          20 :   mesh->subdomain_name(_new_block_id) = _new_block_name;
      97             : 
      98          20 :   mesh->set_isnt_prepared();
      99          40 :   return dynamic_pointer_cast<MeshBase>(mesh);
     100          20 : }

Generated by: LCOV version 1.14