1 #include "Teko_MLLinearOp.hpp"
3 #include "Teko_EpetraOperatorWrapper.hpp"
4 #include "Teko_mlutils.hpp"
5 #include "Teko_PreconditionerLinearOp.hpp"
7 #include "ml_MultiLevelPreconditioner.h"
11 MLLinearOp::MLLinearOp(
const Teuchos::RCP<ML_Epetra::MultiLevelPreconditioner> & mlPrecOp)
14 extractConversionInformation(*mlPrecOp_);
17 void MLLinearOp::extractConversionInformation(ML_Epetra::MultiLevelPreconditioner & mlPrec)
19 const ML * ml = mlPrec.GetML();
20 const ML_Smoother * preSmoother = ml->pre_smoother;
21 const ML_Smoother * postSmoother = ml->post_smoother;
24 const mlutils::SmootherData * smootherData;
26 smootherData = (
const mlutils::SmootherData *) ML_Get_MySmootherData(preSmoother);
27 else if(postSmoother!=0)
28 smootherData = (
const mlutils::SmootherData *) ML_Get_MySmootherData(preSmoother);
30 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::runtime_error,
31 "MLLinearOp::extractConversionInformation pre and post smoother " <<
32 "are both null, cannot build operator");
34 Amat_ = Teuchos::rcp_dynamic_cast<Epetra::EpetraOperatorWrapper>(smootherData->Amat);
37 mappingStrategy_ = Amat_->getMapStrategy();
40 BlockedLinearOp bloA = toBlockedLinearOp(Amat_->getThyraOp());
41 productDomain_ = bloA->productRange();
42 productRange_ = bloA->productDomain();
46 void MLLinearOp::implicitApply(
const BlockedMultiVector & x, BlockedMultiVector & y,
47 const double alpha,
const double beta)
const
49 int columns = x->domain()->dim();
50 TEUCHOS_ASSERT(columns==y->domain()->dim());
53 if(eX_==Teuchos::null || columns!=eX_->NumVectors()) {
54 eX_ = Teuchos::rcp(
new Epetra_MultiVector(mlPrecOp_->OperatorDomainMap(),x->domain()->dim()));
55 eY_ = Teuchos::rcp(
new Epetra_MultiVector(mlPrecOp_->OperatorRangeMap(),y->domain()->dim()));
58 BlockedMultiVector yCopy;
66 mappingStrategy_->copyThyraIntoEpetra(x, *eX_);
69 mlPrecOp_->ApplyInverse(*eX_,*eY_);
72 mappingStrategy_->copyEpetraIntoThyra(*eY_, yCopy.ptr());
76 update(alpha,yCopy,beta,y);
81 void MLLinearOp::describe(Teuchos::FancyOStream & out_arg,
82 const Teuchos::EVerbosityLevel verbLevel)
const
84 out_arg <<
"MLLinearOp";
87 Teuchos::RCP<const ML_Epetra::MultiLevelPreconditioner> MLLinearOp::getMLPreconditioner()
const
92 Teuchos::RCP<ML_Epetra::MultiLevelPreconditioner> MLLinearOp::getMLPreconditioner()
97 Teuchos::RCP<const ML_Epetra::MultiLevelPreconditioner> getMLPreconditioner(
const Teko::LinearOp & lo)
99 Teko::LinearOp precOp = lo;
102 Teuchos::RCP<const Teko::PreconditionerLinearOp<double> > plo
104 if(plo!=Teuchos::null)
108 Teuchos::RCP<const MLLinearOp> mlOp = Teuchos::rcp_dynamic_cast<
const MLLinearOp>(precOp);
110 TEUCHOS_TEST_FOR_EXCEPTION(mlOp==Teuchos::null,std::runtime_error,
111 "Teko::getMLPreconditioner could not extract a MLLinearOp from the passed in argument");
113 return mlOp->getMLPreconditioner();
Teko::LinearOp getOperator() const
Get teko linear operator.
Class that wraps a PreconditionerBase object it makes it behave like a linear operator.