64 const ParameterList &pL = GetParameterList();
66 RCP<Matrix> A = Get<RCP<Matrix> >(fineLevel,
"A");
67 RCP<Matrix> P = Get<RCP<Matrix> >(coarseLevel,
"P");
69 RCP<BlockedCrsMatrix> bA = rcp_dynamic_cast<BlockedCrsMatrix>(A);
70 RCP<BlockedCrsMatrix> bP = rcp_dynamic_cast<BlockedCrsMatrix>(P);
71 TEUCHOS_TEST_FOR_EXCEPTION(bA.is_null() || bP.is_null(),
Exceptions::BadCast,
"Matrices A and P must be of type BlockedCrsMatrix.");
73 RCP<BlockedCrsMatrix> bAP;
74 RCP<BlockedCrsMatrix> bAc;
80 "Block matrix dimensions do not match: "
82 << bA->Rows() <<
"x" << bA->Cols() <<
"P is " << bP->Rows() <<
"x" << bP->Cols());
84 bAP = MatrixMatrix::TwoMatrixMultiplyBlock(*bA,
false, *bP,
false, GetOStream(
Statistics2),
true,
true);
89 bool doOptimizeStorage = !checkAc_;
91 const bool doTranspose =
true;
92 const bool doFillComplete =
true;
93 if (pL.get<
bool>(
"transpose: use implicit") ==
true) {
95 bAc = MatrixMatrix::TwoMatrixMultiplyBlock(*bP, doTranspose, *bAP, !doTranspose, GetOStream(
Statistics2), doFillComplete, doOptimizeStorage);
98 RCP<Matrix> R = Get<RCP<Matrix> >(coarseLevel,
"R");
99 RCP<BlockedCrsMatrix> bR = rcp_dynamic_cast<BlockedCrsMatrix>(R);
100 TEUCHOS_TEST_FOR_EXCEPTION(bR.is_null(),
Exceptions::BadCast,
"Matrix R must be of type BlockedCrsMatrix.");
103 "Block matrix dimensions do not match: "
105 << bR->Rows() <<
"x" << bR->Cols() <<
"A is " << bA->Rows() <<
"x" << bA->Cols());
108 bAc = MatrixMatrix::TwoMatrixMultiplyBlock(*bR, !doTranspose, *bAP, !doTranspose, GetOStream(
Statistics2), doFillComplete, doOptimizeStorage);
112 CheckMainDiagonal(bAc);
116 Set<RCP<Matrix> >(coarseLevel,
"A", bAc);
118 if (transferFacts_.begin() != transferFacts_.end()) {
122 for (std::vector<RCP<const FactoryBase> >::const_iterator it = transferFacts_.begin(); it != transferFacts_.end(); ++it) {
123 RCP<const FactoryBase> fac = *it;
125 GetOStream(
Runtime0) <<
"BlockRAPFactory: call transfer factory: " << fac->description() << std::endl;
127 fac->CallBuild(coarseLevel);
138 RCP<Matrix> c00 = bAc->getMatrix(0, 0);
139 RCP<Matrix> Aout = MatrixFactory::Build(c00->getRowMap(), c00->getGlobalMaxNumRowEntries());
141 RCP<Vector> diagVec = VectorFactory::Build(c00->getRowMap());
142 c00->getLocalDiagCopy(*diagVec);
143 ArrayRCP<SC> diagVal = diagVec->getDataNonConst(0);
146 for (
size_t row = 0; row < c00->getLocalNumRows(); row++) {
148 GO grid = c00->getRowMap()->getGlobalElement(row);
150 ArrayView<const LO> indices;
151 ArrayView<const SC> vals;
152 c00->getLocalRowView(row, indices, vals);
155 ArrayRCP<GO> indout(indices.size(), Teuchos::OrdinalTraits<GO>::zero());
156 ArrayRCP<SC> valout(indices.size(), Teuchos::ScalarTraits<SC>::zero());
159 for (
size_t i = 0; i < as<size_t>(indices.size()); i++) {
160 GO gcid = c00->getColMap()->getGlobalElement(indices[i]);
165 Aout->insertGlobalValues(grid, indout.view(0, indout.size()), valout.view(0, valout.size()));
166 if (diagVal[row] == Teuchos::ScalarTraits<SC>::zero() && repairZeroDiagonals) {
168 Aout->insertGlobalValues(grid, Teuchos::tuple<GO>(grid), Teuchos::tuple<SC>(1.0));
172 Aout->fillComplete(c00->getDomainMap(), c00->getRangeMap());
174 bAc->setMatrix(0, 0, Aout);