| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// ShyLU: Scalable Hybrid LU Preconditioner and Solver |
| 4 |
// |
| 5 |
// Copyright 2011 NTESS and the ShyLU contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#ifndef _THYRA_FROSCH_FACTORY_DEF_HPP |
| 11 |
#define _THYRA_FROSCH_FACTORY_DEF_HPP |
| 12 |
|
| 13 |
#include "Thyra_FROSchFactory_decl.hpp" |
| 14 |
|
| 15 |
#include <FROSch_AlgebraicOverlappingPreconditioner_def.hpp> |
| 16 |
#include <FROSch_GDSWPreconditioner_def.hpp> |
| 17 |
#include <FROSch_RGDSWPreconditioner_def.hpp> |
| 18 |
#include <FROSch_OneLevelPreconditioner_def.hpp> |
| 19 |
#include <FROSch_TwoLevelPreconditioner_def.hpp> |
| 20 |
#include <FROSch_TwoLevelBlockPreconditioner_def.hpp> |
| 21 |
|
| 22 |
#include <FROSch_TpetraPreconditioner_def.hpp> |
| 23 |
|
| 24 |
namespace Thyra { |
| 25 |
|
| 26 |
using namespace FROSch; |
| 27 |
using namespace std; |
| 28 |
using namespace Teuchos; |
| 29 |
using namespace Xpetra; |
| 30 |
|
| 31 |
//Constructor |
| 32 |
template <class SC, class LO, class GO, class NO> |
| 33 |
FROSchFactory<SC,LO,GO,NO>::FROSchFactory() |
| 34 |
{ |
| 35 |
|
| 36 |
} |
| 37 |
|
| 38 |
//----------------------------------------------------------- |
| 39 |
//Check Type -> so far redundant |
| 40 |
template <class SC, class LO, class GO, class NO> |
| 41 |
bool FROSchFactory<SC,LO,GO,NO>::isCompatible(const LinearOpSourceBase<SC>& fwdOpSrc) const |
| 42 |
{ |
| 43 |
const ConstLinearOpBasePtr fwdOp = fwdOpSrc.getOp(); |
| 44 |
if (ThyraUtils<SC,LO,GO,NO>::isEpetra(fwdOp)) { |
| 45 |
return true; |
| 46 |
} else if (ThyraUtils<SC,LO,GO,NO>::isTpetra(fwdOp)) { |
| 47 |
return true; |
| 48 |
} else { |
| 49 |
return false; |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
//-------------------------------------------------------------- |
| 54 |
//Create Default Prec -> Not used here (maybe somewhere else?) |
| 55 |
template<class SC, class LO, class GO , class NO> |
| 56 |
typename FROSchFactory<SC,LO,GO,NO>::PreconditionerBasePtr FROSchFactory<SC,LO,GO,NO>::createPrec() const |
| 57 |
{ |
| 58 |
return rcp(new DefaultPreconditioner<SC>); |
| 59 |
} |
| 60 |
|
| 61 |
//------------------------------------------------------------- |
| 62 |
//Main Function to use FROSch as Prec |
| 63 |
template<class SC, class LO , class GO, class NO> |
| 64 |
void FROSchFactory<SC,LO,GO,NO>::initializePrec(const ConstLinearOpSourceBasePtr& fwdOpSrc, |
| 65 |
PreconditionerBase<SC>* prec, |
| 66 |
const ESupportSolveUse supportSolveUse) const |
| 67 |
{ |
| 68 |
//PreCheck |
| 69 |
TEUCHOS_ASSERT(nonnull(fwdOpSrc)); |
| 70 |
//TEUCHOS_ASSERT(this->isCompatible(*fwdOpSrc)); |
| 71 |
TEUCHOS_ASSERT(prec); |
| 72 |
|
| 73 |
// Retrieve wrapped concrete Xpetra matrix from FwdOp |
| 74 |
const ConstLinearOpBasePtr fwdOp = fwdOpSrc->getOp(); |
| 75 |
TEUCHOS_TEST_FOR_EXCEPT(is_null(fwdOp)); |
| 76 |
|
| 77 |
// Check whether it is Epetra/Tpetra |
| 78 |
bool bIsEpetra = ThyraUtils<SC,LO,GO,NO>::isEpetra(fwdOp); |
| 79 |
bool bIsTpetra = ThyraUtils<SC,LO,GO,NO>::isTpetra(fwdOp); |
| 80 |
bool bIsBlocked = ThyraUtils<SC,LO,GO,NO>::isBlockedOperator(fwdOp); |
| 81 |
TEUCHOS_TEST_FOR_EXCEPT((bIsEpetra == true && bIsTpetra == true)); |
| 82 |
TEUCHOS_TEST_FOR_EXCEPT((bIsEpetra == bIsTpetra) && bIsBlocked == false); |
| 83 |
TEUCHOS_TEST_FOR_EXCEPT((bIsEpetra != bIsTpetra) && bIsBlocked == true); |
| 84 |
|
| 85 |
// Check whether to use HalfPrecision |
| 86 |
#if defined(HAVE_XPETRA_TPETRA) && defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_FLOAT) |
| 87 |
const bool useHalfPrecision = paramList_->get<bool>("Use Half Precision", false); |
| 88 |
#endif |
| 89 |
|
| 90 |
// Retrieve Matrix |
| 91 |
ConstXMatrixPtr A = ThyraUtils<SC,LO,GO,NO>::toXpetra(fwdOp); |
| 92 |
TEUCHOS_TEST_FOR_EXCEPT(is_null(A)); |
| 93 |
|
| 94 |
CommPtr comm = A->getMap()->getComm(); |
| 95 |
UnderlyingLib underlyingLib = A->getMap()->lib(); |
| 96 |
|
| 97 |
// Retrieve concrete preconditioner object |
| 98 |
const Ptr<DefaultPreconditioner<SC> > defaultPrec = ptr(dynamic_cast<DefaultPreconditioner<SC> *>(prec)); |
| 99 |
TEUCHOS_TEST_FOR_EXCEPT(is_null(defaultPrec)); |
| 100 |
|
| 101 |
// extract preconditioner operator |
| 102 |
auto precOp = defaultPrec->getNonconstUnspecifiedPrecOp(); |
| 103 |
|
| 104 |
// Abstract SchwarzPreconditioner |
| 105 |
RCP<SchwarzPreconditioner<SC,LO,GO,NO> > schwarzPreconditioner = null; |
| 106 |
#if defined(HAVE_XPETRA_TPETRA) && defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_FLOAT) |
| 107 |
RCP<SchwarzPreconditioner<HalfSC,LO,GO,NO> > halfSchwarzPreconditioner = null; |
| 108 |
#endif |
| 109 |
const bool startingOver = (precOp.is_null() || !paramList_->isParameter("Recycling") || !paramList_->get("Recycling",true)); |
| 110 |
|
| 111 |
if (startingOver) { |
| 112 |
FROSCH_ASSERT(paramList_->isParameter("FROSch Preconditioner Type"),"FROSch Preconditioner Type is not defined!"); |
| 113 |
|
| 114 |
if (!paramList_->get("FROSch Preconditioner Type","TwoLevelPreconditioner").compare("AlgebraicOverlappingPreconditioner")) { |
| 115 |
// Extract the repeated map |
| 116 |
ConstXMapPtr repeatedMap = extractRepeatedMap(comm,underlyingLib); |
| 117 |
|
| 118 |
RCP<AlgebraicOverlappingPreconditioner<SC,LO,GO,NO> > AOP(new AlgebraicOverlappingPreconditioner<SC,LO,GO,NO>(A,paramList_)); |
| 119 |
|
| 120 |
AOP->initialize(paramList_->get("Overlap",1), |
| 121 |
repeatedMap); |
| 122 |
|
| 123 |
schwarzPreconditioner = AOP; |
| 124 |
} else if (!paramList_->get("FROSch Preconditioner Type","TwoLevelPreconditioner").compare("GDSWPreconditioner")) { |
| 125 |
// Extract the repeated map |
| 126 |
ConstXMapPtr repeatedMap = extractRepeatedMap(comm,underlyingLib); |
| 127 |
|
| 128 |
// Extract the coordinate list |
| 129 |
ConstXMultiVectorPtr coordinatesList = extractCoordinatesList(comm,underlyingLib); |
| 130 |
|
| 131 |
// Extract the dof ordering |
| 132 |
DofOrdering dofOrdering = NodeWise; |
| 133 |
if (!paramList_->get("DofOrdering","NodeWise").compare("NodeWise")) { |
| 134 |
dofOrdering = NodeWise; |
| 135 |
} else if (!paramList_->get("DofOrdering","NodeWise").compare("DimensionWise")) { |
| 136 |
dofOrdering = DimensionWise; |
| 137 |
} else if (!paramList_->get("DofOrdering","NodeWise").compare("Custom")) { |
| 138 |
dofOrdering = Custom; |
| 139 |
} else { |
| 140 |
FROSCH_ASSERT(false,"ERROR: Specify a valid DofOrdering."); |
| 141 |
} |
| 142 |
|
| 143 |
RCP<GDSWPreconditioner<SC,LO,GO,NO> > GP(new GDSWPreconditioner<SC,LO,GO,NO>(A,paramList_)); |
| 144 |
|
| 145 |
GP->initialize(paramList_->get("Dimension",3), |
| 146 |
paramList_->get("DofsPerNode",1), |
| 147 |
dofOrdering, |
| 148 |
paramList_->get("Overlap",1), |
| 149 |
repeatedMap, |
| 150 |
coordinatesList); |
| 151 |
|
| 152 |
schwarzPreconditioner = GP; |
| 153 |
} else if (!paramList_->get("FROSch Preconditioner Type","TwoLevelPreconditioner").compare("RGDSWPreconditioner")) { |
| 154 |
// Extract the repeated map |
| 155 |
ConstXMapPtr repeatedMap = extractRepeatedMap(comm,underlyingLib); |
| 156 |
|
| 157 |
// Extract the coordinate list |
| 158 |
ConstXMultiVectorPtr coordinatesList = extractCoordinatesList(comm,underlyingLib); |
| 159 |
|
| 160 |
// Extract the dof ordering |
| 161 |
DofOrdering dofOrdering = NodeWise; |
| 162 |
if (!paramList_->get("DofOrdering","NodeWise").compare("NodeWise")) { |
| 163 |
dofOrdering = NodeWise; |
| 164 |
} else if (!paramList_->get("DofOrdering","NodeWise").compare("DimensionWise")) { |
| 165 |
dofOrdering = DimensionWise; |
| 166 |
} else if (!paramList_->get("DofOrdering","NodeWise").compare("Custom")) { |
| 167 |
dofOrdering = Custom; |
| 168 |
} else { |
| 169 |
FROSCH_ASSERT(false,"ERROR: Specify a valid DofOrdering."); |
| 170 |
} |
| 171 |
#if defined(HAVE_XPETRA_TPETRA) && defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_FLOAT) |
| 172 |
if (useHalfPrecision) |
| 173 |
{ |
| 174 |
auto ANonConst = rcp_const_cast<XMatrix>(A); |
| 175 |
auto halfA = Xpetra::convertToHalfPrecision(ANonConst); |
| 176 |
|
| 177 |
RCP<RGDSWPreconditioner<HalfSC,LO,GO,NO> > halfRGP(new RGDSWPreconditioner<HalfSC,LO,GO,NO>(halfA,paramList_)); |
| 178 |
|
| 179 |
XMultiVectorPtr coordinatesListNonConst = (coordinatesList == null ? null : rcp_const_cast<XMultiVector>(coordinatesList)); |
| 180 |
auto halfCoordinatesList = rcp_dynamic_cast<const HalfPrecMultiVector> (Xpetra::convertToHalfPrecision(coordinatesListNonConst)); |
| 181 |
halfRGP->initialize(paramList_->get("Dimension",3), |
| 182 |
paramList_->get("DofsPerNode",1), |
| 183 |
dofOrdering, |
| 184 |
paramList_->get("Overlap",1), |
| 185 |
repeatedMap, |
| 186 |
halfCoordinatesList); |
| 187 |
|
| 188 |
halfSchwarzPreconditioner = halfRGP; |
| 189 |
} else |
| 190 |
#endif |
| 191 |
{ |
| 192 |
RCP<RGDSWPreconditioner<SC,LO,GO,NO> > RGP(new RGDSWPreconditioner<SC,LO,GO,NO>(A,paramList_)); |
| 193 |
|
| 194 |
RGP->initialize(paramList_->get("Dimension",3), |
| 195 |
paramList_->get("DofsPerNode",1), |
| 196 |
dofOrdering, |
| 197 |
paramList_->get("Overlap",1), |
| 198 |
repeatedMap, |
| 199 |
coordinatesList); |
| 200 |
|
| 201 |
schwarzPreconditioner = RGP; |
| 202 |
} |
| 203 |
} else if (!paramList_->get("FROSch Preconditioner Type","TwoLevelPreconditioner").compare("OneLevelPreconditioner")) { |
| 204 |
// Extract the repeated map |
| 205 |
ConstXMapPtr repeatedMap = extractRepeatedMap(comm,underlyingLib); |
| 206 |
|
| 207 |
RCP<OneLevelPreconditioner<SC,LO,GO,NO> > OLP(new OneLevelPreconditioner<SC,LO,GO,NO>(A,paramList_)); |
| 208 |
|
| 209 |
OLP->initialize(paramList_->get("Overlap",1), |
| 210 |
repeatedMap); |
| 211 |
|
| 212 |
schwarzPreconditioner = OLP; |
| 213 |
} else if (!paramList_->get("FROSch Preconditioner Type","TwoLevelPreconditioner").compare("TwoLevelPreconditioner")) { |
| 214 |
// Extract the repeated map |
| 215 |
ConstXMapPtr repeatedMap = extractRepeatedMap(comm,underlyingLib); |
| 216 |
|
| 217 |
// Extract the null space |
| 218 |
ConstXMultiVectorPtr nullSpaceBasis = extractNullSpace(comm,underlyingLib); |
| 219 |
|
| 220 |
// Extract the coordinate list |
| 221 |
ConstXMultiVectorPtr coordinatesList = extractCoordinatesList(comm,underlyingLib); |
| 222 |
|
| 223 |
// Extract the dof ordering |
| 224 |
DofOrdering dofOrdering = NodeWise; |
| 225 |
if (!paramList_->get("DofOrdering","NodeWise").compare("NodeWise")) { |
| 226 |
dofOrdering = NodeWise; |
| 227 |
} else if (!paramList_->get("DofOrdering","NodeWise").compare("DimensionWise")) { |
| 228 |
dofOrdering = DimensionWise; |
| 229 |
} else if (!paramList_->get("DofOrdering","NodeWise").compare("Custom")) { |
| 230 |
dofOrdering = Custom; |
| 231 |
} else { |
| 232 |
FROSCH_ASSERT(false,"ERROR: Specify a valid DofOrdering."); |
| 233 |
} |
| 234 |
#if defined(HAVE_XPETRA_TPETRA) && defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_FLOAT) |
| 235 |
if (useHalfPrecision) |
| 236 |
{ |
| 237 |
auto ANonConst = rcp_const_cast<XMatrix>(A); |
| 238 |
auto halfA = Xpetra::convertToHalfPrecision(ANonConst); |
| 239 |
|
| 240 |
RCP<TwoLevelPreconditioner<HalfSC,LO,GO,NO> > halfTLP(new TwoLevelPreconditioner<HalfSC,LO,GO,NO>(halfA,paramList_)); |
| 241 |
|
| 242 |
XMultiVectorPtr coordinatesListNonConst = rcp_const_cast<XMultiVector>(coordinatesList); |
| 243 |
XMultiVectorPtr nullSpaceBasisNonConst = rcp_const_cast<XMultiVector>(nullSpaceBasis); |
| 244 |
auto halfCoordinatesList = (coordinatesListNonConst == null ? null : rcp_dynamic_cast<const HalfPrecMultiVector> (Xpetra::convertToHalfPrecision(coordinatesListNonConst))); |
| 245 |
auto halfNullSpaceBasis = (nullSpaceBasisNonConst == null ? null : rcp_dynamic_cast<const HalfPrecMultiVector> (Xpetra::convertToHalfPrecision(nullSpaceBasisNonConst))); |
| 246 |
halfTLP->initialize(paramList_->get("Dimension",3), |
| 247 |
paramList_->get("DofsPerNode",1), |
| 248 |
paramList_->get("Overlap",1), |
| 249 |
halfNullSpaceBasis, |
| 250 |
halfCoordinatesList, |
| 251 |
dofOrdering, |
| 252 |
repeatedMap); |
| 253 |
|
| 254 |
halfSchwarzPreconditioner = halfTLP; |
| 255 |
} else |
| 256 |
#endif |
| 257 |
{ |
| 258 |
RCP<TwoLevelPreconditioner<SC,LO,GO,NO> > TLP(new TwoLevelPreconditioner<SC,LO,GO,NO>(A,paramList_)); |
| 259 |
|
| 260 |
TLP->initialize(paramList_->get("Dimension",3), |
| 261 |
paramList_->get("DofsPerNode",1), |
| 262 |
paramList_->get("Overlap",1), |
| 263 |
nullSpaceBasis, |
| 264 |
coordinatesList, |
| 265 |
dofOrdering, |
| 266 |
repeatedMap); |
| 267 |
|
| 268 |
schwarzPreconditioner = TLP; |
| 269 |
} |
| 270 |
} else if (!paramList_->get("FROSch Preconditioner Type","TwoLevelPreconditioner").compare("TwoLevelBlockPreconditioner")) { |
| 271 |
ConstXMapPtrVecPtr repeatedMaps = null; |
| 272 |
ConstXMultiVectorPtrVecPtr coordinatesList = null; |
| 273 |
UNVecPtr dofsPerNodeVector; |
| 274 |
DofOrderingVecPtr dofOrderings; |
| 275 |
|
| 276 |
FROSCH_ASSERT(paramList_->isParameter("DofsPerNode Vector"),"Currently, TwoLevelBlockPreconditioner cannot be constructed without DofsPerNode Vector."); |
| 277 |
FROSCH_ASSERT(paramList_->isParameter("DofOrdering Vector"),"Currently, TwoLevelBlockPreconditioner cannot be constructed without DofOrdering Vector."); |
| 278 |
// Extract the repeated map vector |
| 279 |
if (paramList_->isParameter("Repeated Map Vector")) { |
| 280 |
XMapPtrVecPtr repeatedMapsTmp = ExtractVectorFromParameterList<XMapPtr>(*paramList_,"Repeated Map Vector"); |
| 281 |
XMultiVectorPtrVecPtr nodeListVecTmp = ExtractVectorFromParameterList<XMultiVectorPtr>(*paramList_,"Coordinates List Vector"); |
| 282 |
if (!repeatedMapsTmp.is_null()) { |
| 283 |
repeatedMaps.resize(repeatedMapsTmp.size()); |
| 284 |
for (unsigned i=0; i<repeatedMaps.size(); i++) { |
| 285 |
repeatedMaps[i] = repeatedMapsTmp[i].getConst(); |
| 286 |
} |
| 287 |
} |
| 288 |
// Extract the nodeList map vector |
| 289 |
if (!nodeListVecTmp.is_null()) { |
| 290 |
coordinatesList.resize(nodeListVecTmp.size()); |
| 291 |
for (unsigned i = 0; i<coordinatesList.size();i++) { |
| 292 |
coordinatesList[i] = nodeListVecTmp[i].getConst(); |
| 293 |
} |
| 294 |
} |
| 295 |
|
| 296 |
FROSCH_ASSERT(!repeatedMaps.is_null(),"FROSch::FROSchFactory: repeatedMaps.is_null()"); |
| 297 |
// Extract the DofsPerNode vector |
| 298 |
dofsPerNodeVector = ExtractVectorFromParameterList<UN>(*paramList_,"DofsPerNode Vector"); |
| 299 |
// Extract the DofOrdering vector |
| 300 |
dofOrderings = ExtractVectorFromParameterList<DofOrdering>(*paramList_,"DofOrdering Vector"); |
| 301 |
} else { |
| 302 |
FROSCH_ASSERT(false,"Currently, TwoLevelBlockPreconditioner cannot be constructed without Repeated Maps."); |
| 303 |
} |
| 304 |
|
| 305 |
FROSCH_ASSERT(repeatedMaps.size()==dofsPerNodeVector.size(),"RepeatedMaps.size()!=dofsPerNodeVector.size()"); |
| 306 |
FROSCH_ASSERT(repeatedMaps.size()==dofOrderings.size(),"RepeatedMaps.size()!=dofOrderings.size()"); |
| 307 |
|
| 308 |
RCP<TwoLevelBlockPreconditioner<SC,LO,GO,NO> > TLBP(new TwoLevelBlockPreconditioner<SC,LO,GO,NO>(A,paramList_)); |
| 309 |
|
| 310 |
TLBP->initialize(paramList_->get("Dimension",3), |
| 311 |
dofsPerNodeVector, |
| 312 |
dofOrderings, |
| 313 |
paramList_->get("Overlap",1), |
| 314 |
coordinatesList, |
| 315 |
repeatedMaps); |
| 316 |
|
| 317 |
schwarzPreconditioner = TLBP; |
| 318 |
} else { |
| 319 |
FROSCH_ASSERT(false,"Thyra::FROSchFactory: Preconditioner Type is unknown."); |
| 320 |
} |
| 321 |
|
| 322 |
//----------------------------------------------- |
| 323 |
|
| 324 |
LinearOpBasePtr thyraPrecOp = null; |
| 325 |
|
| 326 |
#if defined(HAVE_XPETRA_TPETRA) |
| 327 |
if (bIsTpetra) { |
| 328 |
RCP<Tpetra::Operator<SC,LO,GO,NO> > tpOp; |
| 329 |
#if defined(HAVE_XPETRA_TPETRA) && defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_FLOAT) |
| 330 |
if (halfSchwarzPreconditioner != null) |
| 331 |
{ |
| 332 |
halfSchwarzPreconditioner->compute(); |
| 333 |
auto halfSchwarzOperator = rcp (new HalfPrecOp (halfSchwarzPreconditioner)); |
| 334 |
RCP<TpetraPreconditioner<SC,LO,GO,NO> > TPreconditioner (new TpetraPreconditioner<SC,LO,GO,NO>(halfSchwarzOperator)); |
| 335 |
tpOp = rcp_dynamic_cast<Tpetra::Operator<SC,LO,GO,NO> >(TPreconditioner); |
| 336 |
} else |
| 337 |
#endif |
| 338 |
{ |
| 339 |
schwarzPreconditioner->compute(); |
| 340 |
auto schwarzOperator = rcp_dynamic_cast<Xpetra::Operator<SC,LO,GO,NO> >(schwarzPreconditioner); |
| 341 |
RCP<TpetraPreconditioner<SC,LO,GO,NO> > TPreconditioner (new TpetraPreconditioner<SC,LO,GO,NO>(schwarzOperator)); |
| 342 |
tpOp = rcp_dynamic_cast<Tpetra::Operator<SC,LO,GO,NO> >(TPreconditioner); |
| 343 |
} |
| 344 |
thyraPrecOp = Thyra::createLinearOp(tpOp); |
| 345 |
} else |
| 346 |
#endif |
| 347 |
{ |
| 348 |
RCP<Operator<SC,LO,GO,NO> > xpOp; |
| 349 |
#if defined(HAVE_XPETRA_TPETRA) && defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_FLOAT) |
| 350 |
if (halfSchwarzPreconditioner != null) { |
| 351 |
halfSchwarzPreconditioner->compute(); |
| 352 |
xpOp = rcp_dynamic_cast<Operator<SC,LO,GO,NO> >(rcp (new HalfPrecOp (halfSchwarzPreconditioner))); |
| 353 |
} else |
| 354 |
#endif |
| 355 |
{ |
| 356 |
schwarzPreconditioner->compute(); |
| 357 |
xpOp = rcp_dynamic_cast<Operator<SC,LO,GO,NO> >(schwarzPreconditioner); |
| 358 |
} |
| 359 |
|
| 360 |
ConstVectorSpaceBasePtr thyraRangeSpace = ThyraUtils<SC,LO,GO,NO>::toThyra(schwarzPreconditioner->getRangeMap()); |
| 361 |
ConstVectorSpaceBasePtr thyraDomainSpace = ThyraUtils<SC,LO,GO,NO>::toThyra(schwarzPreconditioner->getDomainMap()); |
| 362 |
thyraPrecOp = fROSchLinearOp<SC,LO,GO,NO>(thyraRangeSpace,thyraDomainSpace,xpOp,bIsEpetra,bIsTpetra); |
| 363 |
} |
| 364 |
TEUCHOS_TEST_FOR_EXCEPT(is_null(thyraPrecOp)); |
| 365 |
|
| 366 |
//Set SchwarzPreconditioner |
| 367 |
defaultPrec->initializeUnspecified(thyraPrecOp); |
| 368 |
} else { |
| 369 |
// cast to SchwarzPreconditioner |
| 370 |
RCP<Operator<SC,LO,GO,NO> > xpetraOp; |
| 371 |
#if defined(HAVE_XPETRA_TPETRA) |
| 372 |
if (bIsTpetra) { |
| 373 |
RCP<Thyra::TpetraLinearOp<SC,LO,GO,NO> > thyra_precOp = rcp_dynamic_cast<Thyra::TpetraLinearOp<SC,LO,GO,NO>>(precOp, true); |
| 374 |
RCP<Tpetra::Operator<SC,LO,GO,NO> > tpOp = thyra_precOp->getTpetraOperator(); |
| 375 |
RCP<TpetraPreconditioner<SC,LO,GO,NO> > tpetra_precOp = rcp_dynamic_cast<TpetraPreconditioner<SC,LO,GO,NO>>(tpOp, true); |
| 376 |
xpetraOp = rcp_dynamic_cast<Operator<SC,LO,GO,NO> >(tpetra_precOp->getSchwarzPreconditioner()); |
| 377 |
} else |
| 378 |
#endif |
| 379 |
{ |
| 380 |
RCP<FROSchLinearOp<SC,LO,GO,NO> > fROSch_LinearOp = rcp_dynamic_cast<FROSchLinearOp<SC,LO,GO,NO> >(precOp,true); |
| 381 |
xpetraOp = fROSch_LinearOp->getXpetraOperator(); |
| 382 |
} |
| 383 |
|
| 384 |
#if defined(HAVE_XPETRA_TPETRA) && defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_FLOAT) |
| 385 |
if (useHalfPrecision) |
| 386 |
{ |
| 387 |
if (!paramList_->get("FROSch Preconditioner Type","TwoLevelPreconditioner").compare("RGDSWPreconditioner") || |
| 388 |
!paramList_->get("FROSch Preconditioner Type","TwoLevelPreconditioner").compare("TwoLevelPreconditioner")) { |
| 389 |
auto ANonConst = rcp_const_cast<XMatrix>(A); |
| 390 |
auto halfA = rcp_const_cast<const HalfPrecMatrix>(Xpetra::convertToHalfPrecision(ANonConst)); |
| 391 |
auto halfPrecOp = rcp_dynamic_cast<HalfPrecOp>(xpetraOp); |
| 392 |
auto halfXpetraOp = rcp_dynamic_cast<Operator<HalfSC,LO,GO,NO>>(halfPrecOp->GetHalfPrecisionOperator()); |
| 393 |
RCP<OneLevelPreconditioner<HalfSC,LO,GO,NO> > TLP = rcp_dynamic_cast<OneLevelPreconditioner<HalfSC,LO,GO,NO> >(halfXpetraOp, true); |
| 394 |
TLP->resetMatrix(halfA); |
| 395 |
|
| 396 |
halfSchwarzPreconditioner = rcp_dynamic_cast<SchwarzPreconditioner<HalfSC,LO,GO,NO> >(halfXpetraOp, true); |
| 397 |
halfSchwarzPreconditioner->compute(); |
| 398 |
} |
| 399 |
} else |
| 400 |
#endif |
| 401 |
{ |
| 402 |
if (!paramList_->get("FROSch Preconditioner Type","TwoLevelPreconditioner").compare("AlgebraicOverlappingPreconditioner")) { |
| 403 |
RCP<AlgebraicOverlappingPreconditioner<SC,LO,GO,NO> > AOP = rcp_dynamic_cast<AlgebraicOverlappingPreconditioner<SC,LO,GO,NO> >(xpetraOp, true); |
| 404 |
AOP->resetMatrix(A); |
| 405 |
schwarzPreconditioner = AOP; |
| 406 |
} else if (!paramList_->get("FROSch Preconditioner Type","TwoLevelPreconditioner").compare("GDSWPreconditioner")) { |
| 407 |
RCP<AlgebraicOverlappingPreconditioner<SC,LO,GO,NO> > GP = rcp_dynamic_cast<AlgebraicOverlappingPreconditioner<SC,LO,GO,NO> >(xpetraOp, true); |
| 408 |
GP->resetMatrix(A); |
| 409 |
schwarzPreconditioner = GP; |
| 410 |
} else if (!paramList_->get("FROSch Preconditioner Type","TwoLevelPreconditioner").compare("RGDSWPreconditioner")) { |
| 411 |
RCP<OneLevelPreconditioner<SC,LO,GO,NO> > RGP = rcp_dynamic_cast<OneLevelPreconditioner<SC,LO,GO,NO> >(xpetraOp, true); |
| 412 |
RGP->resetMatrix(A); |
| 413 |
schwarzPreconditioner = RGP; |
| 414 |
} else if (!paramList_->get("FROSch Preconditioner Type","TwoLevelPreconditioner").compare("OneLevelPreconditioner")) { |
| 415 |
RCP<OneLevelPreconditioner<SC,LO,GO,NO> > OLP = rcp_dynamic_cast<OneLevelPreconditioner<SC,LO,GO,NO> >(xpetraOp, true); |
| 416 |
OLP->resetMatrix(A); |
| 417 |
schwarzPreconditioner = OLP; |
| 418 |
} else if (!paramList_->get("FROSch Preconditioner Type","TwoLevelPreconditioner").compare("TwoLevelPreconditioner")) { |
| 419 |
RCP<OneLevelPreconditioner<SC,LO,GO,NO> > TLP = rcp_dynamic_cast<OneLevelPreconditioner<SC,LO,GO,NO> >(xpetraOp, true); |
| 420 |
TLP->resetMatrix(A); |
| 421 |
schwarzPreconditioner = TLP; |
| 422 |
} else if (!paramList_->get("FROSch Preconditioner Type","TwoLevelPreconditioner").compare("TwoLevelBlockPreconditioner")) { |
| 423 |
RCP<OneLevelPreconditioner<SC,LO,GO,NO> > TLBP = rcp_dynamic_cast<OneLevelPreconditioner<SC,LO,GO,NO> >(xpetraOp, true); |
| 424 |
TLBP->resetMatrix(A); |
| 425 |
schwarzPreconditioner = TLBP; |
| 426 |
} else { |
| 427 |
FROSCH_ASSERT(false,"Thyra::FROSchFactory: Preconditioner Type is unknown."); |
| 428 |
} |
| 429 |
// recompute SchwarzPreconditioner |
| 430 |
schwarzPreconditioner->compute(); |
| 431 |
} |
| 432 |
} |
| 433 |
} |
| 434 |
|
| 435 |
//------------------------------------------------------------- |
| 436 |
//uninitialize |
| 437 |
template <class SC, class LO, class GO, class NO> |
| 438 |
void FROSchFactory<SC,LO,GO,NO>::uninitializePrec(PreconditionerBase<SC>* prec, |
| 439 |
ConstLinearOpSourceBasePtr* fwdOp, |
| 440 |
ESupportSolveUse* supportSolveUse) const |
| 441 |
{ |
| 442 |
TEUCHOS_ASSERT(prec); |
| 443 |
|
| 444 |
// Retrieve concrete preconditioner object |
| 445 |
const Ptr<DefaultPreconditioner<SC> > defaultPrec = ptr(dynamic_cast<DefaultPreconditioner<SC> *>(prec)); |
| 446 |
TEUCHOS_TEST_FOR_EXCEPT(is_null(defaultPrec)); |
| 447 |
|
| 448 |
if (fwdOp) { |
| 449 |
// TODO: Implement properly instead of returning default value |
| 450 |
*fwdOp = null; |
| 451 |
} |
| 452 |
|
| 453 |
if (supportSolveUse) { |
| 454 |
// TODO: Implement properly instead of returning default value |
| 455 |
*supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED; |
| 456 |
} |
| 457 |
|
| 458 |
defaultPrec->uninitialize(); |
| 459 |
} |
| 460 |
//----------------------------------------------------------------- |
| 461 |
//Following Functione maybe needed later |
| 462 |
template <class SC, class LO, class GO, class NO> |
| 463 |
void FROSchFactory<SC,LO,GO,NO>::setParameterList(ParameterListPtr const & paramList) |
| 464 |
{ |
| 465 |
TEUCHOS_TEST_FOR_EXCEPT(is_null(paramList)); |
| 466 |
paramList_ = paramList; |
| 467 |
} |
| 468 |
|
| 469 |
template<class SC, class LO,class GO, class NO> |
| 470 |
typename FROSchFactory<SC,LO,GO,NO>::ParameterListPtr FROSchFactory<SC,LO,GO,NO>::unsetParameterList() |
| 471 |
{ |
| 472 |
ParameterListPtr savedParamList = paramList_; |
| 473 |
paramList_ = null; |
| 474 |
return savedParamList; |
| 475 |
} |
| 476 |
|
| 477 |
template <class SC, class LO, class GO, class NO> |
| 478 |
typename FROSchFactory<SC,LO,GO,NO>::ParameterListPtr FROSchFactory<SC,LO,GO,NO>::getNonconstParameterList() |
| 479 |
{ |
| 480 |
return paramList_; |
| 481 |
} |
| 482 |
|
| 483 |
template <class SC, class LO, class GO, class NO> |
| 484 |
typename FROSchFactory<SC,LO,GO,NO>::ConstParameterListPtr FROSchFactory<SC,LO,GO,NO>::getParameterList() const |
| 485 |
{ |
| 486 |
return paramList_; |
| 487 |
} |
| 488 |
|
| 489 |
template <class SC, class LO, class GO, class NO> |
| 490 |
typename FROSchFactory<SC,LO,GO,NO>::ConstParameterListPtr FROSchFactory<SC,LO,GO,NO>::getValidParameters() const |
| 491 |
{ |
| 492 |
static ConstParameterListPtr validPL; |
| 493 |
|
| 494 |
if (is_null(validPL)) |
| 495 |
validPL = rcp(new ParameterList()); |
| 496 |
|
| 497 |
return validPL; |
| 498 |
} |
| 499 |
|
| 500 |
template <class SC, class LO, class GO, class NO> |
| 501 |
string FROSchFactory<SC,LO,GO,NO>::description() const |
| 502 |
{ |
| 503 |
return "FROSchFactory"; |
| 504 |
} |
| 505 |
|
| 506 |
template <class SC, class LO, class GO, class NO> |
| 507 |
typename FROSchFactory<SC,LO,GO,NO>::ConstXMapPtr FROSchFactory<SC,LO,GO,NO>::extractRepeatedMap(CommPtr comm, |
| 508 |
UnderlyingLib lib) const |
| 509 |
{ |
| 510 |
ConstXMapPtr repeatedMap = null; |
| 511 |
if (paramList_->isParameter("Repeated Map")) { |
| 512 |
repeatedMap = ExtractPtrFromParameterList<XMap>(*paramList_,"Repeated Map").getConst(); |
| 513 |
if (repeatedMap.is_null()) { |
| 514 |
if (lib==UseTpetra) { // If coordinatesList.is_null(), we look for Tpetra/Epetra RCPs |
| 515 |
RCP<const Tpetra::Map<LO,GO,NO> > repeatedMapTmp = ExtractPtrFromParameterList<const Tpetra::Map<LO,GO,NO> >(*paramList_,"Repeated Map"); |
| 516 |
|
| 517 |
RCP<const TpetraMap<LO,GO,NO> > xTpetraRepeatedMap(new const TpetraMap<LO,GO,NO>(repeatedMapTmp)); |
| 518 |
repeatedMap = rcp_dynamic_cast<ConstXMap>(xTpetraRepeatedMap); |
| 519 |
} else { |
| 520 |
#ifdef HAVE_SHYLU_DDFROSCH_EPETRA |
| 521 |
FROSCH_WARNING("FROSch::FROSchFactory",comm->getRank()==0,"Cannot retrieve Epetra objects from ParameterList. Use Xpetra instead."); |
| 522 |
#endif |
| 523 |
} |
| 524 |
} |
| 525 |
FROSCH_ASSERT(!repeatedMap.is_null(),"FROSch::FROSchFactory: repeatedMap.is_null()"); |
| 526 |
} |
| 527 |
return repeatedMap; |
| 528 |
} |
| 529 |
|
| 530 |
template <class SC, class LO, class GO, class NO> |
| 531 |
typename FROSchFactory<SC,LO,GO,NO>::ConstXMultiVectorPtr FROSchFactory<SC,LO,GO,NO>::extractCoordinatesList(CommPtr comm, |
| 532 |
UnderlyingLib lib) const |
| 533 |
{ |
| 534 |
ConstXMultiVectorPtr coordinatesList = null; |
| 535 |
if (paramList_->isParameter("Coordinates List")) { |
| 536 |
coordinatesList = ExtractPtrFromParameterList<XMultiVector>(*paramList_,"Coordinates List").getConst(); |
| 537 |
if (coordinatesList.is_null()) { |
| 538 |
if (lib==UseTpetra) { // If coordinatesList.is_null(), we look for Tpetra/Epetra RCPs |
| 539 |
RCP<Tpetra::MultiVector<SC,LO,GO,NO> > coordinatesListTmp = ExtractPtrFromParameterList<Tpetra::MultiVector<SC,LO,GO,NO> >(*paramList_,"Coordinates List"); |
| 540 |
|
| 541 |
RCP<const Xpetra::TpetraMultiVector<SC,LO,GO,NO> > xTpetraCoordinatesList(new const Xpetra::TpetraMultiVector<SC,LO,GO,NO>(coordinatesListTmp)); |
| 542 |
coordinatesList = rcp_dynamic_cast<ConstXMultiVector>(xTpetraCoordinatesList); |
| 543 |
} else { |
| 544 |
#ifdef HAVE_SHYLU_DDFROSCH_EPETRA |
| 545 |
FROSCH_WARNING("FROSch::FROSchFactory",comm->getRank()==0,"Cannot retrieve Epetra objects from ParameterList. Use Xpetra instead."); |
| 546 |
#endif |
| 547 |
} |
| 548 |
} |
| 549 |
FROSCH_ASSERT(!coordinatesList.is_null(),"FROSch::FROSchFactory: coordinatesList.is_null()"); |
| 550 |
} |
| 551 |
return coordinatesList; |
| 552 |
} |
| 553 |
|
| 554 |
template <class SC, class LO, class GO, class NO> |
| 555 |
typename FROSchFactory<SC,LO,GO,NO>::ConstXMultiVectorPtr FROSchFactory<SC,LO,GO,NO>::extractNullSpace(CommPtr comm, |
| 556 |
UnderlyingLib lib) const |
| 557 |
{ |
| 558 |
ConstXMultiVectorPtr nullSpaceBasis = null; |
| 559 |
if (paramList_->isParameter("Null Space")) { |
| 560 |
nullSpaceBasis = ExtractPtrFromParameterList<XMultiVector>(*paramList_,"Null Space").getConst(); |
| 561 |
if (nullSpaceBasis.is_null()) { |
| 562 |
if (lib==UseTpetra) { // If nullSpaceBasis.is_null(), we look for Tpetra/Epetra RCPs |
| 563 |
RCP<Tpetra::MultiVector<SC,LO,GO,NO> > nullSpaceBasisTmp = ExtractPtrFromParameterList<Tpetra::MultiVector<SC,LO,GO,NO> >(*paramList_,"Null Space"); |
| 564 |
|
| 565 |
RCP<const Xpetra::TpetraMultiVector<SC,LO,GO,NO> > xTpetraNullSpaceBasis(new const Xpetra::TpetraMultiVector<SC,LO,GO,NO>(nullSpaceBasisTmp)); |
| 566 |
nullSpaceBasis = rcp_dynamic_cast<ConstXMultiVector>(xTpetraNullSpaceBasis); |
| 567 |
} else { |
| 568 |
#ifdef HAVE_SHYLU_DDFROSCH_EPETRA |
| 569 |
FROSCH_WARNING("FROSch::FROSchFactory",comm->getRank()==0,"Cannot retrieve Epetra objects from ParameterList. Use Xpetra instead."); |
| 570 |
#endif |
| 571 |
} |
| 572 |
} |
| 573 |
FROSCH_ASSERT(!nullSpaceBasis.is_null(),"FROSch::FROSchFactory: nullSpaceBasis.is_null()"); |
| 574 |
} |
| 575 |
return nullSpaceBasis; |
| 576 |
} |
| 577 |
|
| 578 |
} |
| 579 |
#endif |