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 691 : 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 2720 : for (MooseIndex(pattern) i = 0; i < pattern.size(); ++i) 23 7454 : for (MooseIndex(pattern[i]) j = 0; j < pattern[i].size(); ++j) 24 5425 : n += meshes[pattern[i][j]]->n_elem(); 25 : std::vector<dof_id_type> integer_ids; 26 691 : integer_ids.reserve(n); 27 : dof_id_type id = 0; 28 2720 : for (MooseIndex(pattern) i = 0; i < pattern.size(); ++i) 29 7454 : for (MooseIndex(pattern[i]) j = 0; j < pattern[i].size(); ++j) 30 : { 31 : const auto value = 32 5425 : (use_exclude_id && exclude_ids[pattern[i][j]]) ? DofObject::invalid_id : id++; 33 5425 : integer_ids.insert(integer_ids.end(), meshes[pattern[i][j]]->n_elem(), value); 34 : } 35 691 : return integer_ids; 36 0 : } 37 : 38 : std::vector<dof_id_type> 39 49 : 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 287 : for (MooseIndex(pattern) i = 0; i < pattern.size(); ++i) 45 1232 : for (MooseIndex(pattern[i]) j = 0; j < pattern[i].size(); ++j) 46 994 : n += meshes[pattern[i][j]]->n_elem(); 47 : std::vector<dof_id_type> integer_ids; 48 49 : integer_ids.reserve(n); 49 287 : for (MooseIndex(pattern) i = 0; i < pattern.size(); ++i) 50 1232 : for (MooseIndex(pattern[i]) j = 0; j < pattern[i].size(); ++j) 51 994 : integer_ids.insert(integer_ids.end(), meshes[pattern[i][j]]->n_elem(), pattern[i][j]); 52 49 : return integer_ids; 53 0 : } 54 : 55 : std::vector<dof_id_type> 56 49 : 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 266 : for (MooseIndex(pattern) i = 0; i < pattern.size(); ++i) 63 1064 : for (MooseIndex(pattern[i]) j = 0; j < pattern[i].size(); ++j) 64 847 : n += meshes[pattern[i][j]]->n_elem(); 65 : std::vector<dof_id_type> integer_ids; 66 49 : integer_ids.reserve(n); 67 266 : for (MooseIndex(pattern) i = 0; i < pattern.size(); ++i) 68 1064 : for (MooseIndex(pattern[i]) j = 0; j < pattern[i].size(); ++j) 69 847 : integer_ids.insert(integer_ids.end(), meshes[pattern[i][j]]->n_elem(), id_pattern[i][j]); 70 49 : return integer_ids; 71 0 : } 72 : 73 : std::set<SubdomainID> 74 350 : 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 1559 : for (MooseIndex(pattern) i = 0; i < pattern.size(); ++i) 80 4752 : for (MooseIndex(pattern[i]) j = 0; j < pattern[i].size(); ++j) 81 : { 82 : std::set<SubdomainID> mesh_blks; 83 3543 : ReplicatedMesh & mesh = *meshes[pattern[i][j]]; 84 3543 : if (!mesh.preparation().has_cached_elem_data) 85 488 : mesh.cache_elem_data(); 86 3543 : mesh.subdomain_ids(mesh_blks); 87 3543 : blks.insert(mesh_blks.begin(), mesh_blks.end()); 88 : } 89 350 : return blks; 90 : } 91 : 92 : std::map<SubdomainID, unsigned int> 93 350 : ReportingIDGeneratorUtils::getDuckBlockIDs(const MeshBase & mesh, 94 : const bool has_assembly_boundary, 95 : const std::set<subdomain_id_type> background_blk_ids, 96 : const std::set<SubdomainID> & blks) 97 : { 98 : std::map<SubdomainID, unsigned int> blks_duct; 99 350 : if (has_assembly_boundary) 100 : { 101 : std::set<SubdomainID> mesh_blks; 102 350 : mesh.subdomain_ids(mesh_blks); 103 : unsigned int i = 0; 104 1789 : for (const auto mesh_blk : mesh_blks) 105 : if (!blks.count(mesh_blk) && !background_blk_ids.count(mesh_blk)) 106 386 : blks_duct[mesh_blk] = i++; 107 : // delete the first entry because it is for surrouding regions between the assembly duct and pin 108 350 : if (background_blk_ids.size() == 0) 109 79 : blks_duct.erase(blks_duct.begin()); 110 : } 111 350 : return blks_duct; 112 : } 113 : 114 : void 115 789 : ReportingIDGeneratorUtils::assignReportingIDs( 116 : MeshBase & mesh, 117 : const unsigned int extra_id_index, 118 : const ReportingIDGeneratorUtils::AssignType assign_type, 119 : const bool use_exclude_id, 120 : const std::vector<bool> & exclude_ids, 121 : const bool has_assembly_boundary, 122 : const std::set<subdomain_id_type> background_block_ids, 123 : const std::vector<std::unique_ptr<ReplicatedMesh>> & input_meshes, 124 : const std::vector<std::vector<unsigned int>> & pattern, 125 : const std::vector<std::vector<dof_id_type>> & id_pattern) 126 : { 127 : std::vector<dof_id_type> integer_ids; 128 : // get reporting ID map 129 : // assumes that the entire mesh has elements of each individual mesh sequentially ordered. 130 789 : if (assign_type == AssignType::cell) 131 1382 : integer_ids = getCellwiseIntegerIDs(input_meshes, pattern, use_exclude_id, exclude_ids); 132 98 : else if (assign_type == AssignType::pattern) 133 98 : integer_ids = getPatternIntegerIDs(input_meshes, pattern); 134 49 : else if (assign_type == AssignType::manual) 135 98 : integer_ids = getManualIntegerIDs(input_meshes, pattern, id_pattern); 136 : 137 789 : if (has_assembly_boundary) 138 : { 139 : // setup assembly duct information 140 350 : const std::set<SubdomainID> blks = getCellBlockIDs(input_meshes, pattern); 141 : const unsigned int duct_boundary_id = 142 350 : *std::max_element(integer_ids.begin(), integer_ids.end()) + 1; 143 : const std::map<SubdomainID, unsigned int> blks_duct = 144 700 : getDuckBlockIDs(mesh, has_assembly_boundary, background_block_ids, blks); 145 : 146 : // assign reporting IDs to individual elements 147 : unsigned int i = 0; 148 350 : unsigned int id = integer_ids[i]; 149 : unsigned old_id = id; 150 265528 : for (auto elem : mesh.element_ptr_range()) 151 : { 152 132414 : auto blk = elem->subdomain_id(); 153 : // check whether the current element belongs to duct/surrouding regions or not 154 : if (!blks.count(blk)) 155 : { 156 : // check whether the current element belongs to surroudning or duct regions 157 : if (!blks_duct.count(blk)) 158 : // if the current element belongs to the surronding region 159 23632 : elem->set_extra_integer(extra_id_index, old_id); 160 : else 161 : // if the current element belongs to the duct region 162 14872 : elem->set_extra_integer(extra_id_index, duct_boundary_id + blks_duct.at(blk)); 163 : } 164 : else 165 : { 166 : // if the current element belongs to pin regions 167 93910 : elem->set_extra_integer(extra_id_index, id); 168 93910 : ++i; 169 : old_id = id; 170 93910 : if (i < integer_ids.size()) 171 93560 : id = integer_ids[i]; 172 : } 173 350 : } 174 : } 175 : else 176 : { 177 : // assign reporting IDs to individual elements 178 : unsigned int i = 0; 179 922918 : for (auto & elem : mesh.element_ptr_range()) 180 461459 : elem->set_extra_integer(extra_id_index, integer_ids[i++]); 181 : } 182 789 : }