47 #ifndef PACKAGES_XPETRA_SUP_MATRIX_UTILS_HPP_
48 #define PACKAGES_XPETRA_SUP_MATRIX_UTILS_HPP_
53 #include "Xpetra_Map.hpp"
55 #include "Xpetra_StridedMap.hpp"
56 #include "Xpetra_MapFactory.hpp"
57 #include "Xpetra_MapExtractor.hpp"
66 #ifdef HAVE_XPETRA_TPETRA
67 #include "Xpetra_TpetraMultiVector.hpp"
68 #include <Tpetra_RowMatrixTransposer.hpp>
69 #include <Tpetra_Details_extractBlockDiagonal.hpp>
70 #include <Tpetra_Details_scaleBlockDiagonal.hpp>
84 template <
class Scalar,
89 #undef XPETRA_MATRIXUTILS_SHORT
99 Teuchos::ArrayRCP< const Scalar > data = input.
getData(c);
101 ret->replaceLocalValue(Teuchos::as<LocalOrdinal>(r), c, data[r]);
112 RCP< const Teuchos::Comm<int> > comm = input.
getRowMap()->getComm();
115 Teuchos::Array<GlobalOrdinal> ovlUnknownStatusGids;
116 Teuchos::Array<GlobalOrdinal> ovlFoundStatusGids;
119 for(
size_t i = 0; i<input.
getColMap()->getNodeNumElements(); i++) {
120 GlobalOrdinal gcid = input.
getColMap()->getGlobalElement(i);
122 ovlUnknownStatusGids.push_back(gcid);
128 std::vector<int> myUnknownDofGIDs(comm->getSize(),0);
129 std::vector<int> numUnknownDofGIDs(comm->getSize(),0);
130 myUnknownDofGIDs[comm->getRank()] = ovlUnknownStatusGids.size();
131 Teuchos::reduceAll(*comm,Teuchos::REDUCE_MAX,comm->getSize(),&myUnknownDofGIDs[0],&numUnknownDofGIDs[0]);
134 size_t cntUnknownDofGIDs = 0;
135 for(
int p = 0; p < comm->getSize(); p++) cntUnknownDofGIDs += numUnknownDofGIDs[p];
136 std::vector<GlobalOrdinal> lUnknownDofGIDs(cntUnknownDofGIDs,-1);
137 std::vector<GlobalOrdinal> gUnknownDofGIDs(cntUnknownDofGIDs,-1);
139 size_t cntUnknownOffset = 0;
140 for(
int p = 0; p < comm->getRank(); p++) cntUnknownOffset += numUnknownDofGIDs[p];
141 for(
size_t k=0; k < Teuchos::as<size_t>(ovlUnknownStatusGids.size()); k++) {
142 lUnknownDofGIDs[k+cntUnknownOffset] = ovlUnknownStatusGids[k];
144 if(cntUnknownDofGIDs > 0)
145 Teuchos::reduceAll(*comm,Teuchos::REDUCE_MAX,Teuchos::as<int>(cntUnknownDofGIDs),&lUnknownDofGIDs[0],&gUnknownDofGIDs[0]);
146 std::sort(gUnknownDofGIDs.begin(), gUnknownDofGIDs.end());
147 gUnknownDofGIDs.erase(std::unique(gUnknownDofGIDs.begin(), gUnknownDofGIDs.end()), gUnknownDofGIDs.end());
150 for(
size_t k=0; k < gUnknownDofGIDs.size(); k++) {
151 GlobalOrdinal curgid = gUnknownDofGIDs[k];
153 ovlFoundStatusGids.push_back(curgid);
157 std::vector<int> myFoundDofGIDs(comm->getSize(),0);
158 std::vector<int> numFoundDofGIDs(comm->getSize(),0);
159 myFoundDofGIDs[comm->getRank()] = ovlFoundStatusGids.size();
160 Teuchos::reduceAll(*comm,Teuchos::REDUCE_MAX,comm->getSize(),&myFoundDofGIDs[0],&numFoundDofGIDs[0]);
163 size_t cntFoundDofGIDs = 0;
164 for(
int p = 0; p < comm->getSize(); p++) cntFoundDofGIDs += numFoundDofGIDs[p];
165 std::vector<GlobalOrdinal> lFoundDofGIDs(cntFoundDofGIDs,-1);
166 std::vector<GlobalOrdinal> gFoundDofGIDs(cntFoundDofGIDs,-1);
168 size_t cntFoundOffset = 0;
169 for(
int p = 0; p < comm->getRank(); p++) cntFoundOffset += numFoundDofGIDs[p];
170 for(
size_t k=0; k < Teuchos::as<size_t>(ovlFoundStatusGids.size()); k++) {
171 lFoundDofGIDs[k+cntFoundOffset] = ovlFoundStatusGids[k];
173 if(cntFoundDofGIDs > 0)
174 Teuchos::reduceAll(*comm,Teuchos::REDUCE_MAX,Teuchos::as<int>(cntFoundDofGIDs),&lFoundDofGIDs[0],&gFoundDofGIDs[0]);
176 Teuchos::Array<GlobalOrdinal> ovlDomainMapArray;
177 for(
size_t i = 0; i<input.
getColMap()->getNodeNumElements(); i++) {
178 GlobalOrdinal gcid = input.
getColMap()->getGlobalElement(i);
180 std::find(gFoundDofGIDs.begin(), gFoundDofGIDs.end(), gcid) != gFoundDofGIDs.end()) {
181 ovlDomainMapArray.push_back(gcid);
184 RCP<Map> ovlDomainMap =
MapFactory::Build (domainMap.
lib(),Teuchos::OrdinalTraits<GlobalOrdinal>::invalid(),ovlDomainMapArray(),0,comm);
196 static Teuchos::RCP<Xpetra::BlockedCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
SplitMatrix(
201 bool bThyraMode =
false) {
203 size_t numRows = rangeMapExtractor->NumMaps();
204 size_t numCols = domainMapExtractor->NumMaps();
206 TEUCHOS_TEST_FOR_EXCEPTION(rangeMapExtractor->getThyraMode() ==
true,
Xpetra::Exceptions::Incompatible,
"Xpetra::MatrixUtils::Split: RangeMapExtractor must not use Thyra style numbering of GIDs. The MapExtractor must contain all GIDs of the full range map in order to define a proper splitting.")
207 TEUCHOS_TEST_FOR_EXCEPTION(domainMapExtractor->getThyraMode() ==
true,
Xpetra::Exceptions::Incompatible,
"Xpetra::MatrixUtils::Split: DomainMapExtractor must not use Thyra style numbering of GIDs. The MapExtractor must contain all GIDs of the full domain map in order to define a proper splitting.")
209 RCP<const Map> fullRangeMap = rangeMapExtractor->getFullMap();
210 RCP<const Map> fullDomainMap = domainMapExtractor->getFullMap();
212 TEUCHOS_TEST_FOR_EXCEPTION(fullRangeMap->getMaxAllGlobalIndex() != input.
getRowMap()->getMaxAllGlobalIndex(),
Xpetra::Exceptions::Incompatible,
"Xpetra::MatrixUtils::Split: RangeMapExtractor incompatible to row map of input matrix.")
213 TEUCHOS_TEST_FOR_EXCEPTION(fullRangeMap->getGlobalNumElements() != input.
getRowMap()->getGlobalNumElements(),
Xpetra::Exceptions::Incompatible,
"Xpetra::MatrixUtils::Split: RangeMapExtractor incompatible to row map of input matrix.")
214 TEUCHOS_TEST_FOR_EXCEPTION(fullRangeMap->getNodeNumElements() != input.
getRowMap()->getNodeNumElements(),
Xpetra::Exceptions::Incompatible,
"Xpetra::MatrixUtils::Split: RangeMapExtractor incompatible to row map of input matrix.")
215 TEUCHOS_TEST_FOR_EXCEPTION(fullRangeMap->getMaxAllGlobalIndex() != input.
getRangeMap()->getMaxAllGlobalIndex(),
Xpetra::Exceptions::Incompatible,
"Xpetra::MatrixUtils::Split: RangeMapExtractor incompatible to row map of input matrix.")
216 TEUCHOS_TEST_FOR_EXCEPTION(fullRangeMap->getGlobalNumElements() != input.
getRangeMap()->getGlobalNumElements(),
Xpetra::Exceptions::Incompatible,
"Xpetra::MatrixUtils::Split: RangeMapExtractor incompatible to row map of input matrix.")
217 TEUCHOS_TEST_FOR_EXCEPTION(fullRangeMap->getNodeNumElements() != input.
getRangeMap()->getNodeNumElements(),
Xpetra::Exceptions::Incompatible,
"Xpetra::MatrixUtils::Split: RangeMapExtractor incompatible to row map of input matrix.")
219 TEUCHOS_TEST_FOR_EXCEPTION(fullDomainMap->getMaxAllGlobalIndex() != input.
getColMap()->getMaxAllGlobalIndex(),
Xpetra::Exceptions::Incompatible,
"Xpetra::MatrixUtils::Split: DomainMapExtractor incompatible to domain map of input matrix. fullDomainMap->getMaxAllGlobalIndex() = " << fullDomainMap->getMaxAllGlobalIndex() <<
" vs. input.getColMap()->getMaxAllGlobalIndex() = " << input.
getColMap()->getMaxAllGlobalIndex())
220 TEUCHOS_TEST_FOR_EXCEPTION(fullDomainMap->getMaxAllGlobalIndex() != input.
getDomainMap()->getMaxAllGlobalIndex(),
Xpetra::Exceptions::Incompatible,
"Xpetra::MatrixUtils::Split: DomainMapExtractor incompatible to domain map of input matrix.")
221 TEUCHOS_TEST_FOR_EXCEPTION(fullDomainMap->getGlobalNumElements() != input.
getDomainMap()->getGlobalNumElements(),
Xpetra::Exceptions::Incompatible,
"Xpetra::MatrixUtils::Split: DomainMapExtractor incompatible to domain map of input matrix.")
222 TEUCHOS_TEST_FOR_EXCEPTION(fullDomainMap->getNodeNumElements() != input.
getDomainMap()->getNodeNumElements(),
Xpetra::Exceptions::Incompatible,
"Xpetra::MatrixUtils::Split: DomainMapExtractor incompatible to domain map of input matrix.")
225 Teuchos::RCP<const MapExtractor> myColumnMapExtractor = Teuchos::null;
226 if(columnMapExtractor == Teuchos::null) {
227 TEUCHOS_TEST_FOR_EXCEPTION(domainMapExtractor->getThyraMode() ==
true,
Xpetra::Exceptions::Incompatible,
"Xpetra::MatrixUtils::Split: Auto generation of column map extractor not supported for Thyra style numbering.");
229 std::vector<Teuchos::RCP<const Map> > ovlxmaps(numCols, Teuchos::null);
230 for(
size_t c = 0; c < numCols; c++) {
233 ovlxmaps[c] = colMap;
239 myColumnMapExtractor = columnMapExtractor;
243 Teuchos::RCP<const MapExtractor> thyRangeMapExtractor = Teuchos::null;
244 Teuchos::RCP<const MapExtractor> thyDomainMapExtractor = Teuchos::null;
245 Teuchos::RCP<const MapExtractor> thyColMapExtractor = Teuchos::null;
246 if(bThyraMode ==
true) {
248 std::vector<Teuchos::RCP<const Map> > thyRgMapExtractorMaps(numRows, Teuchos::null);
249 for (
size_t r = 0; r < numRows; r++) {
250 RCP<const Map> rMap = rangeMapExtractor->getMap(r);
252 RCP<const StridedMap> strRangeMap = Teuchos::rcp_dynamic_cast<
const StridedMap>(rMap);
253 if(strRangeMap != Teuchos::null) {
255 GlobalOrdinal offset = strRangeMap->getOffset();
256 LocalOrdinal stridedBlockId = strRangeMap->getStridedBlockId();
257 RCP<const StridedMap> strShrinkedMap = Teuchos::rcp(
new StridedMap(shrinkedMap, strInfo, shrinkedMap->getIndexBase(), stridedBlockId, offset));
258 thyRgMapExtractorMaps[r] = strShrinkedMap;
260 thyRgMapExtractorMaps[r] = shrinkedMap;
262 TEUCHOS_TEST_FOR_EXCEPTION(thyRgMapExtractorMaps[r]->getNodeNumElements() != rMap->getNodeNumElements(),
Xpetra::Exceptions::Incompatible,
"Xpetra::MatrixUtils::Split: Thyra-style range map extractor contains faulty data.")
266 std::vector<Teuchos::RCP<const Map> > thyDoMapExtractorMaps (numCols, Teuchos::null);
267 std::vector<Teuchos::RCP<const Map> > thyColMapExtractorMaps(numCols, Teuchos::null);
268 for (
size_t c = 0; c < numCols; c++) {
269 RCP<const Map> cMap = domainMapExtractor->getMap(c);
272 RCP<const StridedMap> strDomainMap = Teuchos::rcp_dynamic_cast<
const StridedMap>(cMap);
273 if(strDomainMap != Teuchos::null) {
275 GlobalOrdinal offset = strDomainMap->getOffset();
276 LocalOrdinal stridedBlockId = strDomainMap->getStridedBlockId();
277 RCP<const StridedMap> strShrinkedDomainMap = Teuchos::rcp(
new StridedMap(shrinkedDomainMap, strInfo, shrinkedDomainMap->getIndexBase(), stridedBlockId, offset));
278 thyDoMapExtractorMaps[c] = strShrinkedDomainMap;
280 thyDoMapExtractorMaps[c] = shrinkedDomainMap;
282 RCP<const Map> colMap = myColumnMapExtractor->getMap(c);
284 RCP<const StridedMap> strColMap = Teuchos::rcp_dynamic_cast<
const StridedMap>(colMap);
285 if(strColMap != Teuchos::null) {
287 GlobalOrdinal offset = strColMap->getOffset();
288 LocalOrdinal stridedBlockId = strColMap->getStridedBlockId();
289 RCP<const StridedMap> strShrinkedColMap = Teuchos::rcp(
new StridedMap(shrinkedColMap, strInfo, shrinkedColMap->getIndexBase(), stridedBlockId, offset));
290 thyColMapExtractorMaps[c] = strShrinkedColMap;
292 thyColMapExtractorMaps[c] = shrinkedColMap;
295 TEUCHOS_TEST_FOR_EXCEPTION(thyColMapExtractorMaps[c]->getNodeNumElements() != colMap->getNodeNumElements(),
Xpetra::Exceptions::Incompatible,
"Xpetra::MatrixUtils::Split: Thyra-style column map extractor contains faulty data.")
296 TEUCHOS_TEST_FOR_EXCEPTION(thyDoMapExtractorMaps[c]->getNodeNumElements() != cMap->getNodeNumElements(),
Xpetra::Exceptions::Incompatible,
"Xpetra::MatrixUtils::Split: Thyra-style domain map extractor contains faulty data.")
304 std::vector<Teuchos::RCP<Matrix> > subMatrices(numRows*numCols, Teuchos::null);
305 for (
size_t r = 0; r < numRows; r++) {
306 for (
size_t c = 0; c < numCols; c++) {
310 if(bThyraMode ==
true)
323 #if 0 // TAW needs to be fixed (does not compile for Scalar=complex)
330 doCheck->putScalar(1.0);
334 TEUCHOS_TEST_FOR_EXCEPTION(coCheck->normInf() != Teuchos::ScalarTraits< Scalar >::magnitude(1.0),
Xpetra::Exceptions::RuntimeError,
"Xpetra::MatrixUtils::SplitMatrix: error when distributing data.");
336 doCheck->putScalar(-1.0);
337 coCheck->putScalar(-1.0);
339 Teuchos::ArrayRCP< Scalar > doCheckData = doCheck->getDataNonConst(0);
340 for (
size_t rrr = 0; rrr < input.
getDomainMap()->getNodeNumElements(); rrr++) {
342 GlobalOrdinal
id = input.
getDomainMap()->getGlobalElement(rrr);
345 size_t BlockId = domainMapExtractor->getMapIndexForGID(
id);
347 doCheckData[rrr] = Teuchos::as<Scalar>(BlockId);
352 Teuchos::ArrayRCP< Scalar > coCheckData = coCheck->getDataNonConst(0);
355 for (
size_t rr = 0; rr < input.
getRowMap()->getNodeNumElements(); rr++) {
358 GlobalOrdinal growid = input.
getRowMap()->getGlobalElement(rr);
367 size_t rowBlockId = rangeMapExtractor->getMapIndexForGID(growid);
370 GlobalOrdinal subblock_growid = growid;
371 if(bThyraMode ==
true) {
373 LocalOrdinal lrowid = rangeMapExtractor->getMap(rowBlockId)->getLocalElement(growid);
375 subblock_growid = thyRangeMapExtractor->getMap(rowBlockId,
true)->getGlobalElement(lrowid);
381 Teuchos::ArrayView<const LocalOrdinal> indices;
382 Teuchos::ArrayView<const Scalar> vals;
385 std::vector<Teuchos::Array<GlobalOrdinal> > blockColIdx (numCols, Teuchos::Array<GlobalOrdinal>());
386 std::vector<Teuchos::Array<Scalar> > blockColVals(numCols, Teuchos::Array<Scalar>());
388 for(
size_t i=0; i<(size_t)indices.size(); i++) {
390 GlobalOrdinal gcolid = input.
getColMap()->getGlobalElement(indices[i]);
392 size_t colBlockId = myColumnMapExtractor->getMapIndexForGID(gcolid);
396 GlobalOrdinal subblock_gcolid = gcolid;
397 if(bThyraMode ==
true) {
399 LocalOrdinal lcolid = myColumnMapExtractor->getMap(colBlockId)->getLocalElement(gcolid);
401 subblock_gcolid = thyColMapExtractor->getMap(colBlockId,
true)->getGlobalElement(lcolid);
403 blockColIdx [colBlockId].push_back(subblock_gcolid);
404 blockColVals[colBlockId].push_back(vals[i]);
407 for (
size_t c = 0; c < numCols; c++) {
408 subMatrices[rowBlockId*numCols+c]->insertGlobalValues(subblock_growid,blockColIdx[c].view(0,blockColIdx[c].size()),blockColVals[c].view(0,blockColVals[c].size()));
414 RCP<BlockedCrsMatrix> bA = Teuchos::null;
415 if(bThyraMode ==
true) {
416 for (
size_t r = 0; r < numRows; r++) {
417 for (
size_t c = 0; c < numCols; c++) {
418 subMatrices[r*numCols+c]->fillComplete(thyDomainMapExtractor->getMap(c,
true), thyRangeMapExtractor->getMap(r,
true));
421 bA = Teuchos::rcp(
new BlockedCrsMatrix(thyRangeMapExtractor, thyDomainMapExtractor, 10 ));
423 for (
size_t r = 0; r < numRows; r++) {
424 for (
size_t c = 0; c < numCols; c++) {
425 subMatrices[r*numCols+c]->fillComplete(domainMapExtractor->getMap(c), rangeMapExtractor->getMap(r));
428 bA = Teuchos::rcp(
new BlockedCrsMatrix(rangeMapExtractor, domainMapExtractor, 10 ));
431 for (
size_t r = 0; r < numRows; r++) {
432 for (
size_t c = 0; c < numCols; c++) {
433 bA->setMatrix(r,c,subMatrices[r*numCols+c]);
442 bool const &repairZeroDiagonals, Teuchos::FancyOStream &fos,
443 const typename Teuchos::ScalarTraits<Scalar>::magnitudeType threshold = Teuchos::ScalarTraits<
typename Teuchos::ScalarTraits<Scalar>::magnitudeType>::zero())
445 typedef typename Teuchos::ScalarTraits<Scalar> TST;
446 Scalar one = TST::one();
448 Teuchos::RCP<Teuchos::ParameterList> p = Teuchos::rcp(
new Teuchos::ParameterList());
449 p->set(
"DoOptimizeStorage",
true);
451 RCP<const Map> rowMap = Ac->getRowMap();
453 Ac->getLocalDiagCopy(*diagVec);
455 LocalOrdinal lZeroDiags = 0;
456 Teuchos::ArrayRCP< const Scalar > diagVal = diagVec->getData(0);
458 for (
size_t i = 0; i < rowMap->getNodeNumElements(); i++) {
459 if (TST::magnitude(diagVal[i]) <= threshold) {
463 GlobalOrdinal gZeroDiags;
464 Teuchos::reduceAll(*(rowMap->getComm()), Teuchos::REDUCE_SUM, Teuchos::as<GlobalOrdinal>(lZeroDiags),
465 Teuchos::outArg(gZeroDiags));
467 if (repairZeroDiagonals && gZeroDiags > 0) {
483 Teuchos::Array<GlobalOrdinal> indout(1);
484 Teuchos::Array<Scalar> valout(1);
485 for (
size_t r = 0; r < rowMap->getNodeNumElements(); r++) {
486 if (TST::magnitude(diagVal[r]) <= threshold) {
487 GlobalOrdinal grid = rowMap->getGlobalElement(r);
490 fixDiagMatrix->insertGlobalValues(grid,indout(), valout());
494 Teuchos::TimeMonitor m1(*Teuchos::TimeMonitor::getNewTimer(
"CheckRepairMainDiagonal: fillComplete1"));
495 fixDiagMatrix->fillComplete(Ac->getDomainMap(),Ac->getRangeMap());
499 Xpetra::MatrixMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node>::TwoMatrixAdd(*Ac,
false, 1.0, *fixDiagMatrix,
false, 1.0, newAc, fos);
500 if (Ac->IsView(
"stridedMaps"))
501 newAc->CreateView(
"stridedMaps", Ac);
504 fixDiagMatrix = Teuchos::null;
510 Teuchos::TimeMonitor m1(*Teuchos::TimeMonitor::getNewTimer(
"CheckRepairMainDiagonal: fillComplete2"));
518 fos <<
"CheckRepairMainDiagonal: " << (repairZeroDiagonals ?
"repaired " :
"found ")
519 << gZeroDiags <<
" too small entries on main diagonal of Ac." << std::endl;
521 #ifdef HAVE_XPETRA_DEBUG // only for debugging
523 Ac->getLocalDiagCopy(*diagVec);
524 diagVal = diagVec->getData(0);
525 for (
size_t r = 0; r < Ac->getRowMap()->getNodeNumElements(); r++) {
526 if (TST::magnitude(diagVal[r]) <= threshold) {
527 fos <<
"Error: there are too small entries left on diagonal after repair..." << std::endl;
543 const Teuchos::ArrayView<const double> & relativeThreshold, Teuchos::FancyOStream &fos)
545 Teuchos::TimeMonitor m1(*Teuchos::TimeMonitor::getNewTimer(
"RelativeDiagonalBoost"));
547 TEUCHOS_TEST_FOR_EXCEPTION(A->GetFixedBlockSize() != relativeThreshold.size() && relativeThreshold.size() != 1,
Xpetra::Exceptions::Incompatible,
"Xpetra::MatrixUtils::RelativeDiagonal Boost: Either A->GetFixedBlockSize() != relativeThreshold.size() OR relativeThreshold.size() == 1");
549 LocalOrdinal numPDEs = A->GetFixedBlockSize();
550 typedef typename Teuchos::ScalarTraits<Scalar> TST;
551 typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType MT;
552 Scalar zero = TST::zero();
553 Scalar one = TST::one();
557 A->getLocalDiagCopy(*diag);
558 Teuchos::ArrayRCP< const Scalar > dataVal = diag->getData(0);
559 size_t N = A->getRowMap()->getNodeNumElements();
562 std::vector<MT> l_diagMax(numPDEs), g_diagMax(numPDEs);
563 for(
size_t i=0; i<N; i++) {
564 int pde = (int) (i % numPDEs);
566 l_diagMax[pde] = TST::magnitude(dataVal[i]);
568 l_diagMax[pde] = std::max(l_diagMax[pde],TST::magnitude(dataVal[i]));
570 Teuchos::reduceAll(*A->getRowMap()->getComm(), Teuchos::REDUCE_MAX, numPDEs, l_diagMax.data(), g_diagMax.data() );
574 Teuchos::Array<GlobalOrdinal> index(1);
575 Teuchos::Array<Scalar> value(1);
576 for (
size_t i = 0; i<N; i++) {
577 GlobalOrdinal GRID = A->getRowMap()->getGlobalElement(i);
578 int pde = (int) (i % numPDEs);
580 if (TST::magnitude(dataVal[i]) < relativeThreshold[pde] * g_diagMax[pde])
581 value[0] = relativeThreshold[pde] * g_diagMax[pde] - TST::magnitude(dataVal[i]);
584 boostMatrix->insertGlobalValues(GRID,index(),value());
586 boostMatrix->fillComplete(A->getDomainMap(),A->getRangeMap());
590 Xpetra::MatrixMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node>::TwoMatrixAdd(*A,
false,one, *boostMatrix,
false,one,newA,fos);
591 if (A->IsView(
"stridedMaps"))
592 newA->CreateView(
"stridedMaps", A);
604 #if defined(HAVE_XPETRA_EPETRA)
606 #endif // HAVE_XPETRA_EPETRA
608 #ifdef HAVE_XPETRA_TPETRA
611 Tpetra::Details::extractBlockDiagonal(At,Dt);
612 #endif // HAVE_XPETRA_TPETRA
624 #if defined(HAVE_XPETRA_EPETRA)
626 #endif // HAVE_XPETRA_EPETRA
628 #ifdef HAVE_XPETRA_TPETRA
629 const Tpetra::MultiVector<SC,LO,GO,NO> & Dt =
Xpetra::toTpetra(blockDiagonal);
631 Tpetra::Details::inverseScaleBlockDiagonal(Dt,doTranspose,St);
632 #endif // HAVE_XPETRA_TPETRA
639 RCP<const Teuchos::Comm<int> > comm = rowMap->getComm();
640 LO numRows = Teuchos::as<LocalOrdinal>(rowMap->getNodeNumElements());
642 for (
LO rowLID = 0; rowLID < numRows; rowLID++) {
643 GO rowGID = rowMap->getGlobalElement(rowLID);
644 LO colLID = colMap->getLocalElement(rowGID);
645 if (rowLID != colLID) {
647 std::cerr <<
"On rank " << comm->getRank() <<
", GID " << rowGID <<
" is LID " << rowLID <<
"in the rowmap, but LID " << colLID <<
" in the column map.\n";
651 "Local parts of row and column map do not match!");
659 #define XPETRA_MATRIXUTILS_SHORT
661 #endif // PACKAGES_XPETRA_SUP_MATRIX_UTILS_HPP_
virtual size_t getNodeMaxNumRowEntries() const =0
Returns the maximum number of entries across all rows/columns on this node.
static Teuchos::RCP< Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > findColumnSubMap(const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &input, const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &domainMap)
static void checkLocalRowMapMatchesColMap(const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A)
static void RelativeDiagonalBoost(RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &A, const Teuchos::ArrayView< const double > &relativeThreshold, Teuchos::FancyOStream &fos)
static Teuchos::RCP< Xpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node >> &map, bool zeroOut=true)
Constructor specifying the number of non-zeros for all rows.
static Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node >> &map, size_t NumVectors, bool zeroOut=true)
Constructor specifying the number of non-zeros for all rows.
static RCP< Matrix > Build(const RCP< const Map > &rowMap)
Exception throws to report errors in the internal logical of the program.
static void CheckRepairMainDiagonal(RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >> &Ac, bool const &repairZeroDiagonals, Teuchos::FancyOStream &fos, const typename Teuchos::ScalarTraits< Scalar >::magnitudeType threshold=Teuchos::ScalarTraits< typename Teuchos::ScalarTraits< Scalar >::magnitudeType >::zero())
static Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > concatenateMaps(const std::vector< Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > > &subMaps)
Helper function to concatenate several maps.
static Teuchos::RCP< Xpetra::BlockedCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > SplitMatrix(const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &input, Teuchos::RCP< const Xpetra::MapExtractor< Scalar, LocalOrdinal, GlobalOrdinal, Node > > rangeMapExtractor, Teuchos::RCP< const Xpetra::MapExtractor< Scalar, LocalOrdinal, GlobalOrdinal, Node > > domainMapExtractor, Teuchos::RCP< const Xpetra::MapExtractor< Scalar, LocalOrdinal, GlobalOrdinal, Node > > columnMapExtractor=Teuchos::null, bool bThyraMode=false)
virtual const RCP< const Map > & getColMap() const
Returns the Map that describes the column distribution in this matrix. This might be null until fillC...
virtual bool isNodeGlobalElement(GlobalOrdinal globalIndex) const =0
Whether the given global index is valid for this Map on this process.
virtual void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const =0
Extract a const, non-persisting view of local indices in a specified row of the matrix.
static Teuchos::RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int >> &comm, LocalGlobal lg=Xpetra::GloballyDistributed)
Map constructor with Xpetra-defined contiguous uniform distribution.
virtual Teuchos::ArrayRCP< const Scalar > getData(size_t j) const =0
Const view of the local values in a particular vector of this multivector.
virtual Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const =0
The Map describing the parallel distribution of this object.
virtual size_t getLocalLength() const =0
Local number of rows on the calling process.
static void inverseScaleBlockDiagonal(const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &blockDiagonal, bool doTranspose, Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &toBeScaled)
static Teuchos::RCP< Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > shrinkMapGIDs(const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &input, const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &nonOvlInput)
Helper function to shrink the GIDs and generate a standard map whith GIDs starting at 0...
static void TwoMatrixAdd(const Matrix &A, bool transposeA, SC alpha, Matrix &B, SC beta)
Helper function to calculate B = alpha*A + beta*B.
static Teuchos::RCP< Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > xpetraGidNumbering2ThyraGidNumbering(const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &input)
std::vector< size_t > getStridingData() const
RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > toTpetra(const RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph)
Exception throws to report incompatible objects (like maps).
static void extractBlockDiagonal(const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diagonal)
virtual Teuchos::RCP< const Map > getRangeMap() const =0
The Map associated with the range of this operator, which must be compatible with Y...
virtual const RCP< const Map > & getRowMap() const
Returns the Map that describes the row distribution in this matrix.
virtual size_t getNumVectors() const =0
Number of columns in the multivector.
virtual UnderlyingLib lib() const =0
Get the library used by this object (Tpetra or Epetra?)
virtual Teuchos::RCP< const Map > getDomainMap() const =0
The Map associated with the domain of this operator, which must be compatible with X...
static RCP< Import< LocalOrdinal, GlobalOrdinal, Node > > Build(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &source, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &target, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying the number of non-zeros for all rows.
Xpetra-specific matrix class.
Class that stores a strided map.
static RCP< const Tpetra::CrsMatrix< SC, LO, GO, NO > > Op2TpetraCrs(RCP< Matrix > Op)