| 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_AMESOSSOLVEREPETRA_DEF_HPP |
| 11 |
#define _FROSCH_AMESOSSOLVEREPETRA_DEF_HPP |
| 12 |
|
| 13 |
#include <FROSch_AmesosSolverEpetra_decl.hpp> |
| 14 |
|
| 15 |
|
| 16 |
namespace FROSch { |
| 17 |
|
| 18 |
using namespace std; |
| 19 |
using namespace Teuchos; |
| 20 |
using namespace Xpetra; |
| 21 |
|
| 22 |
template<class SC,class LO,class GO,class NO> |
| 23 |
AmesosSolverEpetra<SC,LO,GO,NO>::~AmesosSolverEpetra() |
| 24 |
{ |
| 25 |
AmesosSolver_.reset(); |
| 26 |
EpetraLinearProblem_.reset(); |
| 27 |
} |
| 28 |
|
| 29 |
template<class SC,class LO,class GO,class NO> |
| 30 |
int AmesosSolverEpetra<SC,LO,GO,NO>::initialize() |
| 31 |
{ |
| 32 |
FROSCH_TIMER_START_SOLVER(initializeTime,"AmesosSolverEpetra::initialize"); |
| 33 |
this->IsInitialized_ = true; |
| 34 |
this->IsComputed_ = false; |
| 35 |
AMESOS_CHK_ERR(AmesosSolver_->SymbolicFactorization()); |
| 36 |
return 0; |
| 37 |
} |
| 38 |
|
| 39 |
template<class SC,class LO,class GO,class NO> |
| 40 |
int AmesosSolverEpetra<SC,LO,GO,NO>::compute() |
| 41 |
{ |
| 42 |
FROSCH_TIMER_START_SOLVER(computeTime,"AmesosSolverEpetra::compute"); |
| 43 |
FROSCH_ASSERT(this->IsInitialized_,"FROSch::AmesosSolverEpetra: !this->IsInitialized_"); |
| 44 |
this->IsComputed_ = true; |
| 45 |
AMESOS_CHK_ERR(AmesosSolver_->NumericFactorization()); |
| 46 |
return 0; |
| 47 |
} |
| 48 |
|
| 49 |
template<class SC,class LO,class GO,class NO> |
| 50 |
void AmesosSolverEpetra<SC,LO,GO,NO>::apply(const XMultiVector &x, |
| 51 |
XMultiVector &y, |
| 52 |
ETransp mode, |
| 53 |
SC alpha, |
| 54 |
SC beta) const |
| 55 |
{ |
| 56 |
FROSCH_TIMER_START_SOLVER(applyTime,"AmesosSolverEpetra::apply"); |
| 57 |
FROSCH_ASSERT(this->IsComputed_,"FROSch::AmesosSolverEpetra: !this->IsComputed_."); |
| 58 |
|
| 59 |
const EpetraMultiVectorT<GO,NO> * xEpetraMultiVectorX = dynamic_cast<const EpetraMultiVectorT<GO,NO> *>(&x); |
| 60 |
FROSCH_ASSERT(xEpetraMultiVectorX,"FROSch::AmesosSolverEpetra: dynamic_cast failed."); |
| 61 |
RCP<EMultiVector> epetraMultiVectorX = xEpetraMultiVectorX->getEpetra_MultiVector(); |
| 62 |
|
| 63 |
if (Y_.is_null()) Y_ = XMultiVectorFactory::Build(y.getMap(),x.getNumVectors()); |
| 64 |
EpetraMultiVectorT<GO,NO> * xEpetraMultiVectorY = dynamic_cast<EpetraMultiVectorT<GO,NO> *>(Y_.get()); |
| 65 |
FROSCH_ASSERT(xEpetraMultiVectorY,"FROSch::AmesosSolverEpetra: dynamic_cast failed."); |
| 66 |
RCP<EMultiVector> epetraMultiVectorY = xEpetraMultiVectorY->getEpetra_MultiVector(); |
| 67 |
|
| 68 |
EpetraLinearProblem_->SetLHS(epetraMultiVectorY.get()); |
| 69 |
EpetraLinearProblem_->SetRHS(epetraMultiVectorX.get()); |
| 70 |
|
| 71 |
FROSCH_ASSERT(mode==NO_TRANS,"FROSch::AmesosSolverEpetra: mode!=NO_TRANS"); |
| 72 |
EpetraLinearProblem_->GetMatrix()->SetUseTranspose(mode==TRANS); |
| 73 |
AmesosSolver_->Solve(); |
| 74 |
|
| 75 |
y.update(alpha,*Y_,beta); |
| 76 |
} |
| 77 |
|
| 78 |
template<class SC,class LO,class GO,class NO> |
| 79 |
int AmesosSolverEpetra<SC,LO,GO,NO>::updateMatrix(ConstXMatrixPtr k, |
| 80 |
bool reuseInitialize) |
| 81 |
{ |
| 82 |
FROSCH_ASSERT(false,"FROSch::AmesosSolverEpetra: updateMatrix() is not implemented for the AmesosSolverEpetra yet."); |
| 83 |
return 0; |
| 84 |
} |
| 85 |
|
| 86 |
template<class SC,class LO,class GO,class NO> |
| 87 |
AmesosSolverEpetra<SC,LO,GO,NO>::AmesosSolverEpetra(ConstXMatrixPtr k, |
| 88 |
ParameterListPtr parameterList, |
| 89 |
string description) : |
| 90 |
Solver<SC,LO,GO,NO> (k,parameterList,description) |
| 91 |
{ |
| 92 |
FROSCH_TIMER_START_SOLVER(AmesosSolverEpetraTime,"AmesosSolverEpetra::AmesosSolverEpetra"); |
| 93 |
FROSCH_ASSERT(!this->K_.is_null(),"FROSch::AmesosSolverEpetra: K_ is null."); |
| 94 |
FROSCH_ASSERT(this->K_->getRowMap()->lib()==UseEpetra,"FROSch::AmesosSolverEpetra: Not compatible with Tpetra.") |
| 95 |
|
| 96 |
const CrsMatrixWrap<SC,LO,GO,NO>& crsOp = dynamic_cast<const CrsMatrixWrap<SC,LO,GO,NO>&>(*this->K_); |
| 97 |
const EpetraCrsMatrixT<GO,NO>& xEpetraMat = dynamic_cast<const EpetraCrsMatrixT<GO,NO>&>(*crsOp.getCrsMatrix()); |
| 98 |
ECrsMatrixPtr epetraMat = xEpetraMat.getEpetra_CrsMatrixNonConst(); |
| 99 |
TEUCHOS_TEST_FOR_EXCEPT(epetraMat.is_null()); |
| 100 |
|
| 101 |
EMultiVectorPtr xTmp; |
| 102 |
EMultiVectorPtr bTmp; |
| 103 |
|
| 104 |
EpetraLinearProblem_.reset(new ELinearProblem(epetraMat.get(),xTmp.get(),bTmp.get())); |
| 105 |
|
| 106 |
Amesos amesosFactory; |
| 107 |
AmesosSolver_.reset(amesosFactory.Create(this->ParameterList_->get("Solver","Klu"),*EpetraLinearProblem_)); |
| 108 |
|
| 109 |
ParameterListPtr amesosParameterList = sublist(this->ParameterList_,"Amesos"); |
| 110 |
if (amesosParameterList->isSublist(this->ParameterList_->get("Solver","Klu"))) amesosParameterList = sublist(amesosParameterList,this->ParameterList_->get("Solver","Klu")); |
| 111 |
AmesosSolver_->SetParameters(*amesosParameterList); |
| 112 |
} |
| 113 |
|
| 114 |
} |
| 115 |
|
| 116 |
#endif |