LCOV - code coverage report
Current view: top level - src/meshgenerators - DepletionIDGenerator.C (source / functions) Hit Total Coverage
Test: idaholab/moose reactor: #32971 (54bef8) with base c6cf66 Lines: 52 54 96.3 %
Date: 2026-05-29 20:39: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 "DepletionIDGenerator.h"
      11             : #include "MooseMeshUtils.h"
      12             : #include "libmesh/elem.h"
      13             : 
      14             : registerMooseObject("ReactorApp", DepletionIDGenerator);
      15             : 
      16             : InputParameters
      17          70 : DepletionIDGenerator::validParams()
      18             : {
      19          70 :   InputParameters params = MeshGenerator::validParams();
      20         140 :   params.addRequiredParam<MeshGeneratorName>(
      21             :       "input", "Name of an existing mesh generator to which we assign element IDs");
      22         140 :   params.addParam<std::vector<ExtraElementIDName>>("id_name", "Extra integer id names");
      23         140 :   params.addParam<ExtraElementIDName>("material_id_name", "material_id", "Material id name");
      24         140 :   params.addParam<std::vector<dof_id_type>>(
      25             :       "exclude_material_id",
      26             :       "Define a list of material IDs to be excluded in the depletion ID generation");
      27         140 :   params.addParam<std::vector<ExtraElementIDName>>(
      28             :       "exclude_id_name", "Extra ID names that need to be excluded in the depletion ID generation");
      29         140 :   params.addParam<std::vector<std::vector<dof_id_type>>>(
      30             :       "exclude_id_value", "Extra ID values corresponding to names defined in `exclude_id_name`");
      31         140 :   params.addParam<ExtraElementIDName>(
      32             :       "generated_id_name", "depletion_id", "The generated extra element integer name");
      33          70 :   params.addClassDescription(
      34             :       "This DepletionIDGenerator source code is to assign an extra element integer for "
      35             :       "elements on a mesh based on material and other extra element IDs that is typically used for "
      36             :       "depletion.");
      37          70 :   return params;
      38           0 : }
      39          35 : DepletionIDGenerator::DepletionIDGenerator(const InputParameters & params)
      40             :   : MeshGenerator(params),
      41          35 :     _input(getMesh("input")),
      42          70 :     _material_id_name(getParam<ExtraElementIDName>("material_id_name"))
      43             : {
      44          35 : }
      45             : 
      46             : std::unique_ptr<MeshBase>
      47          35 : DepletionIDGenerator::generate()
      48             : {
      49          35 :   std::unique_ptr<MeshBase> mesh = std::move(_input);
      50             :   // parsing the extra ids
      51             :   std::vector<ExtraElementIDName> id_names;
      52         105 :   id_names = getParam<std::vector<ExtraElementIDName>>("id_name");
      53          35 :   if (!mesh->has_elem_integer(_material_id_name))
      54           0 :     paramError("material_id_name",
      55             :                "Material ID name '",
      56             :                _material_id_name,
      57             :                "'is not defined in input mesh!");
      58          35 :   id_names.push_back(_material_id_name);
      59          70 :   auto parsed_ids = MooseMeshUtils::getExtraIDUniqueCombinationMap(*mesh, {}, id_names);
      60             :   // re-numbering if exclude_id_name is used
      61          98 :   if (isParamValid("exclude_id_name") && isParamValid("exclude_id_value"))
      62             :   {
      63          28 :     const auto exclude_id_name = getParam<std::vector<ExtraElementIDName>>("exclude_id_name");
      64             :     const auto & exclude_id_value =
      65          28 :         getParam<std::vector<std::vector<dof_id_type>>>("exclude_id_value");
      66             :     std::vector<unsigned int> id_index;
      67             :     std::vector<std::set<dof_id_type>> id_value_set;
      68          14 :     id_index.resize(exclude_id_name.size());
      69          14 :     id_value_set.resize(exclude_id_name.size());
      70          35 :     for (unsigned int i = 0; i < exclude_id_name.size(); ++i)
      71             :     {
      72          21 :       id_index[i] = mesh->get_elem_integer_index(exclude_id_name[i]);
      73          21 :       std::copy(exclude_id_value[i].begin(),
      74             :                 exclude_id_value[i].end(),
      75             :                 std::inserter(id_value_set[i], id_value_set[i].end()));
      76             :     }
      77             :     // list of unique IDs not removed by "exclude_id_name" and "exclude_id_value" option
      78             :     std::set<dof_id_type> ids;
      79       49884 :     for (const auto & elem : mesh->active_element_ptr_range())
      80             :     {
      81             :       // don't need to check if this unique parsed ID corresponding to this element is already in
      82             :       // the "ids"
      83       39040 :       if (ids.count(parsed_ids[elem->id()]))
      84       10816 :         continue;
      85             :       // check extra IDs of this element is defined in  "exclude_id_name" and "exclude_id_value"
      86             :       bool is_exclude_elem = false;
      87       14752 :       for (unsigned int i = 0; i < id_index.size(); ++i)
      88             :       {
      89       14336 :         const auto id = elem->get_extra_integer(id_index[i]);
      90             :         if (id_value_set[i].count(id))
      91             :         {
      92             :           is_exclude_elem = true;
      93       13696 :           break;
      94             :         }
      95             :       }
      96             :       // if this element does not need to be excluded, having unique ID, add to "ids"
      97             :       if (!is_exclude_elem)
      98         416 :         ids.insert(parsed_ids[elem->id()]);
      99          14 :     }
     100          14 :     comm().set_union(ids);
     101             : 
     102             :     std::map<dof_id_type, dof_id_type> map_ids;
     103       49870 :     for (auto id : parsed_ids)
     104             :     {
     105       24928 :       dof_id_type new_id = std::distance(ids.begin(), ids.find(id.second)) + 1;
     106       24928 :       map_ids[id.second] = new_id;
     107             :     }
     108             : 
     109             :     // reassign parsed (depletion) ids
     110       24956 :     for (const auto & elem : mesh->active_element_ptr_range())
     111             :     {
     112       24928 :       dof_id_type id = parsed_ids[elem->id()];
     113             :       dof_id_type new_id = 0;
     114             :       if (ids.count(id))
     115       11232 :         new_id = map_ids[id];
     116       24928 :       parsed_ids[elem->id()] = new_id;
     117          14 :     }
     118          14 :   }
     119             :   // assign depletion id to mesh
     120             :   const auto depletion_id =
     121         105 :       mesh->add_elem_integer(getParam<ExtraElementIDName>("generated_id_name"));
     122       53734 :   for (Elem * const elem : mesh->active_element_ptr_range())
     123       53699 :     elem->set_extra_integer(depletion_id, parsed_ids.at(elem->id()));
     124          35 :   return mesh;
     125          35 : }

Generated by: LCOV version 1.14