1 #include "Teko_mlutils.hpp"
7 #include "Epetra_MpiComm.h"
9 #include "Epetra_SerialComm.h"
11 #include "Epetra_Vector.h"
13 #include "ml_epetra_utils.h"
14 #include "ml_op_utils.h"
16 #include "Thyra_EpetraLinearOp.hpp"
18 #include "EpetraExt_RowMatrixOut.h"
20 #include "Teuchos_XMLParameterListHelpers.hpp"
22 #include "Teko_InverseFactory.hpp"
23 #include "Teko_InverseLibrary.hpp"
25 #include "Teko_PreconditionerFactory.hpp"
26 #include "Teko_EpetraOperatorWrapper.hpp"
27 #include "Teko_SmootherPreconditionerFactory.hpp"
33 Teuchos::RCP<Epetra_Map> buildRowMap(ML_Operator * mlOp)
35 ML_Comm *comm = mlOp->comm;
38 mpi_comm = comm->USR_comm;
39 Epetra_MpiComm eComm( mpi_comm ) ;
41 Epetra_SerialComm eComm ;
45 int rowCnt = mlOp->outvec_leng;
46 return Teuchos::rcp(
new Epetra_Map(-1,rowCnt,0,eComm));
52 Teuchos::RCP<Epetra_CrsMatrix> convertToCrsMatrix(ML_Operator * mlOp,
53 const Teuchos::RCP<Epetra_Map> & rowMapArg)
55 ML_Comm *comm = mlOp->comm;
58 mpi_comm = comm->USR_comm;
59 Epetra_MpiComm eComm( mpi_comm ) ;
61 Epetra_SerialComm eComm ;
65 Teuchos::RCP<Epetra_Map> rowMap = rowMapArg;
66 if(rowMapArg==Teuchos::null)
67 rowMap = buildRowMap(mlOp);
70 Epetra_CrsMatrix * crsMatrixPtr = 0;
71 int maxNumNonzeros = 0;
74 ML_Operator2EpetraCrsMatrix(mlOp,crsMatrixPtr,maxNumNonzeros,
false,cpuTime,verbose);
76 return Teuchos::rcp(crsMatrixPtr);
79 Teko::LinearOp buildTekoBlockOp(ML_Operator * mlOp,
int level)
81 Teko_DEBUG_SCOPE(
"Teko::mlutils::buildTekoBlockOp",0);
85 int numRows = ML_Operator_BlkMatNumBlockRows(mlOp);
86 int numCols = ML_Operator_BlkMatNumBlockCols(mlOp);
88 Teko::BlockedLinearOp tekoOp = Teko::createBlockedOp();
89 Teko::beginBlockFill(tekoOp,numRows,numCols);
90 for(
int i=0;i<numRows;i++) {
91 for(
int j=0;j<numCols;j++) {
92 ML_Operator * subBlock = ML_Operator_BlkMatExtract(mlOp,i,j);
97 RCP<const Epetra_CrsMatrix> eCrsMat = convertToCrsMatrix(subBlock);
100 std::stringstream ss;
101 ss <<
"A(" << level <<
")_" << i <<
"_" << j <<
".mm";
102 EpetraExt::RowMatrixToMatrixMarketFile(ss.str().c_str(),*eCrsMat);
106 Teko::LinearOp tekoSubBlock = Thyra::epetraLinearOp(eCrsMat);
107 Teko::setBlock(i,j,tekoOp,tekoSubBlock);
111 Teko::endBlockFill(tekoOp);
113 return tekoOp.getConst();
116 int smoother(ML_Smoother *mydata,
int leng1,
double x[],
int leng2,
119 Teko_DEBUG_SCOPE(
"Teko::mlutils::smoother",10);
124 SmootherData * smootherData = (
struct SmootherData *) ML_Get_MySmootherData(mydata);
126 Epetra_Vector X(View, smootherData->Amat->OperatorDomainMap(), x);
127 Epetra_Vector Y(View, smootherData->Amat->OperatorRangeMap(),rhs);
129 smootherData->smootherOperator->Apply(Y,X);
134 Teuchos::RCP<Teko::InverseFactory> ML_Gen_Init_Teko_Prec(
const std::string smoothName,
const Teko::InverseLibrary & invLib)
136 Teko_DEBUG_SCOPE(
"Teko::mlutils::ML_Gen_Init_Teko_Prec",10);
143 Teuchos::RCP<Teko::PreconditionerFactory> precFact;
144 Teuchos::RCP<Teko::InverseFactory> invFact = invLib.getInverseFactory(smoothName);
150 void ML_Destroy_Smoother_Teko(
void * data)
157 int ML_Gen_Smoother_Teko(ML *ml,
int level,
int pre_or_post,
int ntimes,
const Teuchos::RCP<const Teuchos::ParameterList> & tekoPL,
158 const Teuchos::RCP<const Teko::InverseLibrary> & invLib_in,
const std::string & inverse,
bool isBlocked)
160 Teko_DEBUG_SCOPE(
"Teko::mlutils::ML_Gen_Smoother_Teko",10);
161 ML_Operator * BlkMat = &(ml->Amat[level]);
163 Teuchos::RCP<const Teko::InverseLibrary> invLib;
164 if(invLib_in ==Teuchos::null) {
166 Teuchos::RCP<Teko::InverseLibrary> ncInvLib = Teko::InverseLibrary::buildFromParameterList(*tekoPL);
167 ncInvLib->setRequestHandler(rh);
169 invLib = ncInvLib.getConst();
176 Teko::LinearOp tekoAmat;
179 tekoAmat = Teko::mlutils::buildTekoBlockOp(BlkMat,level);
183 Teuchos::RCP<const Epetra_CrsMatrix> eCrsMat = convertToCrsMatrix(BlkMat);
184 tekoAmat = Thyra::epetraLinearOp(eCrsMat);
192 Teuchos::RCP<Teko::InverseFactory> invFact = ML_Gen_Init_Teko_Prec(inverse,*invLib);
193 Teuchos::RCP<Teko::RequestHandler> rh = invFact->getRequestHandler();
197 Teko::LinearOp smootherOp = Teko::buildSmootherLinearOp(tekoAmat,precOp,ntimes,
true);
202 int ret_val = ML_Set_Smoother(ml,level, pre_or_post, (
void*) data, Teko::mlutils::smoother, NULL);
203 ml->post_smoother[level].data_destroy = ML_Destroy_Smoother_Teko;
Implements the Epetra_Operator interface with a Thyra LinearOperator. This enables the use of absrtac...
InverseLinearOp buildInverse(const InverseFactory &factory, const LinearOp &A)
Build an inverse operator using a factory and a linear operator.