10 #ifndef THYRA_MUELU_PRECONDITIONER_FACTORY_DEF_HPP
11 #define THYRA_MUELU_PRECONDITIONER_FACTORY_DEF_HPP
16 #if defined(HAVE_MUELU_STRATIMIKOS) && defined(HAVE_MUELU_THYRA)
19 #if ((defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_FLOAT) && !defined(HAVE_TPETRA_INST_COMPLEX_DOUBLE) && !defined(HAVE_TPETRA_INST_COMPLEX_FLOAT)) || \
20 (!defined(HAVE_TPETRA_INST_DOUBLE) && !defined(HAVE_TPETRA_INST_FLOAT) && defined(HAVE_TPETRA_INST_COMPLEX_DOUBLE) && defined(HAVE_TPETRA_INST_COMPLEX_FLOAT)) || \
21 (defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_FLOAT) && defined(HAVE_TPETRA_INST_COMPLEX_DOUBLE) && defined(HAVE_TPETRA_INST_COMPLEX_FLOAT)))
22 #define MUELU_CAN_USE_MIXED_PRECISION
30 using Teuchos::rcp_const_cast;
31 using Teuchos::rcp_dynamic_cast;
33 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
34 bool Converters<Scalar, LocalOrdinal, GlobalOrdinal, Node>::replaceWithXpetra(ParameterList& paramList, std::string parameterName) {
37 typedef Xpetra::ThyraUtils<Scalar, LocalOrdinal, GlobalOrdinal, Node> XpThyUtils;
45 typedef Thyra::LinearOpBase<Scalar> ThyLinOpBase;
46 typedef Thyra::DiagonalLinearOpBase<Scalar> ThyDiagLinOpBase;
53 typedef Thyra::TpetraVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> thyTpV;
56 #if defined(MUELU_CAN_USE_MIXED_PRECISION)
61 if (paramList.isParameter(parameterName)) {
62 if (paramList.isType<RCP<XpMat> >(parameterName))
64 else if (paramList.isType<RCP<const XpMat> >(parameterName)) {
65 RCP<const XpMat> constM = paramList.get<RCP<const XpMat> >(parameterName);
66 paramList.remove(parameterName);
67 RCP<XpMat> M = rcp_const_cast<XpMat>(constM);
68 paramList.set<RCP<XpMat> >(parameterName, M);
70 }
else if (paramList.isType<RCP<XpMultVec> >(parameterName))
72 else if (paramList.isType<RCP<const XpMultVec> >(parameterName)) {
73 RCP<const XpMultVec> constX = paramList.get<RCP<const XpMultVec> >(parameterName);
74 paramList.remove(parameterName);
75 RCP<XpMultVec> X = rcp_const_cast<XpMultVec>(constX);
76 paramList.set<RCP<XpMultVec> >(parameterName, X);
78 }
else if (paramList.isType<RCP<XpMagMultVec> >(parameterName))
80 else if (paramList.isType<RCP<const XpMagMultVec> >(parameterName)) {
81 RCP<const XpMagMultVec> constX = paramList.get<RCP<const XpMagMultVec> >(parameterName);
82 paramList.remove(parameterName);
83 RCP<XpMagMultVec> X = rcp_const_cast<XpMagMultVec>(constX);
84 paramList.set<RCP<XpMagMultVec> >(parameterName, X);
86 }
else if (paramList.isType<RCP<TpCrsMat> >(parameterName)) {
87 RCP<TpCrsMat> tM = paramList.get<RCP<TpCrsMat> >(parameterName);
88 paramList.remove(parameterName);
89 RCP<XpMat> xM = MueLu::TpetraCrs_To_XpetraMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tM);
90 paramList.set<RCP<XpMat> >(parameterName, xM);
92 }
else if (paramList.isType<RCP<tMV> >(parameterName)) {
93 RCP<tMV> tpetra_X = paramList.get<RCP<tMV> >(parameterName);
94 paramList.remove(parameterName);
95 RCP<XpMultVec> X = MueLu::TpetraMultiVector_To_XpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tpetra_X);
96 paramList.set<RCP<XpMultVec> >(parameterName, X);
99 }
else if (paramList.isType<RCP<tMagMV> >(parameterName)) {
100 RCP<tMagMV> tpetra_X = paramList.get<RCP<tMagMV> >(parameterName);
101 paramList.remove(parameterName);
102 RCP<XpMagMultVec> X = MueLu::TpetraMultiVector_To_XpetraMultiVector<Magnitude, LocalOrdinal, GlobalOrdinal, Node>(tpetra_X);
103 paramList.set<RCP<XpMagMultVec> >(parameterName, X);
107 #if defined(MUELU_CAN_USE_MIXED_PRECISION)
108 else if (paramList.isType<RCP<tHalfMagMV> >(parameterName)) {
109 RCP<tHalfMagMV> tpetra_hX = paramList.get<RCP<tHalfMagMV> >(parameterName);
110 paramList.remove(parameterName);
111 RCP<tMagMV> tpetra_X =
rcp(
new tMagMV(tpetra_hX->getMap(), tpetra_hX->getNumVectors()));
113 RCP<XpMagMultVec> X = MueLu::TpetraMultiVector_To_XpetraMultiVector<Magnitude, LocalOrdinal, GlobalOrdinal, Node>(tpetra_X);
114 paramList.set<RCP<XpMagMultVec> >(parameterName, X);
119 else if (paramList.isType<RCP<const ThyDiagLinOpBase> >(parameterName) ||
120 (paramList.isType<RCP<const ThyLinOpBase> >(parameterName) && !rcp_dynamic_cast<const ThyDiagLinOpBase>(paramList.get<RCP<const ThyLinOpBase> >(parameterName)).is_null())) {
121 RCP<const ThyDiagLinOpBase> thyM;
122 if (paramList.isType<RCP<const ThyDiagLinOpBase> >(parameterName))
123 thyM = paramList.get<RCP<const ThyDiagLinOpBase> >(parameterName);
125 thyM = rcp_dynamic_cast<
const ThyDiagLinOpBase>(paramList.get<RCP<const ThyLinOpBase> >(parameterName),
true);
126 paramList.remove(parameterName);
127 RCP<const Thyra::VectorBase<Scalar> > diag = thyM->getDiag();
129 RCP<const XpVec> xpDiag;
130 if (!rcp_dynamic_cast<const thyTpV>(diag).
is_null()) {
131 RCP<const tV> tDiag = Thyra::TpetraOperatorVectorExtraction<Scalar, LocalOrdinal, GlobalOrdinal, Node>::getConstTpetraVector(diag);
132 if (!tDiag.is_null())
137 paramList.set<RCP<XpMat> >(parameterName, M);
139 }
else if (paramList.isType<RCP<const ThyLinOpBase> >(parameterName)) {
140 RCP<const ThyLinOpBase> thyM = paramList.get<RCP<const ThyLinOpBase> >(parameterName);
141 paramList.remove(parameterName);
143 RCP<XpMat> M = XpThyUtils::toXpetra(Teuchos::rcp_const_cast<ThyLinOpBase>(thyM));
144 paramList.set<RCP<XpMat> >(parameterName, M);
145 }
catch (std::exception& e) {
146 RCP<XpOp> M = XpThyUtils::toXpetraOperator(Teuchos::rcp_const_cast<ThyLinOpBase>(thyM));
150 if (tO->hasDiagonal()) {
151 diag =
rcp(
new tV(tO->getRangeMap()));
152 tO->getLocalDiagCopy(*diag);
156 auto op = rcp_dynamic_cast<XpOp>(tpFOp);
157 paramList.set<RCP<XpOp> >(parameterName, op);
168 #ifdef HAVE_MUELU_EPETRA
169 template <
class GlobalOrdinal>
170 bool Converters<double, int, GlobalOrdinal, Tpetra::KokkosCompat::KokkosSerialWrapperNode>::replaceWithXpetra(ParameterList& paramList, std::string parameterName) {
173 typedef Tpetra::KokkosCompat::KokkosSerialWrapperNode
Node;
176 typedef Xpetra::ThyraUtils<Scalar, LocalOrdinal, GlobalOrdinal, Node> XpThyUtils;
184 typedef Thyra::LinearOpBase<Scalar> ThyLinOpBase;
185 typedef Thyra::DiagonalLinearOpBase<Scalar> ThyDiagLinOpBase;
186 typedef Thyra::SpmdVectorSpaceBase<Scalar> ThyVSBase;
191 typedef Thyra::TpetraVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> thyTpV;
194 #if defined(MUELU_CAN_USE_MIXED_PRECISION)
198 #if defined(HAVE_MUELU_EPETRA)
202 if (paramList.isParameter(parameterName)) {
203 if (paramList.isType<RCP<XpMat> >(parameterName))
205 else if (paramList.isType<RCP<const XpMat> >(parameterName)) {
206 RCP<const XpMat> constM = paramList.get<RCP<const XpMat> >(parameterName);
207 paramList.remove(parameterName);
208 RCP<XpMat> M = rcp_const_cast<XpMat>(constM);
209 paramList.set<RCP<XpMat> >(parameterName, M);
211 }
else if (paramList.isType<RCP<XpMultVec> >(parameterName))
213 else if (paramList.isType<RCP<const XpMultVec> >(parameterName)) {
214 RCP<const XpMultVec> constX = paramList.get<RCP<const XpMultVec> >(parameterName);
215 paramList.remove(parameterName);
216 RCP<XpMultVec> X = rcp_const_cast<XpMultVec>(constX);
217 paramList.set<RCP<XpMultVec> >(parameterName, X);
219 }
else if (paramList.isType<RCP<XpMagMultVec> >(parameterName))
221 else if (paramList.isType<RCP<const XpMagMultVec> >(parameterName)) {
222 RCP<const XpMagMultVec> constX = paramList.get<RCP<const XpMagMultVec> >(parameterName);
223 paramList.remove(parameterName);
224 RCP<XpMagMultVec> X = rcp_const_cast<XpMagMultVec>(constX);
225 paramList.set<RCP<XpMagMultVec> >(parameterName, X);
227 }
else if (paramList.isType<RCP<TpCrsMat> >(parameterName)) {
228 RCP<TpCrsMat> tM = paramList.get<RCP<TpCrsMat> >(parameterName);
229 paramList.remove(parameterName);
230 RCP<XpMat> xM = MueLu::TpetraCrs_To_XpetraMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tM);
231 paramList.set<RCP<XpMat> >(parameterName, xM);
233 }
else if (paramList.isType<RCP<tMV> >(parameterName)) {
234 RCP<tMV> tpetra_X = paramList.get<RCP<tMV> >(parameterName);
235 paramList.remove(parameterName);
236 RCP<XpMultVec> X = MueLu::TpetraMultiVector_To_XpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tpetra_X);
237 paramList.set<RCP<XpMultVec> >(parameterName, X);
240 }
else if (paramList.isType<RCP<tMagMV> >(parameterName)) {
241 RCP<tMagMV> tpetra_X = paramList.get<RCP<tMagMV> >(parameterName);
242 paramList.remove(parameterName);
243 RCP<XpMagMultVec> X = MueLu::TpetraMultiVector_To_XpetraMultiVector<Magnitude, LocalOrdinal, GlobalOrdinal, Node>(tpetra_X);
244 paramList.set<RCP<XpMagMultVec> >(parameterName, X);
248 #if defined(MUELU_CAN_USE_MIXED_PRECISION)
249 else if (paramList.isType<RCP<tHalfMagMV> >(parameterName)) {
250 RCP<tHalfMagMV> tpetra_hX = paramList.get<RCP<tHalfMagMV> >(parameterName);
251 paramList.remove(parameterName);
252 RCP<tMagMV> tpetra_X =
rcp(
new tMagMV(tpetra_hX->getMap(), tpetra_hX->getNumVectors()));
254 RCP<XpMagMultVec> X = MueLu::TpetraMultiVector_To_XpetraMultiVector<Magnitude, LocalOrdinal, GlobalOrdinal, Node>(tpetra_X);
255 paramList.set<RCP<XpMagMultVec> >(parameterName, X);
260 #ifdef HAVE_MUELU_EPETRA
261 else if (paramList.isType<RCP<Epetra_CrsMatrix> >(parameterName)) {
262 RCP<Epetra_CrsMatrix> eM = paramList.get<RCP<Epetra_CrsMatrix> >(parameterName);
263 paramList.remove(parameterName);
264 RCP<XpEpCrsMat> xeM =
rcp(
new XpEpCrsMat(eM));
265 RCP<XpCrsMat> xCrsM = rcp_dynamic_cast<XpCrsMat>(xeM,
true);
266 RCP<XpCrsMatWrap> xwM =
rcp(
new XpCrsMatWrap(xCrsM));
267 RCP<XpMat> xM = rcp_dynamic_cast<XpMat>(xwM);
268 paramList.set<RCP<XpMat> >(parameterName, xM);
270 }
else if (paramList.isType<RCP<Epetra_MultiVector> >(parameterName)) {
271 RCP<Epetra_MultiVector> epetra_X = Teuchos::null;
272 epetra_X = paramList.get<RCP<Epetra_MultiVector> >(parameterName);
273 paramList.remove(parameterName);
276 RCP<XpMultVec> X = rcp_dynamic_cast<XpMultVec>(xpEpXMult,
true);
277 paramList.set<RCP<XpMultVec> >(parameterName, X);
281 else if (paramList.isType<RCP<const ThyDiagLinOpBase> >(parameterName) ||
282 (paramList.isType<RCP<const ThyLinOpBase> >(parameterName) && !rcp_dynamic_cast<const ThyDiagLinOpBase>(paramList.get<RCP<const ThyLinOpBase> >(parameterName)).
is_null())) {
283 RCP<const ThyDiagLinOpBase> thyM;
284 if (paramList.isType<RCP<const ThyDiagLinOpBase> >(parameterName))
285 thyM = paramList.get<RCP<const ThyDiagLinOpBase> >(parameterName);
287 thyM = rcp_dynamic_cast<
const ThyDiagLinOpBase>(paramList.get<RCP<const ThyLinOpBase> >(parameterName),
true);
288 paramList.remove(parameterName);
289 RCP<const Thyra::VectorBase<Scalar> > diag = thyM->getDiag();
291 RCP<const XpVec> xpDiag;
292 if (!rcp_dynamic_cast<const thyTpV>(diag).
is_null()) {
293 RCP<const tV> tDiag = Thyra::TpetraOperatorVectorExtraction<Scalar, LocalOrdinal, GlobalOrdinal, Node>::getConstTpetraVector(diag);
294 if (!tDiag.is_null())
297 #ifdef HAVE_MUELU_EPETRA
298 if (xpDiag.is_null()) {
299 RCP<const Epetra_Comm> comm = Thyra::get_Epetra_Comm(*rcp_dynamic_cast<const ThyVSBase>(thyM->range())->getComm());
300 RCP<const Epetra_Map> map = Thyra::get_Epetra_Map(*(thyM->range()), comm);
301 if (!map.is_null()) {
302 RCP<const Epetra_Vector> eDiag = Thyra::get_Epetra_Vector(*map, diag);
303 RCP<Epetra_Vector> nceDiag = rcp_const_cast<
Epetra_Vector>(eDiag);
305 xpDiag = rcp_dynamic_cast<XpVec>(xpEpDiag,
true);
311 paramList.set<RCP<XpMat> >(parameterName, M);
313 }
else if (paramList.isType<RCP<const ThyLinOpBase> >(parameterName)) {
314 RCP<const ThyLinOpBase> thyM = paramList.get<RCP<const ThyLinOpBase> >(parameterName);
315 paramList.remove(parameterName);
317 RCP<XpMat> M = XpThyUtils::toXpetra(Teuchos::rcp_const_cast<ThyLinOpBase>(thyM));
318 paramList.set<RCP<XpMat> >(parameterName, M);
319 }
catch (std::exception& e) {
320 RCP<XpOp> M = XpThyUtils::toXpetraOperator(Teuchos::rcp_const_cast<ThyLinOpBase>(thyM));
324 if (tO->hasDiagonal()) {
325 diag =
rcp(
new tV(tO->getRangeMap()));
326 tO->getLocalDiagCopy(*diag);
330 auto op = rcp_dynamic_cast<XpOp>(tpFOp);
331 paramList.set<RCP<XpOp> >(parameterName, op);
345 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
346 MueLuPreconditionerFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::MueLuPreconditionerFactory()
347 : paramList_(
rcp(new ParameterList())) {}
349 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
350 MueLuPreconditionerFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::~MueLuPreconditionerFactory() =
default;
354 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
355 bool MueLuPreconditionerFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::isCompatible(
const LinearOpSourceBase<Scalar>& fwdOpSrc)
const {
356 const RCP<const LinearOpBase<Scalar> > fwdOp = fwdOpSrc.getOp();
358 if (Xpetra::ThyraUtils<Scalar, LocalOrdinal, GlobalOrdinal, Node>::isTpetra(fwdOp))
return true;
360 #ifdef HAVE_MUELU_EPETRA
361 if (Xpetra::ThyraUtils<Scalar, LocalOrdinal, GlobalOrdinal, Node>::isEpetra(fwdOp))
return true;
364 if (Xpetra::ThyraUtils<Scalar, LocalOrdinal, GlobalOrdinal, Node>::isBlockedOperator(fwdOp))
return true;
369 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
370 RCP<PreconditionerBase<Scalar> > MueLuPreconditionerFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::createPrec()
const {
374 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
375 void MueLuPreconditionerFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
376 initializePrec(
const RCP<
const LinearOpSourceBase<Scalar> >& fwdOpSrc, PreconditionerBase<Scalar>* prec,
const ESupportSolveUse supportSolveUse)
const {
379 using Teuchos::rcp_dynamic_cast;
385 typedef Xpetra::ThyraUtils<Scalar, LocalOrdinal, GlobalOrdinal, Node> XpThyUtils;
391 typedef Thyra::LinearOpBase<Scalar> ThyLinOpBase;
396 #if defined(MUELU_CAN_USE_MIXED_PRECISION)
397 typedef Xpetra::TpetraHalfPrecisionOperator<Scalar, LocalOrdinal, GlobalOrdinal, Node> XpHalfPrecOp;
398 typedef typename XpHalfPrecOp::HalfScalar HalfScalar;
413 ParameterList paramList = *paramList_;
416 const RCP<const ThyLinOpBase> fwdOp = fwdOpSrc->getOp();
420 bool bIsEpetra = XpThyUtils::isEpetra(fwdOp);
421 bool bIsTpetra = XpThyUtils::isTpetra(fwdOp);
422 bool bIsBlocked = XpThyUtils::isBlockedOperator(fwdOp);
427 RCP<XpMat> A = Teuchos::null;
430 Teuchos::rcp_dynamic_cast<
const Thyra::BlockedLinearOpBase<Scalar> >(fwdOp);
440 RCP<XpMat> A00 = XpThyUtils::toXpetra(Teuchos::rcp_const_cast<LinearOpBase<Scalar> >(b00));
443 RCP<const XpMap> rowmap00 = A00->getRowMap();
444 RCP<const Teuchos::Comm<int> > comm = rowmap00->getComm();
447 RCP<XpBlockedCrsMat> bMat =
Teuchos::rcp(
new XpBlockedCrsMat(ThyBlockedOp, comm));
455 A = XpThyUtils::toXpetra(Teuchos::rcp_const_cast<ThyLinOpBase>(fwdOp));
464 RCP<ThyLinOpBase> thyra_precOp = Teuchos::null;
465 thyra_precOp = rcp_dynamic_cast<Thyra::LinearOpBase<Scalar> >(defaultPrec->getNonconstUnspecifiedPrecOp(),
true);
470 const bool startingOver = (thyra_precOp.is_null() || !paramList.isParameter(
"reuse: type") || paramList.get<std::string>(
"reuse: type") ==
"none");
471 bool useHalfPrecision =
false;
472 if (paramList.isParameter(
"half precision"))
473 useHalfPrecision = paramList.get<
bool>(
"half precision");
474 else if (paramList.isSublist(
"Hierarchy") && paramList.sublist(
"Hierarchy").isParameter(
"half precision"))
475 useHalfPrecision = paramList.sublist(
"Hierarchy").get<
bool>(
"half precision");
476 if (useHalfPrecision)
480 if (startingOver ==
true) {
482 std::list<std::string> convertXpetra = {
"Coordinates",
"Nullspace"};
483 for (
auto it = convertXpetra.begin(); it != convertXpetra.end(); ++it)
484 Converters<Scalar, LocalOrdinal, GlobalOrdinal, Node>::replaceWithXpetra(paramList, *it);
486 for (
int lvlNo = 0; lvlNo < 10; ++lvlNo) {
487 if (paramList.isSublist(
"level " + std::to_string(lvlNo) +
" user data")) {
488 ParameterList& lvlList = paramList.sublist(
"level " + std::to_string(lvlNo) +
" user data");
489 std::list<std::string> convertKeys;
490 for (
auto it = lvlList.begin(); it != lvlList.end(); ++it)
491 convertKeys.push_back(lvlList.name(it));
492 for (
auto it = convertKeys.begin(); it != convertKeys.end(); ++it)
493 Converters<Scalar, LocalOrdinal, GlobalOrdinal, Node>::replaceWithXpetra(lvlList, *it);
497 if (useHalfPrecision) {
498 #if defined(MUELU_CAN_USE_MIXED_PRECISION)
505 RCP<XphMat> halfA = Xpetra::convertToHalfPrecision(A);
506 const std::string userName =
"user data";
508 if (userParamList.
isType<RCP<XpmMV> >(
"Coordinates")) {
509 RCP<XpmMV> coords = userParamList.
get<RCP<XpmMV> >(
"Coordinates");
510 userParamList.
remove(
"Coordinates");
511 RCP<XphmMV> halfCoords = Xpetra::convertToHalfPrecision(coords);
512 userParamList.
set(
"Coordinates", halfCoords);
514 if (userParamList.
isType<RCP<XpMV> >(
"Nullspace")) {
515 RCP<XpMV> nullspace = userParamList.
get<RCP<XpMV> >(
"Nullspace");
516 userParamList.
remove(
"Nullspace");
517 RCP<XphMV> halfNullspace = Xpetra::convertToHalfPrecision(nullspace);
518 userParamList.
set(
"Nullspace", halfNullspace);
520 if (paramList.isType<RCP<XpmMV> >(
"Coordinates")) {
521 RCP<XpmMV> coords = paramList.
get<RCP<XpmMV> >(
"Coordinates");
522 paramList.remove(
"Coordinates");
523 RCP<XphmMV> halfCoords = Xpetra::convertToHalfPrecision(coords);
524 userParamList.
set(
"Coordinates", halfCoords);
526 if (paramList.isType<RCP<XpMV> >(
"Nullspace")) {
527 RCP<XpMV> nullspace = paramList.
get<RCP<XpMV> >(
"Nullspace");
528 paramList.remove(
"Nullspace");
529 RCP<XphMV> halfNullspace = Xpetra::convertToHalfPrecision(nullspace);
530 userParamList.
set(
"Nullspace", halfNullspace);
536 RCP<MueLuHalfXpOp> xpOp =
rcp(
new MueLuHalfXpOp(H));
537 xpPrecOp =
rcp(
new XpHalfPrecOp(xpOp));
542 const std::string userName =
"user data";
544 if (paramList.isType<RCP<XpmMV> >(
"Coordinates")) {
545 RCP<XpmMV> coords = paramList.
get<RCP<XpmMV> >(
"Coordinates");
546 paramList.remove(
"Coordinates");
547 userParamList.
set(
"Coordinates", coords);
549 if (paramList.isType<RCP<XpMV> >(
"Nullspace")) {
550 RCP<XpMV> nullspace = paramList.
get<RCP<XpMV> >(
"Nullspace");
551 paramList.remove(
"Nullspace");
552 userParamList.
set(
"Nullspace", nullspace);
557 xpPrecOp =
rcp(
new MueLuXpOp(H));
561 RCP<ThyXpOp> thyXpOp = rcp_dynamic_cast<ThyXpOp>(thyra_precOp,
true);
562 xpPrecOp = rcp_dynamic_cast<XpOp>(thyXpOp->getXpetraOperator(),
true);
563 #if defined(MUELU_CAN_USE_MIXED_PRECISION)
564 RCP<XpHalfPrecOp> xpHalfPrecOp = rcp_dynamic_cast<XpHalfPrecOp>(xpPrecOp);
565 if (!xpHalfPrecOp.is_null()) {
566 RCP<MueLu::Hierarchy<HalfScalar, LocalOrdinal, GlobalOrdinal, Node> > H = rcp_dynamic_cast<MueLuHalfXpOp>(xpHalfPrecOp->GetHalfPrecisionOperator(),
true)->GetHierarchy();
567 RCP<XphMat> halfA = Xpetra::convertToHalfPrecision(A);
570 "Thyra::MueLuPreconditionerFactory: Hierarchy has no levels in it");
572 "Thyra::MueLuPreconditionerFactory: Hierarchy has no fine level operator");
573 RCP<MueLu::Level> level0 = H->GetLevel(0);
574 RCP<XpHalfOp> O0 = level0->Get<RCP<XpHalfOp> >(
"A");
575 RCP<XphMat> A0 = rcp_dynamic_cast<XphMat>(O0,
true);
581 halfA->SetFixedBlockSize(A0->GetFixedBlockSize());
585 level0->Set(
"A", halfA);
592 RCP<MueLuXpOp> xpOp = rcp_dynamic_cast<MueLuXpOp>(thyXpOp->getXpetraOperator(),
true);
593 RCP<MueLu::Hierarchy<Scalar, LocalOrdinal, GlobalOrdinal, Node> > H = xpOp->GetHierarchy();
597 "Thyra::MueLuPreconditionerFactory: Hierarchy has no levels in it");
599 "Thyra::MueLuPreconditionerFactory: Hierarchy has no fine level operator");
600 RCP<MueLu::Level> level0 = H->GetLevel(0);
601 RCP<XpOp> O0 = level0->Get<RCP<XpOp> >(
"A");
602 RCP<XpMat> A0 = rcp_dynamic_cast<XpMat>(O0);
608 A->SetFixedBlockSize(A0->GetFixedBlockSize());
619 RCP<const VectorSpaceBase<Scalar> > thyraRangeSpace = Xpetra::ThyraUtils<Scalar, LocalOrdinal, GlobalOrdinal, Node>::toThyra(xpPrecOp->getRangeMap());
620 RCP<const VectorSpaceBase<Scalar> > thyraDomainSpace = Xpetra::ThyraUtils<Scalar, LocalOrdinal, GlobalOrdinal, Node>::toThyra(xpPrecOp->getDomainMap());
622 RCP<ThyLinOpBase> thyraPrecOp = Thyra::xpetraLinearOp<Scalar, LocalOrdinal, GlobalOrdinal, Node>(thyraRangeSpace, thyraDomainSpace, xpPrecOp);
625 defaultPrec->initializeUnspecified(thyraPrecOp);
628 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
629 void MueLuPreconditionerFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
630 uninitializePrec(PreconditionerBase<Scalar>* prec, RCP<
const LinearOpSourceBase<Scalar> >* fwdOp, ESupportSolveUse* supportSolveUse)
const {
639 *fwdOp = Teuchos::null;
642 if (supportSolveUse) {
644 *supportSolveUse = Thyra::SUPPORT_SOLVE_UNSPECIFIED;
647 defaultPrec->uninitialize();
651 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
652 void MueLuPreconditionerFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::setParameterList(RCP<ParameterList>
const& paramList) {
654 paramList_ = paramList;
657 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
658 RCP<ParameterList> MueLuPreconditionerFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::getNonconstParameterList() {
662 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
663 RCP<ParameterList> MueLuPreconditionerFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::unsetParameterList() {
664 RCP<ParameterList> savedParamList = paramList_;
665 paramList_ = Teuchos::null;
666 return savedParamList;
669 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
670 RCP<const ParameterList> MueLuPreconditionerFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::getParameterList()
const {
674 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
675 RCP<const ParameterList> MueLuPreconditionerFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::getValidParameters()
const {
676 static RCP<const ParameterList> validPL;
679 validPL =
rcp(
new ParameterList());
685 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
686 std::string MueLuPreconditionerFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::description()
const {
687 return "Thyra::MueLuPreconditionerFactory";
691 #endif // HAVE_MUELU_STRATIMIKOS
693 #endif // ifdef THYRA_MUELU_PRECONDITIONER_FACTORY_DEF_HPP
MueLu::DefaultLocalOrdinal LocalOrdinal
bool is_null(const boost::shared_ptr< T > &p)
T & get(const std::string &name, T def_value)
bool nonnull(const std::shared_ptr< T > &p)
bool is_null(const std::shared_ptr< T > &p)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
static RCP< Time > getNewTimer(const std::string &name)
Teuchos::RCP< MueLu::Hierarchy< Scalar, LocalOrdinal, GlobalOrdinal, Node > > CreateXpetraPreconditioner(Teuchos::RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >> op, const Teuchos::ParameterList &inParamList)
Helper function to create a MueLu preconditioner that can be used by Xpetra.Given an Xpetra::Matrix...
void deep_copy(MultiVector< DS, DL, DG, DN > &dst, const MultiVector< SS, SL, SG, SN > &src)
bool remove(std::string const &name, bool throwIfNotExists=true)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
MueLu::DefaultScalar Scalar
Concrete Thyra::LinearOpBase subclass for Xpetra::Operator.
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)
bool isType(const std::string &name) const
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
static RCP< Matrix > Build(const RCP< const Map > &rowMap, size_t maxNumEntriesPerRow, Xpetra::ProfileType pftype=Xpetra::DynamicProfile)
Exception throws to report errors in the internal logical of the program.
#define TEUCHOS_ASSERT(assertion_test)
RCP< Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getOperator()
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
Wraps an existing MueLu::Hierarchy as a Xpetra::Operator.