LCOV - code coverage report
Current view: top level - src/meshgenerators - ExtraElementIDCopyGenerator.C (source / functions) Hit Total Coverage
Test: idaholab/moose reactor: #31405 (292dce) with base fef103 Lines: 35 36 97.2 %
Date: 2025-09-04 07:56:24 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 "ExtraElementIDCopyGenerator.h"
      11             : 
      12             : #include "libmesh/elem.h"
      13             : 
      14             : registerMooseObject("ReactorApp", ExtraElementIDCopyGenerator);
      15             : 
      16             : InputParameters
      17          66 : ExtraElementIDCopyGenerator::validParams()
      18             : {
      19          66 :   InputParameters params = MeshGenerator::validParams();
      20         132 :   params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
      21         132 :   params.addRequiredParam<std::string>("source_extra_element_id",
      22             :                                        "The extra element ID to be copied");
      23         132 :   params.addRequiredParam<std::vector<std::string>>("target_extra_element_ids",
      24             :                                                     "The target extra element IDs");
      25          66 :   params.addClassDescription("Copy an extra element ID to other extra element IDs.");
      26          66 :   return params;
      27           0 : }
      28             : 
      29          33 : ExtraElementIDCopyGenerator::ExtraElementIDCopyGenerator(const InputParameters & params)
      30          33 :   : MeshGenerator(params), _input(getMesh("input"))
      31             : {
      32          33 : }
      33             : 
      34             : std::unique_ptr<MeshBase>
      35          29 : ExtraElementIDCopyGenerator::generate()
      36             : {
      37          29 :   std::unique_ptr<MeshBase> mesh = std::move(_input);
      38             : 
      39          58 :   auto src_id_name = getParam<std::string>("source_extra_element_id");
      40          29 :   bool copy_subdomain_id = (src_id_name == "subdomain_id");
      41          29 :   bool copy_element_id = (src_id_name == "element_id");
      42             :   unsigned int src_id = 0;
      43          29 :   if (!copy_subdomain_id && !copy_element_id)
      44             :   {
      45          11 :     if (!mesh->has_elem_integer(src_id_name))
      46           2 :       mooseError("The source element ID does not exist on the input mesh");
      47           9 :     src_id = mesh->get_elem_integer_index(src_id_name);
      48             :   }
      49             : 
      50          81 :   auto target_id_names = getParam<std::vector<std::string>>("target_extra_element_ids");
      51             : 
      52             :   std::vector<unsigned int> target_ids;
      53          63 :   for (auto & name : target_id_names)
      54             :   {
      55          36 :     if (!mesh->has_elem_integer(name))
      56          72 :       mesh->add_elem_integer(name);
      57             : 
      58          36 :     target_ids.push_back(mesh->get_elem_integer_index(name));
      59             :   }
      60             : 
      61        5454 :   for (auto & elem : mesh->element_ptr_range())
      62             :   {
      63             :     dof_id_type id;
      64        2700 :     if (copy_subdomain_id)
      65         900 :       id = elem->subdomain_id();
      66        1800 :     else if (copy_element_id)
      67         900 :       id = elem->id();
      68             :     else
      69         900 :       id = elem->get_extra_integer(src_id);
      70             : 
      71        6300 :     for (auto & target_id : target_ids)
      72        3600 :       elem->set_extra_integer(target_id, id);
      73          27 :   }
      74             : 
      75          27 :   return mesh;
      76          27 : }

Generated by: LCOV version 1.14