| 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_AMESOS2SOLVEREPETRA_DEF_HPP |
| 11 |
#define _FROSCH_AMESOS2SOLVEREPETRA_DEF_HPP |
| 12 |
|
| 13 |
#include <FROSch_Amesos2SolverEpetra_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 |
Amesos2SolverEpetra<SC,LO,GO,NO>::~Amesos2SolverEpetra() |
| 24 |
{ |
| 25 |
Amesos2Solver_.reset(); |
| 26 |
} |
| 27 |
|
| 28 |
template<class SC,class LO,class GO,class NO> |
| 29 |
int Amesos2SolverEpetra<SC,LO,GO,NO>::initialize() |
| 30 |
{ |
| 31 |
FROSCH_TIMER_START_SOLVER(initializeTime,"Amesos2SolverEpetra::initialize"); |
| 32 |
this->IsInitialized_ = true; |
| 33 |
this->IsComputed_ = false; |
| 34 |
Amesos2Solver_->symbolicFactorization(); |
| 35 |
return 0; |
| 36 |
} |
| 37 |
|
| 38 |
template<class SC,class LO,class GO,class NO> |
| 39 |
int Amesos2SolverEpetra<SC,LO,GO,NO>::compute() |
| 40 |
{ |
| 41 |
FROSCH_TIMER_START_SOLVER(computeTime,"Amesos2SolverEpetra::compute"); |
| 42 |
FROSCH_ASSERT(this->IsInitialized_,"FROSch::Amesos2SolverEpetra: !this->IsInitialized_"); |
| 43 |
this->IsComputed_ = true; |
| 44 |
Amesos2Solver_->numericFactorization(); |
| 45 |
return 0; |
| 46 |
} |
| 47 |
|
| 48 |
template<class SC,class LO,class GO,class NO> |
| 49 |
void Amesos2SolverEpetra<SC,LO,GO,NO>::apply(const XMultiVector &x, |
| 50 |
XMultiVector &y, |
| 51 |
ETransp mode, |
| 52 |
SC alpha, |
| 53 |
SC beta) const |
| 54 |
{ |
| 55 |
FROSCH_TIMER_START_SOLVER(applyTime,"Amesos2SolverEpetra::apply"); |
| 56 |
FROSCH_ASSERT(this->IsComputed_,"FROSch::Amesos2SolverEpetra: !this->IsComputed_."); |
| 57 |
|
| 58 |
const EpetraMultiVectorT<GO,NO> * xEpetraMultiVectorX = dynamic_cast<const EpetraMultiVectorT<GO,NO> *>(&x); |
| 59 |
FROSCH_ASSERT(xEpetraMultiVectorX,"FROSch::Amesos2SolverEpetra: dynamic_cast failed."); |
| 60 |
RCP<EMultiVector> epetraMultiVectorX = xEpetraMultiVectorX->getEpetra_MultiVector(); |
| 61 |
|
| 62 |
if (Y_.is_null()) Y_ = XMultiVectorFactory::Build(y.getMap(),x.getNumVectors()); |
| 63 |
EpetraMultiVectorT<GO,NO> * xEpetraMultiVectorY = dynamic_cast<EpetraMultiVectorT<GO,NO> *>(Y_.get()); |
| 64 |
FROSCH_ASSERT(xEpetraMultiVectorY,"FROSch::Amesos2SolverEpetra: dynamic_cast failed."); |
| 65 |
RCP<EMultiVector> epetraMultiVectorY = xEpetraMultiVectorY->getEpetra_MultiVector(); |
| 66 |
|
| 67 |
Amesos2Solver_->setX(epetraMultiVectorY); |
| 68 |
Amesos2Solver_->setB(epetraMultiVectorX); |
| 69 |
|
| 70 |
FROSCH_ASSERT(mode==NO_TRANS,"FROSch::Amesos2SolverEpetra: mode!=NO_TRANS"); |
| 71 |
Amesos2Solver_->solve(); // What about solving with transposed matrices? |
| 72 |
|
| 73 |
y.update(alpha,*Y_,beta); |
| 74 |
} |
| 75 |
|
| 76 |
template<class SC,class LO,class GO,class NO> |
| 77 |
int Amesos2SolverEpetra<SC,LO,GO,NO>::updateMatrix(ConstXMatrixPtr k, |
| 78 |
bool reuseInitialize) |
| 79 |
{ |
| 80 |
FROSCH_TIMER_START_SOLVER(updateMatrixTime,"Amesos2SolverEpetra::updateMatrix"); |
| 81 |
this->K_ = k; |
| 82 |
FROSCH_ASSERT(!this->K_.is_null(),"FROSch::Amesos2SolverEpetra: K_ is null."); |
| 83 |
|
| 84 |
const CrsMatrixWrap<SC,LO,GO,NO>& crsOp = dynamic_cast<const CrsMatrixWrap<SC,LO,GO,NO>&>(*this->K_); |
| 85 |
const EpetraCrsMatrixT<GO,NO>& xEpetraMat = dynamic_cast<const EpetraCrsMatrixT<GO,NO>&>(*crsOp.getCrsMatrix()); |
| 86 |
ECrsMatrixPtr epetraMat = xEpetraMat.getEpetra_CrsMatrixNonConst(); |
| 87 |
TEUCHOS_TEST_FOR_EXCEPT(epetraMat.is_null()); |
| 88 |
|
| 89 |
if (reuseInitialize) { |
| 90 |
Amesos2Solver_->setA(epetraMat,Amesos2::SYMBFACT); |
| 91 |
} else { |
| 92 |
Amesos2Solver_->setA(epetraMat,Amesos2::CLEAN); |
| 93 |
} |
| 94 |
return 0; |
| 95 |
} |
| 96 |
|
| 97 |
template<class SC,class LO,class GO,class NO> |
| 98 |
Amesos2SolverEpetra<SC,LO,GO,NO>::Amesos2SolverEpetra(ConstXMatrixPtr k, |
| 99 |
ParameterListPtr parameterList, |
| 100 |
string description) : |
| 101 |
Solver<SC,LO,GO,NO> (k,parameterList,description) |
| 102 |
{ |
| 103 |
FROSCH_TIMER_START_SOLVER(Amesos2SolverEpetraTime,"Amesos2SolverEpetra::Amesos2SolverEpetra"); |
| 104 |
FROSCH_ASSERT(!this->K_.is_null(),"FROSch::Amesos2SolverEpetra: K_ is null."); |
| 105 |
FROSCH_ASSERT(this->K_->getRowMap()->lib()==UseEpetra,"FROSch::Amesos2SolverEpetra: Not compatible with Tpetra.") |
| 106 |
|
| 107 |
const CrsMatrixWrap<SC,LO,GO,NO>& crsOp = dynamic_cast<const CrsMatrixWrap<SC,LO,GO,NO>&>(*this->K_); |
| 108 |
const EpetraCrsMatrixT<GO,NO>& xEpetraMat = dynamic_cast<const EpetraCrsMatrixT<GO,NO>&>(*crsOp.getCrsMatrix()); |
| 109 |
ECrsMatrixPtr epetraMat = xEpetraMat.getEpetra_CrsMatrixNonConst(); |
| 110 |
TEUCHOS_TEST_FOR_EXCEPT(epetraMat.is_null()); |
| 111 |
|
| 112 |
EMultiVectorPtr xTmp; |
| 113 |
EMultiVectorPtr bTmp; |
| 114 |
|
| 115 |
ParameterListPtr amesos2ParameterList = sublist(this->ParameterList_,"Amesos2"); |
| 116 |
if (amesos2ParameterList->isSublist(this->ParameterList_->get("Solver","Klu"))) amesos2ParameterList = sublist(amesos2ParameterList,this->ParameterList_->get("Solver","Klu")); |
| 117 |
amesos2ParameterList->setName("Amesos2"); |
| 118 |
|
| 119 |
Amesos2Solver_ = Amesos2::create<ECrsMatrix,EMultiVector>(this->ParameterList_->get("Solver","Klu"),epetraMat,xTmp,bTmp); |
| 120 |
Amesos2Solver_->setParameters(amesos2ParameterList); |
| 121 |
} |
| 122 |
|
| 123 |
} |
| 124 |
|
| 125 |
#endif |