43 #ifndef IFPACK2_OVERLAPPINGROWMATRIX_DEF_HPP 44 #define IFPACK2_OVERLAPPINGROWMATRIX_DEF_HPP 45 #include "Ifpack2_OverlappingRowMatrix_decl.hpp" 46 #include "Tpetra_CrsMatrix.hpp" 48 #include "Teuchos_CommHelpers.hpp" 53 template<
class MatrixType>
55 int OverlapLevel_in) :
57 OverlapLevel_(OverlapLevel_in),
65 typedef typename Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> MapType;
66 typedef typename Tpetra::Import<LocalOrdinal,GlobalOrdinal,Node> ImportType;
67 typedef typename Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> CrsMatrixType;
68 typedef typename Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> RowMatrixType;
70 TEUCHOS_TEST_FOR_EXCEPTION(OverlapLevel_ <= 0, std::runtime_error, "Ifpack2::OverlappingRowMatrix: OverlapLevel must be > 0.
"); 73 RCP<const CrsMatrixType> ACRS = Teuchos::rcp_dynamic_cast<const CrsMatrixType,const RowMatrixType>(A_); 74 TEUCHOS_TEST_FOR_EXCEPTION(ACRS == Teuchos::null, std::runtime_error, "Ifpack2::OverlappingRowMatrix: Matrix must be Tpetra::CrsMatrix.
"); 76 NumMyRowsA_ = A_->getNodeNumRows(); 78 GlobalOrdinal global_invalid = Teuchos::OrdinalTraits<global_size_t>::invalid(); 81 Array<GlobalOrdinal> ExtElements; 83 RCP<CrsMatrixType> TmpMatrix; 84 RCP<ImportType> TmpImporter; 85 RCP<const MapType> RowMap, ColMap; 87 // The big import loop 88 for (int overlap = 0 ; overlap < OverlapLevel_ ; ++overlap) { 89 // Get the current maps 91 RowMap = A_->getRowMap(); 92 ColMap = A_->getColMap(); 95 RowMap = TmpMatrix->getRowMap(); 96 ColMap = TmpMatrix->getColMap(); 99 size_t size = ColMap->getNodeNumElements() - RowMap->getNodeNumElements(); 100 Array<GlobalOrdinal> mylist(size); 103 // define the set of rows that are in ColMap but not in RowMap 104 for (LocalOrdinal i = 0 ; (size_t) i < ColMap->getNodeNumElements() ; ++i) { 105 GlobalOrdinal GID = ColMap->getGlobalElement(i); 106 if (A_->getRowMap()->getLocalElement(GID) == global_invalid) { 107 typename Array<GlobalOrdinal>::iterator pos 108 = std::find(ExtElements.begin(),ExtElements.end(),GID); 109 if (pos == ExtElements.end()) { 110 ExtElements.push_back(GID); 117 // Allocate & import new matrices, maps, etc. 118 TmpMap = rcp(new MapType(global_invalid,mylist(0,count),Teuchos::OrdinalTraits<GlobalOrdinal>::zero(),A_->getComm(),A_->getNode())); 119 TmpMatrix = rcp(new CrsMatrixType(TmpMap,0)); 120 TmpImporter = rcp(new ImportType(A_->getRowMap(),TmpMap)); 122 TmpMatrix->doImport(*ACRS,*TmpImporter,Tpetra::INSERT); 123 TmpMatrix->fillComplete(A_->getDomainMap(),TmpMap); 126 // build the map containing all the nodes (original 127 // matrix + extended matrix) 128 Array<GlobalOrdinal> mylist(NumMyRowsA_ + ExtElements.size()); 129 for (LocalOrdinal i = 0 ; (size_t)i < NumMyRowsA_ ; ++i) 130 mylist[i] = A_->getRowMap()->getGlobalElement(i); 131 for (LocalOrdinal i = 0 ; i < ExtElements.size() ; ++i) 132 mylist[i + NumMyRowsA_] = ExtElements[i]; 134 RowMap_= rcp(new MapType(global_invalid,mylist(),Teuchos::OrdinalTraits<GlobalOrdinal>::zero(),A_->getComm(),A_->getNode())); 137 // now build the map corresponding to all the external nodes 138 // (with respect to A().RowMatrixRowMap(). 139 ExtMap_ = rcp(new MapType(global_invalid,ExtElements(),Teuchos::OrdinalTraits<GlobalOrdinal>::zero(),A_->getComm(),A_->getNode())); 140 ExtMatrix_ = rcp(new CrsMatrixType(ExtMap_,ColMap_,0)); 141 ExtImporter_ = rcp(new ImportType(A_->getRowMap(),ExtMap_)); 143 RCP<CrsMatrixType> ExtMatrixCRS = Teuchos::rcp_dynamic_cast<CrsMatrixType,RowMatrixType>(ExtMatrix_); 144 ExtMatrixCRS->doImport(*ACRS,*ExtImporter_,Tpetra::INSERT); 145 ExtMatrixCRS->fillComplete(A_->getDomainMap(),RowMap_); 147 Importer_ = rcp(new ImportType(A_->getRowMap(),RowMap_)); 149 // fix indices for overlapping matrix 150 NumMyRowsB_ = ExtMatrix_->getNodeNumRows(); 151 NumMyRows_ = NumMyRowsA_ + NumMyRowsB_; 152 NumMyCols_ = NumMyRows_; 154 NumMyDiagonals_ = A_->getNodeNumDiags() + ExtMatrix_->getNodeNumDiags(); 155 NumMyNonzeros_ = A_->getNodeNumEntries() + ExtMatrix_->getNodeNumEntries(); 157 // FIXME: Fix this later when Teuchos::Comm gets redone 158 Tpetra::global_size_t NumMyNonzeros_tmp = NumMyNonzeros_; 159 Teuchos::reduceAll<int,Tpetra::global_size_t>(*A_->getComm(),Teuchos::REDUCE_SUM,NumMyNonzeros_tmp,Teuchos::outArg(NumGlobalNonzeros_)); 160 Tpetra::global_size_t NumMyRows_tmp = NumMyRows_; 161 Teuchos::reduceAll<int,Tpetra::global_size_t>(*A_->getComm(),Teuchos::REDUCE_SUM,NumMyRows_tmp,Teuchos::outArg(NumGlobalRows_)); 163 MaxNumEntries_ = A_->getNodeMaxNumRowEntries(); 164 if (MaxNumEntries_ < ExtMatrix_->getNodeMaxNumRowEntries()) 165 MaxNumEntries_ = ExtMatrix_->getNodeMaxNumRowEntries(); 167 // Resize temp arrays 168 Indices_.resize(MaxNumEntries_); 169 Values_.resize(MaxNumEntries_); 174 //========================================================================== 175 // Sub-communicator constructor 176 template<class MatrixType> 177 OverlappingRowMatrix<MatrixType>::OverlappingRowMatrix(const Teuchos::RCP<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& Matrix_in, 178 int OverlapLevel_in, int subdomainID) 181 throw std::runtime_error("Ifpack2::OverlappingRowMatrix - subdomain code not implemented yet.
"); 184 //========================================================================== 186 template<class MatrixType> 187 OverlappingRowMatrix<MatrixType>::~OverlappingRowMatrix() 191 //========================================================================== 192 // Returns the communicator. 193 template<class MatrixType> 194 const Teuchos::RCP<const Teuchos::Comm<int> > & OverlappingRowMatrix<MatrixType>::getComm() const 196 return A_->getComm(); 199 //========================================================================== 200 // Returns the underlying node. 201 template<class MatrixType> 202 Teuchos::RCP<typename MatrixType::node_type> OverlappingRowMatrix<MatrixType>::getNode() const 204 return A_->getNode(); 207 //========================================================================== 208 // Returns the Map that describes the row distribution in this matrix. 209 template<class MatrixType> 210 const Teuchos::RCP<const Tpetra::Map<typename MatrixType::local_ordinal_type, typename MatrixType::global_ordinal_type, typename MatrixType::node_type> > & OverlappingRowMatrix<MatrixType>::getRowMap() const 215 //========================================================================== 216 // Returns the Map that describes the column distribution in this matrix. 217 template<class MatrixType> 218 const Teuchos::RCP<const Tpetra::Map<typename MatrixType::local_ordinal_type, typename MatrixType::global_ordinal_type, typename MatrixType::node_type> > & OverlappingRowMatrix<MatrixType>::getColMap() const 223 //========================================================================== 224 // Returns the Map that describes the column distribution in this matrix. 225 template<class MatrixType> 226 const Teuchos::RCP<const Tpetra::Map<typename MatrixType::local_ordinal_type, typename MatrixType::global_ordinal_type, typename MatrixType::node_type> > & OverlappingRowMatrix<MatrixType>::getDomainMap() const 228 return A_->getDomainMap(); 231 //========================================================================== 232 // Returns the Map that describes the column distribution in this matrix. 233 template<class MatrixType> 234 const Teuchos::RCP<const Tpetra::Map<typename MatrixType::local_ordinal_type, typename MatrixType::global_ordinal_type, typename MatrixType::node_type> > & OverlappingRowMatrix<MatrixType>::getRangeMap() const 236 return A_->getRangeMap(); 239 //========================================================================== 240 // Returns the RowGraph associated with this matrix. 241 template<class MatrixType> 242 Teuchos::RCP<const Tpetra::RowGraph<typename MatrixType::local_ordinal_type, typename MatrixType::global_ordinal_type, typename MatrixType::node_type> > OverlappingRowMatrix<MatrixType>::getGraph() const 244 throw std::runtime_error("Ifpack2::OverlappingRowMatrix - ERROR
getGraph() is not implemented.
"); 247 //========================================================================== 248 // Returns the number of global rows in this matrix. 249 template<class MatrixType> 250 global_size_t OverlappingRowMatrix<MatrixType>::getGlobalNumRows() const 252 return NumGlobalRows_; 255 //========================================================================== 256 // Returns the number of global columns in this matrix. 257 template<class MatrixType> 258 global_size_t OverlappingRowMatrix<MatrixType>::getGlobalNumCols() const 260 return NumGlobalRows_; 263 //========================================================================== 264 // Returns the number of rows owned on the calling node. 265 template<class MatrixType> 266 size_t OverlappingRowMatrix<MatrixType>::getNodeNumRows() const 271 //========================================================================== 272 // Returns the number of columns needed to apply the forward operator on this node, i.e., the number of elements listed in the column map. 273 template<class MatrixType> 274 size_t OverlappingRowMatrix<MatrixType>::getNodeNumCols() const 279 //========================================================================== 280 // Returns the index base for global indices for this matrix. 281 template<class MatrixType> 282 typename MatrixType::global_ordinal_type OverlappingRowMatrix<MatrixType>::getIndexBase() const 284 return A_->getIndexBase(); 287 //========================================================================== 288 // Returns the global number of entries in this matrix. 289 template<class MatrixType> 290 Tpetra::global_size_t OverlappingRowMatrix<MatrixType>::getGlobalNumEntries() const 292 return NumGlobalNonzeros_; 295 //========================================================================== 296 // Returns the local number of entries in this matrix. 297 template<class MatrixType> 298 size_t OverlappingRowMatrix<MatrixType>::getNodeNumEntries() const 300 return NumMyNonzeros_; 303 //========================================================================== 304 // Returns the current number of entries on this node in the specified global row. 305 /* Returns Teuchos::OrdinalTraits<size_t>::invalid() if the specified global row is not valid for this graph. */ 306 template<class MatrixType> 307 size_t OverlappingRowMatrix<MatrixType>::getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const 309 LocalOrdinal localRow = RowMap_->getLocalElement(globalRow); 310 if(localRow == Teuchos::OrdinalTraits<LocalOrdinal>::invalid()) return Teuchos::OrdinalTraits<size_t>::invalid(); 311 else return getNumEntriesInLocalRow(localRow); 315 //========================================================================== 316 // Returns the current number of entries on this node in the specified local row. 317 /* Returns Teuchos::OrdinalTraits<size_t>::invalid() if the specified local row is not valid for this graph. */ 318 template<class MatrixType> 319 size_t OverlappingRowMatrix<MatrixType>::getNumEntriesInLocalRow(LocalOrdinal localRow) const 321 if ((size_t)localRow < NumMyRowsA_) 322 return A_->getNumEntriesInLocalRow(localRow); 324 return ExtMatrix_->getNumEntriesInLocalRow((LocalOrdinal)(localRow-NumMyRowsA_)); 327 //========================================================================== 328 // Returns the number of global diagonal entries, based on global row/column index comparisons. 329 template<class MatrixType> 330 global_size_t OverlappingRowMatrix<MatrixType>::getGlobalNumDiags() const 332 throw std::runtime_error("Ifpack2::OverlappingRowMatrix::getGlobalNumDiags() not supported.
"); 335 //========================================================================== 336 // Returns the number of local diagonal entries, based on global row/column index comparisons. 337 template<class MatrixType> 338 size_t OverlappingRowMatrix<MatrixType>::getNodeNumDiags() const 340 return A_->getNodeNumDiags(); 343 //========================================================================== 344 // Returns the maximum number of entries across all rows/columns on all nodes. 345 template<class MatrixType> 346 size_t OverlappingRowMatrix<MatrixType>::getGlobalMaxNumRowEntries() const 348 throw std::runtime_error("Ifpack2::OverlappingRowMatrix::getGlobalMaxNumRowEntries() not supported.
"); 351 //========================================================================== 352 template<class MatrixType> 353 // Returns the maximum number of entries across all rows/columns on this node. 354 size_t OverlappingRowMatrix<MatrixType>::getNodeMaxNumRowEntries() const 356 return MaxNumEntries_; 359 //========================================================================== 360 // Indicates whether this matrix has a well-defined column map 361 template<class MatrixType> 362 bool OverlappingRowMatrix<MatrixType>::hasColMap() const 367 //========================================================================== 368 // Indicates whether this matrix is lower triangular. 369 template<class MatrixType> 370 bool OverlappingRowMatrix<MatrixType>::isLowerTriangular() const 372 return A_->isLowerTriangular(); 375 //========================================================================== 376 // Indicates whether this matrix is upper triangular. 377 template<class MatrixType> 378 bool OverlappingRowMatrix<MatrixType>::isUpperTriangular() const 380 return A_->isUpperTriangular(); 382 //========================================================================== 383 // If matrix indices are in the local range, this function returns true. Otherwise, this function returns false. */ 384 template<class MatrixType> 385 bool OverlappingRowMatrix<MatrixType>::isLocallyIndexed() const 390 //========================================================================== 391 // If matrix indices are in the global range, this function returns true. Otherwise, this function returns false. */ 392 template<class MatrixType> 393 bool OverlappingRowMatrix<MatrixType>::isGloballyIndexed() const 398 //========================================================================== 399 // Returns \c true if fillComplete() has been called. 400 template<class MatrixType> 401 bool OverlappingRowMatrix<MatrixType>::isFillComplete() const 406 //========================================================================== 407 // Extract a list of entries in a specified global row of this matrix. Put into pre-allocated storage. 409 \param LocalRow - (In) Global row number for which indices are desired. 410 \param Indices - (Out) Global column indices corresponding to values. 411 \param Values - (Out) Matrix values. 412 \param NumEntries - (Out) Number of indices. 414 Note: A std::runtime_error exception is thrown if either \c Indices or \c Values is not large enough to hold the data associated 415 with row \c GlobalRow. If \c GlobalRow does not belong to this node, then \c Indices and \c Values are unchanged and \c NumIndices is 416 returned as Teuchos::OrdinalTraits<size_t>::invalid(). 418 template<class MatrixType> 419 void OverlappingRowMatrix<MatrixType>::getGlobalRowCopy(GlobalOrdinal GlobalRow, 420 const Teuchos::ArrayView<GlobalOrdinal> &Indices, 421 const Teuchos::ArrayView<Scalar> &Values, 422 size_t &NumEntries) const 424 LocalOrdinal LocalRow=RowMap_->getLocalElement(GlobalRow); 425 if(LocalRow == Teuchos::OrdinalTraits<LocalOrdinal>::invalid()) NumEntries = Teuchos::OrdinalTraits<size_t>::invalid(); 427 if ((size_t)LocalRow < NumMyRowsA_) 428 A_->getGlobalRowCopy(GlobalRow,Indices,Values,NumEntries); 430 ExtMatrix_->getGlobalRowCopy(GlobalRow,Indices,Values,NumEntries); 435 //========================================================================== 436 // Extract a list of entries in a specified local row of the graph. Put into storage allocated by calling routine. 438 \param LocalRow - (In) Local row number for which indices are desired. 439 \param Indices - (Out) Local column indices corresponding to values. 440 \param Values - (Out) Matrix values. 441 \param NumIndices - (Out) Number of indices. 443 Note: A std::runtime_error exception is thrown if either \c Indices or \c Values is not large enough to hold the data associated 444 with row \c LocalRow. If \c LocalRow is not valid for this node, then \c Indices and \c Values are unchanged and \c NumIndices is 445 returned as Teuchos::OrdinalTraits<size_t>::invalid(). 447 template<class MatrixType> 448 void OverlappingRowMatrix<MatrixType>::getLocalRowCopy(LocalOrdinal LocalRow, 449 const Teuchos::ArrayView<LocalOrdinal> &Indices, 450 const Teuchos::ArrayView<Scalar> &Values, 451 size_t &NumEntries) const 453 if ((size_t)LocalRow < NumMyRowsA_) 454 A_->getLocalRowCopy(LocalRow,Indices,Values,NumEntries); 456 ExtMatrix_->getLocalRowCopy(LocalRow-(LocalOrdinal)(NumMyRowsA_),Indices,Values,NumEntries); 459 //========================================================================== 460 // Extract a const, non-persisting view of global indices in a specified row of the matrix. 462 \param GlobalRow - (In) Global row number for which indices are desired. 463 \param Indices - (Out) Global column indices corresponding to values. 464 \param Values - (Out) Row values 465 \pre <tt>isLocallyIndexed() == false</tt> 466 \post <tt>indices.size() == getNumEntriesInGlobalRow(GlobalRow)</tt> 468 Note: If \c GlobalRow does not belong to this node, then \c indices is set to null. 470 template<class MatrixType> 471 void OverlappingRowMatrix<MatrixType>::getGlobalRowView(GlobalOrdinal GlobalRow, 472 Teuchos::ArrayView<const GlobalOrdinal> &indices, 473 Teuchos::ArrayView<const Scalar> &values) const 475 LocalOrdinal LocalRow=RowMap_->getLocalElement(GlobalRow); 476 if(LocalRow == Teuchos::OrdinalTraits<LocalOrdinal>::invalid()) { 477 indices=Teuchos::null; 478 values =Teuchos::null; 481 if ((size_t)LocalRow < NumMyRowsA_) 482 A_->getGlobalRowView(GlobalRow,indices,values); 484 ExtMatrix_->getGlobalRowView(GlobalRow,indices,values); 488 //========================================================================== 489 // Extract a const, non-persisting view of local indices in a specified row of the matrix. 491 \param LocalRow - (In) Local row number for which indices are desired. 492 \param Indices - (Out) Global column indices corresponding to values. 493 \param Values - (Out) Row values 494 \pre <tt>isGloballyIndexed() == false</tt> 495 \post <tt>indices.size() == getNumEntriesInLocalRow(LocalRow)</tt> 497 Note: If \c LocalRow does not belong to this node, then \c indices is set to null. 499 template<class MatrixType> 500 void OverlappingRowMatrix<MatrixType>::getLocalRowView(LocalOrdinal LocalRow, 501 Teuchos::ArrayView<const LocalOrdinal> &indices, 502 Teuchos::ArrayView<const Scalar> &values) const 504 if ((size_t)LocalRow < NumMyRowsA_) 505 A_->getLocalRowView(LocalRow,indices,values); 507 ExtMatrix_->getLocalRowView(LocalRow-(LocalOrdinal)(NumMyRowsA_),indices,values); 510 //========================================================================== 511 // Get a copy of the diagonal entries owned by this node, with local row indices. 512 /* Returns a distributed Vector object partitioned according to this matrix's row map, containing the 513 the zero and non-zero diagonals owned by this node. */ 514 template<class MatrixType> 515 void OverlappingRowMatrix<MatrixType>::getLocalDiagCopy(Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &diag) const 517 throw std::runtime_error("Ifpack2::OverlappingRowMatrix::getLocalDiagCopy not supported.
"); 520 //========================================================================== 521 template<class MatrixType> 522 void OverlappingRowMatrix<MatrixType>::leftScale(const Tpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& x) 524 throw std::runtime_error("Ifpack2::OverlappingRowMatrix does not support
leftScale.
"); 527 //========================================================================== 528 template<class MatrixType> 529 void OverlappingRowMatrix<MatrixType>::rightScale(const Tpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& x) 531 throw std::runtime_error("Ifpack2::OverlappingRowMatrix does not support
leftScale.
"); 534 //========================================================================== 535 // Returns the Frobenius norm of the matrix. 536 template<class MatrixType> 537 typename Teuchos::ScalarTraits<typename MatrixType::scalar_type>::magnitudeType OverlappingRowMatrix<MatrixType>::getFrobeniusNorm() const 539 throw std::runtime_error("Ifpack2::OverlappingRowMatrix does not support
getFrobeniusNorm.
"); 544 //========================================================================== 545 // \brief Computes the operator-multivector application. 546 /* Loosely, performs \f$Y = \alpha \cdot A^{\textrm{mode}} \cdot X + \beta \cdot Y\f$. However, the details of operation 547 vary according to the values of \c alpha and \c beta. Specifically 548 - if <tt>beta == 0</tt>, apply() <b>must</b> overwrite \c Y, so that any values in \c Y (including NaNs) are ignored. 549 - if <tt>alpha == 0</tt>, apply() <b>may</b> short-circuit the operator, so that any values in \c X (including NaNs) are ignored. 551 This is analagous to the *Multiply* function in Ifpack, not the *Apply* 553 template<class MatrixType> 554 void OverlappingRowMatrix<MatrixType>::apply(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &X, 555 Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &Y, 556 Teuchos::ETransp mode, 560 this->template applyTempl<Scalar,Scalar>(X, Y, mode, alpha, beta); 564 //========================================================================== 565 // \brief Computes the operator-multivector application. 566 /* Loosely, performs \f$Y = \alpha \cdot A^{\textrm{mode}} \cdot X + \beta \cdot Y\f$. However, the details of operation 567 vary according to the values of \c alpha and \c beta. Specifically 568 - if <tt>beta == 0</tt>, apply() <b>must</b> overwrite \c Y, so that any values in \c Y (including NaNs) are ignored. 569 - if <tt>alpha == 0</tt>, apply() <b>may</b> short-circuit the operator, so that any values in \c X (including NaNs) are ignored. 571 This is analagous to the *Multiply* function in Ifpack, not the *Apply* 573 template<class MatrixType> 574 template<class DomainScalar, class RangeScalar> 575 void OverlappingRowMatrix<MatrixType>::applyTempl(const Tpetra::MultiVector<DomainScalar,LocalOrdinal,GlobalOrdinal,Node> &X, 576 Tpetra::MultiVector<RangeScalar,LocalOrdinal,GlobalOrdinal,Node> &Y, 577 Teuchos::ETransp mode, 579 RangeScalar beta) const 581 // Note: This isn't AztecOO compliant. But neither was Ifpack's version. 582 TEUCHOS_TEST_FOR_EXCEPTION(X.getNumVectors() != Y.getNumVectors(), std::runtime_error, 583 "Ifpack2::OverlappingRowMatrix::apply ERROR: X.getNumVectors() != Y.getNumVectors().
"); 585 RangeScalar zero = Teuchos::ScalarTraits<RangeScalar>::zero(); 586 Teuchos::ArrayRCP<Teuchos::ArrayRCP<const DomainScalar> > x_ptr = X.get2dView(); 587 Teuchos::ArrayRCP<Teuchos::ArrayRCP<RangeScalar> > y_ptr = Y.get2dViewNonConst(); 589 size_t NumVectors = Y.getNumVectors(); 591 for (size_t i = 0 ; i < NumMyRowsA_ ; ++i) { 593 // Use this class's getrow to make the below code simpler 594 A_->getLocalRowCopy(i,Indices_(),Values_(),Nnz); 595 if (mode==Teuchos::NO_TRANS){ 596 for (size_t j = 0 ; j < Nnz ; ++j) 597 for (size_t k = 0 ; k < NumVectors ; ++k) 598 y_ptr[k][i] += (RangeScalar)Values_[j] * (RangeScalar)x_ptr[k][Indices_[j]]; 600 else if (mode==Teuchos::TRANS){ 601 for (size_t j = 0 ; j < Nnz ; ++j) 602 for (size_t k = 0 ; k < NumVectors ; ++k) 603 y_ptr[k][Indices_[j]] += (RangeScalar)Values_[j] * (RangeScalar)x_ptr[k][i]; 605 else { //mode==Teuchos::CONJ_TRANS 606 for (size_t j = 0 ; j < Nnz ; ++j) 607 for (size_t k = 0 ; k < NumVectors ; ++k) 608 y_ptr[k][Indices_[j]] += Teuchos::ScalarTraits<RangeScalar>::conjugate((RangeScalar)Values_[j]) * (RangeScalar)x_ptr[k][i]; 612 for (size_t i = 0 ; i < NumMyRowsB_ ; ++i) { 614 // Use this class's getrow to make the below code simpler 615 ExtMatrix_->getLocalRowCopy(i,Indices_(),Values_(),Nnz); 616 if (mode==Teuchos::NO_TRANS){ 617 for (size_t j = 0 ; j < Nnz ; ++j) 618 for (size_t k = 0 ; k < NumVectors ; ++k) 619 y_ptr[k][NumMyRowsA_+i] += (RangeScalar)Values_[j] * (RangeScalar)x_ptr[k][Indices_[j]]; 621 else if (mode==Teuchos::TRANS){ 622 for (size_t j = 0 ; j < Nnz ; ++j) 623 for (size_t k = 0 ; k < NumVectors ; ++k) 624 y_ptr[k][NumMyRowsA_+Indices_[j]] += (RangeScalar)Values_[j] * (RangeScalar)x_ptr[k][i]; 626 else { //mode==Teuchos::CONJ_TRANS 627 for (size_t j = 0 ; j < Nnz ; ++j) 628 for (size_t k = 0 ; k < NumVectors ; ++k) 629 y_ptr[k][NumMyRowsA_+Indices_[j]] += Teuchos::ScalarTraits<RangeScalar>::conjugate((RangeScalar)Values_[j]) * (RangeScalar)x_ptr[k][i]; 636 // ====================================================================== 637 template<class MatrixType> 638 void OverlappingRowMatrix<MatrixType>::importMultiVector(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &X, 639 Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &OvX, 640 Tpetra::CombineMode CM) 642 this->template importMultiVectorTempl<Scalar>(X, OvX, CM); 645 // ====================================================================== 646 template<class MatrixType> 647 template<class OpScalar> 648 void OverlappingRowMatrix<MatrixType>::importMultiVectorTempl(const Tpetra::MultiVector<OpScalar,LocalOrdinal,GlobalOrdinal,Node> &X, 649 Tpetra::MultiVector<OpScalar,LocalOrdinal,GlobalOrdinal,Node> &OvX, 650 Tpetra::CombineMode CM) 652 OvX.doImport(X,*Importer_,CM); 656 // ====================================================================== 657 template<class MatrixType> 658 void OverlappingRowMatrix<MatrixType>::exportMultiVector(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &OvX, 659 Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &X, 660 Tpetra::CombineMode CM) 662 this->template exportMultiVectorTempl<Scalar>(OvX, X, CM); 665 // ====================================================================== 666 template<class MatrixType> 667 template<class OpScalar> 668 void OverlappingRowMatrix<MatrixType>::exportMultiVectorTempl(const Tpetra::MultiVector<OpScalar,LocalOrdinal,GlobalOrdinal,Node> &OvX, 669 Tpetra::MultiVector<OpScalar,LocalOrdinal,GlobalOrdinal,Node> &X, 670 Tpetra::CombineMode CM) 672 X.doExport(OvX,*Importer_,CM); 675 //========================================================================== 676 // Indicates whether this operator supports applying the adjoint operator. 677 template<class MatrixType> 678 bool OverlappingRowMatrix<MatrixType>::hasTransposeApply() const 683 //========================================================================== 684 template<class MatrixType> 685 bool OverlappingRowMatrix<MatrixType>::supportsRowViews() const 691 } // namespace Ifpack2 693 #endif // IFPACK2_OVERLAPPINGROWMATRIX_DEF_HPP virtual void leftScale(const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
Scales the RowMatrix on the left with the Vector x.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:522
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:537
virtual Teuchos::RCP< const Tpetra::RowGraph< LocalOrdinal, GlobalOrdinal, Node > > getGraph() const
Returns the RowGraph associated with this matrix.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:242
Ifpack2::OverlappingRowMatrix: matrix with ghost rows, based on Tpetra::RowMatrix.
Definition: Ifpack2_OverlappingRowMatrix_decl.hpp:60
OverlappingRowMatrix(const Teuchos::RCP< const Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &Matrix_in, int OverlapLevel_in)
Standard constructor.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:54
Ifpack2::Container: a pure virtual class for creating and solving local linear problems.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:67