| 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 _FROSCH_THYRAPRECONDITIONER_DEF_HPP |
| 11 |
#define _FROSCH_THYRAPRECONDITIONER_DEF_HPP |
| 12 |
|
| 13 |
#include <FROSch_ThyraPreconditioner_decl.hpp> |
| 14 |
|
| 15 |
|
| 16 |
namespace FROSch { |
| 17 |
|
| 18 |
using namespace Stratimikos; |
| 19 |
using namespace Teuchos; |
| 20 |
using namespace Thyra; |
| 21 |
using namespace Xpetra; |
| 22 |
|
| 23 |
template<class SC,class LO,class GO,class NO> |
| 24 |
int ThyraPreconditioner<SC,LO,GO,NO>::initialize() |
| 25 |
{ |
| 26 |
FROSCH_TIMER_START_SOLVER(initializeTime,"ThyraPreconditioner::initialize"); |
| 27 |
this->IsInitialized_ = true; |
| 28 |
this->IsComputed_ = false; |
| 29 |
return 0; |
| 30 |
} |
| 31 |
|
| 32 |
template<class SC,class LO,class GO,class NO> |
| 33 |
int ThyraPreconditioner<SC,LO,GO,NO>::compute() |
| 34 |
{ |
| 35 |
FROSCH_TIMER_START_SOLVER(computeTime,"ThyraPreconditioner::compute"); |
| 36 |
FROSCH_ASSERT(this->IsInitialized_,"FROSch::ThyraPreconditioner: !this->IsInitialized_"); |
| 37 |
this->IsComputed_ = true; |
| 38 |
return 0; |
| 39 |
} |
| 40 |
|
| 41 |
template<class SC,class LO,class GO,class NO> |
| 42 |
void ThyraPreconditioner<SC,LO,GO,NO>::apply(const XMultiVector &x, |
| 43 |
XMultiVector &y, |
| 44 |
ETransp mode, |
| 45 |
SC alpha, |
| 46 |
SC beta) const |
| 47 |
{ |
| 48 |
FROSCH_TIMER_START_SOLVER(applyTime,"ThyraPreconditioner::apply"); |
| 49 |
FROSCH_ASSERT(this->IsComputed_,"FROSch::ThyraPreconditioner: !this->IsComputed_."); |
| 50 |
|
| 51 |
ConstMultiVectorBasePtr xThyra = ThyraUtils<SC,LO,GO,NO>::toThyraMultiVector(rcpFromRef(x)); |
| 52 |
MultiVectorBasePtr yThyra = rcp_const_cast<MultiVectorBase<SC> >(ThyraUtils<SC,LO,GO,NO>::toThyraMultiVector(rcpFromRef(y))); |
| 53 |
|
| 54 |
EOpTransp tMode = NOTRANS; |
| 55 |
switch (mode) { |
| 56 |
case Teuchos::NO_TRANS: tMode = Thyra::NOTRANS; break; |
| 57 |
case Teuchos::TRANS: tMode = Thyra::TRANS; break; |
| 58 |
case Teuchos::CONJ_TRANS: tMode = Thyra::CONJTRANS; break; |
| 59 |
default: FROSCH_ASSERT(false,"FROSch::ThyraPreconditioner: mode unknown."); |
| 60 |
} |
| 61 |
|
| 62 |
ThyraPreconditioner_->getUnspecifiedPrecOp()->apply(tMode,*xThyra,yThyra.ptr(),alpha,beta); |
| 63 |
|
| 64 |
// It seems that we have to convert the Thyra vector back to Xpetra. Is there a cheaper/more elegant way? |
| 65 |
// Same for ThyraSolver |
| 66 |
XMultiVectorPtr yXpetra = ThyraUtils<SC,LO,GO,NO>::toXpetra(yThyra,y.getMap()->getComm()); |
| 67 |
y = *yXpetra; |
| 68 |
} |
| 69 |
|
| 70 |
template<class SC,class LO,class GO,class NO> |
| 71 |
int ThyraPreconditioner<SC,LO,GO,NO>::updateMatrix(ConstXMatrixPtr k, |
| 72 |
bool reuseInitialize) |
| 73 |
{ |
| 74 |
FROSCH_ASSERT(false,"FROSch::ThyraPreconditioner: updateMatrix() is not implemented for the ThyraPreconditioner yet."); |
| 75 |
} |
| 76 |
|
| 77 |
template<class SC,class LO,class GO,class NO> |
| 78 |
ThyraPreconditioner<SC,LO,GO,NO>::ThyraPreconditioner(ConstXMatrixPtr k, |
| 79 |
ParameterListPtr parameterList, |
| 80 |
string description) : |
| 81 |
Solver<SC,LO,GO,NO> (k,parameterList,description) |
| 82 |
{ |
| 83 |
FROSCH_TIMER_START_SOLVER(ThyraPreconditionerTime,"ThyraPreconditioner::ThyraPreconditioner"); |
| 84 |
FROSCH_ASSERT(!this->K_.is_null(),"FROSch::ThyraPreconditioner: K_ is null."); |
| 85 |
|
| 86 |
const CrsMatrixWrap<SC,LO,GO,NO>& crsOp = dynamic_cast<const CrsMatrixWrap<SC,LO,GO,NO>&>(*this->K_); |
| 87 |
RCP<const Thyra::LinearOpBase<SC> > thyraOp = ThyraUtils<SC,LO,GO,NO>::toThyra(crsOp.getCrsMatrix()); |
| 88 |
|
| 89 |
LinearSolverBuilder<SC> linearSolverBuilder; |
| 90 |
enableFROSch<SC,LO,GO,NO>(linearSolverBuilder); |
| 91 |
linearSolverBuilder.setParameterList(sublist(this->ParameterList_,"ThyraPreconditioner")); |
| 92 |
|
| 93 |
PreconditionerFactoryBasePtr thyraFactory = linearSolverBuilder.createPreconditioningStrategy(""); |
| 94 |
ThyraPreconditioner_ = prec(*thyraFactory,thyraOp); |
| 95 |
} |
| 96 |
|
| 97 |
} |
| 98 |
|
| 99 |
#endif |