| 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_TOOLS_DEF_HPP |
| 11 |
#define _FROSCH_TOOLS_DEF_HPP |
| 12 |
|
| 13 |
#include <FROSch_Tools_decl.hpp> |
| 14 |
|
| 15 |
#include <Xpetra_Export.hpp> |
| 16 |
#include <Xpetra_Import.hpp> |
| 17 |
#include <Xpetra_ImportFactory.hpp> |
| 18 |
|
| 19 |
|
| 20 |
namespace FROSch { |
| 21 |
|
| 22 |
using namespace std; |
| 23 |
using namespace Teuchos; |
| 24 |
using namespace Xpetra; |
| 25 |
|
| 26 |
template <typename LO,typename GO> |
| 27 |
OverlappingData<LO,GO>::OverlappingData(GO gid, |
| 28 |
int pid, |
| 29 |
LO lid) : |
| 30 |
GID_ (gid), |
| 31 |
PIDs_ (1,pid), |
| 32 |
LIDs_ (1,lid) |
| 33 |
{ |
| 34 |
|
| 35 |
} |
| 36 |
|
| 37 |
template <typename LO,typename GO> |
| 38 |
int OverlappingData<LO,GO>::Merge(const RCP<OverlappingData<LO,GO> > od) const |
| 39 |
{ |
| 40 |
FROSCH_ASSERT(GID_ == od->GID_,"FROSch::OverlappingData: GID_ != od->GID_"); |
| 41 |
for (typename IntVec::iterator it = od->PIDs_.begin(); it != od->PIDs_.end(); it++) { |
| 42 |
PIDs_.push_back(*it); |
| 43 |
} |
| 44 |
for (typename LOVec::iterator it = od->LIDs_.begin(); it != od->LIDs_.end(); it++) { |
| 45 |
LIDs_.push_back(*it); |
| 46 |
} |
| 47 |
return 0; |
| 48 |
} |
| 49 |
|
| 50 |
template <typename LO,typename GO> |
| 51 |
int MergeList(Array<RCP<OverlappingData<LO,GO> > > &odList) |
| 52 |
{ |
| 53 |
int numPackages = 0; |
| 54 |
std::sort(odList.begin(), |
| 55 |
odList.end(), |
| 56 |
[] (const RCP<OverlappingData<LO,GO> >& lhs, const RCP<OverlappingData<LO,GO> >& rhs) { |
| 57 |
return lhs->GID_ < rhs->GID_; |
| 58 |
} |
| 59 |
); |
| 60 |
odList.erase(unique(odList.begin(), |
| 61 |
odList.end(), |
| 62 |
[] (const RCP<OverlappingData<LO,GO> > lhs, const RCP<OverlappingData<LO,GO> > rhs) { |
| 63 |
if (lhs->GID_ == rhs->GID_) { |
| 64 |
lhs->Merge(rhs); |
| 65 |
return true; |
| 66 |
} else { |
| 67 |
return false; |
| 68 |
} |
| 69 |
} |
| 70 |
),odList.end()); |
| 71 |
|
| 72 |
typename Array<RCP<OverlappingData<LO,GO> > >::iterator tmpODPtrVecIt; |
| 73 |
for (tmpODPtrVecIt=odList.begin(); tmpODPtrVecIt!=odList.end(); tmpODPtrVecIt++) { |
| 74 |
numPackages += (*tmpODPtrVecIt)->PIDs_.size()*(*tmpODPtrVecIt)->PIDs_.size(); |
| 75 |
} |
| 76 |
return numPackages; |
| 77 |
} |
| 78 |
|
| 79 |
template <typename LO,typename GO,typename NO> |
| 80 |
LowerPIDTieBreak<LO,GO,NO>::LowerPIDTieBreak(CommPtr comm, |
| 81 |
ConstXMapPtr originalMap, |
| 82 |
UN dimension, |
| 83 |
UN levelID) : |
| 84 |
MpiComm_ (comm), |
| 85 |
OriginalMap_ (originalMap), |
| 86 |
ElementCounter_ (), |
| 87 |
OverlappingDataList_ (dimension*(OriginalMap_->getGlobalNumElements()/MpiComm_->getSize())+pow(3,dimension)), |
| 88 |
ComponentsSubdomains_ (OriginalMap_->getLocalNumElements()), |
| 89 |
LevelID_ (levelID) |
| 90 |
{ |
| 91 |
FROSCH_DETAILTIMER_START_LEVELID(lowerPIDTieBreakTime,"LowerPIDTieBreak::LowerPIDTieBreak"); |
| 92 |
} |
| 93 |
|
| 94 |
template <typename LO,typename GO,typename NO> |
| 95 |
int LowerPIDTieBreak<LO,GO,NO>::sendDataToOriginalMap() |
| 96 |
{ |
| 97 |
FROSCH_DETAILTIMER_START_LEVELID(sendDataToOriginalMapTime,"LowerPIDTieBreak::sendDataToOriginalMap"); |
| 98 |
// This is done analogously to DistributedNoncontiguousDirectory<LO, GO, NT>::DistributedNoncontiguousDirectory(const map_type& map,const tie_break_type& tie_break) |
| 99 |
typedef typename ArrayView<const GO>::size_type size_type; |
| 100 |
|
| 101 |
OverlappingDataList_.resize(ElementCounter_); |
| 102 |
|
| 103 |
int numPackages = MergeList(OverlappingDataList_); |
| 104 |
|
| 105 |
Tpetra::Distributor distor (MpiComm_); |
| 106 |
|
| 107 |
const int packetSize = 2; |
| 108 |
IntVec sendImageIDs(numPackages); |
| 109 |
GOView exportEntries("FROSch::sendDataToOriginalMap::exportEntries", packetSize*numPackages); // data to send out |
| 110 |
{ |
| 111 |
typename OverlappingDataPtrVec::iterator tmpODPtrVecIt; |
| 112 |
typename IntVec::iterator tmpIntVecIt; |
| 113 |
typename IntVec::iterator tmpIntVecIt2; |
| 114 |
typename LOVec::iterator tmpLOVecIt; |
| 115 |
|
| 116 |
size_type exportIndex = 0; |
| 117 |
size_type exportIndex2 = 0; |
| 118 |
for (tmpODPtrVecIt = OverlappingDataList_.begin(); tmpODPtrVecIt!=OverlappingDataList_.end(); tmpODPtrVecIt++) { |
| 119 |
tmpLOVecIt = (*tmpODPtrVecIt)->LIDs_.begin(); |
| 120 |
for (tmpIntVecIt = (*tmpODPtrVecIt)->PIDs_.begin(); tmpIntVecIt != (*tmpODPtrVecIt)->PIDs_.end(); tmpIntVecIt++) { |
| 121 |
for (tmpIntVecIt2 = (*tmpODPtrVecIt)->PIDs_.begin(); tmpIntVecIt2 != (*tmpODPtrVecIt)->PIDs_.end(); tmpIntVecIt2++) { |
| 122 |
exportEntries(exportIndex++) = (*tmpODPtrVecIt)->GID_; |
| 123 |
exportEntries(exportIndex++) = as<GO>(*tmpIntVecIt2); |
| 124 |
sendImageIDs[exportIndex2++] = *tmpIntVecIt; |
| 125 |
} |
| 126 |
tmpLOVecIt++; |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
distor.createFromSends(sendImageIDs); |
| 131 |
|
| 132 |
GOView importElements("FROSch::sendDataToOriginalMap::importElements", packetSize*distor.getTotalReceiveLength()); |
| 133 |
|
| 134 |
distor.doPostsAndWaits(exportEntries,packetSize,importElements); |
| 135 |
|
| 136 |
LO length = importElements.extent(0)/packetSize; |
| 137 |
for (LO i=0; i<length; i++) { |
| 138 |
ComponentsSubdomains_[OriginalMap_->getLocalElement(importElements(2*i))].push_back(importElements(2*i+1)); |
| 139 |
} |
| 140 |
|
| 141 |
return 0; |
| 142 |
} |
| 143 |
|
| 144 |
template <typename LO,typename GO,typename NO> |
| 145 |
size_t LowerPIDTieBreak<LO,GO,NO>::selectedIndex(GO GID, |
| 146 |
const vector<pair<int,LO> > & pid_and_lid) const |
| 147 |
{ |
| 148 |
// Always choose index of pair with smallest pid |
| 149 |
const size_t numLids = pid_and_lid.size(); |
| 150 |
size_t idx = 0; |
| 151 |
int minpid = pid_and_lid[0].first; |
| 152 |
size_t minidx = 0; |
| 153 |
|
| 154 |
static int counter = 0; |
| 155 |
for (idx = 0; idx < numLids; ++idx) { |
| 156 |
// Organize the overlapping data to send it back to the original processes |
| 157 |
if (ElementCounter_<OverlappingDataList_.size()) { |
| 158 |
OverlappingDataList_[ElementCounter_].reset(new OverlappingData<LO,GO>(GID, |
| 159 |
pid_and_lid[idx].first, |
| 160 |
pid_and_lid[idx].second)); |
| 161 |
} else { |
| 162 |
FROSCH_WARNING("FROSch::LowerPIDTieBreak",counter == 0,"Preallocation for OverlappingDataList_ is not sufficient on proc."); |
| 163 |
OverlappingDataList_.push_back(RCP<OverlappingData<LO,GO> >(new OverlappingData<LO,GO>(GID, |
| 164 |
pid_and_lid[idx].first, |
| 165 |
pid_and_lid[idx].second))); |
| 166 |
counter++; |
| 167 |
} |
| 168 |
ElementCounter_++; |
| 169 |
if (pid_and_lid[idx].first < minpid) { |
| 170 |
minpid = pid_and_lid[idx].first; |
| 171 |
minidx = idx; |
| 172 |
} |
| 173 |
} |
| 174 |
return minidx; |
| 175 |
} |
| 176 |
|
| 177 |
template <class SC, class LO, class GO, class NO> |
| 178 |
void writeMM(std::string fileName, Teuchos::RCP<Xpetra::Matrix<SC,LO,GO,NO> > &matrix_) |
| 179 |
{ |
| 180 |
FROSCH_DETAILTIMER_START(writeMMTime,"writeMM"); |
| 181 |
|
| 182 |
TEUCHOS_TEST_FOR_EXCEPTION( matrix_.is_null(), std::runtime_error,"Matrix in writeMM is null."); |
| 183 |
TEUCHOS_TEST_FOR_EXCEPTION( !(matrix_->getMap()->lib()==Xpetra::UseTpetra), std::logic_error,"Only available for Tpetra underlying lib."); |
| 184 |
typedef Tpetra::CrsMatrix<SC,LO,GO,NO> TpetraCrsMatrix; |
| 185 |
typedef Teuchos::RCP<TpetraCrsMatrix> TpetraCrsMatrixPtr; |
| 186 |
|
| 187 |
Xpetra::CrsMatrixWrap<SC,LO,GO,NO>& crsOp = dynamic_cast<Xpetra::CrsMatrixWrap<SC,LO,GO,NO>&>(*matrix_); |
| 188 |
Xpetra::TpetraCrsMatrix<SC,LO,GO,NO>& xTpetraMat = dynamic_cast<Xpetra::TpetraCrsMatrix<SC,LO,GO,NO>&>(*crsOp.getCrsMatrix()); |
| 189 |
|
| 190 |
TpetraCrsMatrixPtr tpetraMat = xTpetraMat.getTpetra_CrsMatrixNonConst(); |
| 191 |
|
| 192 |
Tpetra::MatrixMarket::Writer< TpetraCrsMatrix > tpetraWriter; |
| 193 |
|
| 194 |
tpetraWriter.writeSparseFile(fileName, tpetraMat, "matrix", ""); |
| 195 |
} |
| 196 |
|
| 197 |
template <class SC, class LO, class GO, class NO> |
| 198 |
void readMM(std::string fileName, Teuchos::RCP<Xpetra::Matrix<SC,LO,GO,NO> > &matrix_,RCP<const Comm<int> > &comm) |
| 199 |
{ |
| 200 |
FROSCH_DETAILTIMER_START(readMMTime,"readMM"); |
| 201 |
|
| 202 |
TEUCHOS_TEST_FOR_EXCEPTION( !(matrix_->getMap()->lib()==Xpetra::UseTpetra), std::logic_error,"Only available for Tpetra underlying lib."); |
| 203 |
typedef Tpetra::CrsMatrix<SC,LO,GO,NO> TpetraCrsMatrix; |
| 204 |
typedef Teuchos::RCP<TpetraCrsMatrix> TpetraCrsMatrixPtr; |
| 205 |
|
| 206 |
TpetraCrsMatrixPtr tmpMatrix; |
| 207 |
Tpetra::MatrixMarket::Reader<TpetraCrsMatrix> tpetraReader; |
| 208 |
|
| 209 |
tmpMatrix = tpetraReader.readSparseFile(fileName,comm); |
| 210 |
|
| 211 |
matrix_ = rcp_dynamic_cast<Matrix<SC,LO,GO,NO> >(tmpMatrix); |
| 212 |
} |
| 213 |
|
| 214 |
template <class SC,class LO,class GO,class NO> |
| 215 |
RCP<Map<LO,GO,NO> > BuildRepeatedMapGaleriStruct2D(RCP<const Matrix<SC,LO,GO,NO> > matrix,int M,int Dim) |
| 216 |
{ |
| 217 |
Teuchos::ArrayView< const GO> eleList; |
| 218 |
eleList = matrix->getMap()->getLocalElementList(); |
| 219 |
Teuchos::RCP< const Teuchos::Comm< int > > Comm = matrix->getMap()->getComm(); |
| 220 |
|
| 221 |
int size = Comm->getSize(); |
| 222 |
int rank = Comm->getRank(); |
| 223 |
|
| 224 |
Teuchos::Array<GO> vert; |
| 225 |
vert.reserve(M*Dim); |
| 226 |
Teuchos::Array<GO> horz; |
| 227 |
horz.reserve((M+1)*Dim); |
| 228 |
int numSubPerRow = sqrt(size); |
| 229 |
GO nodesInRow = M*Dim*numSubPerRow; |
| 230 |
Teuchos::Array<GO> newEle; |
| 231 |
newEle.reserve(eleList.size()+M*Dim+(M+1)*Dim); |
| 232 |
int count = 0; |
| 233 |
for (int i = 0;i<eleList.size();i++) { |
| 234 |
newEle.push_back(eleList[i]); |
| 235 |
count++; |
| 236 |
} |
| 237 |
|
| 238 |
if (rank%numSubPerRow != numSubPerRow-1) { |
| 239 |
for (int j = 0;j<M;j++) { |
| 240 |
for (int i = 0;i<Dim;i++) { |
| 241 |
vert.push_back(eleList[Dim*M*(j+1)-1]+(i+1)); |
| 242 |
newEle.push_back(vert[j*Dim+i]); |
| 243 |
count++; |
| 244 |
} |
| 245 |
} |
| 246 |
} |
| 247 |
|
| 248 |
if (rank<size-numSubPerRow){ |
| 249 |
if (rank%numSubPerRow == numSubPerRow-1) { |
| 250 |
for (int j=0;j<Dim*M;j++) { |
| 251 |
horz.push_back(eleList[eleList.size()-Dim*M]+nodesInRow+j); |
| 252 |
newEle.push_back(horz[j]); |
| 253 |
count++; |
| 254 |
} |
| 255 |
} else { |
| 256 |
for (int j=0;j<Dim*M+2;j++) { |
| 257 |
horz.push_back(eleList[eleList.size()-Dim*M]+nodesInRow+j); |
| 258 |
newEle.push_back(horz[j]); |
| 259 |
count++; |
| 260 |
} |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
return Xpetra::MapFactory<LO,GO,NO>::Build(matrix->getMap()->lib(),matrix->getMap()->getGlobalNumElements(),newEle(),0,Comm); |
| 265 |
|
| 266 |
} |
| 267 |
|
| 268 |
template <class SC,class LO,class GO,class NO> |
| 269 |
RCP<Map<LO,GO,NO> > BuildRepeatedMapGaleriStruct3D(RCP<const Map<LO,GO,NO> > matrix,int M,int Dim) |
| 270 |
{ |
| 271 |
|
| 272 |
FROSCH_DETAILTIMER_START(Galeri3DMap,"BuildGeometricMap3D"); |
| 273 |
|
| 274 |
Teuchos::ArrayView< const GO> eleList; |
| 275 |
eleList = matrix->getLocalElementList(); |
| 276 |
Teuchos::RCP< const Teuchos::Comm< int > > Comm = matrix->getComm(); |
| 277 |
|
| 278 |
int size = Comm->getSize(); |
| 279 |
int rank = Comm->getRank(); |
| 280 |
|
| 281 |
Teuchos::Array<GO> vert; |
| 282 |
vert.reserve(M*Dim); |
| 283 |
Teuchos::Array<GO> horz; |
| 284 |
horz.reserve((M+1)*Dim); |
| 285 |
int numSubPerRow = std::pow(size,1/3.)+0.7; |
| 286 |
//int numSubPerRow = numSubPerRow1; |
| 287 |
// numSubPerRow = numSubPerRow+1; |
| 288 |
//if(Comm->getRank() == 0) std::cout<<"Size "<<size<<"\n"; |
| 289 |
//if(Comm->getRank() == 0) std::cout<<"numSubPerRow1 "<<numSubPerRow1<<" numSubPerRow "<<numSubPerRow<<"\n"; |
| 290 |
int subInLev = numSubPerRow*numSubPerRow; |
| 291 |
//if(Comm->getRank() == 0) std::cout<<"subInLev "<<subInLev<<"\n"; |
| 292 |
GO nodesInRow = M*numSubPerRow; |
| 293 |
//if(Comm->getRank() == 0) std::cout<<"nodesInRow "<<nodesInRow<<"\n"; |
| 294 |
GO nodesInLev = nodesInRow*nodesInRow; |
| 295 |
//if(Comm->getRank() == 0) std::cout<<"nodesInLev "<<nodesInLev<<"\n"; |
| 296 |
int subLevel = rank/(numSubPerRow*numSubPerRow); |
| 297 |
|
| 298 |
|
| 299 |
Teuchos::Array<GO> newEle; |
| 300 |
newEle.reserve(eleList.size()+M*Dim+(M+1)*Dim); |
| 301 |
GO startval = eleList[0]/Dim; |
| 302 |
|
| 303 |
//Differentiate between locations of the sub |
| 304 |
//not back |
| 305 |
if (rank<size-subInLev) { |
| 306 |
//not right boundary |
| 307 |
if (rank%numSubPerRow != numSubPerRow-1) { |
| 308 |
//not top |
| 309 |
if (subLevel*subInLev <=rank && rank<(subLevel+1)*subInLev-numSubPerRow) { |
| 310 |
for (int k = 0;k<M+1;k++) { |
| 311 |
for (int j = 0;j<M+1;j++) { |
| 312 |
for (int i = 0;i<M+1;i++) { |
| 313 |
newEle.push_back(startval+i+j*nodesInRow+nodesInLev*k); |
| 314 |
} |
| 315 |
} |
| 316 |
} |
| 317 |
} else { |
| 318 |
//top |
| 319 |
for (int k = 0;k<M+1;k++) { |
| 320 |
for (int j = 0;j<M;j++) { |
| 321 |
for (int i = 0;i<M+1;i++) { |
| 322 |
newEle.push_back(startval+i+j*nodesInRow+nodesInLev*k); |
| 323 |
} |
| 324 |
} |
| 325 |
} |
| 326 |
} |
| 327 |
} else { |
| 328 |
//rightboundary |
| 329 |
if(subLevel*subInLev <=rank && rank<(subLevel+1)*subInLev-numSubPerRow){ |
| 330 |
for (int k = 0;k<M+1;k++) { |
| 331 |
for (int j = 0;j<M+1;j++) { |
| 332 |
for (int i = 0;i<M;i++) { |
| 333 |
newEle.push_back(startval+i+j*nodesInRow+nodesInLev*k); |
| 334 |
} |
| 335 |
} |
| 336 |
} |
| 337 |
} else { |
| 338 |
//top |
| 339 |
for (int k = 0;k<M+1;k++) { |
| 340 |
for (int j = 0;j<M;j++) { |
| 341 |
for (int i = 0;i<M;i++) { |
| 342 |
newEle.push_back(startval+i+j*nodesInRow+nodesInLev*k); |
| 343 |
} |
| 344 |
} |
| 345 |
} |
| 346 |
} |
| 347 |
} |
| 348 |
//######################################### |
| 349 |
} else{ |
| 350 |
//back |
| 351 |
if(rank%numSubPerRow != numSubPerRow-1){ |
| 352 |
//not top |
| 353 |
if (subLevel*subInLev <=rank && rank<(subLevel+1)*subInLev-numSubPerRow){ |
| 354 |
for (int k = 0;k<M;k++) { |
| 355 |
for (int j = 0;j<M+1;j++) { |
| 356 |
for (int i = 0;i<M+1;i++) { |
| 357 |
newEle.push_back(startval+i+j*nodesInRow+nodesInLev*k); |
| 358 |
} |
| 359 |
} |
| 360 |
} |
| 361 |
} else { |
| 362 |
//top |
| 363 |
for (int k = 0;k<M;k++) { |
| 364 |
for (int j = 0;j<M;j++) { |
| 365 |
for (int i = 0;i<M+1;i++) { |
| 366 |
newEle.push_back(startval+i+j*nodesInRow+nodesInLev*k); |
| 367 |
} |
| 368 |
} |
| 369 |
} |
| 370 |
} |
| 371 |
} else { |
| 372 |
//rightboundary |
| 373 |
if (subLevel*subInLev <=rank && rank<(subLevel+1)*subInLev-numSubPerRow) { |
| 374 |
for (int k = 0;k<M;k++) { |
| 375 |
for (int j = 0;j<M+1;j++) { |
| 376 |
for (int i = 0;i<M;i++) { |
| 377 |
newEle.push_back(startval+i+j*nodesInRow+nodesInLev*k); |
| 378 |
} |
| 379 |
} |
| 380 |
} |
| 381 |
} else { |
| 382 |
//top |
| 383 |
for (int k = 0;k<M;k++) { |
| 384 |
for (int j = 0;j<M;j++) { |
| 385 |
for (int i = 0;i<M;i++) { |
| 386 |
newEle.push_back(startval+i+j*nodesInRow+nodesInLev*k); |
| 387 |
} |
| 388 |
} |
| 389 |
} |
| 390 |
} |
| 391 |
} |
| 392 |
|
| 393 |
} |
| 394 |
|
| 395 |
return Xpetra::MapFactory<LO,GO,NO>::Build(matrix->getMap()->lib(),matrix->getMap()->getGlobalNumElements(),newEle(),0,Comm); |
| 396 |
|
| 397 |
} |
| 398 |
|
| 399 |
template <class LO,class GO,class NO> |
| 400 |
RCP<const Map<LO,GO,NO> > BuildUniqueMap(const RCP<const Map<LO,GO,NO> > map, |
| 401 |
bool useCreateOneToOneMap, |
| 402 |
RCP<Tpetra::Details::TieBreak<LO,GO> > tieBreak) |
| 403 |
{ |
| 404 |
using Xpetra::Vector; |
| 405 |
FROSCH_DETAILTIMER_START(buildUniqueMapTime,"BuildUniqueMap"); |
| 406 |
if (useCreateOneToOneMap && map->lib()==UseTpetra) { |
| 407 |
// Obtain the underlying Tpetra Map |
| 408 |
const RCP<const TpetraMap<LO,GO,NO> >& xTpetraMap = rcp_dynamic_cast<const TpetraMap<LO,GO,NO> >(map); |
| 409 |
RCP<const Tpetra::Map<LO,GO,NO> > tpetraMap = xTpetraMap->getTpetra_Map(); |
| 410 |
|
| 411 |
RCP<const Tpetra::Map<LO,GO,NO> > tpetraMapUnique; |
| 412 |
if (tieBreak.is_null()) { |
| 413 |
tpetraMapUnique = createOneToOne(tpetraMap); |
| 414 |
} else { |
| 415 |
tpetraMapUnique = createOneToOne(tpetraMap,*tieBreak); |
| 416 |
} |
| 417 |
|
| 418 |
RCP<const TpetraMap<LO,GO,NO> > xTpetraMapUnique(new const TpetraMap<LO,GO,NO>(tpetraMapUnique)); |
| 419 |
return rcp_dynamic_cast<const Map<LO,GO,NO> >(xTpetraMapUnique); |
| 420 |
} else { // This is an alternative implementation to createOneToOneMap() |
| 421 |
FROSCH_WARNING("FROSch::BuildUniqueMap",(map->lib()==UseEpetra && map->getComm()->getRank()==0),"createOneToOneMap() does not exist for Epetra => Using a different implementation."); |
| 422 |
|
| 423 |
RCP<Vector<GO,LO,GO,NO> > myIndices = VectorFactory<GO,LO,GO,NO>::Build(map); |
| 424 |
myIndices->putScalar(map->getComm()->getRank()+1); |
| 425 |
|
| 426 |
RCP<Map<LO,GO,NO> > linearMap = MapFactory<LO,GO,NO>::Build(map->lib(),map->getMaxAllGlobalIndex()+1,0,map->getComm()); |
| 427 |
RCP<Vector<GO,LO,GO,NO> > globalIndices = VectorFactory<GO,LO,GO,NO>::Build(linearMap); |
| 428 |
|
| 429 |
RCP<Import<LO,GO,NO> > importer = ImportFactory<LO,GO,NO>::Build(map,linearMap); |
| 430 |
RCP<Import<LO,GO,NO> > importer2 = ImportFactory<LO,GO,NO>::Build(linearMap,map); // AH 10/16/2017: Ist der notwendig??? Mit Epetra ging es auch ohne einen zweiten XImport und stattdessen mit einem Export |
| 431 |
globalIndices->doImport(*myIndices,*importer,INSERT); |
| 432 |
myIndices->putScalar(0); |
| 433 |
myIndices->doImport(*globalIndices,*importer2,ADD); |
| 434 |
|
| 435 |
Array<GO> uniqueVector; |
| 436 |
for (unsigned i=0; i<myIndices->getLocalLength(); i++) { |
| 437 |
if (myIndices->getData(0)[i] == map->getComm()->getRank()+1) { |
| 438 |
uniqueVector.push_back(map->getGlobalElement(i)); |
| 439 |
} |
| 440 |
} |
| 441 |
const GO INVALID = Teuchos::OrdinalTraits<GO>::invalid(); |
| 442 |
return MapFactory<LO,GO,NO>::Build(map->lib(),INVALID,uniqueVector(),0,map->getComm()); // We need this setup for maps with offset (with MaxGID+1 not being the number of global elements), or we need an allreduce to determine the number of global elements from uniqueVector |
| 443 |
// return MapFactory<LO,GO,NO>::Build(map->lib(),map->getMaxAllGlobalIndex()+1,uniqueVector(),0,map->getComm()); |
| 444 |
} |
| 445 |
} |
| 446 |
|
| 447 |
template <class SC,class LO,class GO,class NO> |
| 448 |
ArrayRCP<RCP<const Map<LO,GO,NO> > > BuildRepeatedSubMaps(RCP<const Matrix<SC,LO,GO,NO> > matrix, |
| 449 |
ArrayRCP<RCP<const Map<LO,GO,NO> > > subMaps) |
| 450 |
{ |
| 451 |
FROSCH_DETAILTIMER_START(buildRepeatedSubMapsTime,"BuildRepeatedSubMaps"); |
| 452 |
ArrayRCP<RCP<Map<LO,GO,NO> > > repeatedSubMaps(subMaps.size()); |
| 453 |
for (unsigned i = 0; i < subMaps.size(); i++) { |
| 454 |
RCP<Matrix<SC,LO,GO,NO> > subMatrixII; |
| 455 |
ArrayView<GO> indI = av_const_cast<GO> ( subMaps[i]->getLocalElementList() ); |
| 456 |
|
| 457 |
BuildSubmatrix(matrix,indI,subMatrixII); |
| 458 |
|
| 459 |
repeatedSubMaps[i] = BuildRepeatedMap(subMatrixII); |
| 460 |
} |
| 461 |
|
| 462 |
return repeatedSubMaps; |
| 463 |
} |
| 464 |
|
| 465 |
template <class LO,class GO,class NO> |
| 466 |
ArrayRCP<RCP<const Map<LO,GO,NO> > > BuildRepeatedSubMaps(RCP<const CrsGraph<LO,GO,NO> > graph, |
| 467 |
ArrayRCP<RCP<const Map<LO,GO,NO> > > subMaps) |
| 468 |
{ |
| 469 |
FROSCH_DETAILTIMER_START(buildRepeatedSubMapsTime,"BuildRepeatedSubMaps"); |
| 470 |
ArrayRCP<RCP<Map<LO,GO,NO> > > repeatedSubMaps(subMaps.size()); |
| 471 |
for (unsigned i = 0; i < subMaps.size(); i++) { |
| 472 |
RCP<CrsGraph<LO,GO,NO> > subGraphII; |
| 473 |
ArrayView<GO> indI = av_const_cast<GO> ( subMaps[i]->getLocalElementList() ); |
| 474 |
|
| 475 |
BuildSubgraph(graph,indI,subGraphII); |
| 476 |
|
| 477 |
repeatedSubMaps[i] = BuildRepeatedMap(subGraphII); |
| 478 |
} |
| 479 |
|
| 480 |
return repeatedSubMaps; |
| 481 |
} |
| 482 |
|
| 483 |
template <class SC,class LO,class GO,class NO> |
| 484 |
RCP<Map<LO,GO,NO> > BuildRepeatedMapNonConstOld(RCP<const Matrix<SC,LO,GO,NO> > matrix) |
| 485 |
{ |
| 486 |
FROSCH_DETAILTIMER_START(buildRepeatedMapNonConstTime,"BuildRepeatedMapNonConstOld"); |
| 487 |
RCP<Map<LO,GO,NO> > uniqueMap = MapFactory<LO,GO,NO>::Build(matrix->getRowMap(),1); |
| 488 |
RCP<const Map<LO,GO,NO> > overlappingMap = uniqueMap.getConst(); |
| 489 |
ExtendOverlapByOneLayer<SC,LO,GO,NO>(matrix,overlappingMap,matrix,overlappingMap); |
| 490 |
|
| 491 |
RCP<Matrix<SC,LO,GO,NO> > tmpMatrix = MatrixFactory<SC,LO,GO,NO>::Build(overlappingMap,matrix->getGlobalMaxNumRowEntries()); |
| 492 |
|
| 493 |
RCP<Import<LO,GO,NO> > scatter; |
| 494 |
RCP<Export<LO,GO,NO> > gather = ExportFactory<LO,GO,NO>::Build(overlappingMap,uniqueMap); |
| 495 |
|
| 496 |
if (tmpMatrix->getRowMap()->lib()==UseEpetra) { |
| 497 |
scatter = ImportFactory<LO,GO,NO>::Build(uniqueMap,overlappingMap); |
| 498 |
tmpMatrix->doImport(*matrix,*scatter,ADD); |
| 499 |
} else { |
| 500 |
tmpMatrix->doImport(*matrix,*gather,ADD); |
| 501 |
} |
| 502 |
|
| 503 |
Array<SC> one(1,ScalarTraits<SC>::one()); |
| 504 |
Array<GO> myPID(1,uniqueMap->getComm()->getRank()); |
| 505 |
|
| 506 |
RCP<Matrix<SC,LO,GO,NO> > commMat = MatrixFactory<SC,LO,GO,NO>::Build(overlappingMap,10); |
| 507 |
RCP<Matrix<SC,LO,GO,NO> > commMatTmp = MatrixFactory<SC,LO,GO,NO>::Build(uniqueMap,10); |
| 508 |
|
| 509 |
for (unsigned i=0; i<overlappingMap->getLocalNumElements(); i++) { |
| 510 |
GO globalRow = overlappingMap->getGlobalElement(i); |
| 511 |
if (uniqueMap->getLocalElement(globalRow)<0) { |
| 512 |
ArrayView<const GO> indices; |
| 513 |
ArrayView<const SC> values; |
| 514 |
tmpMatrix->getGlobalRowView(globalRow,indices,values); |
| 515 |
|
| 516 |
LO j=0; |
| 517 |
while (j<indices.size() && overlappingMap->getLocalElement(indices[j])>=0) { |
| 518 |
j++; |
| 519 |
} |
| 520 |
if (j!=indices.size()) { |
| 521 |
commMat->insertGlobalValues(overlappingMap->getGlobalElement(i),myPID(),one()); // Hier werden immer nur einzelne Werte eingefügt -> Das geht schneller, wenn es Zeilenwise gemacht wird |
| 522 |
} |
| 523 |
} |
| 524 |
} |
| 525 |
commMat->fillComplete(); |
| 526 |
commMatTmp->doExport(*commMat,*gather,INSERT); |
| 527 |
|
| 528 |
RCP<Matrix<SC,LO,GO,NO> > commMatTmp2 = MatrixFactory<SC,LO,GO,NO>::Build(uniqueMap,10); |
| 529 |
for (unsigned i=0; i<uniqueMap->getLocalNumElements(); i++) { |
| 530 |
GO globalRow = uniqueMap->getGlobalElement(i); |
| 531 |
ArrayView<const GO> indices; |
| 532 |
ArrayView<const SC> values; |
| 533 |
commMatTmp->getGlobalRowView(globalRow,indices,values); |
| 534 |
|
| 535 |
if (indices.size()>0) { |
| 536 |
for (LO j=0; j<indices.size(); j++) { |
| 537 |
Array<GO> pID(1,indices[j]); |
| 538 |
if (pID<myPID) { |
| 539 |
commMatTmp2->insertGlobalValues(globalRow,pID(),one()); // Hier werden immer nur einzelne Werte eingefügt -> Das geht schneller, wenn es Zeilenwise gemacht wird |
| 540 |
} |
| 541 |
} |
| 542 |
} |
| 543 |
} |
| 544 |
commMatTmp2->fillComplete(); |
| 545 |
commMatTmp.reset(); |
| 546 |
commMat = MatrixFactory<SC,LO,GO,NO>::Build(overlappingMap,10); |
| 547 |
|
| 548 |
commMat->doImport(*commMatTmp2,*gather,ADD); |
| 549 |
|
| 550 |
ArrayView<const GO> myGlobalElements = uniqueMap->getLocalElementList(); |
| 551 |
Array<GO> repeatedIndices(uniqueMap->getLocalNumElements()); |
| 552 |
for (unsigned i=0; i<uniqueMap->getLocalNumElements(); i++) { |
| 553 |
repeatedIndices.at(i) = myGlobalElements[i]; |
| 554 |
} |
| 555 |
|
| 556 |
for (unsigned i=0; i<overlappingMap->getLocalNumElements(); i++) { |
| 557 |
GO globalRow = overlappingMap->getGlobalElement(i); |
| 558 |
ArrayView<const GO> indices; |
| 559 |
ArrayView<const SC> values; |
| 560 |
commMat->getGlobalRowView(globalRow,indices,values); |
| 561 |
|
| 562 |
if (indices.size()>0) { |
| 563 |
for (LO j=0; j<indices.size(); j++) { |
| 564 |
GO pID = indices[j]; |
| 565 |
if (pID==myPID[0]) { |
| 566 |
repeatedIndices.push_back(globalRow); |
| 567 |
} |
| 568 |
} |
| 569 |
} |
| 570 |
} |
| 571 |
sortunique(repeatedIndices); |
| 572 |
const GO INVALID = Teuchos::OrdinalTraits<GO>::invalid(); |
| 573 |
return MapFactory<LO,GO,NO>::Build(tmpMatrix->getRowMap()->lib(),INVALID,repeatedIndices(),0,matrix->getRowMap()->getComm()); |
| 574 |
} |
| 575 |
|
| 576 |
template <class SC,class LO,class GO,class NO> |
| 577 |
RCP<const Map<LO,GO,NO> > BuildRepeatedMapOld(RCP<const Matrix<SC,LO,GO,NO> > matrix) |
| 578 |
{ |
| 579 |
return BuildRepeatedMapNonConst(matrix).getConst(); |
| 580 |
} |
| 581 |
|
| 582 |
template <class LO,class GO,class NO> |
| 583 |
RCP<Map<LO,GO,NO> > BuildRepeatedMapNonConstOld(RCP<const CrsGraph<LO,GO,NO> > graph) |
| 584 |
{ |
| 585 |
FROSCH_DETAILTIMER_START(buildRepeatedMapNonConstTime,"BuildRepeatedMapNonConstOld"); |
| 586 |
RCP<Map<LO,GO,NO> > uniqueMap = MapFactory<LO,GO,NO>::Build(graph->getRowMap(),1); |
| 587 |
RCP<const Map<LO,GO,NO> > overlappingMap = uniqueMap.getConst(); |
| 588 |
ExtendOverlapByOneLayer<LO,GO,NO>(graph,overlappingMap,graph,overlappingMap); |
| 589 |
|
| 590 |
RCP<CrsGraph<LO,GO,NO> > tmpGraph = CrsGraphFactory<LO,GO,NO>::Build(overlappingMap); |
| 591 |
|
| 592 |
RCP<Import<LO,GO,NO> > scatter; |
| 593 |
RCP<Export<LO,GO,NO> > gather = ExportFactory<LO,GO,NO>::Build(overlappingMap,uniqueMap); |
| 594 |
|
| 595 |
if (tmpGraph->getRowMap()->lib()==UseEpetra) { |
| 596 |
scatter = ImportFactory<LO,GO,NO>::Build(uniqueMap,overlappingMap); |
| 597 |
tmpGraph->doImport(*graph,*scatter,ADD); |
| 598 |
} else { |
| 599 |
tmpGraph->doImport(*graph,*gather,ADD); |
| 600 |
} |
| 601 |
|
| 602 |
Array<GO> myPID(1,uniqueMap->getComm()->getRank()); |
| 603 |
|
| 604 |
RCP<CrsGraph<LO,GO,NO> > commGraph = CrsGraphFactory<LO,GO,NO>::Build(overlappingMap,10); |
| 605 |
RCP<CrsGraph<LO,GO,NO> > commGraphTmp = CrsGraphFactory<LO,GO,NO>::Build(uniqueMap,10); |
| 606 |
|
| 607 |
for (unsigned i=0; i<overlappingMap->getLocalNumElements(); i++) { |
| 608 |
GO globalRow = overlappingMap->getGlobalElement(i); |
| 609 |
if (uniqueMap->getLocalElement(globalRow)<0) { |
| 610 |
ArrayView<const GO> indices; |
| 611 |
tmpGraph->getGlobalRowView(globalRow,indices); |
| 612 |
|
| 613 |
LO j=0; |
| 614 |
while (j<indices.size() && overlappingMap->getLocalElement(indices[j])>=0) { |
| 615 |
j++; |
| 616 |
} |
| 617 |
if (j!=indices.size()) { |
| 618 |
commGraph->insertGlobalIndices(overlappingMap->getGlobalElement(i),myPID()); |
| 619 |
} |
| 620 |
} |
| 621 |
} |
| 622 |
commGraph->fillComplete(); |
| 623 |
commGraphTmp->doExport(*commGraph,*gather,INSERT); |
| 624 |
|
| 625 |
RCP<CrsGraph<LO,GO,NO> > commGraphTmp2 = CrsGraphFactory<LO,GO,NO>::Build(uniqueMap,10); |
| 626 |
for (unsigned i=0; i<uniqueMap->getLocalNumElements(); i++) { |
| 627 |
GO globalRow = uniqueMap->getGlobalElement(i); |
| 628 |
ArrayView<const GO> indices; |
| 629 |
commGraphTmp->getGlobalRowView(globalRow,indices); |
| 630 |
|
| 631 |
if (indices.size()>0) { |
| 632 |
for (LO j=0; j<indices.size(); j++) { |
| 633 |
Array<GO> pID(1,indices[j]); |
| 634 |
if (pID<myPID) { |
| 635 |
commGraphTmp2->insertGlobalIndices(globalRow,pID()); |
| 636 |
} |
| 637 |
} |
| 638 |
} |
| 639 |
} |
| 640 |
commGraphTmp2->fillComplete(); |
| 641 |
commGraphTmp.reset(); |
| 642 |
commGraph = CrsGraphFactory<LO,GO,NO>::Build(overlappingMap,10); |
| 643 |
|
| 644 |
commGraph->doImport(*commGraphTmp2,*gather,ADD); |
| 645 |
|
| 646 |
ArrayView<const GO> myGlobalElements = uniqueMap->getLocalElementList(); |
| 647 |
Array<GO> repeatedIndices(uniqueMap->getLocalNumElements()); |
| 648 |
for (unsigned i=0; i<uniqueMap->getLocalNumElements(); i++) { |
| 649 |
repeatedIndices.at(i) = myGlobalElements[i]; |
| 650 |
} |
| 651 |
|
| 652 |
for (unsigned i=0; i<overlappingMap->getLocalNumElements(); i++) { |
| 653 |
GO globalRow = overlappingMap->getGlobalElement(i); |
| 654 |
ArrayView<const GO> indices; |
| 655 |
commGraph->getGlobalRowView(globalRow,indices); |
| 656 |
|
| 657 |
if (indices.size()>0) { |
| 658 |
for (LO j=0; j<indices.size(); j++) { |
| 659 |
GO pID = indices[j]; |
| 660 |
if (pID==myPID[0]) { |
| 661 |
repeatedIndices.push_back(globalRow); |
| 662 |
} |
| 663 |
} |
| 664 |
} |
| 665 |
} |
| 666 |
sortunique(repeatedIndices); |
| 667 |
const GO INVALID = Teuchos::OrdinalTraits<GO>::invalid(); |
| 668 |
return MapFactory<LO,GO,NO>::Build(tmpGraph->getRowMap()->lib(),INVALID,repeatedIndices(),0,graph->getRowMap()->getComm()); |
| 669 |
} |
| 670 |
|
| 671 |
template <class LO,class GO,class NO> |
| 672 |
RCP<const Map<LO,GO,NO> > BuildRepeatedMapOld(RCP<const CrsGraph<LO,GO,NO> > graph) |
| 673 |
{ |
| 674 |
return BuildRepeatedMapNonConstOld(graph).getConst(); |
| 675 |
} |
| 676 |
|
| 677 |
template <class SC,class LO,class GO,class NO> |
| 678 |
RCP<Map<LO,GO,NO> > BuildRepeatedMapNonConst(RCP<const Matrix<SC,LO,GO,NO> > matrix) |
| 679 |
{ |
| 680 |
return BuildRepeatedMapNonConst(matrix->getCrsGraph()); |
| 681 |
} |
| 682 |
|
| 683 |
template <class SC,class LO,class GO,class NO> |
| 684 |
RCP<const Map<LO,GO,NO> > BuildRepeatedMap(RCP<const Matrix<SC,LO,GO,NO> > matrix) |
| 685 |
{ |
| 686 |
return BuildRepeatedMapNonConst(matrix).getConst(); |
| 687 |
} |
| 688 |
|
| 689 |
template <class LO,class GO,class NO> |
| 690 |
RCP<Map<LO,GO,NO> > BuildRepeatedMapNonConst(RCP<const CrsGraph<LO,GO,NO> > graph) |
| 691 |
{ |
| 692 |
FROSCH_DETAILTIMER_START(buildRepeatedMapNonConstTime,"BuildRepeatedMapNonConst"); |
| 693 |
const GO INVALID = Teuchos::OrdinalTraits<GO>::invalid(); |
| 694 |
RCP<const Map<LO,GO,NO> > uniqueMap = graph->getRowMap(); |
| 695 |
RCP<const Map<LO,GO,NO> > overlappingMap; |
| 696 |
ExtendOverlapByOneLayer<LO,GO,NO>(graph,uniqueMap,graph,overlappingMap); |
| 697 |
|
| 698 |
RCP<CrsGraph<LO,GO,NO> > tmpGraphUnique = CrsGraphFactory<LO,GO,NO>::Build(uniqueMap,1); |
| 699 |
Array<GO> myPID(1,uniqueMap->getComm()->getRank()); |
| 700 |
for (unsigned i=0; i<uniqueMap->getLocalNumElements(); i++) { |
| 701 |
tmpGraphUnique->insertGlobalIndices(uniqueMap->getGlobalElement(i),myPID()); |
| 702 |
} |
| 703 |
RCP<Map<LO,GO,NO> > domainMap = MapFactory<LO,GO,NO>::Build(uniqueMap->lib(),INVALID,myPID(),0,uniqueMap->getComm()); |
| 704 |
tmpGraphUnique->fillComplete(domainMap,uniqueMap); |
| 705 |
RCP<CrsGraph<LO,GO,NO> > tmpGraphOverlap = CrsGraphFactory<LO,GO,NO>::Build(overlappingMap); |
| 706 |
RCP<Import<LO,GO,NO> > importer = ImportFactory<LO,GO,NO>::Build(uniqueMap,overlappingMap); |
| 707 |
tmpGraphOverlap->doImport(*tmpGraphUnique,*importer,ADD); |
| 708 |
ArrayView<const GO> indices; |
| 709 |
Array<GO> repeatedIndices(0); |
| 710 |
for (unsigned i=0; i<overlappingMap->getLocalNumElements(); i++) { |
| 711 |
tmpGraphOverlap->getGlobalRowView(overlappingMap->getGlobalElement(i),indices); |
| 712 |
for (unsigned j=0; j<indices.size(); j++) { |
| 713 |
if (indices[j]<=uniqueMap->getComm()->getRank()) { |
| 714 |
repeatedIndices.push_back(overlappingMap->getGlobalElement(i)); |
| 715 |
} |
| 716 |
} |
| 717 |
} |
| 718 |
sortunique(repeatedIndices); |
| 719 |
return MapFactory<LO,GO,NO>::Build(uniqueMap->lib(),INVALID,repeatedIndices(),0,uniqueMap->getComm()); |
| 720 |
} |
| 721 |
|
| 722 |
template <class LO,class GO,class NO> |
| 723 |
RCP<const Map<LO,GO,NO> > BuildRepeatedMap(RCP<const CrsGraph<LO,GO,NO> > graph) |
| 724 |
{ |
| 725 |
return BuildRepeatedMapNonConst(graph).getConst(); |
| 726 |
} |
| 727 |
|
| 728 |
template <class LO,class GO,class NO> |
| 729 |
Teuchos::RCP<Xpetra::Map<LO,GO,NO> > BuildMapFromNodeMapRepeated(Teuchos::RCP<const Xpetra::Map<LO,GO,NO> > &nodesMap, |
| 730 |
unsigned dofsPerNode, |
| 731 |
unsigned dofOrdering) |
| 732 |
{ |
| 733 |
FROSCH_ASSERT(dofOrdering==0 || dofOrdering==1,"ERROR: Specify a valid DofOrdering."); |
| 734 |
FROSCH_ASSERT(!nodesMap.is_null(),"nodesMap.is_null()."); |
| 735 |
|
| 736 |
unsigned numNodes = nodesMap->getLocalNumElements(); |
| 737 |
Teuchos::Array<GO> globalIDs(dofsPerNode*numNodes); |
| 738 |
if (dofOrdering==0) { |
| 739 |
for (unsigned i=0; i<dofsPerNode; i++) { |
| 740 |
for (unsigned j=0; j<numNodes; j++) { |
| 741 |
globalIDs[dofsPerNode*j+i] = dofsPerNode*(nodesMap->getMaxGlobalIndex()+1)+i; |
| 742 |
} |
| 743 |
} |
| 744 |
} else if (dofOrdering == 1) { |
| 745 |
for (unsigned i=0; i<dofsPerNode; i++) { |
| 746 |
for (unsigned j=0; j<numNodes; j++) { |
| 747 |
globalIDs[j+i*numNodes] = nodesMap->getGlobalElement(j)+i*(nodesMap->getMaxGlobalIndex()+1); |
| 748 |
} |
| 749 |
} |
| 750 |
} else { |
| 751 |
FROSCH_ASSERT(false,"dofOrdering unknown."); |
| 752 |
} |
| 753 |
|
| 754 |
const GO INVALID = Teuchos::OrdinalTraits<GO>::invalid(); |
| 755 |
return Xpetra::MapFactory<LO,GO,NO>::Build(nodesMap->lib(),INVALID,globalIDs(),0,nodesMap->getComm()); |
| 756 |
} |
| 757 |
|
| 758 |
/* |
| 759 |
template <class SC,class LO,class GO,class NO> |
| 760 |
RCP<Map<LO,GO,NO> > BuildRepeatedMap(RCP<Matrix<SC,LO,GO,NO> > matrix) |
| 761 |
{ |
| 762 |
RCP<Map<LO,GO,NO> > uniqueMap = MapFactory<LO,GO,NO>::Build(matrix->getRowMap(),1); |
| 763 |
RCP<Map<LO,GO,NO> > overlappingMap = uniqueMap; |
| 764 |
ExtendOverlapByOneLayer<SC,LO,GO,NO>(matrix,overlappingMap); |
| 765 |
|
| 766 |
RCP<Matrix<SC,LO,GO,NO> > tmpMatrix = matrix; |
| 767 |
matrix = MatrixFactory<SC,LO,GO,NO>::Build(overlappingMap,2*tmpMatrix->getGlobalMaxNumRowEntries()); |
| 768 |
RCP<Import<LO,GO,NO> > scatter = ImportFactory<LO,GO,NO>::Build(uniqueMap,overlappingMap); |
| 769 |
|
| 770 |
matrix->doImport(*tmpMatrix,*scatter,ADD); |
| 771 |
|
| 772 |
Array<SC> one(1,ScalarTraits<SC>::one()); |
| 773 |
Array<GO> myPID(1,uniqueMap->getComm()->getRank()); |
| 774 |
|
| 775 |
RCP<Matrix<SC,LO,GO,NO> > commMat = MatrixFactory<SC,LO,GO,NO>::Build(overlappingMap,10); |
| 776 |
RCP<Matrix<SC,LO,GO,NO> > commMatTmp = MatrixFactory<SC,LO,GO,NO>::Build(uniqueMap,10); |
| 777 |
RCP<Export<LO,GO,NO> > commExporter = ExportFactory<LO,GO,NO>::Build(overlappingMap,uniqueMap); |
| 778 |
|
| 779 |
for (unsigned i=0; i<overlappingMap->getLocalNumElements(); i++) { |
| 780 |
GO globalRow = overlappingMap->getGlobalElement(i); |
| 781 |
if (uniqueMap->getLocalElement(globalRow)<0) { |
| 782 |
ArrayView<const GO> indices; |
| 783 |
ArrayView<const SC> values; |
| 784 |
matrix->getGlobalRowView(globalRow,indices,values); |
| 785 |
|
| 786 |
LO j=0; |
| 787 |
while (j<indices.size() && overlappingMap->getLocalElement(indices[j])>=0) { |
| 788 |
j++; |
| 789 |
} |
| 790 |
if (j!=indices.size()) { |
| 791 |
commMat->insertGlobalValues(overlappingMap->getGlobalElement(i),myPID(),one()); // Hier werden immer nur einzelne Werte eingefügt -> Das geht schneller, wenn es Zeilenwise gemacht wird |
| 792 |
} |
| 793 |
} |
| 794 |
} |
| 795 |
commMat->fillComplete(); |
| 796 |
commMatTmp->doExport(*commMat,*commExporter,INSERT); |
| 797 |
|
| 798 |
RCP<Matrix<SC,LO,GO,NO> > commMatTmp2 = MatrixFactory<SC,LO,GO,NO>::Build(uniqueMap,10); |
| 799 |
for (unsigned i=0; i<uniqueMap->getLocalNumElements(); i++) { |
| 800 |
GO globalRow = uniqueMap->getGlobalElement(i); |
| 801 |
ArrayView<const GO> indices; |
| 802 |
ArrayView<const SC> values; |
| 803 |
commMatTmp->getGlobalRowView(globalRow,indices,values); |
| 804 |
|
| 805 |
if (indices.size()>0) { |
| 806 |
for (LO j=0; j<indices.size(); j++) { |
| 807 |
Array<GO> pID(1,indices[j]); |
| 808 |
if (pID<myPID) { |
| 809 |
commMatTmp2->insertGlobalValues(globalRow,pID(),one()); // Hier werden immer nur einzelne Werte eingefügt -> Das geht schneller, wenn es Zeilenwise gemacht wird |
| 810 |
} |
| 811 |
} |
| 812 |
} |
| 813 |
} |
| 814 |
commMatTmp2->fillComplete(); |
| 815 |
commMatTmp.reset(); |
| 816 |
commMat = MatrixFactory<SC,LO,GO,NO>::Build(overlappingMap,10); |
| 817 |
commMat->doImport(*commMatTmp2,*commExporter,ADD); |
| 818 |
|
| 819 |
ArrayView<const GO> myGlobalElements = uniqueMap->getLocalElementList(); |
| 820 |
Array<GO> repeatedIndices(uniqueMap->getLocalNumElements()); |
| 821 |
for (unsigned i=0; i<uniqueMap->getLocalNumElements(); i++) { |
| 822 |
repeatedIndices.at(i) = myGlobalElements[i]; |
| 823 |
} |
| 824 |
|
| 825 |
for (unsigned i=0; i<overlappingMap->getLocalNumElements(); i++) { |
| 826 |
GO globalRow = overlappingMap->getGlobalElement(i); |
| 827 |
ArrayView<const GO> indices; |
| 828 |
ArrayView<const SC> values; |
| 829 |
commMat->getGlobalRowView(globalRow,indices,values); |
| 830 |
|
| 831 |
if (indices.size()>0) { |
| 832 |
for (LO j=0; j<indices.size(); j++) { |
| 833 |
GO pID = indices[j]; |
| 834 |
if (pID==myPID[0]) { |
| 835 |
repeatedIndices.push_back(globalRow); |
| 836 |
} |
| 837 |
} |
| 838 |
} |
| 839 |
} |
| 840 |
sortunique(repeatedIndices); |
| 841 |
return MapFactory<LO,GO,NO>::Build(matrix->getRowMap()->lib(),-1,repeatedIndices(),0,matrix->getRowMap()->getComm()); |
| 842 |
} |
| 843 |
*/ |
| 844 |
|
| 845 |
template <class SC,class LO,class GO,class NO> |
| 846 |
int ExtendOverlapByOneLayer_Old(RCP<const Matrix<SC,LO,GO,NO> > inputMatrix, |
| 847 |
RCP<const Map<LO,GO,NO> > inputMap, |
| 848 |
RCP<const Matrix<SC,LO,GO,NO> > &outputMatrix, |
| 849 |
RCP<const Map<LO,GO,NO> > &outputMap) |
| 850 |
{ |
| 851 |
FROSCH_DETAILTIMER_START(extendOverlapByOneLayer_OldTime,"ExtendOverlapByOneLayer_Old"); |
| 852 |
RCP<Matrix<SC,LO,GO,NO> > tmpMatrix = MatrixFactory<SC,LO,GO,NO>::Build(inputMap,inputMatrix->getGlobalMaxNumRowEntries()); |
| 853 |
RCP<Import<LO,GO,NO> > scatter = ImportFactory<LO,GO,NO>::Build(inputMatrix->getRowMap(),inputMap); |
| 854 |
tmpMatrix->doImport(*inputMatrix,*scatter,ADD); |
| 855 |
outputMatrix = tmpMatrix.getConst(); |
| 856 |
|
| 857 |
Array<GO> indicesOverlappingSubdomain(0); |
| 858 |
for (unsigned i=0; i<inputMap->getLocalNumElements(); i++) { |
| 859 |
ArrayView<const GO> indices; |
| 860 |
ArrayView<const SC> values; |
| 861 |
outputMatrix->getGlobalRowView(inputMap->getGlobalElement(i),indices,values); |
| 862 |
|
| 863 |
for (LO j=0; j<indices.size(); j++) { |
| 864 |
indicesOverlappingSubdomain.push_back(indices[j]); |
| 865 |
} |
| 866 |
} |
| 867 |
sortunique(indicesOverlappingSubdomain); |
| 868 |
const GO INVALID = Teuchos::OrdinalTraits<GO>::invalid(); |
| 869 |
outputMap = MapFactory<LO,GO,NO>::Build(inputMap->lib(),INVALID,indicesOverlappingSubdomain(),0,inputMap->getComm()); |
| 870 |
tmpMatrix->fillComplete(inputMatrix->getDomainMap(),inputMatrix->getRangeMap()); |
| 871 |
|
| 872 |
return 0; |
| 873 |
} |
| 874 |
|
| 875 |
template <class SC,class LO,class GO,class NO> |
| 876 |
int ExtendOverlapByOneLayer(RCP<const Matrix<SC,LO,GO,NO> > inputMatrix, |
| 877 |
RCP<const Map<LO,GO,NO> > inputMap, |
| 878 |
RCP<const Matrix<SC,LO,GO,NO> > &outputMatrix, |
| 879 |
RCP<const Map<LO,GO,NO> > &outputMap) |
| 880 |
{ |
| 881 |
FROSCH_DETAILTIMER_START(extendOverlapByOneLayerTime,"ExtendOverlapByOneLayer"); |
| 882 |
RCP<Matrix<SC,LO,GO,NO> > tmpMatrix = MatrixFactory<SC,LO,GO,NO>::Build(inputMap,inputMatrix->getGlobalMaxNumRowEntries()); |
| 883 |
RCP<Import<LO,GO,NO> > scatter = ImportFactory<LO,GO,NO>::Build(inputMatrix->getRowMap(),inputMap); |
| 884 |
tmpMatrix->doImport(*inputMatrix,*scatter,ADD); |
| 885 |
tmpMatrix->fillComplete(inputMatrix->getDomainMap(),inputMatrix->getRangeMap()); |
| 886 |
|
| 887 |
outputMatrix = tmpMatrix.getConst(); |
| 888 |
outputMap = outputMatrix->getColMap(); |
| 889 |
|
| 890 |
return 0; |
| 891 |
} |
| 892 |
|
| 893 |
template <class LO,class GO,class NO> |
| 894 |
int ExtendOverlapByOneLayer(RCP<const CrsGraph<LO,GO,NO> > inputGraph, |
| 895 |
RCP<const Map<LO,GO,NO> > inputMap, |
| 896 |
RCP<const CrsGraph<LO,GO,NO> > &outputGraph, |
| 897 |
RCP<const Map<LO,GO,NO> > &outputMap) |
| 898 |
{ |
| 899 |
FROSCH_DETAILTIMER_START(extendOverlapByOneLayerTime,"ExtendOverlapByOneLayer"); |
| 900 |
RCP<CrsGraph<LO,GO,NO> > tmpGraph = CrsGraphFactory<LO,GO,NO>::Build(inputMap,inputGraph->getGlobalMaxNumRowEntries()); |
| 901 |
RCP<Import<LO,GO,NO> > scatter = ImportFactory<LO,GO,NO>::Build(inputGraph->getRowMap(),inputMap); |
| 902 |
tmpGraph->doImport(*inputGraph,*scatter,ADD); |
| 903 |
tmpGraph->fillComplete(inputGraph->getDomainMap(),inputGraph->getRangeMap()); |
| 904 |
|
| 905 |
outputGraph = tmpGraph.getConst(); |
| 906 |
outputMap = outputGraph->getColMap(); |
| 907 |
|
| 908 |
return 0; |
| 909 |
} |
| 910 |
|
| 911 |
template <class LO,class GO,class NO> |
| 912 |
RCP<const Map<LO,GO,NO> > SortMapByGlobalIndex(RCP<const Map<LO,GO,NO> > inputMap) |
| 913 |
{ |
| 914 |
FROSCH_DETAILTIMER_START(sortMapByGlobalIndexTime,"SortMapByGlobalIndex"); |
| 915 |
Array<GO> globalIDs(inputMap->getLocalElementList()); |
| 916 |
sort(globalIDs); |
| 917 |
|
| 918 |
const GO INVALID = Teuchos::OrdinalTraits<GO>::invalid(); |
| 919 |
return MapFactory<LO,GO,NO>::Build(inputMap->lib(),INVALID,globalIDs(),0,inputMap->getComm()); |
| 920 |
} |
| 921 |
|
| 922 |
template <class LO,class GO,class NO> |
| 923 |
RCP<Map<LO,GO,NO> > AssembleMaps(ArrayView<RCP<const Map<LO,GO,NO> > > mapVector, |
| 924 |
ArrayRCP<ArrayRCP<LO> > &partMappings) |
| 925 |
{ |
| 926 |
FROSCH_DETAILTIMER_START(assembleMapsTime,"AssembleMaps"); |
| 927 |
FROSCH_ASSERT(mapVector.size()>0,"Length of mapVector is == 0!"); |
| 928 |
LO i = 0; |
| 929 |
LO localstart = 0; |
| 930 |
LO sizetmp = 0; |
| 931 |
LO size = 0; |
| 932 |
GO globalstart = 0; |
| 933 |
|
| 934 |
partMappings = ArrayRCP<ArrayRCP<LO> >(mapVector.size()); |
| 935 |
|
| 936 |
ArrayRCP<GO> assembledMapTmp(0); |
| 937 |
for (unsigned j=0; j<mapVector.size(); j++) { |
| 938 |
sizetmp = mapVector[j]->getLocalNumElements(); |
| 939 |
partMappings[j] = ArrayRCP<LO>(sizetmp); |
| 940 |
|
| 941 |
size += sizetmp; |
| 942 |
assembledMapTmp.resize(size); |
| 943 |
|
| 944 |
localstart = i; |
| 945 |
while (i<localstart+sizetmp) { |
| 946 |
partMappings[j][i-localstart] = i; |
| 947 |
assembledMapTmp[i] = globalstart + mapVector[j]->getGlobalElement(i-localstart); |
| 948 |
i++; |
| 949 |
} |
| 950 |
//cout << mapVector[j]->getMaxAllGlobalIndex() << endl; |
| 951 |
/* |
| 952 |
globalstart += mapVector[j]->getMaxAllGlobalIndex(); |
| 953 |
|
| 954 |
if (mapVector[0]->lib()==UseEpetra || mapVector[j]->getGlobalNumElements()>0) { |
| 955 |
globalstart += 1; |
| 956 |
} |
| 957 |
*/ |
| 958 |
|
| 959 |
globalstart += max(mapVector[j]->getMaxAllGlobalIndex(),(GO)-1)+1; // AH 04/05/2018: mapVector[j]->getMaxAllGlobalIndex() can result in -2147483648 if the map is empty on the process => introducing max(,) |
| 960 |
|
| 961 |
//if (mapVector[j]->getComm()->getRank() == 0) cout << endl << globalstart << endl; |
| 962 |
} |
| 963 |
|
| 964 |
const GO INVALID = Teuchos::OrdinalTraits<GO>::invalid(); |
| 965 |
return MapFactory<LO,GO,NO>::Build(mapVector[0]->lib(),INVALID,assembledMapTmp(),0,mapVector[0]->getComm()); |
| 966 |
} |
| 967 |
|
| 968 |
template <class LO,class GO,class NO> |
| 969 |
RCP<Map<LO,GO,NO> > AssembleMapsNonConst(ArrayView<RCP<Map<LO,GO,NO> > > mapVector, |
| 970 |
ArrayRCP<ArrayRCP<LO> > &partMappings) |
| 971 |
{ |
| 972 |
FROSCH_DETAILTIMER_START(assembleMapsTime,"AssembleMapsNonConst"); |
| 973 |
FROSCH_ASSERT(mapVector.size()>0,"Length of mapVector is == 0!"); |
| 974 |
LO i = 0; |
| 975 |
LO localstart = 0; |
| 976 |
LO sizetmp = 0; |
| 977 |
LO size = 0; |
| 978 |
GO globalstart = 0; |
| 979 |
|
| 980 |
partMappings = ArrayRCP<ArrayRCP<LO> >(mapVector.size()); |
| 981 |
|
| 982 |
ArrayRCP<GO> assembledMapTmp(0); |
| 983 |
for (unsigned j=0; j<mapVector.size(); j++) { |
| 984 |
sizetmp = mapVector[j]->getLocalNumElements(); |
| 985 |
partMappings[j] = ArrayRCP<LO>(sizetmp); |
| 986 |
|
| 987 |
size += sizetmp; |
| 988 |
assembledMapTmp.resize(size); |
| 989 |
|
| 990 |
localstart = i; |
| 991 |
while (i<localstart+sizetmp) { |
| 992 |
partMappings[j][i-localstart] = i; |
| 993 |
assembledMapTmp[i] = globalstart + mapVector[j]->getGlobalElement(i-localstart); |
| 994 |
i++; |
| 995 |
} |
| 996 |
//std::cout << mapVector[j]->getMaxAllGlobalIndex() << std::endl; |
| 997 |
/* |
| 998 |
globalstart += mapVector[j]->getMaxAllGlobalIndex(); |
| 999 |
|
| 1000 |
if (mapVector[0]->lib()==UseEpetra || mapVector[j]->getGlobalNumElements()>0) { |
| 1001 |
globalstart += 1; |
| 1002 |
} |
| 1003 |
*/ |
| 1004 |
|
| 1005 |
globalstart += std::max(mapVector[j]->getMaxAllGlobalIndex(),(GO)-1)+1; // AH 04/05/2018: mapVector[j]->getMaxAllGlobalIndex() can result in -2147483648 if the map is empty on the process => introducing max(,) |
| 1006 |
|
| 1007 |
//if (mapVector[j]->getComm()->getRank() == 0) std::cout << std::endl << globalstart << std::endl; |
| 1008 |
} |
| 1009 |
|
| 1010 |
const GO INVALID = Teuchos::OrdinalTraits<GO>::invalid(); |
| 1011 |
return MapFactory<LO,GO,NO>::Build(mapVector[0]->lib(),INVALID,assembledMapTmp(),0,mapVector[0]->getComm()); |
| 1012 |
} |
| 1013 |
|
| 1014 |
template <class LO,class GO,class NO> |
| 1015 |
RCP<Map<LO,GO,NO> > AssembleSubdomainMap(unsigned numberOfBlocks, |
| 1016 |
ArrayRCP<ArrayRCP<RCP<const Map<LO,GO,NO> > > > dofsMaps, |
| 1017 |
ArrayRCP<unsigned> dofsPerNode) |
| 1018 |
{ |
| 1019 |
FROSCH_DETAILTIMER_START(assembleSubdomainMapTime,"AssembleSubdomainMap"); |
| 1020 |
FROSCH_ASSERT(numberOfBlocks>0,"FROSch: numberOfBlocks==0"); |
| 1021 |
FROSCH_ASSERT(dofsMaps.size()==numberOfBlocks,"FROSch: dofsMaps.size()!=NumberOfBlocks_"); |
| 1022 |
FROSCH_ASSERT(dofsPerNode.size()==numberOfBlocks,"FROSch: dofsPerNode.size()!=NumberOfBlocks_"); |
| 1023 |
|
| 1024 |
Array<GO> mapVector(0); |
| 1025 |
for (unsigned i=0; i<numberOfBlocks; i++) { |
| 1026 |
FROSCH_ASSERT(!dofsMaps[i].is_null(),"FROSch: dofsMaps[i].is_null()"); |
| 1027 |
FROSCH_ASSERT(dofsMaps[i].size()==dofsPerNode[i],"FROSch: dofsMaps[i].size()!=dofsPerNode[i]"); |
| 1028 |
unsigned numMyElements = dofsMaps[i][0]->getLocalNumElements(); |
| 1029 |
for (unsigned j=1; j<dofsPerNode[i]; j++) { |
| 1030 |
FROSCH_ASSERT(dofsMaps[i][j]->getLocalNumElements()==(unsigned) numMyElements,"FROSch: dofsMaps[i][j]->getLocalNumElements()==numMyElements"); |
| 1031 |
} |
| 1032 |
for (unsigned j=0; j<numMyElements; j++) { |
| 1033 |
for (unsigned k=0; k<dofsPerNode[i]; k++) { |
| 1034 |
mapVector.push_back(dofsMaps[i][k]->getGlobalElement(j)); |
| 1035 |
} |
| 1036 |
} |
| 1037 |
} |
| 1038 |
|
| 1039 |
FROSCH_ASSERT(!dofsMaps[0].is_null(),"FROSch: dofsMaps[0].is_null()"); |
| 1040 |
const GO INVALID = Teuchos::OrdinalTraits<GO>::invalid(); |
| 1041 |
return MapFactory<LO,GO,NO>::Build(dofsMaps[0][0]->lib(),INVALID,mapVector(),0,dofsMaps[0][0]->getComm()); |
| 1042 |
} |
| 1043 |
|
| 1044 |
template <class LO,class GO,class NO> |
| 1045 |
RCP<Map<LO,GO,NO> > MergeMapsNonConst(ArrayRCP<RCP<const Map<LO,GO,NO> > > mapVector) |
| 1046 |
{ |
| 1047 |
FROSCH_DETAILTIMER_START(mergeMapsNonConstTime,"MergeMapsNonConst"); |
| 1048 |
FROSCH_ASSERT(!mapVector.is_null(),"mapVector is null!"); |
| 1049 |
FROSCH_ASSERT(mapVector.size()>0,"Length of mapVector is == 0!"); |
| 1050 |
|
| 1051 |
Array<GO> elementList(mapVector[0]->getLocalElementList()); |
| 1052 |
GO tmpOffset = 0; |
| 1053 |
for (unsigned i=1; i<mapVector.size(); i++) { |
| 1054 |
LO nodeNumElements = mapVector[i]->getLocalNumElements(); |
| 1055 |
tmpOffset += mapVector[i-1]->getMaxAllGlobalIndex()+1; |
| 1056 |
|
| 1057 |
Array<GO> subElementList(nodeNumElements); |
| 1058 |
for (LO j=0; j<nodeNumElements; j++) { |
| 1059 |
subElementList.at(j) = mapVector[i]->getGlobalElement(j)+tmpOffset; |
| 1060 |
} |
| 1061 |
|
| 1062 |
elementList.insert(elementList.end(),subElementList.begin(),subElementList.end()); |
| 1063 |
} |
| 1064 |
|
| 1065 |
const GO INVALID = Teuchos::OrdinalTraits<GO>::invalid(); |
| 1066 |
return MapFactory<LO,GO,NO>::Build(mapVector[0]->lib(),INVALID,elementList(),0,mapVector[0]->getComm()); |
| 1067 |
} |
| 1068 |
|
| 1069 |
template <class LO,class GO,class NO> |
| 1070 |
RCP<const Map<LO,GO,NO> > MergeMaps(ArrayRCP<RCP<const Map<LO,GO,NO> > > mapVector) |
| 1071 |
{ |
| 1072 |
return MergeMapsNonConst(mapVector).getConst(); |
| 1073 |
} |
| 1074 |
|
| 1075 |
template <class LO,class GO,class NO> |
| 1076 |
int BuildDofMapsVec(const ArrayRCP<RCP<const Map<LO,GO,NO> > > mapVec, |
| 1077 |
ArrayRCP<unsigned> dofsPerNodeVec, |
| 1078 |
ArrayRCP<FROSch::DofOrdering> dofOrderingVec, |
| 1079 |
ArrayRCP<RCP<const Map<LO,GO,NO> > > &nodesMapVec, |
| 1080 |
ArrayRCP<ArrayRCP<RCP<const Map<LO,GO,NO> > > >&dofMapsVec) |
| 1081 |
{ |
| 1082 |
FROSCH_DETAILTIMER_START(buildDofMapsVecTime,"BuildDofMapsVec"); |
| 1083 |
unsigned numberBlocks = mapVec.size(); |
| 1084 |
nodesMapVec = ArrayRCP<RCP<const Map<LO,GO,NO> > > (numberBlocks); |
| 1085 |
dofMapsVec = ArrayRCP<ArrayRCP<RCP<const Map<LO,GO,NO> > > > (numberBlocks); |
| 1086 |
|
| 1087 |
GO tmpOffset = 0; |
| 1088 |
for (unsigned i = 0 ; i < numberBlocks; i++) { |
| 1089 |
BuildDofMaps(mapVec[i],dofsPerNodeVec[i],dofOrderingVec[i],nodesMapVec[i],dofMapsVec[i],tmpOffset); |
| 1090 |
tmpOffset += mapVec[i]->getMaxAllGlobalIndex()+1; |
| 1091 |
} |
| 1092 |
|
| 1093 |
return 0; |
| 1094 |
} |
| 1095 |
|
| 1096 |
|
| 1097 |
template <class LO,class GO,class NO> |
| 1098 |
int BuildDofMaps(const RCP<const Map<LO,GO,NO> > map, |
| 1099 |
unsigned dofsPerNode, |
| 1100 |
unsigned dofOrdering, |
| 1101 |
RCP<const Map<LO,GO,NO> > &nodesMap, |
| 1102 |
ArrayRCP<RCP<const Map<LO,GO,NO> > > &dofMaps, |
| 1103 |
GO offset) |
| 1104 |
{ |
| 1105 |
FROSCH_DETAILTIMER_START(buildDofMapsTime,"BuildDofMaps"); |
| 1106 |
//if (map->getComm()->getRank()==0) cout << "WARNING: BuildDofMaps is yet to be tested...\n"; |
| 1107 |
FROSCH_ASSERT(dofOrdering==0 || dofOrdering==1,"ERROR: Specify a valid DofOrdering."); |
| 1108 |
FROSCH_ASSERT(map->getGlobalNumElements()%dofsPerNode==0 && map->getLocalNumElements()%dofsPerNode==0,"ERROR: The number of dofsPerNode does not divide the number of global dofs in the map!"); |
| 1109 |
|
| 1110 |
Array<GO> nodes(map->getLocalNumElements()/dofsPerNode); |
| 1111 |
Array<ArrayRCP<GO> > dofs(dofsPerNode); |
| 1112 |
for (unsigned j=0; j<dofsPerNode; j++) { |
| 1113 |
dofs[j] = ArrayRCP<GO>(map->getLocalNumElements()/dofsPerNode); |
| 1114 |
} |
| 1115 |
if (dofOrdering==0) { |
| 1116 |
for (unsigned i=0; i<nodes.size(); i++) { |
| 1117 |
nodes[i] = map->getGlobalElement(dofsPerNode*i)/dofsPerNode; |
| 1118 |
for (unsigned j=0; j<dofsPerNode; j++) { |
| 1119 |
dofs[j][i] = dofsPerNode*nodes[i]+j+offset; |
| 1120 |
} |
| 1121 |
} |
| 1122 |
} else if (dofOrdering == 1) { |
| 1123 |
GO numGlobalIDs = map->getMaxAllGlobalIndex()+1; |
| 1124 |
for (unsigned i=0; i<nodes.size(); i++) { |
| 1125 |
nodes[i] = map->getGlobalElement(i); |
| 1126 |
for (unsigned j=0; j<dofsPerNode; j++) { |
| 1127 |
dofs[j][i] = nodes[i]+j*numGlobalIDs/dofsPerNode+offset; |
| 1128 |
} |
| 1129 |
} |
| 1130 |
} else { |
| 1131 |
FROSCH_ASSERT(false,"dofOrdering unknown."); |
| 1132 |
} |
| 1133 |
|
| 1134 |
const GO INVALID = Teuchos::OrdinalTraits<GO>::invalid(); |
| 1135 |
nodesMap = MapFactory<LO,GO,NO>::Build(map->lib(),INVALID,nodes(),0,map->getComm()); |
| 1136 |
|
| 1137 |
dofMaps = ArrayRCP<RCP<const Map<LO,GO,NO> > >(dofsPerNode); |
| 1138 |
for (unsigned j=0; j<dofsPerNode; j++) { |
| 1139 |
dofMaps[j] = MapFactory<LO,GO,NO>::Build(map->lib(),INVALID,dofs[j](),0,map->getComm()); |
| 1140 |
} |
| 1141 |
return 0; |
| 1142 |
} |
| 1143 |
|
| 1144 |
template <class LO,class GO,class NO> |
| 1145 |
RCP<const Map<LO,GO,NO> > BuildMapFromDofMaps(const ArrayRCP<RCP<const Map<LO,GO,NO> > > &dofMaps, |
| 1146 |
unsigned dofsPerNode, |
| 1147 |
unsigned dofOrdering) |
| 1148 |
{ |
| 1149 |
FROSCH_DETAILTIMER_START(buildMapFromDofMapsTime,"BuildMapFromDofMaps"); |
| 1150 |
FROSCH_ASSERT(dofOrdering==0 || dofOrdering==1,"ERROR: Specify a valid DofOrdering."); |
| 1151 |
FROSCH_ASSERT(!dofMaps.is_null(),"dofMaps.is_null()."); |
| 1152 |
FROSCH_ASSERT(dofMaps.size()==dofsPerNode,"dofMaps.size!=dofsPerNode."); |
| 1153 |
for (unsigned i=0; i<dofMaps.size(); i++) { |
| 1154 |
FROSCH_ASSERT(dofMaps[i]->getGlobalNumElements()%dofsPerNode==0 && dofMaps[i]->getLocalNumElements()%dofsPerNode==0,"ERROR: The number of dofsPerNode does not divide the number of global dofs in the dofMaps!"); |
| 1155 |
} |
| 1156 |
|
| 1157 |
unsigned numNodes = dofMaps[0]->getLocalNumElements(); |
| 1158 |
Array<GO> globalIDs(numNodes); |
| 1159 |
if (dofOrdering==0) { |
| 1160 |
for (unsigned i=0; i<dofsPerNode; i++) { |
| 1161 |
for (unsigned j=0; j<numNodes; j++) { |
| 1162 |
globalIDs[dofsPerNode*j+i] = dofMaps[i]->getGlobalElement(j); |
| 1163 |
} |
| 1164 |
} |
| 1165 |
} else if (dofOrdering == 1) { |
| 1166 |
for (unsigned i=0; i<dofsPerNode; i++) { |
| 1167 |
for (unsigned j=0; j<numNodes; j++) { |
| 1168 |
globalIDs[j+i*numNodes] = dofMaps[i]->getGlobalElement(j); |
| 1169 |
} |
| 1170 |
} |
| 1171 |
} else { |
| 1172 |
FROSCH_ASSERT(false,"dofOrdering unknown."); |
| 1173 |
} |
| 1174 |
|
| 1175 |
const GO INVALID = Teuchos::OrdinalTraits<GO>::invalid(); |
| 1176 |
return MapFactory<LO,GO,NO>::Build(dofMaps[0]->lib(),INVALID,globalIDs(),0,dofMaps[0]->getComm()); |
| 1177 |
} |
| 1178 |
|
| 1179 |
template <class LO,class GO,class NO> |
| 1180 |
RCP<Map<LO,GO,NO> > BuildMapFromNodeMap(RCP<const Map<LO,GO,NO> > &nodesMap, |
| 1181 |
unsigned dofsPerNode, |
| 1182 |
unsigned dofOrdering) |
| 1183 |
{ |
| 1184 |
FROSCH_DETAILTIMER_START(buildMapFromNodeMapTime,"BuildMapFromNodeMap"); |
| 1185 |
FROSCH_ASSERT(dofOrdering==0 || dofOrdering==1,"ERROR: Specify a valid DofOrdering."); |
| 1186 |
FROSCH_ASSERT(!nodesMap.is_null(),"nodesMap.is_null()."); |
| 1187 |
|
| 1188 |
unsigned numNodes = nodesMap->getLocalNumElements(); |
| 1189 |
Array<GO> globalIDs(dofsPerNode*numNodes); |
| 1190 |
if (dofOrdering==0) { |
| 1191 |
for (unsigned i=0; i<dofsPerNode; i++) { |
| 1192 |
for (unsigned j=0; j<numNodes; j++) { |
| 1193 |
globalIDs[dofsPerNode*j+i] = dofsPerNode*nodesMap->getGlobalElement(j)+i; |
| 1194 |
} |
| 1195 |
} |
| 1196 |
} else if (dofOrdering == 1) { |
| 1197 |
for (unsigned i=0; i<dofsPerNode; i++) { |
| 1198 |
for (unsigned j=0; j<numNodes; j++) { |
| 1199 |
globalIDs[j+i*numNodes] = nodesMap->getGlobalElement(j)+i*nodesMap->getGlobalNumElements(); |
| 1200 |
} |
| 1201 |
} |
| 1202 |
} else { |
| 1203 |
FROSCH_ASSERT(false,"dofOrdering unknown."); |
| 1204 |
} |
| 1205 |
|
| 1206 |
const GO INVALID = Teuchos::OrdinalTraits<GO>::invalid(); |
| 1207 |
return MapFactory<LO,GO,NO>::Build(nodesMap->lib(),INVALID,globalIDs(),0,nodesMap->getComm()); |
| 1208 |
} |
| 1209 |
|
| 1210 |
template <class LO,class GO,class NO> |
| 1211 |
ArrayRCP<RCP<const Map<LO,GO,NO> > > BuildNodeMapsFromDofMaps(ArrayRCP<ArrayRCP<RCP<const Map<LO,GO,NO> > > > dofsMapsVecVec, |
| 1212 |
ArrayRCP<unsigned> dofsPerNodeVec, |
| 1213 |
ArrayRCP<DofOrdering> dofOrderingVec) |
| 1214 |
{ |
| 1215 |
|
| 1216 |
typedef Map<LO,GO,NO> Map; |
| 1217 |
typedef RCP<const Map> MapConstPtr; |
| 1218 |
typedef ArrayRCP<MapConstPtr> MapConstPtrVecPtr; |
| 1219 |
|
| 1220 |
FROSCH_ASSERT(!dofsMapsVecVec.is_null(),"dofsMapsVecVec.is_null()."); |
| 1221 |
FROSCH_ASSERT(dofsPerNodeVec.size()==dofOrderingVec.size() && dofsPerNodeVec.size()==dofsMapsVecVec.size(),"ERROR: Wrong number of maps, dof information and/or dof orderings"); |
| 1222 |
unsigned nmbBlocks = dofsMapsVecVec.size(); |
| 1223 |
for (unsigned i=0; i<nmbBlocks; i++) { |
| 1224 |
FROSCH_ASSERT(dofOrderingVec[i]==NodeWise || dofOrderingVec[i]==DimensionWise,"ERROR: Specify a valid DofOrdering."); |
| 1225 |
FROSCH_ASSERT(dofsMapsVecVec[i].size() == dofsPerNodeVec[i] ,"ERROR: The number of dofsPerNode does not match the number of dofsMaps for a block."); |
| 1226 |
} |
| 1227 |
|
| 1228 |
RCP<const Comm<int> > comm = dofsMapsVecVec[0][0]->getComm(); |
| 1229 |
|
| 1230 |
//Check if the current block is a real block, or if dof indicies are consecutive over more than one block. |
| 1231 |
Array<bool> isMergedPrior( nmbBlocks, false ); |
| 1232 |
Array<bool> isMergedAfter( nmbBlocks, false ); |
| 1233 |
|
| 1234 |
for (unsigned block=1; block<nmbBlocks; block++) { |
| 1235 |
if ( dofsMapsVecVec[block-1][0]->getMaxAllGlobalIndex() > dofsMapsVecVec[block][0]->getMinAllGlobalIndex()) {// It is enough to compare the first dofMaps of each block |
| 1236 |
isMergedPrior[block] = true; |
| 1237 |
isMergedAfter[block-1] = true; |
| 1238 |
} |
| 1239 |
} |
| 1240 |
|
| 1241 |
//Determine offset for each block based on isMergedPrior and isMergedAfter. |
| 1242 |
Array<GO> blockOffset( nmbBlocks, ScalarTraits<GO>::zero() ); //if blocks are real blocks, this entry here will give provide the correct offset. |
| 1243 |
Array<GO> consBlockOffset( nmbBlocks, ScalarTraits<GO>::zero() ); |
| 1244 |
Array<GO> consThisBlockOffset( nmbBlocks, ScalarTraits<GO>::zero() ); |
| 1245 |
for (unsigned block=0; block<nmbBlocks; block++) { |
| 1246 |
|
| 1247 |
consBlockOffset[block] += dofsPerNodeVec[block]; //add own dofs |
| 1248 |
|
| 1249 |
unsigned i = block; |
| 1250 |
while (isMergedAfter[i]) { |
| 1251 |
consBlockOffset[block] += dofsPerNodeVec[i+1]; |
| 1252 |
i++; |
| 1253 |
} |
| 1254 |
i = block; |
| 1255 |
while (isMergedPrior[i]) { |
| 1256 |
consBlockOffset[block] += dofsPerNodeVec[i-1]; |
| 1257 |
i--; |
| 1258 |
} |
| 1259 |
|
| 1260 |
if ( !isMergedPrior[block] && block>0 ) { |
| 1261 |
blockOffset[block] += dofsMapsVecVec[block-1][dofsMapsVecVec[block-1].size()-1]->getMaxAllGlobalIndex(); //It is assumed that the last dofMap of a block has the highest GID of all block dof maps. |
| 1262 |
unsigned j = block; |
| 1263 |
while (isMergedAfter[j]) { |
| 1264 |
blockOffset[j] = blockOffset[block]; |
| 1265 |
j++; |
| 1266 |
} |
| 1267 |
} |
| 1268 |
} |
| 1269 |
|
| 1270 |
MapConstPtrVecPtr nodeMapsVec( nmbBlocks ); |
| 1271 |
// Build node maps for all blocks |
| 1272 |
const GO INVALID = Teuchos::OrdinalTraits<GO>::invalid(); |
| 1273 |
for (unsigned block=0; block<nmbBlocks; block++) { |
| 1274 |
|
| 1275 |
if (dofOrderingVec[block] == NodeWise) { |
| 1276 |
ArrayView< const GO > globalIndices = dofsMapsVecVec[block][0]->getLocalElementList(); |
| 1277 |
Array<GO> globalIndicesNode( globalIndices ); |
| 1278 |
GO offset = dofsMapsVecVec[block][0]->getMinAllGlobalIndex(); |
| 1279 |
for (unsigned i=0; i<globalIndicesNode.size(); i++) { |
| 1280 |
// multiplier is not correct if isMergedPrior==true because we substract minAllGIDBlock. We have to adjust for this later |
| 1281 |
// was ist wenn mergedPrior und blockOffset existiert, dann ist multiplier falsch. |
| 1282 |
GO multiplier = (globalIndicesNode[i] - offset) / (consBlockOffset[block]); |
| 1283 |
GO rest = (globalIndicesNode[i] - offset) % (consBlockOffset[block]); |
| 1284 |
globalIndicesNode[i] = multiplier + rest; |
| 1285 |
|
| 1286 |
} |
| 1287 |
nodeMapsVec[block] = MapFactory<LO,GO,NO>::Build( dofsMapsVecVec[block][0]->lib(), INVALID,globalIndicesNode(), 0, dofsMapsVecVec[block][0]->getComm() ); |
| 1288 |
} else { //DimensionWise |
| 1289 |
GO minGID = dofsMapsVecVec[block][0]->getMinAllGlobalIndex(); |
| 1290 |
ArrayView< const GO > globalIndices = dofsMapsVecVec[block][0]->getLocalElementList(); |
| 1291 |
Array<GO> globalIndicesNode( globalIndices ); |
| 1292 |
for (unsigned i=0; i<globalIndicesNode.size(); i++) |
| 1293 |
globalIndicesNode[i] -= minGID; |
| 1294 |
|
| 1295 |
nodeMapsVec[block] = MapFactory<LO,GO,NO>::Build( dofsMapsVecVec[block][0]->lib(), INVALID,globalIndicesNode(), 0, dofsMapsVecVec[block][0]->getComm() ); |
| 1296 |
} |
| 1297 |
} |
| 1298 |
return nodeMapsVec; |
| 1299 |
} |
| 1300 |
|
| 1301 |
template <class LO,class GO,class NO> |
| 1302 |
ArrayRCP<RCP<Map<LO,GO,NO> > > BuildSubMaps(RCP<const Map<LO,GO,NO> > &fullMap, |
| 1303 |
ArrayRCP<GO> maxSubGIDVec) |
| 1304 |
{ |
| 1305 |
FROSCH_DETAILTIMER_START(buildSubMapsTime,"BuildSubMaps"); |
| 1306 |
ArrayRCP<RCP<Map<LO,GO,NO> > > subMaps(maxSubGIDVec.size()); |
| 1307 |
|
| 1308 |
Array<Array<GO> > indicesSubMaps(maxSubGIDVec.size()); |
| 1309 |
ArrayView<const GO> nodeElementList = fullMap->getLocalElementList(); |
| 1310 |
for (unsigned i = 0; i<fullMap->getLocalNumElements(); i++) { |
| 1311 |
LO subMapNumber = -1; |
| 1312 |
for (unsigned j = (maxSubGIDVec.size()); j > 0; j--) { |
| 1313 |
if (nodeElementList[i] <= maxSubGIDVec[j-1]) { |
| 1314 |
subMapNumber = j-1; |
| 1315 |
} |
| 1316 |
} |
| 1317 |
FROSCH_ASSERT(subMapNumber>-1,"Index not resolved on sub map."); |
| 1318 |
indicesSubMaps[subMapNumber].push_back(nodeElementList[i]); |
| 1319 |
} |
| 1320 |
|
| 1321 |
const GO INVALID = Teuchos::OrdinalTraits<GO>::invalid(); |
| 1322 |
for (unsigned j = 0 ; j < maxSubGIDVec.size(); j++) { |
| 1323 |
subMaps[j] = MapFactory<LO,GO,NO>::Build(fullMap->lib(),INVALID,indicesSubMaps[j](),0,fullMap->getComm()); |
| 1324 |
} |
| 1325 |
return subMaps; |
| 1326 |
} |
| 1327 |
|
| 1328 |
template <class SC,class LO,class GO,class NO> |
| 1329 |
ArrayRCP<GO> FindOneEntryOnlyRowsGlobal(RCP<const Matrix<SC,LO,GO,NO> > matrix, |
| 1330 |
RCP<const Map<LO,GO,NO> > repeatedMap) |
| 1331 |
{ |
| 1332 |
FROSCH_DETAILTIMER_START(findOneEntryOnlyRowsGlobalTime,"FindOneEntryOnlyRowsGlobal"); |
| 1333 |
RCP<Matrix<SC,LO,GO,NO> > repeatedMatrix = MatrixFactory<SC,LO,GO,NO>::Build(repeatedMap,2*matrix->getGlobalMaxNumRowEntries()); |
| 1334 |
RCP<Import<LO,GO,NO> > scatter = ImportFactory<LO,GO,NO>::Build(matrix->getRowMap(),repeatedMap); |
| 1335 |
repeatedMatrix->doImport(*matrix,*scatter,ADD); |
| 1336 |
|
| 1337 |
ArrayRCP<GO> oneEntryOnlyRows(repeatedMatrix->getLocalNumRows()); |
| 1338 |
LO tmp = 0; |
| 1339 |
LO nnz; |
| 1340 |
GO row; |
| 1341 |
for (unsigned i=0; i<repeatedMatrix->getLocalNumRows(); i++) { |
| 1342 |
row = repeatedMap->getGlobalElement(i); |
| 1343 |
ArrayView<const GO> indices; |
| 1344 |
ArrayView<const SC> values; |
| 1345 |
repeatedMatrix->getGlobalRowView(row,indices,values); |
| 1346 |
nnz = indices.size(); |
| 1347 |
if (indices.size()==1) { |
| 1348 |
oneEntryOnlyRows[tmp] = row; |
| 1349 |
tmp++; |
| 1350 |
} else { |
| 1351 |
for (LO j=0; j<values.size(); j++) { |
| 1352 |
if (fabs(values[j])<1.0e-12) { |
| 1353 |
nnz--; |
| 1354 |
} |
| 1355 |
} |
| 1356 |
if (nnz == 1) { |
| 1357 |
oneEntryOnlyRows[tmp] = row; |
| 1358 |
tmp++; |
| 1359 |
} |
| 1360 |
} |
| 1361 |
} |
| 1362 |
oneEntryOnlyRows.resize(tmp); |
| 1363 |
return oneEntryOnlyRows; |
| 1364 |
} |
| 1365 |
|
| 1366 |
template <class LO,class GO,class NO> |
| 1367 |
ArrayRCP<GO> FindOneEntryOnlyRowsGlobal(RCP<const CrsGraph<LO,GO,NO> > graph, |
| 1368 |
RCP<const Map<LO,GO,NO> > repeatedMap) |
| 1369 |
{ |
| 1370 |
FROSCH_DETAILTIMER_START(findOneEntryOnlyRowsGlobalTime,"FindOneEntryOnlyRowsGlobal"); |
| 1371 |
RCP<CrsGraph<LO,GO,NO> > repeatedGraph = CrsGraphFactory<LO,GO,NO>::Build(repeatedMap,2*graph->getGlobalMaxNumRowEntries()); |
| 1372 |
RCP<Import<LO,GO,NO> > scatter = ImportFactory<LO,GO,NO>::Build(graph->getRowMap(),repeatedMap); |
| 1373 |
repeatedGraph->doImport(*graph,*scatter,ADD); |
| 1374 |
|
| 1375 |
ArrayRCP<GO> oneEntryOnlyRows(repeatedGraph->getLocalNumRows()); |
| 1376 |
LO tmp = 0; |
| 1377 |
GO row; |
| 1378 |
for (unsigned i=0; i<repeatedGraph->getLocalNumRows(); i++) { |
| 1379 |
row = repeatedMap->getGlobalElement(i); |
| 1380 |
ArrayView<const GO> indices; |
| 1381 |
repeatedGraph->getGlobalRowView(row,indices); |
| 1382 |
if (indices.size()==1) { |
| 1383 |
oneEntryOnlyRows[tmp] = row; |
| 1384 |
tmp++; |
| 1385 |
} |
| 1386 |
} |
| 1387 |
oneEntryOnlyRows.resize(tmp); |
| 1388 |
return oneEntryOnlyRows; |
| 1389 |
} |
| 1390 |
|
| 1391 |
template <class SC,class LO> |
| 1392 |
bool ismultiple(ArrayView<SC> A, |
| 1393 |
ArrayView<SC> B) |
| 1394 |
{ |
| 1395 |
Array<LO> zeros; |
| 1396 |
Array<LO> nonzeros; |
| 1397 |
|
| 1398 |
FROSCH_ASSERT(A.size()==B.size(),"Cannot be multiple (size)"); |
| 1399 |
|
| 1400 |
// Search for non-zeros |
| 1401 |
for (unsigned i=0; i<A.size(); i++) { |
| 1402 |
if (fabs(A[i])<1.0e-12) { |
| 1403 |
zeros.push_back(i); |
| 1404 |
} else { |
| 1405 |
nonzeros.push_back(i); |
| 1406 |
} |
| 1407 |
} |
| 1408 |
|
| 1409 |
// Search for non-zeros |
| 1410 |
for (unsigned i=0; i<zeros.size(); i++) { |
| 1411 |
if (fabs(B[zeros.at(i)])>=1.0e-12) { |
| 1412 |
return false; |
| 1413 |
} |
| 1414 |
} |
| 1415 |
|
| 1416 |
// Check nonzeros for multiple |
| 1417 |
double mult = B[nonzeros.at(0)]/A[nonzeros.at(0)], mult2; |
| 1418 |
for (unsigned i=1; i<nonzeros.size(); i++) { |
| 1419 |
mult2 = B[nonzeros.at(i)]/A[nonzeros.at(i)]; |
| 1420 |
if (fabs(mult2-mult)>=1.0e-12) { |
| 1421 |
return false; |
| 1422 |
} |
| 1423 |
} |
| 1424 |
return true; |
| 1425 |
} |
| 1426 |
|
| 1427 |
template<class T> |
| 1428 |
inline void sort(T &v) |
| 1429 |
{ |
| 1430 |
std::sort(v.begin(),v.end()); |
| 1431 |
} |
| 1432 |
|
| 1433 |
template<class T> |
| 1434 |
inline void sortunique(T &v) |
| 1435 |
{ |
| 1436 |
std::sort(v.begin(),v.end()); |
| 1437 |
v.erase(unique(v.begin(),v.end()),v.end()); |
| 1438 |
} |
| 1439 |
|
| 1440 |
template <class SC, class LO,class GO,class NO> |
| 1441 |
RCP<MultiVector<SC,LO,GO,NO> > ModifiedGramSchmidt(RCP<const MultiVector<SC,LO,GO,NO> > multiVector, |
| 1442 |
ArrayView<unsigned> zero) |
| 1443 |
{ |
| 1444 |
using Xpetra::Vector; |
| 1445 |
FROSCH_DETAILTIMER_START(modifiedGramSchmidtTime,"ModifiedGramSchmidt"); |
| 1446 |
/* |
| 1447 |
n = size(V,1); |
| 1448 |
k = size(V,2); |
| 1449 |
U = zeros(n,k); |
| 1450 |
U(:,1) = V(:,1)/sqrt(V(:,1)'*V(:,1)); |
| 1451 |
for i = 2:k |
| 1452 |
U(:,i) = V(:,i); |
| 1453 |
for j = 1:i-1 |
| 1454 |
U(:,i) = U(:,i) - ( U(:,i)'*U(:,j) )/( U(:,j)'*U(:,j) )*U(:,j); |
| 1455 |
end |
| 1456 |
U(:,i) = U(:,i)/sqrt(U(:,i)'*U(:,i)); |
| 1457 |
end |
| 1458 |
*/ |
| 1459 |
unsigned numVec = multiVector->getNumVectors(); |
| 1460 |
Array<unsigned> arrayZero(0); |
| 1461 |
RCP<const Map<LO,GO,NO> > multiVectorMap = multiVector->getMap(); |
| 1462 |
RCP<MultiVector<SC,LO,GO,NO> > resultMultiVector; |
| 1463 |
if (numVec>0) { |
| 1464 |
unsigned itmp = 0; |
| 1465 |
SC en = ScalarTraits<SC>::zero(); |
| 1466 |
SC de = ScalarTraits<SC>::zero(); |
| 1467 |
SC norm = ScalarTraits<SC>::zero(); |
| 1468 |
RCP<MultiVector<SC,LO,GO,NO> > tmpMultiVector = MultiVectorFactory<SC,LO,GO,NO>::Build(multiVectorMap,numVec); |
| 1469 |
for (unsigned i=0; i<numVec; i++) { |
| 1470 |
RCP<const Vector<SC,LO,GO,NO> > multiVector_i = multiVector->getVector(i); |
| 1471 |
RCP<Vector<SC,LO,GO,NO> > tmpMultiVectorNonConst_i_itmp = tmpMultiVector->getVectorNonConst(i-itmp); |
| 1472 |
tmpMultiVectorNonConst_i_itmp->update(ScalarTraits<SC>::one(),*multiVector_i,ScalarTraits<SC>::zero()); |
| 1473 |
for (unsigned j=0; j<i-itmp; j++) { |
| 1474 |
RCP<const Vector<SC,LO,GO,NO> > tmpMultiVector_j = tmpMultiVector->getVector(j); |
| 1475 |
en = tmpMultiVectorNonConst_i_itmp->dot(*tmpMultiVector_j); |
| 1476 |
de = tmpMultiVector_j->dot(*tmpMultiVector_j); |
| 1477 |
tmpMultiVectorNonConst_i_itmp->update(-en/de,*tmpMultiVector_j,ScalarTraits<SC>::one()); |
| 1478 |
} |
| 1479 |
norm = tmpMultiVectorNonConst_i_itmp->norm2(); |
| 1480 |
if (norm<1.0e-10) { |
| 1481 |
arrayZero.push_back(i); |
| 1482 |
itmp++; |
| 1483 |
} else { |
| 1484 |
//tmpMultiVector->getVectorNonConst(i-itmp)->scale(1.0/norm); |
| 1485 |
} |
| 1486 |
} |
| 1487 |
resultMultiVector = MultiVectorFactory<SC,LO,GO,NO>::Build(multiVectorMap,numVec); |
| 1488 |
for (unsigned i=0; i<numVec-itmp; i++) { |
| 1489 |
resultMultiVector->getVectorNonConst(i)->update(ScalarTraits<SC>::one(),*tmpMultiVector->getVector(i),ScalarTraits<SC>::zero()); |
| 1490 |
} |
| 1491 |
} |
| 1492 |
zero = arrayZero(); |
| 1493 |
return resultMultiVector; |
| 1494 |
} |
| 1495 |
|
| 1496 |
template <class SC, class LO,class GO,class NO> |
| 1497 |
RCP<const MultiVector<SC,LO,GO,NO> > BuildNullSpace(unsigned dimension, |
| 1498 |
const NullSpaceType nullSpaceType, |
| 1499 |
RCP<const Map<LO,GO,NO> > repeatedMap, |
| 1500 |
unsigned dofsPerNode, |
| 1501 |
ArrayRCP<RCP<const Map<LO,GO,NO> > > dofsMaps, |
| 1502 |
RCP<const MultiVector<SC,LO,GO,NO> > nodeList) |
| 1503 |
{ |
| 1504 |
FROSCH_DETAILTIMER_START(buildNullSpaceTime,"BuildNullSpace"); |
| 1505 |
/* |
| 1506 |
Here, the nodeList has to be ordered in accordence to the dofsMaps. |
| 1507 |
*/ |
| 1508 |
FROSCH_ASSERT(dofsMaps.size()==dofsPerNode,"dofsMaps.size()!=dofsPerNode."); |
| 1509 |
|
| 1510 |
RCP<MultiVector<SC,LO,GO,NO> > nullSpaceBasis; |
| 1511 |
if (nullSpaceType == NullSpaceType::Laplace) { |
| 1512 |
nullSpaceBasis = MultiVectorFactory<SC,LO,GO,NO>::Build(repeatedMap,dofsPerNode); |
| 1513 |
for (unsigned i=0; i<dofsPerNode; i++) { |
| 1514 |
for (unsigned j=0; j<dofsMaps[i]->getLocalNumElements(); j++) { |
| 1515 |
nullSpaceBasis->getDataNonConst(i)[repeatedMap->getLocalElement(dofsMaps[i]->getGlobalElement(j))] = ScalarTraits<SC>::one(); |
| 1516 |
} |
| 1517 |
} |
| 1518 |
} else if (nullSpaceType == NullSpaceType::Elasticity) { |
| 1519 |
FROSCH_ASSERT(!nodeList.is_null(),"nodeList.is_null()==true. Cannot build the null space for linear elasticity."); |
| 1520 |
FROSCH_ASSERT(nodeList->getNumVectors()==dimension,"nodeList->getNumVectors()!=dimension."); |
| 1521 |
FROSCH_ASSERT(dofsPerNode==dimension,"dofsPerNode==dimension."); |
| 1522 |
|
| 1523 |
if (dimension==2) { |
| 1524 |
nullSpaceBasis = MultiVectorFactory<SC,LO,GO,NO>::Build(repeatedMap,3); |
| 1525 |
// translations |
| 1526 |
for (unsigned i=0; i<2; i++) { |
| 1527 |
for (unsigned j=0; j<dofsMaps[i]->getLocalNumElements(); j++) { |
| 1528 |
nullSpaceBasis->getDataNonConst(i)[repeatedMap->getLocalElement(dofsMaps[i]->getGlobalElement(j))] = ScalarTraits<SC>::one(); |
| 1529 |
} |
| 1530 |
} |
| 1531 |
// rotation |
| 1532 |
for (unsigned j=0; j<dofsMaps[0]->getLocalNumElements(); j++) { |
| 1533 |
nullSpaceBasis->getDataNonConst(2)[repeatedMap->getLocalElement(dofsMaps[0]->getGlobalElement(j))] = -nodeList->getData(1)[j]; |
| 1534 |
nullSpaceBasis->getDataNonConst(2)[repeatedMap->getLocalElement(dofsMaps[1]->getGlobalElement(j))] = nodeList->getData(0)[j]; |
| 1535 |
} |
| 1536 |
} else if (dimension==3) { |
| 1537 |
nullSpaceBasis = MultiVectorFactory<SC,LO,GO,NO>::Build(repeatedMap,6); |
| 1538 |
// translations |
| 1539 |
for (unsigned i=0; i<3; i++) { |
| 1540 |
for (unsigned j=0; j<dofsMaps[i]->getLocalNumElements(); j++) { |
| 1541 |
nullSpaceBasis->getDataNonConst(i)[repeatedMap->getLocalElement(dofsMaps[i]->getGlobalElement(j))] = ScalarTraits<SC>::one(); |
| 1542 |
} |
| 1543 |
} |
| 1544 |
// rotations |
| 1545 |
for (unsigned j=0; j<dofsMaps[0]->getLocalNumElements(); j++) { |
| 1546 |
nullSpaceBasis->getDataNonConst(3)[repeatedMap->getLocalElement(dofsMaps[0]->getGlobalElement(j))] = nodeList->getData(1)[j]; |
| 1547 |
nullSpaceBasis->getDataNonConst(3)[repeatedMap->getLocalElement(dofsMaps[1]->getGlobalElement(j))] = -nodeList->getData(0)[j]; |
| 1548 |
nullSpaceBasis->getDataNonConst(3)[repeatedMap->getLocalElement(dofsMaps[2]->getGlobalElement(j))] = ScalarTraits<SC>::zero(); |
| 1549 |
|
| 1550 |
nullSpaceBasis->getDataNonConst(4)[repeatedMap->getLocalElement(dofsMaps[0]->getGlobalElement(j))] = -nodeList->getData(2)[j]; |
| 1551 |
nullSpaceBasis->getDataNonConst(4)[repeatedMap->getLocalElement(dofsMaps[1]->getGlobalElement(j))] = ScalarTraits<SC>::zero(); |
| 1552 |
nullSpaceBasis->getDataNonConst(4)[repeatedMap->getLocalElement(dofsMaps[2]->getGlobalElement(j))] = nodeList->getData(0)[j]; |
| 1553 |
|
| 1554 |
nullSpaceBasis->getDataNonConst(5)[repeatedMap->getLocalElement(dofsMaps[0]->getGlobalElement(j))] = ScalarTraits<SC>::zero(); |
| 1555 |
nullSpaceBasis->getDataNonConst(5)[repeatedMap->getLocalElement(dofsMaps[1]->getGlobalElement(j))] = nodeList->getData(2)[j]; |
| 1556 |
nullSpaceBasis->getDataNonConst(5)[repeatedMap->getLocalElement(dofsMaps[2]->getGlobalElement(j))] = -nodeList->getData(1)[j]; |
| 1557 |
} |
| 1558 |
} |
| 1559 |
} else { |
| 1560 |
FROSCH_ASSERT(false,"NullSpaceType unknown."); |
| 1561 |
} |
| 1562 |
return nullSpaceBasis; |
| 1563 |
} |
| 1564 |
|
| 1565 |
#ifdef HAVE_SHYLU_DDFROSCH_EPETRA |
| 1566 |
template <class SC,class LO,class GO,class NO> |
| 1567 |
RCP<Map<LO,GO,NO> > ConvertToXpetra<SC,LO,GO,NO>::ConvertMap(UnderlyingLib lib, |
| 1568 |
const Epetra_BlockMap &map, |
| 1569 |
RCP<const Comm<int> > comm) |
| 1570 |
{ |
| 1571 |
FROSCH_ASSERT(false,"FROSch::ConvertToXpetra: Needs specialization."); |
| 1572 |
return null; |
| 1573 |
} |
| 1574 |
|
| 1575 |
template <class SC,class LO,class GO,class NO> |
| 1576 |
RCP<Matrix<SC,LO,GO,NO> > ConvertToXpetra<SC,LO,GO,NO>::ConvertMatrix(UnderlyingLib lib, |
| 1577 |
Epetra_CrsMatrix &matrix, |
| 1578 |
RCP<const Comm<int> > comm) |
| 1579 |
{ |
| 1580 |
FROSCH_ASSERT(false,"FROSch::ConvertToXpetra: Needs specialization."); |
| 1581 |
return null; |
| 1582 |
} |
| 1583 |
|
| 1584 |
template <class SC,class LO,class GO,class NO> |
| 1585 |
RCP<MultiVector<SC,LO,GO,NO> > ConvertToXpetra<SC,LO,GO,NO>::ConvertMultiVector(UnderlyingLib lib, |
| 1586 |
Epetra_MultiVector &vector, |
| 1587 |
RCP<const Comm<int> > comm) |
| 1588 |
{ |
| 1589 |
FROSCH_DETAILTIMER_START(convertMultiVectorTime,"ConvertToXpetra::ConvertMultiVector"); |
| 1590 |
RCP<Map<LO,GO,NO> > map = ConvertToXpetra<SC,LO,GO,NO>::ConvertMap(lib,vector.Map(),comm); |
| 1591 |
RCP<MultiVector<SC,LO,GO,NO> > xMultiVector = MultiVectorFactory<SC,LO,GO,NO>::Build(map,vector.NumVectors()); |
| 1592 |
for (LO i=0; i<vector.NumVectors(); i++) { |
| 1593 |
for (LO j=0; j<vector.MyLength(); j++) { |
| 1594 |
xMultiVector->getDataNonConst(i)[j] = vector[i][j]; |
| 1595 |
} |
| 1596 |
} |
| 1597 |
return xMultiVector; |
| 1598 |
} |
| 1599 |
|
| 1600 |
template <class SC,class LO,class NO> |
| 1601 |
RCP<Map<LO,int,NO> > ConvertToXpetra<SC,LO,int,NO>::ConvertMap(UnderlyingLib lib, |
| 1602 |
const Epetra_BlockMap &map, |
| 1603 |
RCP<const Comm<int> > comm) |
| 1604 |
{ |
| 1605 |
FROSCH_DETAILTIMER_START(convertMapTime,"ConvertToXpetra::ConvertMap"); |
| 1606 |
ArrayView<int> mapArrayView(map.MyGlobalElements(),map.NumMyElements()); |
| 1607 |
|
| 1608 |
const int INVALID = Teuchos::OrdinalTraits<int>::invalid(); |
| 1609 |
return MapFactory<LO,int,NO>::Build(lib,INVALID,mapArrayView,0,comm); |
| 1610 |
} |
| 1611 |
|
| 1612 |
template <class SC,class LO,class NO> |
| 1613 |
RCP<Matrix<SC,LO,int,NO> > ConvertToXpetra<SC,LO,int,NO>::ConvertMatrix(UnderlyingLib lib, |
| 1614 |
Epetra_CrsMatrix &matrix, |
| 1615 |
RCP<const Comm<int> > comm) |
| 1616 |
{ |
| 1617 |
FROSCH_DETAILTIMER_START(convertMatrixTime,"ConvertToXpetra::ConvertMatrix"); |
| 1618 |
RCP<Map<LO,int,NO> > rowMap = ConvertToXpetra<SC,LO,int,NO>::ConvertMap(lib,matrix.RowMap(),comm); |
| 1619 |
RCP<Matrix<SC,LO,int,NO> > xmatrix = MatrixFactory<SC,LO,int,NO>::Build(rowMap,matrix.MaxNumEntries()); |
| 1620 |
for (unsigned i=0; i<xmatrix->getLocalNumRows(); i++) { |
| 1621 |
LO numEntries; |
| 1622 |
LO* indices; |
| 1623 |
SC* values; |
| 1624 |
matrix.ExtractMyRowView(i,numEntries,values,indices); |
| 1625 |
|
| 1626 |
Array<int> indicesArray(numEntries); |
| 1627 |
ArrayView<SC> valuesArrayView(values,numEntries); |
| 1628 |
for (LO j=0; j<numEntries; j++) { |
| 1629 |
indicesArray[j] = matrix.ColMap().GID(indices[j]); |
| 1630 |
} |
| 1631 |
xmatrix->insertGlobalValues(matrix.RowMap().GID(i),indicesArray(),valuesArrayView); |
| 1632 |
} |
| 1633 |
xmatrix->fillComplete(); |
| 1634 |
return xmatrix; |
| 1635 |
} |
| 1636 |
|
| 1637 |
template <class SC,class LO,class NO> |
| 1638 |
RCP<MultiVector<SC,LO,int,NO> > ConvertToXpetra<SC,LO,int,NO>::ConvertMultiVector(UnderlyingLib lib, |
| 1639 |
Epetra_MultiVector &vector, |
| 1640 |
RCP<const Comm<int> > comm) |
| 1641 |
{ |
| 1642 |
FROSCH_DETAILTIMER_START(convertMultiVectorTime,"ConvertToXpetra::ConvertMultiVector"); |
| 1643 |
RCP<Map<LO,int,NO> > map = ConvertToXpetra<SC,LO,int,NO>::ConvertMap(lib,vector.Map(),comm); |
| 1644 |
RCP<MultiVector<SC,LO,int,NO> > xMultiVector = MultiVectorFactory<SC,LO,int,NO>::Build(map,vector.NumVectors()); |
| 1645 |
for (LO i=0; i<vector.NumVectors(); i++) { |
| 1646 |
for (LO j=0; j<vector.MyLength(); j++) { |
| 1647 |
xMultiVector->getDataNonConst(i)[j] = vector[i][j]; |
| 1648 |
} |
| 1649 |
} |
| 1650 |
return xMultiVector; |
| 1651 |
} |
| 1652 |
|
| 1653 |
template <class SC,class LO,class NO> |
| 1654 |
RCP<Map<LO,long long,NO> > ConvertToXpetra<SC,LO,long long,NO>::ConvertMap(UnderlyingLib lib, |
| 1655 |
const Epetra_BlockMap &map, |
| 1656 |
RCP<const Comm<int> > comm) |
| 1657 |
{ |
| 1658 |
FROSCH_DETAILTIMER_START(convertMapTime,"ConvertToXpetra::ConvertMap"); |
| 1659 |
ArrayView<long long> mapArrayView(map.MyGlobalElements64(),map.NumMyElements()); |
| 1660 |
|
| 1661 |
const long long INVALID = Teuchos::OrdinalTraits<long long>::invalid(); |
| 1662 |
return MapFactory<LO,long long,NO>::Build(lib,INVALID,mapArrayView,0,comm); |
| 1663 |
} |
| 1664 |
|
| 1665 |
template <class SC,class LO,class NO> |
| 1666 |
RCP<Matrix<SC,LO,long long,NO> > ConvertToXpetra<SC,LO,long long,NO>::ConvertMatrix(UnderlyingLib lib, |
| 1667 |
Epetra_CrsMatrix &matrix, |
| 1668 |
RCP<const Comm<int> > comm) |
| 1669 |
{ |
| 1670 |
FROSCH_DETAILTIMER_START(convertMatrixTime,"ConvertToXpetra::ConvertMatrix"); |
| 1671 |
RCP<Map<LO,long long,NO> > rowMap = ConvertToXpetra<SC,LO,long long,NO>::ConvertMap(lib,matrix.RowMap(),comm); |
| 1672 |
RCP<Matrix<SC,LO,long long,NO> > xmatrix = MatrixFactory<SC,LO,long long,NO>::Build(rowMap,matrix.MaxNumEntries()); |
| 1673 |
for (unsigned i=0; i<xmatrix->getLocalNumRows(); i++) { |
| 1674 |
LO numEntries; |
| 1675 |
LO* indices; |
| 1676 |
SC* values; |
| 1677 |
matrix.ExtractMyRowView(i,numEntries,values,indices); |
| 1678 |
|
| 1679 |
Array<long long> indicesArray(numEntries); |
| 1680 |
ArrayView<SC> valuesArrayView(values,numEntries); |
| 1681 |
for (LO j=0; j<numEntries; j++) { |
| 1682 |
indicesArray[j] = matrix.ColMap().GID64(indices[j]); |
| 1683 |
} |
| 1684 |
xmatrix->insertGlobalValues(matrix.RowMap().GID64(i),indicesArray(),valuesArrayView); |
| 1685 |
} |
| 1686 |
xmatrix->fillComplete(); |
| 1687 |
return xmatrix; |
| 1688 |
} |
| 1689 |
|
| 1690 |
template <class SC,class LO,class NO> |
| 1691 |
RCP<MultiVector<SC,LO,long long,NO> > ConvertToXpetra<SC,LO,long long,NO>::ConvertMultiVector(UnderlyingLib lib, |
| 1692 |
Epetra_MultiVector &vector, |
| 1693 |
RCP<const Comm<int> > comm) |
| 1694 |
{ |
| 1695 |
FROSCH_DETAILTIMER_START(convertMultiVectorTime,"ConvertToXpetra::ConvertMultiVector"); |
| 1696 |
RCP<Map<LO,long long,NO> > map = ConvertToXpetra<SC,LO,long long,NO>::ConvertMap(lib,vector.Map(),comm); |
| 1697 |
RCP<MultiVector<SC,LO,long long,NO> > xMultiVector = MultiVectorFactory<SC,LO,long long,NO>::Build(map,vector.NumVectors()); |
| 1698 |
for (LO i=0; i<vector.NumVectors(); i++) { |
| 1699 |
for (LO j=0; j<vector.MyLength(); j++) { |
| 1700 |
xMultiVector->getDataNonConst(i)[j] = vector[i][j]; |
| 1701 |
} |
| 1702 |
} |
| 1703 |
return xMultiVector; |
| 1704 |
} |
| 1705 |
#endif |
| 1706 |
|
| 1707 |
template <class Type> |
| 1708 |
RCP<Type> ExtractPtrFromParameterList(ParameterList& paramList, |
| 1709 |
string namePtr) |
| 1710 |
{ |
| 1711 |
FROSCH_DETAILTIMER_START(extractPtrFromParameterListTime,"ExtractPtrFromParameterList"); |
| 1712 |
RCP<Type> pointer = null; |
| 1713 |
|
| 1714 |
if (paramList.isParameter(namePtr) == false) |
| 1715 |
return pointer; |
| 1716 |
|
| 1717 |
if (paramList.isType<decltype(pointer)>(namePtr)) { |
| 1718 |
pointer = paramList.get<decltype(pointer)>(namePtr); |
| 1719 |
} |
| 1720 |
|
| 1721 |
return pointer; |
| 1722 |
} |
| 1723 |
|
| 1724 |
template <class Type> |
| 1725 |
ArrayRCP<Type> ExtractVectorFromParameterList(ParameterList& paramList, |
| 1726 |
string nameVector) |
| 1727 |
{ |
| 1728 |
FROSCH_DETAILTIMER_START(extractVectorFromParameterListTime,"ExtractVectorFromParameterList"); |
| 1729 |
ArrayRCP<Type> vector = null; |
| 1730 |
|
| 1731 |
if (paramList.isParameter(nameVector) == false) |
| 1732 |
return vector; |
| 1733 |
|
| 1734 |
if (paramList.isType<decltype(vector)>(nameVector)) { |
| 1735 |
vector = paramList.get<decltype(vector)>(nameVector); |
| 1736 |
} |
| 1737 |
|
| 1738 |
return vector; |
| 1739 |
} |
| 1740 |
|
| 1741 |
#ifdef HAVE_SHYLU_DDFROSCH_EPETRA |
| 1742 |
template <class LO,class GO,class NO> |
| 1743 |
RCP<Epetra_Map> ConvertToEpetra(const Map<LO,GO,NO> &map, |
| 1744 |
RCP<Epetra_Comm> epetraComm) |
| 1745 |
{ |
| 1746 |
FROSCH_DETAILTIMER_START(convertToEpetraTime,"ConvertToEpetra"); |
| 1747 |
ArrayView<const GO> elementList = map.getLocalElementList(); |
| 1748 |
|
| 1749 |
GO numGlobalElements = map.getGlobalNumElements(); |
| 1750 |
|
| 1751 |
if (elementList.size()>0) |
| 1752 |
return rcp(new Epetra_Map(numGlobalElements,elementList.size(),elementList.getRawPtr(),0,*epetraComm)); |
| 1753 |
else |
| 1754 |
return rcp(new Epetra_Map(numGlobalElements,0,NULL,0,*epetraComm)); |
| 1755 |
} |
| 1756 |
|
| 1757 |
template <class SC, class LO, class GO,class NO> |
| 1758 |
RCP<Epetra_MultiVector> ConvertToEpetra(const MultiVector<SC,LO,GO,NO> &vector, |
| 1759 |
RCP<Epetra_Comm> epetraComm) |
| 1760 |
{ |
| 1761 |
FROSCH_DETAILTIMER_START(convertToEpetraTime,"ConvertToEpetra"); |
| 1762 |
RCP<Epetra_Map> map = ConvertToEpetra<LO,GO,NO>(*vector.getMap(),epetraComm); |
| 1763 |
RCP<Epetra_MultiVector > multiVector(new Epetra_MultiVector(*map,vector.getNumVectors())); |
| 1764 |
for (LO i=0; i<vector.getNumVectors(); i++) { |
| 1765 |
for (LO j=0; j<vector.getLocalLength(); j++) { |
| 1766 |
(*multiVector)[i][j] = vector.getData(i)[j]; |
| 1767 |
} |
| 1768 |
} |
| 1769 |
return multiVector; |
| 1770 |
} |
| 1771 |
|
| 1772 |
template <class SC, class LO,class GO, class NO> |
| 1773 |
RCP<Epetra_CrsMatrix> ConvertToEpetra(const Matrix<SC,LO,GO,NO> &matrix, |
| 1774 |
RCP<Epetra_Comm> epetraComm) |
| 1775 |
{ |
| 1776 |
FROSCH_DETAILTIMER_START(convertToEpetraTime,"ConvertToEpetra"); |
| 1777 |
RCP<Epetra_Map> map = ConvertToEpetra<LO,GO,NO>(*matrix.getMap(),epetraComm); |
| 1778 |
RCP<Epetra_CrsMatrix> matrixEpetra(new Epetra_CrsMatrix(::Copy,*map,matrix.getGlobalMaxNumRowEntries())); |
| 1779 |
ArrayView<const SC> valuesArrayView; |
| 1780 |
ArrayView<const LO> indicesArrayView; |
| 1781 |
|
| 1782 |
for (LO i=0; i<(LO) matrix.getRowMap()->getLocalNumElements(); i++) { |
| 1783 |
matrix.getLocalRowView(i, indicesArrayView, valuesArrayView); |
| 1784 |
Array<GO> indicesGlobal(indicesArrayView.size()); |
| 1785 |
for (LO j=0; j<indicesArrayView.size(); j++) { |
| 1786 |
indicesGlobal[j] = matrix.getColMap()->getGlobalElement(indicesArrayView[j]); |
| 1787 |
} |
| 1788 |
if (indicesArrayView.size()>0) { |
| 1789 |
matrixEpetra->InsertGlobalValues(matrix.getRowMap()->getGlobalElement(i), indicesArrayView.size(), &(valuesArrayView[0]), &(indicesGlobal[0])); |
| 1790 |
} |
| 1791 |
} |
| 1792 |
matrixEpetra->FillComplete(); |
| 1793 |
return matrixEpetra; |
| 1794 |
} |
| 1795 |
#endif |
| 1796 |
|
| 1797 |
template <class LO> |
| 1798 |
Array<LO> GetIndicesFromString(string string, LO dummy) |
| 1799 |
{ |
| 1800 |
Array<LO> indices(0); |
| 1801 |
for (unsigned i=0; i<string.length(); i++) { |
| 1802 |
indices.push_back((LO) stoi(string.substr(i,i+1))); |
| 1803 |
} |
| 1804 |
return indices; |
| 1805 |
} |
| 1806 |
|
| 1807 |
#ifdef HAVE_SHYLU_DDFROSCH_ZOLTAN2 |
| 1808 |
template <class SC, class LO,class GO,class NO> |
| 1809 |
int RepartionMatrixZoltan2(RCP<Matrix<SC,LO,GO,NO> > &crsMatrix, |
| 1810 |
RCP<ParameterList> parameterList) |
| 1811 |
{ |
| 1812 |
FROSCH_DETAILTIMER_START(repartionMatrixZoltan2Time,"RepartionMatrixZoltan2"); |
| 1813 |
RCP<FancyOStream> fancy = fancyOStream(rcpFromRef(cout)); |
| 1814 |
|
| 1815 |
using inputAdapter = Zoltan2::XpetraCrsMatrixAdapter<CrsMatrix<SC,LO,GO,NO> >; |
| 1816 |
|
| 1817 |
RCP<CrsMatrixWrap<SC,LO,GO,NO> > tmpCrsWrap = rcp_dynamic_cast<CrsMatrixWrap<SC,LO,GO,NO> >(crsMatrix); |
| 1818 |
RCP<CrsMatrix<SC,LO,GO,NO> > tmpCrsMatrix = tmpCrsWrap->getCrsMatrix(); |
| 1819 |
inputAdapter adaptedMatrix(tmpCrsMatrix); |
| 1820 |
|
| 1821 |
RCP<Zoltan2::PartitioningProblem<inputAdapter> > problem = |
| 1822 |
rcp(new Zoltan2::PartitioningProblem<inputAdapter>(&adaptedMatrix, parameterList.get())); |
| 1823 |
|
| 1824 |
problem->solve(); |
| 1825 |
|
| 1826 |
RCP<CrsMatrix<SC,LO,GO,NO> > matrixRepartition; |
| 1827 |
adaptedMatrix.applyPartitioningSolution(*tmpCrsMatrix,matrixRepartition,problem->getSolution()); |
| 1828 |
|
| 1829 |
RCP<CrsMatrixWrap<SC,LO,GO,NO> > tmpCrsWrap2 = rcp(new CrsMatrixWrap<SC,LO,GO,NO>(matrixRepartition)); |
| 1830 |
crsMatrix = rcp_dynamic_cast<Matrix<SC,LO,GO,NO> >(tmpCrsWrap2); |
| 1831 |
return 0; |
| 1832 |
} |
| 1833 |
|
| 1834 |
template <class LO,class GO, class NO> |
| 1835 |
int BuildRepMapZoltan(RCP<CrsGraph<LO,GO,NO> > Xgraph, |
| 1836 |
RCP<CrsGraph<LO,GO,NO> > B, |
| 1837 |
RCP<ParameterList> parameterList, |
| 1838 |
Teuchos::RCP<const Teuchos::Comm<int> > TeuchosComm, |
| 1839 |
RCP<Map<LO,GO,NO> > &RepeatedMap) |
| 1840 |
{ |
| 1841 |
FROSCH_DETAILTIMER_START(BuildRepMapZoltanTime,"Tools::BuildRepMapZoltan"); |
| 1842 |
|
| 1843 |
//Zoltan2 Problem |
| 1844 |
typedef Zoltan2::XpetraCrsGraphAdapter<Xpetra::CrsGraph<LO,GO,NO> > inputAdapter; |
| 1845 |
Teuchos::RCP<Teuchos::ParameterList> tmpList = Teuchos::sublist(parameterList,"Zoltan2 Parameter"); |
| 1846 |
Teuchos::RCP<inputAdapter> adaptedMatrix = Teuchos::rcp(new inputAdapter(Xgraph,0,0)); |
| 1847 |
size_t MaxRow = B->getGlobalMaxNumRowEntries(); |
| 1848 |
Teuchos::RCP<const Xpetra::Map<LO, GO, NO> > ColMap = Xpetra::MapFactory<LO,GO,NO>::createLocalMap(Xgraph->getRowMap()->lib(),MaxRow,TeuchosComm); |
| 1849 |
Teuchos::RCP<Zoltan2::PartitioningProblem<inputAdapter> >problem; |
| 1850 |
{ |
| 1851 |
problem = Teuchos::RCP<Zoltan2::PartitioningProblem<inputAdapter> >(new Zoltan2::PartitioningProblem<inputAdapter> (adaptedMatrix.getRawPtr(), tmpList.get(),TeuchosComm)); |
| 1852 |
problem->solve(); |
| 1853 |
} |
| 1854 |
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1855 |
Teuchos::RCP<Xpetra::CrsGraph<LO,GO,NO> > ReGraph; |
| 1856 |
{ |
| 1857 |
adaptedMatrix->applyPartitioningSolution(*Xgraph,ReGraph,problem->getSolution()); |
| 1858 |
} |
| 1859 |
Teuchos::RCP<Xpetra::Import<LO,GO,NO> > scatter = Xpetra::ImportFactory<LO,GO,NO>::Build(Xgraph->getRowMap(),ReGraph->getRowMap()); |
| 1860 |
Teuchos::RCP<Xpetra::CrsGraph<LO,GO,NO> > BB = Xpetra::CrsGraphFactory<LO,GO,NO>::Build(ReGraph->getRowMap(),MaxRow); |
| 1861 |
{ |
| 1862 |
BB->doImport(*B,*scatter,Xpetra::INSERT); |
| 1863 |
} |
| 1864 |
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1865 |
Teuchos::Array<GO> repeatedMapEntries(0); |
| 1866 |
for (unsigned i = 0; i<ReGraph->getRowMap()->getLocalNumElements(); i++) { |
| 1867 |
Teuchos::ArrayView<const GO> arr; |
| 1868 |
Teuchos::ArrayView<const LO> cc; |
| 1869 |
GO gi = ReGraph->getRowMap()->getGlobalElement(i); |
| 1870 |
BB->getGlobalRowView(gi,arr); |
| 1871 |
for (unsigned j=0; j<arr.size(); j++) { |
| 1872 |
repeatedMapEntries.push_back(arr[j]); |
| 1873 |
} |
| 1874 |
} |
| 1875 |
sortunique(repeatedMapEntries); |
| 1876 |
const GO INVALID = Teuchos::OrdinalTraits<GO>::invalid(); |
| 1877 |
RepeatedMap = Xpetra::MapFactory<LO,GO,NO>::Build(ReGraph->getColMap()->lib(),INVALID,repeatedMapEntries(),0,ReGraph->getColMap()->getComm()); |
| 1878 |
return 0; |
| 1879 |
} |
| 1880 |
#endif |
| 1881 |
} // namespace FROSch |
| 1882 |
|
| 1883 |
#endif |