LCOV - code coverage report
Current view: top level - src/utils - ReportingIDGeneratorUtils.C (source / functions) Hit Total Coverage
Test: idaholab/moose reactor: #31405 (292dce) with base fef103 Lines: 66 69 95.7 %
Date: 2025-09-04 07:56:24 Functions: 6 6 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 "ReportingIDGeneratorUtils.h"
      11             : 
      12             : using namespace libMesh;
      13             : 
      14             : std::vector<dof_id_type>
      15         855 : ReportingIDGeneratorUtils::getCellwiseIntegerIDs(
      16             :     const std::vector<std::unique_ptr<ReplicatedMesh>> & meshes,
      17             :     const std::vector<std::vector<unsigned int>> & pattern,
      18             :     const bool use_exclude_id,
      19             :     const std::vector<bool> & exclude_ids)
      20             : {
      21             :   dof_id_type n = 0;
      22        3362 :   for (MooseIndex(pattern) i = 0; i < pattern.size(); ++i)
      23        9218 :     for (MooseIndex(pattern[i]) j = 0; j < pattern[i].size(); ++j)
      24        6711 :       n += meshes[pattern[i][j]]->n_elem();
      25             :   std::vector<dof_id_type> integer_ids;
      26         855 :   integer_ids.reserve(n);
      27             :   dof_id_type id = 0;
      28        3362 :   for (MooseIndex(pattern) i = 0; i < pattern.size(); ++i)
      29        9218 :     for (MooseIndex(pattern[i]) j = 0; j < pattern[i].size(); ++j)
      30             :     {
      31             :       const auto value =
      32        6711 :           (use_exclude_id && exclude_ids[pattern[i][j]]) ? DofObject::invalid_id : id++;
      33        6711 :       integer_ids.insert(integer_ids.end(), meshes[pattern[i][j]]->n_elem(), value);
      34             :     }
      35         855 :   return integer_ids;
      36           0 : }
      37             : 
      38             : std::vector<dof_id_type>
      39          63 : ReportingIDGeneratorUtils::getPatternIntegerIDs(
      40             :     const std::vector<std::unique_ptr<ReplicatedMesh>> & meshes,
      41             :     const std::vector<std::vector<unsigned int>> & pattern)
      42             : {
      43             :   dof_id_type n = 0;
      44         369 :   for (MooseIndex(pattern) i = 0; i < pattern.size(); ++i)
      45        1584 :     for (MooseIndex(pattern[i]) j = 0; j < pattern[i].size(); ++j)
      46        1278 :       n += meshes[pattern[i][j]]->n_elem();
      47             :   std::vector<dof_id_type> integer_ids;
      48          63 :   integer_ids.reserve(n);
      49         369 :   for (MooseIndex(pattern) i = 0; i < pattern.size(); ++i)
      50        1584 :     for (MooseIndex(pattern[i]) j = 0; j < pattern[i].size(); ++j)
      51        1278 :       integer_ids.insert(integer_ids.end(), meshes[pattern[i][j]]->n_elem(), pattern[i][j]);
      52          63 :   return integer_ids;
      53           0 : }
      54             : 
      55             : std::vector<dof_id_type>
      56          63 : ReportingIDGeneratorUtils::getManualIntegerIDs(
      57             :     const std::vector<std::unique_ptr<ReplicatedMesh>> & meshes,
      58             :     const std::vector<std::vector<unsigned int>> & pattern,
      59             :     const std::vector<std::vector<dof_id_type>> & id_pattern)
      60             : {
      61             :   dof_id_type n = 0;
      62         342 :   for (MooseIndex(pattern) i = 0; i < pattern.size(); ++i)
      63        1368 :     for (MooseIndex(pattern[i]) j = 0; j < pattern[i].size(); ++j)
      64        1089 :       n += meshes[pattern[i][j]]->n_elem();
      65             :   std::vector<dof_id_type> integer_ids;
      66          63 :   integer_ids.reserve(n);
      67         342 :   for (MooseIndex(pattern) i = 0; i < pattern.size(); ++i)
      68        1368 :     for (MooseIndex(pattern[i]) j = 0; j < pattern[i].size(); ++j)
      69        1089 :       integer_ids.insert(integer_ids.end(), meshes[pattern[i][j]]->n_elem(), id_pattern[i][j]);
      70          63 :   return integer_ids;
      71           0 : }
      72             : 
      73             : std::set<SubdomainID>
      74         428 : ReportingIDGeneratorUtils::getCellBlockIDs(
      75             :     const std::vector<std::unique_ptr<ReplicatedMesh>> & meshes,
      76             :     const std::vector<std::vector<unsigned int>> & pattern)
      77             : {
      78             :   std::set<SubdomainID> blks;
      79        1915 :   for (MooseIndex(pattern) i = 0; i < pattern.size(); ++i)
      80        5864 :     for (MooseIndex(pattern[i]) j = 0; j < pattern[i].size(); ++j)
      81             :     {
      82             :       std::set<SubdomainID> mesh_blks;
      83        4377 :       meshes[pattern[i][j]]->subdomain_ids(mesh_blks);
      84        4377 :       blks.insert(mesh_blks.begin(), mesh_blks.end());
      85             :     }
      86         428 :   return blks;
      87             : }
      88             : 
      89             : std::map<SubdomainID, unsigned int>
      90         428 : ReportingIDGeneratorUtils::getDuckBlockIDs(const MeshBase & mesh,
      91             :                                            const bool has_assembly_boundary,
      92             :                                            const std::set<subdomain_id_type> background_blk_ids,
      93             :                                            const std::set<SubdomainID> & blks)
      94             : {
      95             :   std::map<SubdomainID, unsigned int> blks_duct;
      96         428 :   if (has_assembly_boundary)
      97             :   {
      98             :     std::set<SubdomainID> mesh_blks;
      99         428 :     mesh.subdomain_ids(mesh_blks);
     100             :     unsigned int i = 0;
     101        2193 :     for (const auto mesh_blk : mesh_blks)
     102             :       if (!blks.count(mesh_blk) && !background_blk_ids.count(mesh_blk))
     103         480 :         blks_duct[mesh_blk] = i++;
     104             :     // delete the first entry because it is for surrouding regions between the assembly duct and pin
     105         428 :     if (background_blk_ids.size() == 0)
     106         101 :       blks_duct.erase(blks_duct.begin());
     107             :   }
     108         428 :   return blks_duct;
     109             : }
     110             : 
     111             : void
     112         981 : ReportingIDGeneratorUtils::assignReportingIDs(
     113             :     MeshBase & mesh,
     114             :     const unsigned int extra_id_index,
     115             :     const ReportingIDGeneratorUtils::AssignType assign_type,
     116             :     const bool use_exclude_id,
     117             :     const std::vector<bool> & exclude_ids,
     118             :     const bool has_assembly_boundary,
     119             :     const std::set<subdomain_id_type> background_block_ids,
     120             :     const std::vector<std::unique_ptr<ReplicatedMesh>> & input_meshes,
     121             :     const std::vector<std::vector<unsigned int>> & pattern,
     122             :     const std::vector<std::vector<dof_id_type>> & id_pattern)
     123             : {
     124             :   std::vector<dof_id_type> integer_ids;
     125             :   // get reporting ID map
     126             :   // assumes that the entire mesh has elements of each individual mesh sequentially ordered.
     127         981 :   if (assign_type == AssignType::cell)
     128        1710 :     integer_ids = getCellwiseIntegerIDs(input_meshes, pattern, use_exclude_id, exclude_ids);
     129         126 :   else if (assign_type == AssignType::pattern)
     130         126 :     integer_ids = getPatternIntegerIDs(input_meshes, pattern);
     131          63 :   else if (assign_type == AssignType::manual)
     132         126 :     integer_ids = getManualIntegerIDs(input_meshes, pattern, id_pattern);
     133             : 
     134         981 :   if (has_assembly_boundary)
     135             :   {
     136             :     // setup assembly duct information
     137         428 :     const std::set<SubdomainID> blks = getCellBlockIDs(input_meshes, pattern);
     138             :     const unsigned int duct_boundary_id =
     139         428 :         *std::max_element(integer_ids.begin(), integer_ids.end()) + 1;
     140             :     const std::map<SubdomainID, unsigned int> blks_duct =
     141         856 :         getDuckBlockIDs(mesh, has_assembly_boundary, background_block_ids, blks);
     142             : 
     143             :     // assign reporting IDs to individual elements
     144             :     unsigned int i = 0;
     145         428 :     unsigned int id = integer_ids[i];
     146             :     unsigned old_id = id;
     147      328596 :     for (auto elem : mesh.element_ptr_range())
     148             :     {
     149      163870 :       auto blk = elem->subdomain_id();
     150             :       // check whether the current element belongs to duct/surrouding regions or not
     151             :       if (!blks.count(blk))
     152             :       {
     153             :         // check whether the current element belongs to surroudning or duct regions
     154             :         if (!blks_duct.count(blk))
     155             :           // if the current element belongs to the surronding region
     156       29480 :           elem->set_extra_integer(extra_id_index, old_id);
     157             :         else
     158             :           // if the current element belongs to the duct region
     159       18384 :           elem->set_extra_integer(extra_id_index, duct_boundary_id + blks_duct.at(blk));
     160             :       }
     161             :       else
     162             :       {
     163             :         // if the current element belongs to pin regions
     164      116006 :         elem->set_extra_integer(extra_id_index, id);
     165      116006 :         ++i;
     166             :         old_id = id;
     167      116006 :         if (i < integer_ids.size())
     168      115578 :           id = integer_ids[i];
     169             :       }
     170         428 :     }
     171             :   }
     172             :   else
     173             :   {
     174             :     // assign reporting IDs to individual elements
     175             :     unsigned int i = 0;
     176     1121842 :     for (auto & elem : mesh.element_ptr_range())
     177      560921 :       elem->set_extra_integer(extra_id_index, integer_ids[i++]);
     178             :   }
     179         981 : }

Generated by: LCOV version 1.14