LCOV - code coverage report
Current view: top level - src/meshgenerators - ReactorGeometryMeshBuilderBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose reactor: #32971 (54bef8) with base c6cf66 Lines: 138 150 92.0 %
Date: 2026-05-29 20:39:24 Functions: 12 12 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             : #include "CSGPlane.h"
      14             : 
      15             : InputParameters
      16        3286 : ReactorGeometryMeshBuilderBase::validParams()
      17             : {
      18        3286 :   InputParameters params = MeshGenerator::validParams();
      19             : 
      20        6572 :   params.addDeprecatedParam<bool>("show_rgmb_metadata",
      21             :                                   "Print out RGMB-related metadata to console output",
      22             :                                   "This parameter is deprecated. Please use MeshMetaDataReporter "
      23             :                                   "system to print out mesh metadata to JSON output file instead");
      24        3286 :   params.addClassDescription("A base class that contains common members and methods for Reactor "
      25             :                              "Geometry Mesh Builder mesh generators.");
      26             : 
      27             :   // Declare that this generator has a generateData method
      28        3286 :   MeshGenerator::setHasGenerateData(params);
      29        3286 :   return params;
      30           0 : }
      31             : 
      32             : void
      33        1496 : ReactorGeometryMeshBuilderBase::addDepletionIDParams(InputParameters & params)
      34             : {
      35        2992 :   params.addParam<bool>(
      36        2992 :       "generate_depletion_id", false, "Determine wheter the depletion ID is assigned.");
      37        2992 :   MooseEnum depletion_id_option("assembly assembly_type pin pin_type");
      38        2992 :   params.addParam<MooseEnum>("depletion_id_type",
      39             :                              depletion_id_option,
      40             :                              "Determine level of details in depletion ID assignment.");
      41        2992 :   params.addParamNamesToGroup("generate_depletion_id depletion_id_type", "Depletion ID assignment");
      42        1496 : }
      43             : 
      44        1660 : ReactorGeometryMeshBuilderBase::ReactorGeometryMeshBuilderBase(const InputParameters & parameters)
      45        1660 :   : MeshGenerator(parameters)
      46             : {
      47        1660 : }
      48             : 
      49             : void
      50        1654 : ReactorGeometryMeshBuilderBase::initializeReactorMeshParams(const std::string reactor_param_name)
      51             : {
      52        1654 :   _reactor_params = reactor_param_name;
      53             : 
      54             :   // Ensure that the user has supplied a valid ReactorMeshParams object
      55        1654 :   _reactor_params_mesh = &getMeshByName(reactor_param_name);
      56        1654 :   if (*_reactor_params_mesh)
      57           0 :     mooseError("The reactor_params mesh is not of the correct type");
      58             : 
      59        4962 :   if (!hasMeshProperty<unsigned int>("mesh_dimensions", _reactor_params) ||
      60        4962 :       !hasMeshProperty<std::string>("mesh_geometry", _reactor_params))
      61           0 :     mooseError("The reactor_params input must be a ReactorMeshParams type MeshGenerator\n Please "
      62             :                "check that a valid definition and name of ReactorMeshParams has been provided.");
      63             : 
      64             :   // Set reactor_params_name metadata for use by future mesh generators
      65        3308 :   declareMeshProperty("reactor_params_name", std::string(_reactor_params));
      66             : 
      67             :   // Store CSGBase object if we are in CSG only mode
      68        1654 :   if (_app.getMeshGeneratorSystem().getCSGOnly())
      69         130 :     _reactor_params_csg = &getCSGBaseByName(_reactor_params);
      70        1654 : }
      71             : 
      72             : void
      73        1252 : ReactorGeometryMeshBuilderBase::freeReactorParamsMesh()
      74             : {
      75        1252 :   _reactor_params_mesh->reset();
      76        1252 : }
      77             : 
      78             : void
      79         130 : ReactorGeometryMeshBuilderBase::freeReactorParamsCSG()
      80             : {
      81         130 :   _reactor_params_csg->reset();
      82         130 : }
      83             : 
      84             : unsigned int
      85        4569 : ReactorGeometryMeshBuilderBase::getElemIntegerFromMesh(MeshBase & input_mesh,
      86             :                                                        std::string extra_int_name,
      87             :                                                        bool should_exist)
      88             : {
      89        4569 :   if (input_mesh.has_elem_integer(extra_int_name))
      90        1902 :     return input_mesh.get_elem_integer_index(extra_int_name);
      91             :   else
      92             :   {
      93        2667 :     if (should_exist)
      94           0 :       mooseError("Expected extruded mesh to have " + extra_int_name + " extra integers");
      95             :     else
      96        5334 :       return input_mesh.add_elem_integer(extra_int_name);
      97             :   }
      98             : }
      99             : 
     100             : void
     101      551920 : ReactorGeometryMeshBuilderBase::updateElementBlockNameId(
     102             :     MeshBase & input_mesh,
     103             :     Elem * elem,
     104             :     std::map<std::string, SubdomainID> & name_id_map,
     105             :     std::string elem_block_name,
     106             :     SubdomainID & next_free_id)
     107             : {
     108             :   SubdomainID elem_block_id;
     109      551920 :   if (name_id_map.find(elem_block_name) == name_id_map.end())
     110             :   {
     111             :     // Block name does not exist in mesh yet, assign new block id and name
     112        3459 :     elem_block_id = next_free_id++;
     113        3459 :     elem->subdomain_id() = elem_block_id;
     114        3459 :     input_mesh.subdomain_name(elem_block_id) = elem_block_name;
     115        3459 :     name_id_map[elem_block_name] = elem_block_id;
     116             :   }
     117             :   else
     118             :   {
     119             :     // Block name exists in mesh, reuse block id
     120      548461 :     elem_block_id = name_id_map[elem_block_name];
     121      548461 :     elem->subdomain_id() = elem_block_id;
     122             :   }
     123             : 
     124             :   input_mesh.unset_has_cached_elem_data();
     125      551920 : }
     126             : 
     127             : void
     128          45 : ReactorGeometryMeshBuilderBase::addDepletionId(MeshBase & input_mesh,
     129             :                                                const MooseEnum & option,
     130             :                                                const DepletionIDGenerationLevel generation_level,
     131             :                                                const bool extrude)
     132             : {
     133             :   // prepare set of extra elem ids for depletion ID generation
     134             :   std::vector<ExtraElementIDName> id_names = {};
     135          45 :   if (extrude)
     136          24 :     id_names.push_back("plane_id");
     137          45 :   if (generation_level == DepletionIDGenerationLevel::Core)
     138             :   {
     139          24 :     if (option == "pin")
     140          36 :       id_names.insert(id_names.end(), {"assembly_id", "pin_id"});
     141          12 :     else if (option == "pin_type")
     142          36 :       id_names.insert(id_names.end(), {"assembly_id", "pin_type_id"});
     143           0 :     else if (option == "assembly")
     144           0 :       id_names.push_back("assembly_id");
     145           0 :     else if (option == "assembly_type")
     146           0 :       id_names.push_back("assembly_type_id");
     147             :   }
     148          21 :   else if (generation_level == DepletionIDGenerationLevel::Assembly)
     149             :   {
     150          14 :     if (option == "pin")
     151           7 :       id_names.push_back("pin_id");
     152           7 :     else if (option == "pin_type")
     153           7 :       id_names.push_back("pin_type_id");
     154             :     else
     155           0 :       paramError("depletion_id_type",
     156             :                  "'assembly_id' or 'assembly_type_id' is not allowed in depletion ID generation at "
     157             :                  "assembly level");
     158             :   }
     159           7 :   else if (generation_level == DepletionIDGenerationLevel::Drum)
     160             :   {
     161           7 :     if (option == "pin_type")
     162           5 :       id_names.push_back("pin_type_id");
     163             :     else
     164           2 :       paramError("depletion_id_type",
     165             :                  "Only 'pin_type' is allowed in depletion ID generation at "
     166             :                  "drum level");
     167             :   }
     168           0 :   else if (generation_level == DepletionIDGenerationLevel::Pin)
     169           0 :     mooseError("Depletion ID generation is not supported at pin level yet in RGMB");
     170          43 :   id_names.push_back("region_id");
     171             :   // no block restriction
     172             :   std::set<SubdomainID> block_ids = {};
     173             :   // create depletion IDs
     174             :   // depletion IDs will be assigned in the following order:
     175             :   // regions (materials) within pin -> pins in assembly -> assemblies in core -> axial planes
     176             :   std::unordered_map<dof_id_type, dof_id_type> depl_ids =
     177          43 :       MooseMeshUtils::getExtraIDUniqueCombinationMap(input_mesh, block_ids, id_names);
     178             :   // assign depletion ids to elements
     179          43 :   const auto depl_id_index = input_mesh.add_elem_integer("depletion_id");
     180       55906 :   for (Elem * const elem : input_mesh.active_element_ptr_range())
     181       55863 :     elem->set_extra_integer(depl_id_index, depl_ids.at(elem->id()));
     182          43 : }
     183             : 
     184             : MeshGeneratorName
     185         187 : ReactorGeometryMeshBuilderBase::callExtrusionMeshSubgenerators(
     186             :     const MeshGeneratorName input_mesh_name)
     187             : {
     188         187 :   std::vector<Real> axial_boundaries = getReactorParam<std::vector<Real>>(RGMB::axial_mesh_sizes);
     189         187 :   const auto top_boundary = getReactorParam<boundary_id_type>(RGMB::top_boundary_id);
     190         187 :   const auto bottom_boundary = getReactorParam<boundary_id_type>(RGMB::bottom_boundary_id);
     191             : 
     192             :   {
     193         187 :     auto params = _app.getFactory().getValidParams("AdvancedExtruderGenerator");
     194             : 
     195         187 :     params.set<MeshGeneratorName>("input") = input_mesh_name;
     196         187 :     params.set<Point>("direction") = Point(0, 0, 1);
     197         187 :     params.set<std::vector<unsigned int>>("num_layers") =
     198         187 :         getReactorParam<std::vector<unsigned int>>(RGMB::axial_mesh_intervals);
     199         187 :     params.set<std::vector<Real>>("heights") = axial_boundaries;
     200         561 :     params.set<BoundaryName>("bottom_boundary") = std::to_string(bottom_boundary);
     201         561 :     params.set<BoundaryName>("top_boundary") = std::to_string(top_boundary);
     202         374 :     addMeshSubgenerator("AdvancedExtruderGenerator", name() + "_extruded", params);
     203         187 :   }
     204             : 
     205             :   {
     206         374 :     auto params = _app.getFactory().getValidParams("RenameBoundaryGenerator");
     207             : 
     208         561 :     params.set<MeshGeneratorName>("input") = name() + "_extruded";
     209         374 :     params.set<std::vector<BoundaryName>>("old_boundary") = {
     210         187 :         std::to_string(top_boundary),
     211        1309 :         std::to_string(bottom_boundary)}; // hard coded boundary IDs in patterned mesh generator
     212         748 :     params.set<std::vector<BoundaryName>>("new_boundary") = {"top", "bottom"};
     213         374 :     addMeshSubgenerator("RenameBoundaryGenerator", name() + "_change_plane_name", params);
     214         187 :   }
     215             : 
     216         187 :   const MeshGeneratorName output_mesh_name = name() + "_extrudedIDs";
     217             :   {
     218         374 :     auto params = _app.getFactory().getValidParams("PlaneIDMeshGenerator");
     219             : 
     220         561 :     params.set<MeshGeneratorName>("input") = name() + "_change_plane_name";
     221             : 
     222         187 :     std::vector<Real> plane_heights{0};
     223         451 :     for (Real z : axial_boundaries)
     224         264 :       plane_heights.push_back(z + plane_heights.back());
     225             : 
     226         187 :     params.set<std::vector<Real>>("plane_coordinates") = plane_heights;
     227             : 
     228         187 :     std::string plane_id_name = "plane_id";
     229         187 :     params.set<std::string>("id_name") = "plane_id";
     230             : 
     231         374 :     addMeshSubgenerator("PlaneIDMeshGenerator", output_mesh_name, params);
     232         187 :   }
     233             : 
     234         187 :   return output_mesh_name;
     235         187 : }
     236             : 
     237             : std::vector<std::reference_wrapper<const CSG::CSGSurface>>
     238         190 : ReactorGeometryMeshBuilderBase::getOuterRadialSurfacesForUnitCell(unsigned int radial_index,
     239             :                                                                   Real halfpitch,
     240             :                                                                   CSG::CSGBase & csg_obj)
     241             : {
     242             :   std::vector<std::reference_wrapper<const CSG::CSGSurface>> duct_surfaces;
     243         190 :   const auto mesh_geometry = getReactorParam<std::string>(RGMB::mesh_geometry);
     244         190 :   const auto n_azim_surfaces = mesh_geometry == "Square" ? 4 : 6;
     245             : 
     246             :   // Convert halfpitch to radius (distance from vertex to center)
     247         190 :   const Real angle_offset_degrees = mesh_geometry == "Square" ? 45. : 30.;
     248         190 :   const Real angle_offset_radians = angle_offset_degrees * (M_PI / 180.);
     249         190 :   const auto radius = halfpitch / std::cos(angle_offset_radians);
     250             : 
     251         190 :   Real angle_increment_radians = 360. / n_azim_surfaces * (M_PI / 180.);
     252             : 
     253        1130 :   for (const auto i : make_range(n_azim_surfaces))
     254             :   {
     255             :     const auto surf_name =
     256        2820 :         name() + "_radial_duct_" + std::to_string(radial_index) + "_surf_" + std::to_string(i);
     257             : 
     258             :     // Define 3 points on the surface
     259         940 :     const auto current_angle = i * angle_increment_radians + angle_offset_radians;
     260         940 :     const auto next_angle = (i + 1) * angle_increment_radians + angle_offset_radians;
     261         940 :     libMesh::Point p0(radius * std::cos(current_angle), radius * std::sin(current_angle), 0.);
     262         940 :     libMesh::Point p1(radius * std::cos(next_angle), radius * std::sin(next_angle), 0.);
     263             :     libMesh::Point p2 = (p0 + p1) / 2.;
     264             :     // Place third point above the two others to form a vertical plane
     265         940 :     p2(2) = angle_offset_degrees;
     266             : 
     267             :     std::unique_ptr<CSG::CSGSurface> duct_surf_ptr =
     268         940 :         std::make_unique<CSG::CSGPlane>(surf_name, p0, p1, p2);
     269         940 :     const auto & duct_surf = csg_obj.addSurface(std::move(duct_surf_ptr));
     270         940 :     duct_surfaces.push_back(duct_surf);
     271         940 :   }
     272             : 
     273         190 :   return duct_surfaces;
     274           0 : }
     275             : 
     276             : std::vector<std::reference_wrapper<const CSG::CSGSurface>>
     277          65 : ReactorGeometryMeshBuilderBase::getAxialPlaneSurfaces(CSG::CSGBase & csg_obj)
     278             : {
     279             :   std::vector<std::reference_wrapper<const CSG::CSGSurface>> surfaces_by_axial_region;
     280          65 :   const auto axial_boundaries = getReactorParam<std::vector<Real>>(RGMB::axial_mesh_sizes);
     281          65 :   Real axial_level = 0.;
     282             : 
     283             :   // Check if axial planes have been defined in CSGBase based on a surface name we expect
     284             :   // to find
     285          65 :   auto axial_surf_name = RGMB::CSG_AXIAL_PLANE_PREFIX + "0";
     286             :   const auto has_axial_surfaces = csg_obj.hasSurface(axial_surf_name);
     287             : 
     288         250 :   for (const auto i : make_range(axial_boundaries.size() + 1))
     289             :   {
     290         185 :     axial_surf_name = RGMB::CSG_AXIAL_PLANE_PREFIX + std::to_string(i);
     291         185 :     if (has_axial_surfaces)
     292             :       // Surface should exist in CSGBase, retrieve from object
     293          45 :       surfaces_by_axial_region.push_back(csg_obj.getSurfaceByName(axial_surf_name));
     294             :     else
     295             :     {
     296             :       // Surface has not been defined, create it and add to CSGBase
     297         140 :       axial_level += (i != 0) ? axial_boundaries[i - 1] : 0.;
     298             :       std::unique_ptr<CSG::CSGSurface> plane_surf_ptr =
     299         140 :           std::make_unique<CSG::CSGPlane>(axial_surf_name, 0, 0, 1, axial_level);
     300         140 :       const auto & plane_surf = csg_obj.addSurface(std::move(plane_surf_ptr));
     301         140 :       surfaces_by_axial_region.push_back(plane_surf);
     302         140 :     }
     303             :   }
     304             : 
     305          65 :   return surfaces_by_axial_region;
     306          65 : }

Generated by: LCOV version 1.14