LCOV - code coverage report
Current view: top level - src/meshgenerators - SideSetsFromNodeSetsGenerator.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #31730 (e8b711) with base e0c998 Lines: 26 30 86.7 %
Date: 2025-10-29 16:49:47 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 "SideSetsFromNodeSetsGenerator.h"
      11             : 
      12             : #include "CastUniquePointer.h"
      13             : #include "libmesh/boundary_info.h"
      14             : #include "libmesh/elem_side_builder.h"
      15             : 
      16             : registerMooseObject("MooseApp", SideSetsFromNodeSetsGenerator);
      17             : 
      18             : InputParameters
      19       14911 : SideSetsFromNodeSetsGenerator::validParams()
      20             : {
      21       14911 :   InputParameters params = MeshGenerator::validParams();
      22             : 
      23       29822 :   params.addClassDescription("Mesh generator which constructs side sets from node sets");
      24       59644 :   params.addRequiredParam<MeshGeneratorName>("input",
      25             :                                              "Input mesh the operation will be applied to");
      26       44733 :   params.addParam<std::vector<BoundaryName>>(
      27             :       "nodesets_to_convert",
      28             :       "If specified, list of nodesets to convert. If not specified, all nodesets are converted");
      29       14911 :   return params;
      30           0 : }
      31             : 
      32          22 : SideSetsFromNodeSetsGenerator::SideSetsFromNodeSetsGenerator(const InputParameters & parameters)
      33          44 :   : MeshGenerator(parameters), _input(getMesh("input"))
      34             : {
      35          22 : }
      36             : 
      37             : std::unique_ptr<MeshBase>
      38          22 : SideSetsFromNodeSetsGenerator::generate()
      39             : {
      40          66 :   if (!isParamValid("nodesets_to_convert"))
      41          11 :     _input->get_boundary_info().build_side_list_from_node_list();
      42             :   else
      43             :   {
      44          22 :     const auto & nodeset_names = getParam<std::vector<BoundaryName>>("nodesets_to_convert");
      45          11 :     auto & binfo = _input->get_boundary_info();
      46             : 
      47          11 :     std::set<BoundaryID> nodeset_ids;
      48          22 :     for (const auto & nodeset_name : nodeset_names)
      49             :     {
      50             :       // Look through the nodeset map.
      51          11 :       BoundaryID nodeset_id = std::numeric_limits<BoundaryID>::max();
      52          77 :       for (const auto & [id, name] : binfo.get_nodeset_name_map())
      53          66 :         if (name == nodeset_name)
      54          11 :           nodeset_id = id;
      55          11 :       if (MooseUtils::isDigits(nodeset_name))
      56           0 :         nodeset_id = std::stoi(nodeset_name);
      57          11 :       if (nodeset_id == std::numeric_limits<BoundaryID>::max())
      58           0 :         paramError("nodesets_to_convert",
      59           0 :                    "Nodeset '" + nodeset_name + "' does not exist in the input mesh");
      60          11 :       nodeset_ids.insert(nodeset_id);
      61             :     }
      62          11 :     _input->get_boundary_info().build_side_list_from_node_list(nodeset_ids);
      63          11 :   }
      64             : 
      65          22 :   return dynamic_pointer_cast<MeshBase>(_input);
      66             : }

Generated by: LCOV version 1.14