LCOV - code coverage report
Current view: top level - src/meshgenerators - ReactorGeometryMeshBuilderBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose reactor: #31405 (292dce) with base fef103 Lines: 99 110 90.0 %
Date: 2025-09-04 07:56:24 Functions: 9 9 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 "ReactorGeometryMeshBuilderBase.h"
      11             : #include "DepletionIDGenerator.h"
      12             : #include "MooseMeshUtils.h"
      13             : 
      14             : InputParameters
      15        3666 : ReactorGeometryMeshBuilderBase::validParams()
      16             : {
      17        3666 :   InputParameters params = MeshGenerator::validParams();
      18             : 
      19        7332 :   params.addDeprecatedParam<bool>("show_rgmb_metadata",
      20             :                                   "Print out RGMB-related metadata to console output",
      21             :                                   "This parameter is deprecated. Please use MeshMetaDataReporter "
      22             :                                   "system to print out mesh metadata to JSON output file instead");
      23        3666 :   params.addClassDescription("A base class that contains common members and methods for Reactor "
      24             :                              "Geometry Mesh Builder mesh generators.");
      25             : 
      26             :   // Declare that this generator has a generateData method
      27        3666 :   MeshGenerator::setHasGenerateData(params);
      28        3666 :   return params;
      29           0 : }
      30             : 
      31             : void
      32        1720 : ReactorGeometryMeshBuilderBase::addDepletionIDParams(InputParameters & params)
      33             : {
      34        3440 :   params.addParam<bool>(
      35        3440 :       "generate_depletion_id", false, "Determine wheter the depletion ID is assigned.");
      36        3440 :   MooseEnum depletion_id_option("assembly assembly_type pin pin_type");
      37        3440 :   params.addParam<MooseEnum>("depletion_id_type",
      38             :                              depletion_id_option,
      39             :                              "Determine level of details in depletion ID assignment.");
      40        3440 :   params.addParamNamesToGroup("generate_depletion_id depletion_id_type", "Depletion ID assignment");
      41        1720 : }
      42             : 
      43        1850 : ReactorGeometryMeshBuilderBase::ReactorGeometryMeshBuilderBase(const InputParameters & parameters)
      44        1850 :   : MeshGenerator(parameters)
      45             : {
      46        1850 : }
      47             : 
      48             : void
      49        1844 : ReactorGeometryMeshBuilderBase::initializeReactorMeshParams(const std::string reactor_param_name)
      50             : {
      51        1844 :   _reactor_params = reactor_param_name;
      52             : 
      53             :   // Ensure that the user has supplied a valid ReactorMeshParams object
      54        1844 :   _reactor_params_mesh = &getMeshByName(reactor_param_name);
      55        1844 :   if (*_reactor_params_mesh)
      56           0 :     mooseError("The reactor_params mesh is not of the correct type");
      57             : 
      58        5532 :   if (!hasMeshProperty<unsigned int>("mesh_dimensions", _reactor_params) ||
      59        5532 :       !hasMeshProperty<std::string>("mesh_geometry", _reactor_params))
      60           0 :     mooseError("The reactor_params input must be a ReactorMeshParams type MeshGenerator\n Please "
      61             :                "check that a valid definition and name of ReactorMeshParams has been provided.");
      62             : 
      63             :   // Set reactor_params_name metadata for use by future mesh generators
      64        3688 :   declareMeshProperty("reactor_params_name", std::string(_reactor_params));
      65        1844 : }
      66             : 
      67             : void
      68        1520 : ReactorGeometryMeshBuilderBase::freeReactorMeshParams()
      69             : {
      70        1520 :   _reactor_params_mesh->reset();
      71        1520 : }
      72             : 
      73             : unsigned int
      74        5547 : ReactorGeometryMeshBuilderBase::getElemIntegerFromMesh(MeshBase & input_mesh,
      75             :                                                        std::string extra_int_name,
      76             :                                                        bool should_exist)
      77             : {
      78        5547 :   if (input_mesh.has_elem_integer(extra_int_name))
      79        2324 :     return input_mesh.get_elem_integer_index(extra_int_name);
      80             :   else
      81             :   {
      82        3223 :     if (should_exist)
      83           0 :       mooseError("Expected extruded mesh to have " + extra_int_name + " extra integers");
      84             :     else
      85        6446 :       return input_mesh.add_elem_integer(extra_int_name);
      86             :   }
      87             : }
      88             : 
      89             : void
      90      617664 : ReactorGeometryMeshBuilderBase::updateElementBlockNameId(
      91             :     MeshBase & input_mesh,
      92             :     Elem * elem,
      93             :     std::map<std::string, SubdomainID> & name_id_map,
      94             :     std::string elem_block_name,
      95             :     SubdomainID & next_free_id)
      96             : {
      97             :   SubdomainID elem_block_id;
      98      617664 :   if (name_id_map.find(elem_block_name) == name_id_map.end())
      99             :   {
     100             :     // Block name does not exist in mesh yet, assign new block id and name
     101        4083 :     elem_block_id = next_free_id++;
     102        4083 :     elem->subdomain_id() = elem_block_id;
     103        4083 :     input_mesh.subdomain_name(elem_block_id) = elem_block_name;
     104        4083 :     name_id_map[elem_block_name] = elem_block_id;
     105             :   }
     106             :   else
     107             :   {
     108             :     // Block name exists in mesh, reuse block id
     109      613581 :     elem_block_id = name_id_map[elem_block_name];
     110      613581 :     elem->subdomain_id() = elem_block_id;
     111             :   }
     112      617664 : }
     113             : 
     114             : void
     115          53 : ReactorGeometryMeshBuilderBase::addDepletionId(MeshBase & input_mesh,
     116             :                                                const MooseEnum & option,
     117             :                                                const DepletionIDGenerationLevel generation_level,
     118             :                                                const bool extrude)
     119             : {
     120             :   // prepare set of extra elem ids for depletion ID generation
     121             :   std::vector<ExtraElementIDName> id_names = {};
     122          53 :   if (extrude)
     123          28 :     id_names.push_back("plane_id");
     124          53 :   if (generation_level == DepletionIDGenerationLevel::Core)
     125             :   {
     126          28 :     if (option == "pin")
     127          42 :       id_names.insert(id_names.end(), {"assembly_id", "pin_id"});
     128          14 :     else if (option == "pin_type")
     129          42 :       id_names.insert(id_names.end(), {"assembly_id", "pin_type_id"});
     130           0 :     else if (option == "assembly")
     131           0 :       id_names.push_back("assembly_id");
     132           0 :     else if (option == "assembly_type")
     133           0 :       id_names.push_back("assembly_type_id");
     134             :   }
     135          25 :   else if (generation_level == DepletionIDGenerationLevel::Assembly)
     136             :   {
     137          18 :     if (option == "pin")
     138           9 :       id_names.push_back("pin_id");
     139           9 :     else if (option == "pin_type")
     140           9 :       id_names.push_back("pin_type_id");
     141             :     else
     142           0 :       paramError("depletion_id_type",
     143             :                  "'assembly_id' or 'assembly_type_id' is not allowed in depletion ID generation at "
     144             :                  "assembly level");
     145             :   }
     146           7 :   else if (generation_level == DepletionIDGenerationLevel::Drum)
     147             :   {
     148           7 :     if (option == "pin_type")
     149           5 :       id_names.push_back("pin_type_id");
     150             :     else
     151           2 :       paramError("depletion_id_type",
     152             :                  "Only 'pin_type' is allowed in depletion ID generation at "
     153             :                  "drum level");
     154             :   }
     155           0 :   else if (generation_level == DepletionIDGenerationLevel::Pin)
     156           0 :     mooseError("Depletion ID generation is not supported at pin level yet in RGMB");
     157          51 :   id_names.push_back("region_id");
     158             :   // no block restriction
     159             :   std::set<SubdomainID> block_ids = {};
     160             :   // create depletion IDs
     161             :   // depletion IDs will be assigned in the following order:
     162             :   // regions (materials) within pin -> pins in assembly -> assemblies in core -> axial planes
     163             :   std::unordered_map<dof_id_type, dof_id_type> depl_ids =
     164          51 :       MooseMeshUtils::getExtraIDUniqueCombinationMap(input_mesh, block_ids, id_names);
     165             :   // assign depletion ids to elements
     166          51 :   const auto depl_id_index = input_mesh.add_elem_integer("depletion_id");
     167       62498 :   for (Elem * const elem : input_mesh.active_element_ptr_range())
     168       62447 :     elem->set_extra_integer(depl_id_index, depl_ids.at(elem->id()));
     169          51 : }
     170             : 
     171             : MeshGeneratorName
     172         229 : ReactorGeometryMeshBuilderBase::callExtrusionMeshSubgenerators(
     173             :     const MeshGeneratorName input_mesh_name)
     174             : {
     175         229 :   std::vector<Real> axial_boundaries = getReactorParam<std::vector<Real>>(RGMB::axial_mesh_sizes);
     176         229 :   const auto top_boundary = getReactorParam<boundary_id_type>(RGMB::top_boundary_id);
     177         229 :   const auto bottom_boundary = getReactorParam<boundary_id_type>(RGMB::bottom_boundary_id);
     178             : 
     179             :   {
     180         229 :     auto params = _app.getFactory().getValidParams("AdvancedExtruderGenerator");
     181             : 
     182         229 :     params.set<MeshGeneratorName>("input") = input_mesh_name;
     183         229 :     params.set<Point>("direction") = Point(0, 0, 1);
     184         229 :     params.set<std::vector<unsigned int>>("num_layers") =
     185         229 :         getReactorParam<std::vector<unsigned int>>(RGMB::axial_mesh_intervals);
     186         229 :     params.set<std::vector<Real>>("heights") = axial_boundaries;
     187         687 :     params.set<BoundaryName>("bottom_boundary") = std::to_string(bottom_boundary);
     188         687 :     params.set<BoundaryName>("top_boundary") = std::to_string(top_boundary);
     189         458 :     addMeshSubgenerator("AdvancedExtruderGenerator", name() + "_extruded", params);
     190         229 :   }
     191             : 
     192             :   {
     193         458 :     auto params = _app.getFactory().getValidParams("RenameBoundaryGenerator");
     194             : 
     195         687 :     params.set<MeshGeneratorName>("input") = name() + "_extruded";
     196         458 :     params.set<std::vector<BoundaryName>>("old_boundary") = {
     197         229 :         std::to_string(top_boundary),
     198        1603 :         std::to_string(bottom_boundary)}; // hard coded boundary IDs in patterned mesh generator
     199         916 :     params.set<std::vector<BoundaryName>>("new_boundary") = {"top", "bottom"};
     200         458 :     addMeshSubgenerator("RenameBoundaryGenerator", name() + "_change_plane_name", params);
     201         229 :   }
     202             : 
     203         229 :   const MeshGeneratorName output_mesh_name = name() + "_extrudedIDs";
     204             :   {
     205         458 :     auto params = _app.getFactory().getValidParams("PlaneIDMeshGenerator");
     206             : 
     207         687 :     params.set<MeshGeneratorName>("input") = name() + "_change_plane_name";
     208             : 
     209         229 :     std::vector<Real> plane_heights{0};
     210         557 :     for (Real z : axial_boundaries)
     211         328 :       plane_heights.push_back(z + plane_heights.back());
     212             : 
     213         229 :     params.set<std::vector<Real>>("plane_coordinates") = plane_heights;
     214             : 
     215         229 :     std::string plane_id_name = "plane_id";
     216         229 :     params.set<std::string>("id_name") = "plane_id";
     217             : 
     218         458 :     addMeshSubgenerator("PlaneIDMeshGenerator", output_mesh_name, params);
     219         229 :   }
     220             : 
     221         229 :   return output_mesh_name;
     222         229 : }

Generated by: LCOV version 1.14