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 3756 : ReactorGeometryMeshBuilderBase::validParams() 16 : { 17 3756 : InputParameters params = MeshGenerator::validParams(); 18 : 19 7512 : 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 3756 : 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 3756 : MeshGenerator::setHasGenerateData(params); 28 3756 : 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 1895 : ReactorGeometryMeshBuilderBase::ReactorGeometryMeshBuilderBase(const InputParameters & parameters) 44 1895 : : MeshGenerator(parameters) 45 : { 46 1895 : } 47 : 48 : void 49 1889 : ReactorGeometryMeshBuilderBase::initializeReactorMeshParams(const std::string reactor_param_name) 50 : { 51 1889 : _reactor_params = reactor_param_name; 52 : 53 : // Ensure that the user has supplied a valid ReactorMeshParams object 54 1889 : _reactor_params_mesh = &getMeshByName(reactor_param_name); 55 1889 : if (*_reactor_params_mesh) 56 0 : mooseError("The reactor_params mesh is not of the correct type"); 57 : 58 5667 : if (!hasMeshProperty<unsigned int>("mesh_dimensions", _reactor_params) || 59 5667 : !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 3778 : declareMeshProperty("reactor_params_name", std::string(_reactor_params)); 65 : 66 : // Store CSGBase object if we are in CSG only mode 67 1889 : if (_app.getMeshGeneratorSystem().getCSGOnly()) 68 45 : _reactor_params_csg = &getCSGBaseByName(_reactor_params); 69 1889 : } 70 : 71 : void 72 1520 : ReactorGeometryMeshBuilderBase::freeReactorParamsMesh() 73 : { 74 1520 : _reactor_params_mesh->reset(); 75 1520 : } 76 : 77 : void 78 45 : ReactorGeometryMeshBuilderBase::freeReactorParamsCSG() 79 : { 80 45 : _reactor_params_csg->reset(); 81 45 : } 82 : 83 : unsigned int 84 5547 : ReactorGeometryMeshBuilderBase::getElemIntegerFromMesh(MeshBase & input_mesh, 85 : std::string extra_int_name, 86 : bool should_exist) 87 : { 88 5547 : if (input_mesh.has_elem_integer(extra_int_name)) 89 2324 : return input_mesh.get_elem_integer_index(extra_int_name); 90 : else 91 : { 92 3223 : if (should_exist) 93 0 : mooseError("Expected extruded mesh to have " + extra_int_name + " extra integers"); 94 : else 95 6446 : return input_mesh.add_elem_integer(extra_int_name); 96 : } 97 : } 98 : 99 : void 100 617664 : ReactorGeometryMeshBuilderBase::updateElementBlockNameId( 101 : MeshBase & input_mesh, 102 : Elem * elem, 103 : std::map<std::string, SubdomainID> & name_id_map, 104 : std::string elem_block_name, 105 : SubdomainID & next_free_id) 106 : { 107 : SubdomainID elem_block_id; 108 617664 : if (name_id_map.find(elem_block_name) == name_id_map.end()) 109 : { 110 : // Block name does not exist in mesh yet, assign new block id and name 111 4083 : elem_block_id = next_free_id++; 112 4083 : elem->subdomain_id() = elem_block_id; 113 4083 : input_mesh.subdomain_name(elem_block_id) = elem_block_name; 114 4083 : name_id_map[elem_block_name] = elem_block_id; 115 : } 116 : else 117 : { 118 : // Block name exists in mesh, reuse block id 119 613581 : elem_block_id = name_id_map[elem_block_name]; 120 613581 : elem->subdomain_id() = elem_block_id; 121 : } 122 617664 : } 123 : 124 : void 125 53 : ReactorGeometryMeshBuilderBase::addDepletionId(MeshBase & input_mesh, 126 : const MooseEnum & option, 127 : const DepletionIDGenerationLevel generation_level, 128 : const bool extrude) 129 : { 130 : // prepare set of extra elem ids for depletion ID generation 131 : std::vector<ExtraElementIDName> id_names = {}; 132 53 : if (extrude) 133 28 : id_names.push_back("plane_id"); 134 53 : if (generation_level == DepletionIDGenerationLevel::Core) 135 : { 136 28 : if (option == "pin") 137 42 : id_names.insert(id_names.end(), {"assembly_id", "pin_id"}); 138 14 : else if (option == "pin_type") 139 42 : id_names.insert(id_names.end(), {"assembly_id", "pin_type_id"}); 140 0 : else if (option == "assembly") 141 0 : id_names.push_back("assembly_id"); 142 0 : else if (option == "assembly_type") 143 0 : id_names.push_back("assembly_type_id"); 144 : } 145 25 : else if (generation_level == DepletionIDGenerationLevel::Assembly) 146 : { 147 18 : if (option == "pin") 148 9 : id_names.push_back("pin_id"); 149 9 : else if (option == "pin_type") 150 9 : id_names.push_back("pin_type_id"); 151 : else 152 0 : paramError("depletion_id_type", 153 : "'assembly_id' or 'assembly_type_id' is not allowed in depletion ID generation at " 154 : "assembly level"); 155 : } 156 7 : else if (generation_level == DepletionIDGenerationLevel::Drum) 157 : { 158 7 : if (option == "pin_type") 159 5 : id_names.push_back("pin_type_id"); 160 : else 161 2 : paramError("depletion_id_type", 162 : "Only 'pin_type' is allowed in depletion ID generation at " 163 : "drum level"); 164 : } 165 0 : else if (generation_level == DepletionIDGenerationLevel::Pin) 166 0 : mooseError("Depletion ID generation is not supported at pin level yet in RGMB"); 167 51 : id_names.push_back("region_id"); 168 : // no block restriction 169 : std::set<SubdomainID> block_ids = {}; 170 : // create depletion IDs 171 : // depletion IDs will be assigned in the following order: 172 : // regions (materials) within pin -> pins in assembly -> assemblies in core -> axial planes 173 : std::unordered_map<dof_id_type, dof_id_type> depl_ids = 174 51 : MooseMeshUtils::getExtraIDUniqueCombinationMap(input_mesh, block_ids, id_names); 175 : // assign depletion ids to elements 176 51 : const auto depl_id_index = input_mesh.add_elem_integer("depletion_id"); 177 62498 : for (Elem * const elem : input_mesh.active_element_ptr_range()) 178 62447 : elem->set_extra_integer(depl_id_index, depl_ids.at(elem->id())); 179 51 : } 180 : 181 : MeshGeneratorName 182 229 : ReactorGeometryMeshBuilderBase::callExtrusionMeshSubgenerators( 183 : const MeshGeneratorName input_mesh_name) 184 : { 185 229 : std::vector<Real> axial_boundaries = getReactorParam<std::vector<Real>>(RGMB::axial_mesh_sizes); 186 229 : const auto top_boundary = getReactorParam<boundary_id_type>(RGMB::top_boundary_id); 187 229 : const auto bottom_boundary = getReactorParam<boundary_id_type>(RGMB::bottom_boundary_id); 188 : 189 : { 190 229 : auto params = _app.getFactory().getValidParams("AdvancedExtruderGenerator"); 191 : 192 229 : params.set<MeshGeneratorName>("input") = input_mesh_name; 193 229 : params.set<Point>("direction") = Point(0, 0, 1); 194 229 : params.set<std::vector<unsigned int>>("num_layers") = 195 229 : getReactorParam<std::vector<unsigned int>>(RGMB::axial_mesh_intervals); 196 229 : params.set<std::vector<Real>>("heights") = axial_boundaries; 197 687 : params.set<BoundaryName>("bottom_boundary") = std::to_string(bottom_boundary); 198 687 : params.set<BoundaryName>("top_boundary") = std::to_string(top_boundary); 199 458 : addMeshSubgenerator("AdvancedExtruderGenerator", name() + "_extruded", params); 200 229 : } 201 : 202 : { 203 458 : auto params = _app.getFactory().getValidParams("RenameBoundaryGenerator"); 204 : 205 687 : params.set<MeshGeneratorName>("input") = name() + "_extruded"; 206 458 : params.set<std::vector<BoundaryName>>("old_boundary") = { 207 229 : std::to_string(top_boundary), 208 1603 : std::to_string(bottom_boundary)}; // hard coded boundary IDs in patterned mesh generator 209 916 : params.set<std::vector<BoundaryName>>("new_boundary") = {"top", "bottom"}; 210 458 : addMeshSubgenerator("RenameBoundaryGenerator", name() + "_change_plane_name", params); 211 229 : } 212 : 213 229 : const MeshGeneratorName output_mesh_name = name() + "_extrudedIDs"; 214 : { 215 458 : auto params = _app.getFactory().getValidParams("PlaneIDMeshGenerator"); 216 : 217 687 : params.set<MeshGeneratorName>("input") = name() + "_change_plane_name"; 218 : 219 229 : std::vector<Real> plane_heights{0}; 220 557 : for (Real z : axial_boundaries) 221 328 : plane_heights.push_back(z + plane_heights.back()); 222 : 223 229 : params.set<std::vector<Real>>("plane_coordinates") = plane_heights; 224 : 225 229 : std::string plane_id_name = "plane_id"; 226 229 : params.set<std::string>("id_name") = "plane_id"; 227 : 228 458 : addMeshSubgenerator("PlaneIDMeshGenerator", output_mesh_name, params); 229 229 : } 230 : 231 229 : return output_mesh_name; 232 229 : }