| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// ShyLU: Scalable Hybrid LU Preconditioner and Solver |
| 4 |
// |
| 5 |
// Copyright 2011 NTESS and the ShyLU contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#ifndef _FROSCH_DDINTERFACE_DEF_HPP |
| 11 |
#define _FROSCH_DDINTERFACE_DEF_HPP |
| 12 |
|
| 13 |
#include <FROSch_DDInterface_decl.hpp> |
| 14 |
|
| 15 |
|
| 16 |
namespace FROSch { |
| 17 |
|
| 18 |
using namespace std; |
| 19 |
using namespace Teuchos; |
| 20 |
using namespace Xpetra; |
| 21 |
|
| 22 |
template <class SC,class LO,class GO,class NO> |
| 23 |
DDInterface<SC,LO,GO,NO>::DDInterface(UN dimension, |
| 24 |
UN dofsPerNode, |
| 25 |
ConstXMapPtr localToGlobalMap, |
| 26 |
Verbosity verbosity, |
| 27 |
UN levelID, |
| 28 |
CommunicationStrategy commStrategy) : |
| 29 |
MpiComm_ (localToGlobalMap->getComm()), |
| 30 |
Dimension_ (dimension), |
| 31 |
DofsPerNode_ (dofsPerNode), |
| 32 |
NumMyNodes_ (localToGlobalMap->getLocalNumElements()), |
| 33 |
NodesMap_ (localToGlobalMap), |
| 34 |
CommStrategy_ (commStrategy), |
| 35 |
Verbose_ (MpiComm_->getRank()==0), |
| 36 |
Verbosity_ (verbosity), |
| 37 |
LevelID_ (levelID) |
| 38 |
{ |
| 39 |
FROSCH_DETAILTIMER_START_LEVELID(dDInterfaceTime,"DDInterface::DDInterface"); |
| 40 |
FROSCH_ASSERT(((Dimension_==2)||(Dimension_==3)),"FROSch::DDInterface: Only dimension 2 and 3 are available"); |
| 41 |
|
| 42 |
//if (Verbose_ && Verbosity_==All) cout << "FROSch::DDInterface" << endl; |
| 43 |
|
| 44 |
IntVecVecPtr componentsSubdomains; |
| 45 |
IntVecVec componentsSubdomainsUnique; |
| 46 |
|
| 47 |
communicateLocalComponents(componentsSubdomains,componentsSubdomainsUnique); |
| 48 |
|
| 49 |
identifyLocalComponents(componentsSubdomains,componentsSubdomainsUnique); |
| 50 |
} |
| 51 |
|
| 52 |
template <class SC,class LO,class GO,class NO> |
| 53 |
DDInterface<SC,LO,GO,NO>::~DDInterface() |
| 54 |
{ |
| 55 |
|
| 56 |
} // Do we need sth here? |
| 57 |
|
| 58 |
template <class SC,class LO,class GO,class NO> |
| 59 |
int DDInterface<SC,LO,GO,NO>::resetGlobalDofs(ConstXMapPtrVecPtr dofsMaps) |
| 60 |
{ |
| 61 |
FROSCH_DETAILTIMER_START_LEVELID(resetGlobalDofsTime,"DDInterface::resetGlobalDofs"); |
| 62 |
//if (Verbose_ && Verbosity_==All) cout << "FROSch::DDInterface : Resetting Global IDs" << endl; |
| 63 |
|
| 64 |
// EntityVector |
| 65 |
for (UN l=0; l<EntitySetVector_.size(); l++) { |
| 66 |
for (UN i=0; i<EntitySetVector_[l]->getNumEntities(); i++) { |
| 67 |
for (UN j=0; j<EntitySetVector_[l]->getEntity(i)->getNumNodes(); j++) { |
| 68 |
LO localID = EntitySetVector_[l]->getEntity(i)->getLocalNodeID(j); |
| 69 |
UNVecPtr dofIDs(DofsPerNode_); |
| 70 |
GOVecPtr dofsGlobal(DofsPerNode_); |
| 71 |
for (UN k=0; k<DofsPerNode_; k++) { |
| 72 |
dofIDs[k] = k; |
| 73 |
dofsGlobal[k] = dofsMaps[k]->getGlobalElement(localID); |
| 74 |
} |
| 75 |
EntitySetVector_[l]->getEntity(i)->resetGlobalDofs(j,DofsPerNode_,&(dofIDs[0]),&(dofsGlobal[0])); |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
// Interface |
| 81 |
for (UN i=0; i<Interface_->getNumEntities(); i++) { |
| 82 |
for (UN j=0; j<Interface_->getEntity(i)->getNumNodes(); j++) { |
| 83 |
LO localID = Interface_->getEntity(i)->getLocalNodeID(j); |
| 84 |
UNVecPtr dofIDs(DofsPerNode_); |
| 85 |
GOVecPtr dofsGlobal(DofsPerNode_); |
| 86 |
for (UN k=0; k<DofsPerNode_; k++) { |
| 87 |
dofIDs[k] = k; |
| 88 |
dofsGlobal[k] = dofsMaps[k]->getGlobalElement(localID); |
| 89 |
} |
| 90 |
Interface_->getEntity(i)->resetGlobalDofs(j,DofsPerNode_,&(dofIDs[0]),&(dofsGlobal[0])); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
// Interior |
| 95 |
for (UN i=0; i<Interior_->getNumEntities(); i++) { |
| 96 |
for (UN j=0; j<Interior_->getEntity(i)->getNumNodes(); j++) { |
| 97 |
LO localID = Interior_->getEntity(i)->getLocalNodeID(j); |
| 98 |
UNVecPtr dofIDs(DofsPerNode_); |
| 99 |
GOVecPtr dofsGlobal(DofsPerNode_); |
| 100 |
for (UN k=0; k<DofsPerNode_; k++) { |
| 101 |
dofIDs[k] = k; |
| 102 |
dofsGlobal[k] = dofsMaps[k]->getGlobalElement(localID); |
| 103 |
} |
| 104 |
Interior_->getEntity(i)->resetGlobalDofs(j,DofsPerNode_,&(dofIDs[0]),&(dofsGlobal[0])); |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
return 0; |
| 109 |
} |
| 110 |
|
| 111 |
template <class SC,class LO,class GO,class NO> |
| 112 |
int DDInterface<SC,LO,GO,NO>::removeDirichletNodes(GOVecView dirichletBoundaryDofs) |
| 113 |
{ |
| 114 |
FROSCH_DETAILTIMER_START_LEVELID(removeDirichletNodesTime,"DDInterface::removeDirichletNodes"); |
| 115 |
//if (Verbose_ && Verbosity_==All) cout << "FROSch::DDInterface : Removing Dirichlet Nodes from the domain decomposition interface" << endl; |
| 116 |
|
| 117 |
// EntityVector |
| 118 |
for (UN l=0; l<EntitySetVector_.size(); l++) { |
| 119 |
EntitySetVector_[l]->removeNodesWithDofs(dirichletBoundaryDofs); |
| 120 |
} |
| 121 |
removeEmptyEntities(); |
| 122 |
for (UN l=0; l<EntitySetVector_.size(); l++) { |
| 123 |
EntitySetVector_[l]->setUniqueIDToFirstGlobalNodeID(); |
| 124 |
} |
| 125 |
return 0; |
| 126 |
} |
| 127 |
|
| 128 |
template <class SC,class LO,class GO,class NO> |
| 129 |
int DDInterface<SC,LO,GO,NO>::divideUnconnectedEntities(ConstXMatrixPtr matrix) |
| 130 |
{ |
| 131 |
FROSCH_DETAILTIMER_START_LEVELID(divideUnconnectedEntitiesTime,"DDInterface::divideUnconnectedEntities"); |
| 132 |
//if (Verbose_ && Verbosity_==All) cout << "FROSch::DDInterface : Decomposing unconnected interface components" << endl; |
| 133 |
|
| 134 |
GOVecPtr indicesGammaDofs(DofsPerNode_*Interface_->getEntity(0)->getNumNodes()); |
| 135 |
for (UN k=0; k<DofsPerNode_; k++) { |
| 136 |
for (UN i=0; i<Interface_->getEntity(0)->getNumNodes(); i++) { |
| 137 |
indicesGammaDofs[Interface_->getEntity(0)->getGammaDofID(i,k)] = Interface_->getEntity(0)->getGlobalDofID(i,k); |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
const GO INVALID = Teuchos::OrdinalTraits<GO>::invalid(); |
| 142 |
XMapPtr map = MapFactory<LO,GO,NO>::Build(matrix->getRowMap()->lib(),INVALID,indicesGammaDofs(),0,MpiComm_); |
| 143 |
matrix = FROSch::ExtractLocalSubdomainMatrix(matrix.getConst(),map.getConst(),ScalarTraits<SC>::one()); |
| 144 |
|
| 145 |
// Operate on hierarchy |
| 146 |
for (UN i=0; i<EntitySetVector_.size(); i++) { |
| 147 |
EntitySetVector_[i]->divideUnconnectedEntities(matrix,MpiComm_->getRank()); |
| 148 |
} |
| 149 |
|
| 150 |
/* |
| 151 |
LO numSeparateEdges = Edges_->divideUnconnectedEntities(matrix,MpiComm_->getRank()); |
| 152 |
LO numSeparateFaces = Faces_->divideUnconnectedEntities(matrix,MpiComm_->getRank()); |
| 153 |
|
| 154 |
if (Verbose_ && Verbosity_==All) { |
| 155 |
cout << "\n\ |
| 156 |
--------------------------------------------\n\ |
| 157 |
# separate edges: --- " << numSeparateEdges << "\n\ |
| 158 |
# separate faces: --- " << numSeparateFaces << "\n\ |
| 159 |
--------------------------------------------\n"; |
| 160 |
} |
| 161 |
*/ |
| 162 |
|
| 163 |
removeEmptyEntities(); |
| 164 |
|
| 165 |
// We need to set the unique ID; otherwise, we cannot sort entities |
| 166 |
for (UN i=0; i<EntitySetVector_.size(); i++) { |
| 167 |
EntitySetVector_[i]->setUniqueIDToFirstGlobalNodeID(); |
| 168 |
} |
| 169 |
return 0; |
| 170 |
} |
| 171 |
|
| 172 |
template <class SC,class LO,class GO,class NO> |
| 173 |
int DDInterface<SC,LO,GO,NO>::flagEntities(ConstXMultiVectorPtr nodeList) |
| 174 |
{ |
| 175 |
FROSCH_DETAILTIMER_START_LEVELID(flagEntitiesTime,"DDInterface::flagEntities"); |
| 176 |
for (UN l=0; l<EntitySetVector_.size(); l++) { |
| 177 |
EntitySetVector_[l]->flagNodes(); |
| 178 |
EntitySetVector_[l]->flagShortEntities(); |
| 179 |
} |
| 180 |
if (!nodeList.is_null()) { |
| 181 |
for (UN l=0; l<EntitySetVector_.size(); l++) { |
| 182 |
EntitySetVector_[l]->flagStraightEntities(Dimension_,nodeList); |
| 183 |
} |
| 184 |
} |
| 185 |
return 0; |
| 186 |
} |
| 187 |
|
| 188 |
template <class SC,class LO,class GO,class NO> |
| 189 |
int DDInterface<SC,LO,GO,NO>::removeEmptyEntities() |
| 190 |
{ |
| 191 |
FROSCH_DETAILTIMER_START_LEVELID(removeEmptyEntitiesTime,"DDInterface::removeEmptyEntities"); |
| 192 |
//if (Verbose_ && Verbosity_==All) cout << "FROSch::DDInterface : Removing empty interface components" << endl; |
| 193 |
|
| 194 |
for (UN l=0; l<EntitySetVector_.size(); l++) { |
| 195 |
EntitySetVector_[l]->removeEmptyEntities(); |
| 196 |
} |
| 197 |
return 0; |
| 198 |
} |
| 199 |
|
| 200 |
template <class SC,class LO,class GO,class NO> |
| 201 |
int DDInterface<SC,LO,GO,NO>::sortVerticesEdgesFaces(ConstXMultiVectorPtr nodeList) |
| 202 |
{ |
| 203 |
FROSCH_DETAILTIMER_START_LEVELID(sortVerticesEdgesFacesTime,"DDInterface::sortVerticesEdgesFaces"); |
| 204 |
//if (Verbose_ && Verbosity_==All) cout << "FROSch::DDInterface : Sorting interface components" << endl; |
| 205 |
|
| 206 |
// Clear EntitySets if non-empty |
| 207 |
if (Vertices_->getNumEntities()>0) Vertices_.reset(new EntitySet<SC,LO,GO,NO>(VertexType)); |
| 208 |
if (ShortEdges_->getNumEntities()>0) ShortEdges_.reset(new EntitySet<SC,LO,GO,NO>(EdgeType)); |
| 209 |
if (StraightEdges_->getNumEntities()>0) StraightEdges_.reset(new EntitySet<SC,LO,GO,NO>(EdgeType)); |
| 210 |
if (Edges_->getNumEntities()>0) Edges_.reset(new EntitySet<SC,LO,GO,NO>(EdgeType)); |
| 211 |
if (Faces_->getNumEntities()>0) Faces_.reset(new EntitySet<SC,LO,GO,NO>(FaceType)); |
| 212 |
|
| 213 |
flagEntities(nodeList); |
| 214 |
|
| 215 |
// Make sure that we do not sort any empty entities |
| 216 |
removeEmptyEntities(); |
| 217 |
|
| 218 |
for (UN l=0; l<EntitySetVector_.size(); l++) { |
| 219 |
switch (l) { |
| 220 |
case 0: |
| 221 |
FROSCH_ASSERT(EntitySetVector_[l]->getNumEntities()==0,"FROSch::DDInterface: This case is impossible."); |
| 222 |
break; |
| 223 |
case 1: |
| 224 |
FROSCH_ASSERT(EntitySetVector_[l]->getNumEntities()==0,"FROSch::DDInterface: In this case, the entity is interior to the subdomain."); |
| 225 |
break; |
| 226 |
case 2: |
| 227 |
for (UN i=0; i<EntitySetVector_[l]->getNumEntities(); i++) { |
| 228 |
switch (EntitySetVector_[l]->getEntity(i)->getEntityFlag()) { |
| 229 |
case DefaultFlag: // By default, an entity which belongs to 2 subdomains is a face |
| 230 |
EntitySetVector_[l]->getEntity(i)->resetEntityType(FaceType); |
| 231 |
Faces_->addEntity(EntitySetVector_[l]->getEntity(i)); |
| 232 |
break; |
| 233 |
case StraightFlag: // If an entity is straight, it is always a straight edge |
| 234 |
EntitySetVector_[l]->getEntity(i)->resetEntityType(EdgeType); |
| 235 |
StraightEdges_->addEntity(EntitySetVector_[l]->getEntity(i)); |
| 236 |
break; |
| 237 |
case ShortFlag: // If an entity is a short, it is always a short edge |
| 238 |
EntitySetVector_[l]->getEntity(i)->resetEntityType(EdgeType); |
| 239 |
ShortEdges_->addEntity(EntitySetVector_[l]->getEntity(i)); |
| 240 |
break; |
| 241 |
case NodeFlag: // If an entity is a node, it is always a vertex |
| 242 |
EntitySetVector_[l]->getEntity(i)->resetEntityType(VertexType); |
| 243 |
Vertices_->addEntity(EntitySetVector_[l]->getEntity(i)); |
| 244 |
break; |
| 245 |
default: |
| 246 |
break; |
| 247 |
} |
| 248 |
} |
| 249 |
break; |
| 250 |
default: |
| 251 |
for (UN i=0; i<EntitySetVector_[l]->getNumEntities(); i++) { |
| 252 |
switch (EntitySetVector_[l]->getEntity(i)->getEntityFlag()) { |
| 253 |
case DefaultFlag: // By default, an entity which belongs to more than 2 subdomains is an edge |
| 254 |
EntitySetVector_[l]->getEntity(i)->resetEntityType(EdgeType); |
| 255 |
Edges_->addEntity(EntitySetVector_[l]->getEntity(i)); |
| 256 |
break; |
| 257 |
case StraightFlag: // If an entity is straight, it is always a straight edge |
| 258 |
EntitySetVector_[l]->getEntity(i)->resetEntityType(EdgeType); |
| 259 |
StraightEdges_->addEntity(EntitySetVector_[l]->getEntity(i)); |
| 260 |
break; |
| 261 |
case ShortFlag: // If an entity is a short, it is always a short edge |
| 262 |
EntitySetVector_[l]->getEntity(i)->resetEntityType(EdgeType); |
| 263 |
ShortEdges_->addEntity(EntitySetVector_[l]->getEntity(i)); |
| 264 |
break; |
| 265 |
case NodeFlag: // If an entity is a node, it is always a vertex |
| 266 |
EntitySetVector_[l]->getEntity(i)->resetEntityType(VertexType); |
| 267 |
Vertices_->addEntity(EntitySetVector_[l]->getEntity(i)); |
| 268 |
break; |
| 269 |
default: |
| 270 |
break; |
| 271 |
} |
| 272 |
} |
| 273 |
break; |
| 274 |
} |
| 275 |
|
| 276 |
} |
| 277 |
return 0; |
| 278 |
} |
| 279 |
|
| 280 |
template <class SC,class LO,class GO,class NO> |
| 281 |
int DDInterface<SC,LO,GO,NO>::buildEntityMaps(bool buildVerticesMap, |
| 282 |
bool buildShortEdgesMap, |
| 283 |
bool buildStraightEdgesMap, |
| 284 |
bool buildEdgesMap, |
| 285 |
bool buildFacesMap, |
| 286 |
bool buildRootsMap, |
| 287 |
bool buildLeafsMap) |
| 288 |
{ |
| 289 |
FROSCH_DETAILTIMER_START_LEVELID(buildEntityMapsTime,"DDInterface::buildEntityMaps"); |
| 290 |
//if (Verbose_ && Verbosity_==All) cout << "FROSch::DDInterface : Building global interface component maps" << endl; |
| 291 |
|
| 292 |
if (buildVerticesMap) Vertices_->buildEntityMap(NodesMap_); |
| 293 |
if (buildShortEdgesMap) ShortEdges_->buildEntityMap(NodesMap_); |
| 294 |
if (buildStraightEdgesMap) StraightEdges_->buildEntityMap(NodesMap_); |
| 295 |
if (buildEdgesMap) Edges_->buildEntityMap(NodesMap_); |
| 296 |
if (buildFacesMap) Faces_->buildEntityMap(NodesMap_); |
| 297 |
if (buildRootsMap) Roots_->buildEntityMap(NodesMap_); |
| 298 |
if (buildLeafsMap) Leafs_->buildEntityMap(NodesMap_); |
| 299 |
|
| 300 |
if (Verbosity_==All) { |
| 301 |
FROSCH_DETAILTIMER_START_LEVELID(printStatisticsTime,"print statistics"); |
| 302 |
// Count entities |
| 303 |
GOVec globalVec(7); |
| 304 |
LOVec localVec(7); |
| 305 |
LOVec sumVec(7); |
| 306 |
SCVec avgVec(7); |
| 307 |
LOVec minVec(7); |
| 308 |
LOVec maxVec(7); |
| 309 |
if (buildVerticesMap) { |
| 310 |
globalVec[0] = Vertices_->getEntityMap()->getMaxAllGlobalIndex(); |
| 311 |
if (NodesMap_->lib()==UseEpetra || Vertices_->getEntityMap()->getGlobalNumElements()>0) { |
| 312 |
globalVec[0] += 1; |
| 313 |
} |
| 314 |
if (globalVec[0]<0) globalVec[0] = 0; |
| 315 |
localVec[0] = (LO) max((LO) Vertices_->getEntityMap()->getLocalNumElements(),(LO) 0); |
| 316 |
reduceAll(*this->MpiComm_,REDUCE_SUM,localVec[0],ptr(&sumVec[0])); |
| 317 |
avgVec[0] = max(sumVec[0]/double(MpiComm_->getSize()),0.0); |
| 318 |
reduceAll(*MpiComm_,REDUCE_MIN,localVec[0],ptr(&minVec[0])); |
| 319 |
reduceAll(*MpiComm_,REDUCE_MAX,localVec[0],ptr(&maxVec[0])); |
| 320 |
} else { |
| 321 |
globalVec[0] = -1; |
| 322 |
localVec[0] = -1; |
| 323 |
avgVec[0] = -1; |
| 324 |
minVec[0] = -1; |
| 325 |
maxVec[0] = -1; |
| 326 |
sumVec[0] = -1; |
| 327 |
} |
| 328 |
if (buildShortEdgesMap) { |
| 329 |
globalVec[1] = ShortEdges_->getEntityMap()->getMaxAllGlobalIndex(); |
| 330 |
if (NodesMap_->lib()==UseEpetra || ShortEdges_->getEntityMap()->getGlobalNumElements()>0) { |
| 331 |
globalVec[1] += 1; |
| 332 |
} |
| 333 |
if (globalVec[1]<0) globalVec[1] = 0; |
| 334 |
localVec[1] = (LO) max((LO) ShortEdges_->getEntityMap()->getLocalNumElements(),(LO) 0); |
| 335 |
reduceAll(*this->MpiComm_,REDUCE_SUM,localVec[1],ptr(&sumVec[1])); |
| 336 |
avgVec[1] = max(sumVec[1]/double(MpiComm_->getSize()),0.0); |
| 337 |
reduceAll(*MpiComm_,REDUCE_MIN,localVec[1],ptr(&minVec[1])); |
| 338 |
reduceAll(*MpiComm_,REDUCE_MAX,localVec[1],ptr(&maxVec[1])); |
| 339 |
} else { |
| 340 |
globalVec[1] = -1; |
| 341 |
localVec[1] = -1; |
| 342 |
avgVec[1] = -1; |
| 343 |
minVec[1] = -1; |
| 344 |
maxVec[1] = -1; |
| 345 |
sumVec[1] = -1; |
| 346 |
} |
| 347 |
if (buildStraightEdgesMap) { |
| 348 |
globalVec[2] = StraightEdges_->getEntityMap()->getMaxAllGlobalIndex(); |
| 349 |
if (NodesMap_->lib()==UseEpetra || StraightEdges_->getEntityMap()->getGlobalNumElements()>0) { |
| 350 |
globalVec[2] += 1; |
| 351 |
} |
| 352 |
if (globalVec[2]<0) globalVec[2] = 0; |
| 353 |
localVec[2] = (LO) max((LO) StraightEdges_->getEntityMap()->getLocalNumElements(),(LO) 0); |
| 354 |
reduceAll(*this->MpiComm_,REDUCE_SUM,localVec[2],ptr(&sumVec[2])); |
| 355 |
avgVec[2] = max(sumVec[2]/double(MpiComm_->getSize()),0.0); |
| 356 |
reduceAll(*MpiComm_,REDUCE_MIN,localVec[2],ptr(&minVec[2])); |
| 357 |
reduceAll(*MpiComm_,REDUCE_MAX,localVec[2],ptr(&maxVec[2])); |
| 358 |
} else { |
| 359 |
globalVec[2] = -1; |
| 360 |
localVec[2] = -1; |
| 361 |
avgVec[2] = -1; |
| 362 |
minVec[2] = -1; |
| 363 |
maxVec[2] = -1; |
| 364 |
sumVec[2] = -1; |
| 365 |
} |
| 366 |
if (buildEdgesMap) { |
| 367 |
globalVec[3] = (LO) Edges_->getEntityMap()->getMaxAllGlobalIndex(); |
| 368 |
if (NodesMap_->lib()==UseEpetra || Edges_->getEntityMap()->getGlobalNumElements()>0) { |
| 369 |
globalVec[3] += 1; |
| 370 |
} |
| 371 |
if (globalVec[3]<0) globalVec[3] = 0; |
| 372 |
localVec[3] = max((LO) Edges_->getEntityMap()->getLocalNumElements(),(LO) 0); |
| 373 |
reduceAll(*this->MpiComm_,REDUCE_SUM,localVec[3],ptr(&sumVec[3])); |
| 374 |
avgVec[3] = max(sumVec[3]/double(MpiComm_->getSize()),0.0); |
| 375 |
reduceAll(*MpiComm_,REDUCE_MIN,localVec[3],ptr(&minVec[3])); |
| 376 |
reduceAll(*MpiComm_,REDUCE_MAX,localVec[3],ptr(&maxVec[3])); |
| 377 |
} else { |
| 378 |
globalVec[3] = -1; |
| 379 |
localVec[3] = -1; |
| 380 |
avgVec[3] = -1; |
| 381 |
minVec[3] = -1; |
| 382 |
maxVec[3] = -1; |
| 383 |
sumVec[3] = -1; |
| 384 |
} |
| 385 |
if (buildFacesMap) { |
| 386 |
globalVec[4] = (LO) Faces_->getEntityMap()->getMaxAllGlobalIndex(); |
| 387 |
if (NodesMap_->lib()==UseEpetra || Faces_->getEntityMap()->getGlobalNumElements()>0) { |
| 388 |
globalVec[4] += 1; |
| 389 |
} |
| 390 |
if (globalVec[4]<0) globalVec[4] = 0; |
| 391 |
localVec[4] = max((LO) Faces_->getEntityMap()->getLocalNumElements(),(LO) 0); |
| 392 |
reduceAll(*this->MpiComm_,REDUCE_SUM,localVec[4],ptr(&sumVec[4])); |
| 393 |
avgVec[4] = max(sumVec[4]/double(MpiComm_->getSize()),0.0); |
| 394 |
reduceAll(*MpiComm_,REDUCE_MIN,localVec[4],ptr(&minVec[4])); |
| 395 |
reduceAll(*MpiComm_,REDUCE_MAX,localVec[4],ptr(&maxVec[4])); |
| 396 |
} else { |
| 397 |
globalVec[4] = -1; |
| 398 |
localVec[4] = -1; |
| 399 |
avgVec[4] = -1; |
| 400 |
minVec[4] = -1; |
| 401 |
maxVec[4] = -1; |
| 402 |
sumVec[4] = -1; |
| 403 |
} |
| 404 |
if (buildRootsMap) { |
| 405 |
globalVec[5] = Roots_->getEntityMap()->getMaxAllGlobalIndex(); |
| 406 |
if (NodesMap_->lib()==UseEpetra || Roots_->getEntityMap()->getGlobalNumElements()>0) { |
| 407 |
globalVec[5] += 1; |
| 408 |
} |
| 409 |
if (globalVec[5]<0) globalVec[5] = 0; |
| 410 |
localVec[5] = (LO) max((LO) Roots_->getEntityMap()->getLocalNumElements(),(LO) 0); |
| 411 |
reduceAll(*this->MpiComm_,REDUCE_SUM,localVec[5],ptr(&sumVec[5])); |
| 412 |
avgVec[5] = max(sumVec[5]/double(MpiComm_->getSize()),0.0); |
| 413 |
reduceAll(*MpiComm_,REDUCE_MIN,localVec[5],ptr(&minVec[5])); |
| 414 |
reduceAll(*MpiComm_,REDUCE_MAX,localVec[5],ptr(&maxVec[5])); |
| 415 |
} else { |
| 416 |
globalVec[5] = -1; |
| 417 |
localVec[5] = -1; |
| 418 |
avgVec[5] = -1; |
| 419 |
minVec[5] = -1; |
| 420 |
maxVec[5] = -1; |
| 421 |
sumVec[5] = -1; |
| 422 |
} |
| 423 |
if (buildLeafsMap) { |
| 424 |
globalVec[6] = Leafs_->getEntityMap()->getMaxAllGlobalIndex(); |
| 425 |
if (NodesMap_->lib()==UseEpetra || Leafs_->getEntityMap()->getGlobalNumElements()>0) { |
| 426 |
globalVec[6] += 1; |
| 427 |
} |
| 428 |
if (globalVec[6]<0) globalVec[6] = 0; |
| 429 |
localVec[6] = (LO) max((LO) Leafs_->getEntityMap()->getLocalNumElements(),(LO) 0); |
| 430 |
reduceAll(*this->MpiComm_,REDUCE_SUM,localVec[6],ptr(&sumVec[6])); |
| 431 |
avgVec[6] = max(sumVec[6]/double(MpiComm_->getSize()),0.0); |
| 432 |
reduceAll(*MpiComm_,REDUCE_MIN,localVec[6],ptr(&minVec[6])); |
| 433 |
reduceAll(*MpiComm_,REDUCE_MAX,localVec[6],ptr(&maxVec[6])); |
| 434 |
} else { |
| 435 |
globalVec[6] = -1; |
| 436 |
localVec[6] = -1; |
| 437 |
avgVec[6] = -1; |
| 438 |
minVec[6] = -1; |
| 439 |
maxVec[6] = -1; |
| 440 |
sumVec[6] = -1; |
| 441 |
} |
| 442 |
|
| 443 |
for (UN i=0; i<globalVec.size(); i++) { |
| 444 |
if (globalVec[i]<0) { |
| 445 |
globalVec[i] = -1; |
| 446 |
} |
| 447 |
} |
| 448 |
|
| 449 |
NumEntity_ = globalVec; |
| 450 |
|
| 451 |
if (Verbose_) { |
| 452 |
cout |
| 453 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 454 |
<< setw(89) << "-----------------------------------------------------------------------------------------" |
| 455 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 456 |
<< "| " |
| 457 |
<< left << setw(74) << "> Interface Statistics " << right << setw(8) << "(Level " << setw(2) << LevelID_ << ")" |
| 458 |
<< " |" |
| 459 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 460 |
<< setw(89) << "=========================================================================================" |
| 461 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 462 |
<< "| " << left << setw(41) << "Interface communication strategy" << right |
| 463 |
<< " | " << setw(41) << CommStrategy_ |
| 464 |
<< " |" |
| 465 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 466 |
<< setw(89) << "-----------------------------------------------------------------------------------------" |
| 467 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 468 |
<< "| " << left << setw(20) << " " << right |
| 469 |
<< " | " << setw(10) << "total" |
| 470 |
<< " | " << setw(10) << "avg" |
| 471 |
<< " | " << setw(10) << "min" |
| 472 |
<< " | " << setw(10) << "max" |
| 473 |
<< " | " << setw(10) << "global sum" |
| 474 |
<< " |" |
| 475 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 476 |
<< setw(89) << "-----------------------------------------------------------------------------------------" |
| 477 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 478 |
<< "| " << left << setw(20) << "Vertices" << right |
| 479 |
<< " | "; globalVec[0]<0 ? cout << setw(10) << " " : cout << setw(10) << globalVec[0]; cout |
| 480 |
<< " | "; avgVec[0]<0 ? cout << setw(10) << " " : cout << setw(10) << setprecision(5) << avgVec[0]; cout |
| 481 |
<< " | "; minVec[0]<0 ? cout << setw(10) << " " : cout << setw(10) << minVec[0]; cout |
| 482 |
<< " | "; maxVec[0]<0 ? cout << setw(10) << " " : cout << setw(10) << maxVec[0]; cout |
| 483 |
<< " | "; sumVec[0]<0 ? cout << setw(10) << " " : cout << setw(10) << sumVec[0]; cout |
| 484 |
<< " |" |
| 485 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 486 |
<< "| " << left << setw(20) << "Short edges" << right |
| 487 |
<< " | "; globalVec[1]<0 ? cout << setw(10) << " " : cout << setw(10) << globalVec[1]; cout |
| 488 |
<< " | "; avgVec[1]<0 ? cout << setw(10) << " " : cout << setw(10) << setprecision(5) << avgVec[1]; cout |
| 489 |
<< " | "; minVec[1]<0 ? cout << setw(10) << " " : cout << setw(10) << minVec[1]; cout |
| 490 |
<< " | "; maxVec[1]<0 ? cout << setw(10) << " " : cout << setw(10) << maxVec[1]; cout |
| 491 |
<< " | "; sumVec[1]<0 ? cout << setw(10) << " " : cout << setw(10) << sumVec[1]; cout |
| 492 |
<< " |" |
| 493 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 494 |
<< "| " << left << setw(20) << "Straight edges" << right |
| 495 |
<< " | "; globalVec[2]<0 ? cout << setw(10) << " " : cout << setw(10) << globalVec[2]; cout |
| 496 |
<< " | "; avgVec[2]<0 ? cout << setw(10) << " " : cout << setw(10) << setprecision(5) << avgVec[2]; cout |
| 497 |
<< " | "; minVec[2]<0 ? cout << setw(10) << " " : cout << setw(10) << minVec[2]; cout |
| 498 |
<< " | "; maxVec[2]<0 ? cout << setw(10) << " " : cout << setw(10) << maxVec[2]; cout |
| 499 |
<< " | "; sumVec[2]<0 ? cout << setw(10) << " " : cout << setw(10) << sumVec[2]; cout |
| 500 |
<< " |" |
| 501 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 502 |
<< "| " << left << setw(20) << "Edges" << right |
| 503 |
<< " | "; globalVec[3]<0 ? cout << setw(10) << " " : cout << setw(10) << globalVec[3]; cout |
| 504 |
<< " | "; avgVec[3]<0 ? cout << setw(10) << " " : cout << setw(10) << setprecision(5) << avgVec[3]; cout |
| 505 |
<< " | "; minVec[3]<0 ? cout << setw(10) << " " : cout << setw(10) << minVec[3]; cout |
| 506 |
<< " | "; maxVec[3]<0 ? cout << setw(10) << " " : cout << setw(10) << maxVec[3]; cout |
| 507 |
<< " | "; sumVec[3]<0 ? cout << setw(10) << " " : cout << setw(10) << sumVec[3]; cout |
| 508 |
<< " |" |
| 509 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 510 |
<< "| " << left << setw(20) << "Faces" << right |
| 511 |
<< " | "; globalVec[4]<0 ? cout << setw(10) << " " : cout << setw(10) << globalVec[4]; cout |
| 512 |
<< " | "; avgVec[4]<0 ? cout << setw(10) << " " : cout << setw(10) << setprecision(5) << avgVec[4]; cout |
| 513 |
<< " | "; minVec[4]<0 ? cout << setw(10) << " " : cout << setw(10) << minVec[4]; cout |
| 514 |
<< " | "; maxVec[4]<0 ? cout << setw(10) << " " : cout << setw(10) << maxVec[4]; cout |
| 515 |
<< " | "; sumVec[4]<0 ? cout << setw(10) << " " : cout << setw(10) << sumVec[4]; cout |
| 516 |
<< " |" |
| 517 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 518 |
<< "| " << left << setw(20) << "Roots" << right |
| 519 |
<< " | "; globalVec[5]<0 ? cout << setw(10) << " " : cout << setw(10) << globalVec[5]; cout |
| 520 |
<< " | "; avgVec[5]<0 ? cout << setw(10) << " " : cout << setw(10) << setprecision(5) << avgVec[5]; cout |
| 521 |
<< " | "; minVec[5]<0 ? cout << setw(10) << " " : cout << setw(10) << minVec[5]; cout |
| 522 |
<< " | "; maxVec[5]<0 ? cout << setw(10) << " " : cout << setw(10) << maxVec[5]; cout |
| 523 |
<< " | "; sumVec[5]<0 ? cout << setw(10) << " " : cout << setw(10) << sumVec[5]; cout |
| 524 |
<< " |" |
| 525 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 526 |
<< "| " << left << setw(20) << "Leafs" << right |
| 527 |
<< " | "; globalVec[6]<0 ? cout << setw(10) << " " : cout << setw(10) << globalVec[6]; cout |
| 528 |
<< " | "; avgVec[6]<0 ? cout << setw(10) << " " : cout << setw(10) << setprecision(5) << avgVec[6]; cout |
| 529 |
<< " | "; minVec[6]<0 ? cout << setw(10) << " " : cout << setw(10) << minVec[6]; cout |
| 530 |
<< " | "; maxVec[6]<0 ? cout << setw(10) << " " : cout << setw(10) << maxVec[6]; cout |
| 531 |
<< " | "; sumVec[6]<0 ? cout << setw(10) << " " : cout << setw(10) << sumVec[6]; cout |
| 532 |
<< " |" |
| 533 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 534 |
<< setw(89) << "-----------------------------------------------------------------------------------------" |
| 535 |
<< endl; |
| 536 |
} |
| 537 |
} |
| 538 |
|
| 539 |
return 0; |
| 540 |
} |
| 541 |
|
| 542 |
template <class SC,class LO,class GO,class NO> |
| 543 |
int DDInterface<SC,LO,GO,NO>::buildEntityHierarchy() |
| 544 |
{ |
| 545 |
FROSCH_DETAILTIMER_START_LEVELID(buildEntityHierarchyTime,"DDInterface::buildEntityHierarchy"); |
| 546 |
//if (Verbose_ && Verbosity_==All) cout << "FROSch::DDInterface : Building hierarchy of interface components" << endl; |
| 547 |
|
| 548 |
// Build hierarchy |
| 549 |
for (UN i=0; i<EntitySetVector_.size(); i++) { |
| 550 |
for (UN j=i+1; j<EntitySetVector_.size(); j++) { |
| 551 |
EntitySetVector_[i]->findAncestorsInSet(EntitySetVector_[j]); |
| 552 |
} |
| 553 |
} |
| 554 |
|
| 555 |
// Find roots |
| 556 |
for (UN i=0; i<EntitySetVector_.size(); i++) { |
| 557 |
EntitySetPtr tmpRoots = EntitySetVector_[i]->findRoots(); |
| 558 |
Roots_->addEntitySet(tmpRoots); |
| 559 |
} |
| 560 |
Roots_->sortUnique(); |
| 561 |
Roots_->setRootID(); |
| 562 |
|
| 563 |
// Find Leafs |
| 564 |
for (UN i=0; i<EntitySetVector_.size(); i++) { |
| 565 |
EntitySetPtr tmpLeafs = EntitySetVector_[i]->findLeafs(); |
| 566 |
Leafs_->addEntitySet(tmpLeafs); |
| 567 |
} |
| 568 |
Leafs_->sortUnique(); |
| 569 |
Leafs_->setLeafID(); |
| 570 |
return 0; |
| 571 |
} |
| 572 |
|
| 573 |
template <class SC,class LO,class GO,class NO> |
| 574 |
int DDInterface<SC,LO,GO,NO>::computeDistancesToRoots(UN dimension, |
| 575 |
ConstXMultiVectorPtr &nodeList, |
| 576 |
DistanceFunction distanceFunction) |
| 577 |
{ |
| 578 |
FROSCH_DETAILTIMER_START_LEVELID(computeDistancesToRootsTime,"DDInterface::computeDistancesToRoots"); |
| 579 |
//if (Verbose_ && Verbosity_==All) cout << "FROSch::DDInterface : Computing distances to the coarse nodes" << endl; |
| 580 |
|
| 581 |
for (UN i=0; i<EntitySetVector_.size(); i++) { |
| 582 |
EntitySetVector_[i]->computeDistancesToRoots(dimension,nodeList,distanceFunction); |
| 583 |
} |
| 584 |
return 0; |
| 585 |
} |
| 586 |
|
| 587 |
template <class SC,class LO,class GO,class NO> |
| 588 |
int DDInterface<SC,LO,GO,NO>::identifyConnectivityEntities(UNVecPtr multiplicities, |
| 589 |
EntityFlagVecPtr flags) |
| 590 |
{ |
| 591 |
FROSCH_DETAILTIMER_START_LEVELID(identifyConnectivityEntitiesTime,"DDInterface::identifyConnectivityEntities"); |
| 592 |
//if (Verbose_ && Verbosity_==All) cout << "FROSch::DDInterface : Preparing subdomain graph" << endl; |
| 593 |
|
| 594 |
if (multiplicities.is_null()) { |
| 595 |
multiplicities = UNVecPtr(1,2); |
| 596 |
} |
| 597 |
if (flags.is_null()) { |
| 598 |
flags = EntityFlagVecPtr(4); |
| 599 |
flags[0] = DefaultFlag; |
| 600 |
flags[1] = StraightFlag; |
| 601 |
flags[2] = ShortFlag; |
| 602 |
flags[3] = NodeFlag; |
| 603 |
} |
| 604 |
|
| 605 |
for (UN j=0; j<multiplicities.size(); j++) { |
| 606 |
for (UN i=0; i<EntitySetVector_[multiplicities[j]]->getNumEntities(); i++) { |
| 607 |
if (binary_search(flags.begin(),flags.end(),EntitySetVector_[multiplicities[j]]->getEntity(i)->getEntityFlag())) { |
| 608 |
ConnectivityEntities_->addEntity(EntitySetVector_[multiplicities[j]]->getEntity(i)); |
| 609 |
} |
| 610 |
} |
| 611 |
} |
| 612 |
return 0; |
| 613 |
} |
| 614 |
|
| 615 |
template <class SC,class LO,class GO,class NO> |
| 616 |
typename DDInterface<SC,LO,GO,NO>::UN DDInterface<SC,LO,GO,NO>::getDimension() const |
| 617 |
{ |
| 618 |
return Dimension_; |
| 619 |
} |
| 620 |
|
| 621 |
template <class SC,class LO,class GO,class NO> |
| 622 |
typename DDInterface<SC,LO,GO,NO>::UN DDInterface<SC,LO,GO,NO>::getDofsPerNode() const |
| 623 |
{ |
| 624 |
return DofsPerNode_; |
| 625 |
} |
| 626 |
|
| 627 |
template <class SC,class LO,class GO,class NO> |
| 628 |
LO DDInterface<SC,LO,GO,NO>::getNumMyNodes() const |
| 629 |
{ |
| 630 |
return NumMyNodes_; |
| 631 |
} |
| 632 |
|
| 633 |
template <class SC,class LO,class GO,class NO> |
| 634 |
typename DDInterface<SC,LO,GO,NO>::EntitySetConstPtr & DDInterface<SC,LO,GO,NO>::getVertices() const |
| 635 |
{ |
| 636 |
return Vertices_; |
| 637 |
} |
| 638 |
|
| 639 |
template <class SC,class LO,class GO,class NO> |
| 640 |
typename DDInterface<SC,LO,GO,NO>::EntitySetConstPtr & DDInterface<SC,LO,GO,NO>::getShortEdges() const |
| 641 |
{ |
| 642 |
return ShortEdges_; |
| 643 |
} |
| 644 |
|
| 645 |
template <class SC,class LO,class GO,class NO> |
| 646 |
typename DDInterface<SC,LO,GO,NO>::EntitySetConstPtr & DDInterface<SC,LO,GO,NO>::getStraightEdges() const |
| 647 |
{ |
| 648 |
return StraightEdges_; |
| 649 |
} |
| 650 |
|
| 651 |
template <class SC,class LO,class GO,class NO> |
| 652 |
typename DDInterface<SC,LO,GO,NO>::EntitySetConstPtr & DDInterface<SC,LO,GO,NO>::getEdges() const |
| 653 |
{ |
| 654 |
return Edges_; |
| 655 |
} |
| 656 |
|
| 657 |
template <class SC,class LO,class GO,class NO> |
| 658 |
typename DDInterface<SC,LO,GO,NO>::EntitySetConstPtr & DDInterface<SC,LO,GO,NO>::getFaces() const |
| 659 |
{ |
| 660 |
return Faces_; |
| 661 |
} |
| 662 |
|
| 663 |
template <class SC,class LO,class GO,class NO> |
| 664 |
typename DDInterface<SC,LO,GO,NO>::EntitySetConstPtr & DDInterface<SC,LO,GO,NO>::getInterface() const |
| 665 |
{ |
| 666 |
return Interface_; |
| 667 |
} |
| 668 |
|
| 669 |
template <class SC,class LO,class GO,class NO> |
| 670 |
typename DDInterface<SC,LO,GO,NO>::EntitySetConstPtr & DDInterface<SC,LO,GO,NO>::getInterior() const |
| 671 |
{ |
| 672 |
return Interior_; |
| 673 |
} |
| 674 |
|
| 675 |
template <class SC,class LO,class GO,class NO> |
| 676 |
typename DDInterface<SC,LO,GO,NO>::EntitySetConstPtr & DDInterface<SC,LO,GO,NO>::getRoots() const |
| 677 |
{ |
| 678 |
return Roots_; |
| 679 |
} |
| 680 |
|
| 681 |
template <class SC,class LO,class GO,class NO> |
| 682 |
typename DDInterface<SC,LO,GO,NO>::EntitySetConstPtr & DDInterface<SC,LO,GO,NO>::getLeafs() const |
| 683 |
{ |
| 684 |
return Leafs_; |
| 685 |
} |
| 686 |
|
| 687 |
template <class SC,class LO,class GO,class NO> |
| 688 |
typename DDInterface<SC,LO,GO,NO>::EntitySetPtrConstVecPtr & DDInterface<SC,LO,GO,NO>::getEntitySetVector() const |
| 689 |
{ |
| 690 |
return EntitySetVector_; |
| 691 |
} |
| 692 |
|
| 693 |
template <class SC,class LO,class GO,class NO> |
| 694 |
typename DDInterface<SC,LO,GO,NO>::GOVec DDInterface<SC,LO,GO,NO>::getNumEnt() const |
| 695 |
{ |
| 696 |
return NumEntity_; |
| 697 |
} |
| 698 |
|
| 699 |
template <class SC,class LO,class GO,class NO> |
| 700 |
typename DDInterface<SC,LO,GO,NO>::EntitySetConstPtr & DDInterface<SC,LO,GO,NO>::getConnectivityEntities() const |
| 701 |
{ |
| 702 |
return ConnectivityEntities_; |
| 703 |
} |
| 704 |
|
| 705 |
template <class SC,class LO,class GO,class NO> |
| 706 |
typename DDInterface<SC,LO,GO,NO>::ConstXMapPtr DDInterface<SC,LO,GO,NO>::getNodesMap() const |
| 707 |
{ |
| 708 |
return NodesMap_.getConst(); |
| 709 |
} |
| 710 |
|
| 711 |
template <class SC,class LO,class GO,class NO> |
| 712 |
int DDInterface<SC,LO,GO,NO>::communicateLocalComponents(IntVecVecPtr &componentsSubdomains, |
| 713 |
IntVecVec &componentsSubdomainsUnique) |
| 714 |
{ |
| 715 |
FROSCH_DETAILTIMER_START_LEVELID(communicateLocalComponentsTime,"DDInterface::communicateLocalComponents"); |
| 716 |
//if (Verbose_ && Verbosity_==All) cout << "FROSch::DDInterface : Communicating nodes" << endl; |
| 717 |
|
| 718 |
if (NodesMap_->lib() == UseEpetra && CommStrategy_ == CreateOneToOneMap) { |
| 719 |
FROSCH_WARNING("FROSch::DDInterface",Verbose_,"CreateOneToOneMap communication strategy does not work for Epetra => Switching to CommCrsGraph."); |
| 720 |
CommStrategy_ = CommCrsGraph; |
| 721 |
} |
| 722 |
|
| 723 |
// Different communication strategies |
| 724 |
const GO INVALID = Teuchos::OrdinalTraits<GO>::invalid(); |
| 725 |
switch (CommStrategy_) { |
| 726 |
case CommCrsMatrix: |
| 727 |
{ |
| 728 |
UniqueNodesMap_ = BuildUniqueMap<LO,GO,NO>(NodesMap_); |
| 729 |
RCP<Matrix<SC,LO,GO,NO> > commMat = MatrixFactory<SC,LO,GO,NO>::Build(NodesMap_,10); |
| 730 |
RCP<Matrix<SC,LO,GO,NO> > commMatTmp = MatrixFactory<SC,LO,GO,NO>::Build(UniqueNodesMap_,10); |
| 731 |
XExportPtr commExporter = ExportFactory<LO,GO,NO>::Build(NodesMap_,UniqueNodesMap_); |
| 732 |
|
| 733 |
Array<SC> one(1,ScalarTraits<SC>::one()); |
| 734 |
Array<GO> myPID(1,MpiComm_->getRank()); |
| 735 |
for (int i=0; i<NumMyNodes_; i++) { |
| 736 |
commMat->insertGlobalValues(NodesMap_->getGlobalElement(i),myPID(),one()); |
| 737 |
} |
| 738 |
XMapPtr domainMap = MapFactory<LO,GO,NO>::Build(NodesMap_->lib(),INVALID,myPID(),0,NodesMap_->getComm()); |
| 739 |
|
| 740 |
commMat->fillComplete(domainMap,NodesMap_); |
| 741 |
commMatTmp->doExport(*commMat,*commExporter,INSERT); |
| 742 |
commMatTmp->fillComplete(domainMap,UniqueNodesMap_); |
| 743 |
commMat = MatrixFactory<SC,LO,GO,NO>::Build(NodesMap_,LO(0)); |
| 744 |
commMat->doImport(*commMatTmp,*commExporter,INSERT); |
| 745 |
|
| 746 |
componentsSubdomains = IntVecVecPtr(NumMyNodes_); |
| 747 |
|
| 748 |
ArrayView<const GO> indices; |
| 749 |
ArrayView<const SC> values; |
| 750 |
for (LO i=0; i<NumMyNodes_; i++) { |
| 751 |
commMat->getGlobalRowView(NodesMap_->getGlobalElement(i),indices,values); |
| 752 |
componentsSubdomains[i].resize(indices.size()); |
| 753 |
for (LO j=0; j<indices.size(); j++) { |
| 754 |
componentsSubdomains[i][j] = as<int>(indices[j]); |
| 755 |
} |
| 756 |
} |
| 757 |
} |
| 758 |
break; |
| 759 |
|
| 760 |
case CommCrsGraph: |
| 761 |
{ |
| 762 |
UniqueNodesMap_ = BuildUniqueMap<LO,GO,NO>(NodesMap_); |
| 763 |
|
| 764 |
XCrsGraphPtr commGraph = CrsGraphFactory<LO,GO,NO>::Build(NodesMap_,10); // AH 08/07/2019: Can we put 1 instead of 10 here? |
| 765 |
XCrsGraphPtr commGraphTmp = CrsGraphFactory<LO,GO,NO>::Build(UniqueNodesMap_,10); // We assume that any node is part of no more than 10 subdomains |
| 766 |
XExportPtr commExporter = ExportFactory<LO,GO,NO>::Build(NodesMap_,UniqueNodesMap_); |
| 767 |
|
| 768 |
Array<GO> myPID(1,MpiComm_->getRank()); |
| 769 |
for (int i=0; i<NumMyNodes_; i++) { |
| 770 |
commGraph->insertGlobalIndices(NodesMap_->getGlobalElement(i),myPID()); |
| 771 |
} |
| 772 |
XMapPtr domainMap = MapFactory<LO,GO,NO>::Build(NodesMap_->lib(),INVALID,myPID(),0,NodesMap_->getComm()); |
| 773 |
|
| 774 |
commGraph->fillComplete(domainMap,NodesMap_); // AH 08/07/2019: Can we remove some fillComplete? |
| 775 |
commGraphTmp->doExport(*commGraph,*commExporter,INSERT); |
| 776 |
commGraphTmp->fillComplete(domainMap,UniqueNodesMap_); |
| 777 |
commGraph = CrsGraphFactory<LO,GO,NO>::Build(NodesMap_); |
| 778 |
commGraph->doImport(*commGraphTmp,*commExporter,INSERT); |
| 779 |
|
| 780 |
componentsSubdomains = IntVecVecPtr(NumMyNodes_); |
| 781 |
|
| 782 |
ArrayView<const GO> indices; |
| 783 |
for (LO i=0; i<NumMyNodes_; i++) { |
| 784 |
commGraph->getGlobalRowView(NodesMap_->getGlobalElement(i),indices); |
| 785 |
componentsSubdomains[i].resize(indices.size()); |
| 786 |
for (LO j=0; j<indices.size(); j++) { |
| 787 |
componentsSubdomains[i][j] = as<int>(indices[j]); |
| 788 |
} |
| 789 |
} |
| 790 |
} |
| 791 |
break; |
| 792 |
|
| 793 |
case CreateOneToOneMap: |
| 794 |
{ |
| 795 |
RCP<LowerPIDTieBreak<LO,GO,NO> > lowerPIDTieBreak(new LowerPIDTieBreak<LO,GO,NO>(MpiComm_,NodesMap_,Dimension_,LevelID_)); |
| 796 |
UniqueNodesMap_ = BuildUniqueMap<LO,GO,NO>(NodesMap_,true,lowerPIDTieBreak); |
| 797 |
lowerPIDTieBreak->sendDataToOriginalMap(); |
| 798 |
componentsSubdomains = lowerPIDTieBreak->getComponents(); |
| 799 |
} |
| 800 |
break; |
| 801 |
|
| 802 |
default: |
| 803 |
FROSCH_ASSERT(false,"FROSch::DDInterface: Specify a valid communication strategy."); |
| 804 |
} |
| 805 |
|
| 806 |
componentsSubdomainsUnique = IntVecVec(NumMyNodes_); |
| 807 |
for (LO i=0; i<NumMyNodes_; i++) { |
| 808 |
sortunique(componentsSubdomains[i]); |
| 809 |
if (componentsSubdomains[i].size() == 0) componentsSubdomains[i].push_back(MpiComm_->getRank()); // For Tpetra this is empty if the repeatedMap is already unique. In this case, we have to add the local rank. Otherwise, we obtain nodes with multiplicity 0. |
| 810 |
componentsSubdomainsUnique[i] = componentsSubdomains[i]; |
| 811 |
// if (MpiComm_->getRank() == 0) cout << MpiComm_->getRank() << ": " << i << " " << componentsSubdomains[i] << endl; |
| 812 |
} |
| 813 |
sortunique(componentsSubdomainsUnique); |
| 814 |
|
| 815 |
return 0; |
| 816 |
} |
| 817 |
|
| 818 |
template <class SC,class LO,class GO,class NO> |
| 819 |
int DDInterface<SC,LO,GO,NO>::identifyLocalComponents(IntVecVecPtr &componentsSubdomains, |
| 820 |
IntVecVec &componentsSubdomainsUnique) |
| 821 |
{ |
| 822 |
FROSCH_DETAILTIMER_START_LEVELID(identifyLocalComponentsTime,"DDInterface::identifyLocalComponents"); |
| 823 |
//if (Verbose_ && Verbosity_==All) cout << "FROSch::DDInterface : Classifying interface components based on equivalence classes" << endl; |
| 824 |
|
| 825 |
// Hier herausfinden, ob Ecke, Kante oder Fläche |
| 826 |
UNVecPtr componentsMultiplicity(componentsSubdomainsUnique.size()); |
| 827 |
IntVecVecPtr components(componentsSubdomainsUnique.size()); |
| 828 |
IntVecVecPtr componentsGamma(componentsSubdomainsUnique.size()); |
| 829 |
UN maxMultiplicity = 0; |
| 830 |
for (UN i=0; i<componentsSubdomainsUnique.size(); i++) { |
| 831 |
componentsMultiplicity[i] = componentsSubdomainsUnique[i].size(); |
| 832 |
maxMultiplicity = max(maxMultiplicity,componentsMultiplicity[i]); |
| 833 |
} |
| 834 |
EntitySetVector_ = EntitySetPtrVecPtr(maxMultiplicity+1); |
| 835 |
for (UN i=0; i<maxMultiplicity+1; i++) { |
| 836 |
EntitySetVector_[i].reset(new EntitySet<SC,LO,GO,NO>(DefaultType)); |
| 837 |
} |
| 838 |
|
| 839 |
typename IntVecVec::iterator classIterator; |
| 840 |
LOVecPtr localComponentIndices(NumMyNodes_); |
| 841 |
for (int i=0; i<NumMyNodes_; i++) { |
| 842 |
classIterator = lower_bound(componentsSubdomainsUnique.begin(),componentsSubdomainsUnique.end(),componentsSubdomains[i]); |
| 843 |
localComponentIndices[i] = classIterator - componentsSubdomainsUnique.begin(); |
| 844 |
} |
| 845 |
|
| 846 |
LO tmp1 = 0; // The interface and interior have multiplicity 0 in our construction |
| 847 |
int *tmp2 = NULL; |
| 848 |
RCP<InterfaceEntity<SC,LO,GO,NO> > interior(new InterfaceEntity<SC,LO,GO,NO>(InteriorType,DofsPerNode_,tmp1,tmp2)); |
| 849 |
RCP<InterfaceEntity<SC,LO,GO,NO> > interface(new InterfaceEntity<SC,LO,GO,NO>(InterfaceType,DofsPerNode_,tmp1,tmp2)); |
| 850 |
for (LO i=0; i<NumMyNodes_; i++) { |
| 851 |
if (componentsMultiplicity[localComponentIndices[i]] == 1) { |
| 852 |
LO nodeIDI = interior->getNumNodes(); |
| 853 |
LO nodeIDLocal = i; |
| 854 |
GO nodeIDGlobal = NodesMap_->getGlobalElement(nodeIDLocal); |
| 855 |
LOVecPtr dofsI(DofsPerNode_); |
| 856 |
LOVecPtr dofsLocal(DofsPerNode_); |
| 857 |
GOVecPtr dofsGlobal(DofsPerNode_); |
| 858 |
for (UN k=0; k<DofsPerNode_; k++) { |
| 859 |
dofsI[k] = DofsPerNode_*nodeIDI+k; |
| 860 |
dofsLocal[k] = DofsPerNode_*nodeIDLocal+k; |
| 861 |
dofsGlobal[k] = DofsPerNode_*nodeIDGlobal+k; |
| 862 |
} |
| 863 |
interior->addNode(nodeIDI,nodeIDLocal,nodeIDGlobal,DofsPerNode_,dofsI,dofsLocal,dofsGlobal); |
| 864 |
} else { |
| 865 |
FROSCH_ASSERT(componentsMultiplicity[localComponentIndices[i]]>1,"FROSch::DDInterface: There cannot be any nodes with multiplicity 0."); |
| 866 |
LO nodeIDGamma = interface->getNumNodes(); |
| 867 |
LO nodeIDLocal = i; |
| 868 |
GO nodeIDGlobal = NodesMap_->getGlobalElement(nodeIDLocal); |
| 869 |
LOVecPtr dofsGamma(DofsPerNode_); |
| 870 |
LOVecPtr dofsLocal(DofsPerNode_); |
| 871 |
GOVecPtr dofsGlobal(DofsPerNode_); |
| 872 |
for (UN k=0; k<DofsPerNode_; k++) { |
| 873 |
dofsGamma[k] = DofsPerNode_*nodeIDGamma+k; |
| 874 |
dofsLocal[k] = DofsPerNode_*nodeIDLocal+k; |
| 875 |
dofsGlobal[k] = DofsPerNode_*nodeIDGlobal+k; |
| 876 |
} |
| 877 |
interface->addNode(nodeIDGamma,nodeIDLocal,nodeIDGlobal,DofsPerNode_,dofsGamma,dofsLocal,dofsGlobal); |
| 878 |
|
| 879 |
components[localComponentIndices[i]].push_back(i); |
| 880 |
componentsGamma[localComponentIndices[i]].push_back(interface->getNumNodes()-1); |
| 881 |
} |
| 882 |
} |
| 883 |
Interior_->addEntity(interior); |
| 884 |
Interface_->addEntity(interface); |
| 885 |
|
| 886 |
for (UN i=0; i<componentsSubdomainsUnique.size(); i++) { |
| 887 |
FROSCH_ASSERT(componentsMultiplicity[i]>0,"FROSch::DDInterface: There cannot be any component with multiplicity 0."); |
| 888 |
RCP<InterfaceEntity<SC,LO,GO,NO> > tmpEntity(new InterfaceEntity<SC,LO,GO,NO>(VertexType,DofsPerNode_,componentsMultiplicity[i],&(componentsSubdomainsUnique[i][0]))); |
| 889 |
LO nodeIDGamma; |
| 890 |
LO nodeIDLocal; |
| 891 |
GO nodeIDGlobal; |
| 892 |
LOVecPtr dofsGamma(DofsPerNode_); |
| 893 |
LOVecPtr dofsLocal(DofsPerNode_); |
| 894 |
GOVecPtr dofsGlobal(DofsPerNode_); |
| 895 |
|
| 896 |
sortunique(components[i]); |
| 897 |
|
| 898 |
// |
| 899 |
for (UN j=0; j<components[i].size(); j++) { |
| 900 |
nodeIDGamma = componentsGamma[i][j]; |
| 901 |
nodeIDLocal = components[i][j]; |
| 902 |
nodeIDGlobal = NodesMap_->getGlobalElement(nodeIDLocal); |
| 903 |
for (UN k=0; k<DofsPerNode_; k++) { |
| 904 |
dofsGamma[k] = DofsPerNode_*nodeIDGamma+k; |
| 905 |
dofsLocal[k] = DofsPerNode_*nodeIDLocal+k; |
| 906 |
dofsGlobal[k] = DofsPerNode_*nodeIDGlobal+k; |
| 907 |
} |
| 908 |
|
| 909 |
tmpEntity->addNode(nodeIDGamma,nodeIDLocal,nodeIDGlobal,DofsPerNode_,dofsGamma,dofsLocal,dofsGlobal); |
| 910 |
} |
| 911 |
tmpEntity->resetEntityType(DefaultType); |
| 912 |
EntitySetVector_[componentsMultiplicity[i]]->addEntity(tmpEntity); |
| 913 |
} |
| 914 |
|
| 915 |
// Remove the empty entity stemming from the interior nodes |
| 916 |
removeEmptyEntities(); |
| 917 |
|
| 918 |
// We need to set the unique ID; otherwise, we cannot sort entities |
| 919 |
for (UN i=0; i<EntitySetVector_.size(); i++) { |
| 920 |
EntitySetVector_[i]->setUniqueIDToFirstGlobalNodeID(); |
| 921 |
} |
| 922 |
return 0; |
| 923 |
} |
| 924 |
|
| 925 |
} |
| 926 |
|
| 927 |
#endif |