81 const bool doTranspose =
true;
82 const bool doFillComplete =
true;
83 const bool doOptimizeStorage =
true;
87 std::ostringstream levelstr;
92 "MueLu::RAPFactory::Build(): CallDeclareInput has not been called before Build!");
94 const Teuchos::ParameterList& pL = GetParameterList();
95 RCP<Matrix> A = Get<RCP<Matrix> >(fineLevel,
"A");
96 RCP<Matrix> P = Get<RCP<Matrix> >(coarseLevel,
"P"), AP;
99 if (P == Teuchos::null) {
101 Set(coarseLevel,
"A", Ac);
105 bool isEpetra = A->getRowMap()->lib() == Xpetra::UseEpetra;
106 bool isGPU = Node::is_gpu;
108 if (pL.get<
bool>(
"rap: triple product") ==
false || isEpetra || isGPU) {
109 if (pL.get<
bool>(
"rap: triple product") && isEpetra)
110 GetOStream(
Warnings1) <<
"Switching from triple product to R x (A x P) since triple product has not been implemented for Epetra.\n";
111 if (pL.get<
bool>(
"rap: triple product") && isGPU)
112 GetOStream(
Warnings1) <<
"Switching from triple product to R x (A x P) since triple product has not been implemented for "
113 << Node::execution_space::name() << std::endl;
116 RCP<ParameterList> APparams = rcp(
new ParameterList);
117 if (pL.isSublist(
"matrixmatrix: kernel params"))
118 APparams = rcp(
new ParameterList(pL.sublist(
"matrixmatrix: kernel params")));
121 APparams->set(
"compute global constants: temporaries", APparams->get(
"compute global constants: temporaries",
false));
122 APparams->set(
"compute global constants", APparams->get(
"compute global constants",
false));
124 if (coarseLevel.IsAvailable(
"AP reuse data",
this)) {
125 GetOStream(
static_cast<MsgType>(
Runtime0 |
Test)) <<
"Reusing previous AP data" << std::endl;
127 APparams = coarseLevel.Get<RCP<ParameterList> >(
"AP reuse data",
this);
129 if (APparams->isParameter(
"graph"))
130 AP = APparams->get<RCP<Matrix> >(
"graph");
136 AP = MatrixMatrix::Multiply(*A, !doTranspose, *P, !doTranspose, AP, GetOStream(
Statistics2),
137 doFillComplete, doOptimizeStorage, labelstr + std::string(
"MueLu::A*P-") + levelstr.str(), APparams);
141 RCP<ParameterList> RAPparams = rcp(
new ParameterList);
142 if (pL.isSublist(
"matrixmatrix: kernel params"))
143 RAPparams = rcp(
new ParameterList(pL.sublist(
"matrixmatrix: kernel params")));
145 if (coarseLevel.IsAvailable(
"RAP reuse data",
this)) {
146 GetOStream(
static_cast<MsgType>(
Runtime0 |
Test)) <<
"Reusing previous RAP data" << std::endl;
148 RAPparams = coarseLevel.Get<RCP<ParameterList> >(
"RAP reuse data",
this);
150 if (RAPparams->isParameter(
"graph"))
151 Ac = RAPparams->get<RCP<Matrix> >(
"graph");
155 Ac->SetMaxEigenvalueEstimate(-Teuchos::ScalarTraits<SC>::one());
159 RAPparams->set(
"compute global constants: temporaries", RAPparams->get(
"compute global constants: temporaries",
false));
160 RAPparams->set(
"compute global constants",
true);
166 if (pL.get<
bool>(
"transpose: use implicit") ==
true) {
169 Ac = MatrixMatrix::Multiply(*P, doTranspose, *AP, !doTranspose, Ac, GetOStream(
Statistics2),
170 doFillComplete, doOptimizeStorage, labelstr + std::string(
"MueLu::R*(AP)-implicit-") + levelstr.str(), RAPparams);
173 RCP<Matrix> R = Get<RCP<Matrix> >(coarseLevel,
"R");
177 Ac = MatrixMatrix::Multiply(*R, !doTranspose, *AP, !doTranspose, Ac, GetOStream(
Statistics2),
178 doFillComplete, doOptimizeStorage, labelstr + std::string(
"MueLu::R*(AP)-explicit-") + levelstr.str(), RAPparams);
181 Teuchos::ArrayView<const double> relativeFloor = pL.get<Teuchos::Array<double> >(
"rap: relative diagonal floor")();
182 if (relativeFloor.size() > 0) {
183 Xpetra::MatrixUtils<SC, LO, GO, NO>::RelativeDiagonalBoost(Ac, relativeFloor, GetOStream(
Statistics2));
186 bool repairZeroDiagonals = pL.get<
bool>(
"RepairMainDiagonal") || pL.get<
bool>(
"rap: fix zero diagonals");
187 bool checkAc = pL.get<
bool>(
"CheckMainDiagonal") || pL.get<
bool>(
"rap: fix zero diagonals");
189 if (checkAc || repairZeroDiagonals) {
190 using magnitudeType =
typename Teuchos::ScalarTraits<Scalar>::magnitudeType;
191 magnitudeType threshold;
192 if (pL.isType<magnitudeType>(
"rap: fix zero diagonals threshold"))
193 threshold = pL.get<magnitudeType>(
"rap: fix zero diagonals threshold");
195 threshold = Teuchos::as<magnitudeType>(pL.get<
double>(
"rap: fix zero diagonals threshold"));
196 Scalar replacement = Teuchos::as<Scalar>(pL.get<
double>(
"rap: fix zero diagonals replacement"));
197 Xpetra::MatrixUtils<SC, LO, GO, NO>::CheckRepairMainDiagonal(Ac, repairZeroDiagonals, GetOStream(
Warnings1), threshold, replacement);
201 RCP<ParameterList> params = rcp(
new ParameterList());
203 params->set(
"printLoadBalancingInfo",
true);
204 params->set(
"printCommInfo",
true);
209 std::ostringstream oss;
210 oss <<
"A_" << coarseLevel.GetLevelID();
211 Ac->setObjectLabel(oss.str());
213 Set(coarseLevel,
"A", Ac);
216 APparams->set(
"graph", AP);
217 Set(coarseLevel,
"AP reuse data", APparams);
220 RAPparams->set(
"graph", Ac);
221 Set(coarseLevel,
"RAP reuse data", RAPparams);
224 RCP<ParameterList> RAPparams = rcp(
new ParameterList);
225 if (pL.isSublist(
"matrixmatrix: kernel params"))
226 RAPparams->sublist(
"matrixmatrix: kernel params") = pL.sublist(
"matrixmatrix: kernel params");
228 if (coarseLevel.IsAvailable(
"RAP reuse data",
this)) {
229 GetOStream(
static_cast<MsgType>(
Runtime0 |
Test)) <<
"Reusing previous RAP data" << std::endl;
231 RAPparams = coarseLevel.Get<RCP<ParameterList> >(
"RAP reuse data",
this);
233 if (RAPparams->isParameter(
"graph"))
234 Ac = RAPparams->get<RCP<Matrix> >(
"graph");
238 Ac->SetMaxEigenvalueEstimate(-Teuchos::ScalarTraits<SC>::one());
242 RAPparams->set(
"compute global constants: temporaries", RAPparams->get(
"compute global constants: temporaries",
false));
243 RAPparams->set(
"compute global constants",
true);
245 if (pL.get<
bool>(
"transpose: use implicit") ==
true) {
246 Ac = MatrixFactory::Build(P->getDomainMap(), Teuchos::as<LO>(0));
250 Xpetra::TripleMatrixMultiply<SC, LO, GO, NO>::
251 MultiplyRAP(*P, doTranspose, *A, !doTranspose, *P, !doTranspose, *Ac, doFillComplete,
252 doOptimizeStorage, labelstr + std::string(
"MueLu::R*A*P-implicit-") + levelstr.str(),
255 RCP<Matrix> R = Get<RCP<Matrix> >(coarseLevel,
"R");
256 Ac = MatrixFactory::Build(R->getRowMap(), Teuchos::as<LO>(0));
260 Xpetra::TripleMatrixMultiply<SC, LO, GO, NO>::
261 MultiplyRAP(*R, !doTranspose, *A, !doTranspose, *P, !doTranspose, *Ac, doFillComplete,
262 doOptimizeStorage, labelstr + std::string(
"MueLu::R*A*P-explicit-") + levelstr.str(),
266 Teuchos::ArrayView<const double> relativeFloor = pL.get<Teuchos::Array<double> >(
"rap: relative diagonal floor")();
267 if (relativeFloor.size() > 0) {
268 Xpetra::MatrixUtils<SC, LO, GO, NO>::RelativeDiagonalBoost(Ac, relativeFloor, GetOStream(
Statistics2));
271 bool repairZeroDiagonals = pL.get<
bool>(
"RepairMainDiagonal") || pL.get<
bool>(
"rap: fix zero diagonals");
272 bool checkAc = pL.get<
bool>(
"CheckMainDiagonal") || pL.get<
bool>(
"rap: fix zero diagonals");
274 if (checkAc || repairZeroDiagonals) {
275 using magnitudeType =
typename Teuchos::ScalarTraits<Scalar>::magnitudeType;
276 magnitudeType threshold;
277 if (pL.isType<magnitudeType>(
"rap: fix zero diagonals threshold"))
278 threshold = pL.get<magnitudeType>(
"rap: fix zero diagonals threshold");
280 threshold = Teuchos::as<magnitudeType>(pL.get<
double>(
"rap: fix zero diagonals threshold"));
281 Scalar replacement = Teuchos::as<Scalar>(pL.get<
double>(
"rap: fix zero diagonals replacement"));
282 Xpetra::MatrixUtils<SC, LO, GO, NO>::CheckRepairMainDiagonal(Ac, repairZeroDiagonals, GetOStream(
Warnings1), threshold, replacement);
286 RCP<ParameterList> params = rcp(
new ParameterList());
288 params->set(
"printLoadBalancingInfo",
true);
289 params->set(
"printCommInfo",
true);
294 std::ostringstream oss;
295 oss <<
"A_" << coarseLevel.GetLevelID();
296 Ac->setObjectLabel(oss.str());
298 Set(coarseLevel,
"A", Ac);
301 RAPparams->set(
"graph", Ac);
302 Set(coarseLevel,
"RAP reuse data", RAPparams);
307#ifdef HAVE_MUELU_DEBUG
308 MatrixUtils::checkLocalRowMapMatchesColMap(*Ac);
311 if (transferFacts_.begin() != transferFacts_.end()) {
315 for (std::vector<RCP<const FactoryBase> >::const_iterator it = transferFacts_.begin(); it != transferFacts_.end(); ++it) {
316 RCP<const FactoryBase> fac = *it;
317 GetOStream(
Runtime0) <<
"RAPFactory: call transfer factory: " << fac->description() << std::endl;
318 fac->CallBuild(coarseLevel);