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 90 : DepletionIDGenerator::validParams() 18 : { 19 90 : InputParameters params = MeshGenerator::validParams(); 20 180 : params.addRequiredParam<MeshGeneratorName>( 21 : "input", "Name of an existing mesh generator to which we assign element IDs"); 22 180 : params.addParam<std::vector<ExtraElementIDName>>("id_name", "Extra integer id names"); 23 180 : params.addParam<ExtraElementIDName>("material_id_name", "material_id", "Material id name"); 24 180 : 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 180 : params.addParam<std::vector<ExtraElementIDName>>( 28 : "exclude_id_name", "Extra ID names that need to be excluded in the depletion ID generation"); 29 180 : 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 180 : params.addParam<ExtraElementIDName>( 32 : "generated_id_name", "depletion_id", "The generated extra element integer name"); 33 90 : 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 90 : return params; 38 0 : } 39 45 : DepletionIDGenerator::DepletionIDGenerator(const InputParameters & params) 40 : : MeshGenerator(params), 41 45 : _input(getMesh("input")), 42 90 : _material_id_name(getParam<ExtraElementIDName>("material_id_name")) 43 : { 44 45 : } 45 : 46 : std::unique_ptr<MeshBase> 47 45 : DepletionIDGenerator::generate() 48 : { 49 45 : std::unique_ptr<MeshBase> mesh = std::move(_input); 50 : // parsing the extra ids 51 : std::vector<ExtraElementIDName> id_names; 52 135 : id_names = getParam<std::vector<ExtraElementIDName>>("id_name"); 53 45 : 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 45 : id_names.push_back(_material_id_name); 59 90 : auto parsed_ids = MooseMeshUtils::getExtraIDUniqueCombinationMap(*mesh, {}, id_names); 60 : // re-numbering if exclude_id_name is used 61 126 : if (isParamValid("exclude_id_name") && isParamValid("exclude_id_value")) 62 : { 63 36 : const auto exclude_id_name = getParam<std::vector<ExtraElementIDName>>("exclude_id_name"); 64 : const auto & exclude_id_value = 65 36 : 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 18 : id_index.resize(exclude_id_name.size()); 69 18 : id_value_set.resize(exclude_id_name.size()); 70 45 : for (unsigned int i = 0; i < exclude_id_name.size(); ++i) 71 : { 72 27 : id_index[i] = mesh->get_elem_integer_index(exclude_id_name[i]); 73 27 : 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 59108 : 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 46240 : if (ids.count(parsed_ids[elem->id()])) 84 12832 : 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 17504 : for (unsigned int i = 0; i < id_index.size(); ++i) 88 : { 89 16992 : 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 16192 : 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 512 : ids.insert(parsed_ids[elem->id()]); 99 18 : } 100 18 : comm().set_union(ids); 101 : 102 : std::map<dof_id_type, dof_id_type> map_ids; 103 59090 : for (auto id : parsed_ids) 104 : { 105 29536 : dof_id_type new_id = std::distance(ids.begin(), ids.find(id.second)) + 1; 106 29536 : map_ids[id.second] = new_id; 107 : } 108 : 109 : // reassign parsed (depletion) ids 110 29572 : for (const auto & elem : mesh->active_element_ptr_range()) 111 : { 112 29536 : dof_id_type id = parsed_ids[elem->id()]; 113 : dof_id_type new_id = 0; 114 : if (ids.count(id)) 115 13344 : new_id = map_ids[id]; 116 29536 : parsed_ids[elem->id()] = new_id; 117 18 : } 118 18 : } 119 : // assign depletion id to mesh 120 : const auto depletion_id = 121 135 : mesh->add_elem_integer(getParam<ExtraElementIDName>("generated_id_name")); 122 64058 : for (Elem * const elem : mesh->active_element_ptr_range()) 123 64013 : elem->set_extra_integer(depletion_id, parsed_ids.at(elem->id())); 124 45 : return mesh; 125 45 : }