| 245 | } |
| 246 | |
| 247 | auto mapPointSourcesToClusters(const unsigned* meshIds, |
| 248 | unsigned numberOfSources, |
| 249 | seissol::initializer::LTSTree* ltsTree, |
| 250 | seissol::initializer::LTS* lts, |
| 251 | seissol::initializer::Lut* ltsLut, |
| 252 | seissol::memory::Memkind memkind) |
| 253 | -> std::unordered_map<LayerType, std::vector<ClusterMapping>> { |
| 254 | auto layerClusterToPointSources = |
| 255 | std::unordered_map<LayerType, std::vector<std::vector<unsigned>>>{}; |
| 256 | layerClusterToPointSources[Copy].resize(ltsTree->numChildren()); |
| 257 | layerClusterToPointSources[Interior].resize(ltsTree->numChildren()); |
| 258 | auto layerClusterToMeshIds = std::unordered_map<LayerType, std::vector<std::vector<unsigned>>>{}; |
| 259 | layerClusterToMeshIds[Copy].resize(ltsTree->numChildren()); |
| 260 | layerClusterToMeshIds[Interior].resize(ltsTree->numChildren()); |
| 261 | |
| 262 | for (unsigned source = 0; source < numberOfSources; ++source) { |
| 263 | const unsigned meshId = meshIds[source]; |
| 264 | const unsigned cluster = ltsLut->cluster(meshId); |
| 265 | const LayerType layer = ltsLut->layer(meshId); |
| 266 | assert(layer != Ghost); |
| 267 | layerClusterToPointSources[layer][cluster].push_back(source); |
| 268 | layerClusterToMeshIds[layer][cluster].push_back(meshId); |
| 269 | } |
| 270 | |
| 271 | std::unordered_map<LayerType, std::vector<ClusterMapping>> layeredClusterMapping; |
| 272 | for (auto layer : {Copy, Interior}) { |
| 273 | layeredClusterMapping[layer].resize(ltsTree->numChildren(), ClusterMapping(memkind)); |
| 274 | auto& clusterToMeshIds = layerClusterToMeshIds[layer]; |
| 275 | auto& clusterToPointSources = layerClusterToPointSources[layer]; |
| 276 | auto& clusterMappings = layeredClusterMapping[layer]; |
| 277 | for (unsigned cluster = 0; cluster < ltsTree->numChildren(); ++cluster) { |
| 278 | // Determine number of mappings by counting unique mesh Ids |
| 279 | std::sort(clusterToMeshIds[cluster].begin(), clusterToMeshIds[cluster].end()); |
| 280 | auto last = std::unique(clusterToMeshIds[cluster].begin(), clusterToMeshIds[cluster].end()); |
| 281 | unsigned numberOfMappings = 0; |
| 282 | for (auto it = clusterToMeshIds[cluster].begin(); it != last; ++it) { |
| 283 | const unsigned meshId = *it; |
| 284 | for (unsigned dup = 0; |
| 285 | dup < seissol::initializer::Lut::MaxDuplicates && |
| 286 | ltsLut->ltsId(lts->dofs.mask, meshId, dup) != std::numeric_limits<unsigned>::max(); |
| 287 | ++dup) { |
| 288 | ++numberOfMappings; |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | clusterMappings[cluster].sources.resize(clusterToPointSources[cluster].size()); |
| 293 | clusterMappings[cluster].cellToSources.resize(numberOfMappings); |
| 294 | |
| 295 | for (unsigned source = 0; source < clusterToPointSources[cluster].size(); ++source) { |
| 296 | clusterMappings[cluster].sources[source] = clusterToPointSources[cluster][source]; |
| 297 | } |
| 298 | std::sort(clusterMappings[cluster].sources.begin(), |
| 299 | clusterMappings[cluster].sources.end(), |
| 300 | [&](unsigned i, unsigned j) { return meshIds[i] < meshIds[j]; }); |
| 301 | |
| 302 | mapClusterToMesh(clusterMappings[cluster], |
| 303 | meshIds, |
| 304 | ltsTree, |
no test coverage detected