10 #include "Teko_MLPreconditionerFactory.hpp"
12 #include "Teko_MLLinearOp.hpp"
14 #include "ml_include.h"
15 #include "ml_MultiLevelPreconditioner.h"
16 #include "ml_epetra_utils.h"
17 #include "ml_RowMatrix.h"
19 #include "Thyra_get_Epetra_Operator.hpp"
27 MLPreconditionerState::MLPreconditionerState() : isFilled_(false) {}
30 mlComm_ = Teuchos::rcpWithDealloc(comm, Teuchos::deallocFunctorDelete<ML_Comm>(cleanup_ML_Comm));
35 Teuchos::rcpWithDealloc(op, Teuchos::deallocFunctorDelete<ML_Operator>(cleanup_ML_Operator));
42 void MLPreconditionerState::cleanup_ML_Comm(ML_Comm *mlComm) { ML_Comm_Destroy(&mlComm); }
44 void MLPreconditionerState::cleanup_ML_Operator(ML_Operator *mlOp) { ML_Operator_Destroy(&mlOp); }
51 const Teuchos::ParameterList &mainList,
52 const std::vector<Teuchos::RCP<const Teuchos::ParameterList> > &coarseningParams) {
54 std::vector<Teuchos::ParameterList> cpls(coarseningParams.size());
55 for (std::size_t i = 0; i < coarseningParams.size(); i++) cpls[i] = *coarseningParams[i];
57 mlPreconditioner_ = rcp(
new ML_Epetra::MultiLevelPreconditioner(
58 &*mlOp_, mainList, &diagonalOps_[0], &cpls[0], diagonalOps_.size()));
60 return mlPreconditioner_;
67 MLPreconditionerFactory::MLPreconditionerFactory() {}
76 Teuchos::RCP<ML_Epetra::MultiLevelPreconditioner> mlPrecOp =
80 return Teuchos::rcp(
new MLLinearOp(mlPrecOp));
89 TEUCHOS_ASSERT(not mlState.
isFilled());
91 EpetraExt::CrsMatrix_SolverMap RowMatrixColMapTrans;
93 int rowCnt = blockRowCount(blo);
94 int colCnt = blockRowCount(blo);
98 ML_Comm_Create(&mlComm);
101 ML_Operator *mlBlkMat = ML_Operator_Create(mlComm);
102 ML_Operator_BlkMatInit(mlBlkMat, mlComm, rowCnt, colCnt, ML_DESTROY_EVERYTHING);
104 std::vector<Epetra_RowMatrix *> aggMats;
105 for (
int r = 0; r < rowCnt; r++) {
106 for (
int c = 0; c < colCnt; c++) {
107 ML_Operator *tmp = 0;
108 Epetra_RowMatrix *EMat = 0;
109 std::stringstream ss;
111 ss <<
"fine_" << r <<
"_" << c;
114 Teuchos::RCP<Epetra_CrsMatrix> crsMat = Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(
115 Thyra::get_Epetra_Operator(*blo->getNonconstBlock(r, c)));
116 EMat = ML_Epetra::ModifyEpetraMatrixColMap(*crsMat, RowMatrixColMapTrans, ss.str().c_str());
118 aggMats.push_back(EMat);
121 tmp = ML_Operator_Create(mlComm);
122 ML_Operator_WrapEpetraMatrix(EMat, tmp);
125 ML_Operator_BlkMatInsert(mlBlkMat, tmp, r, c);
128 ML_Operator_BlkMatFinalize(mlBlkMat);
146 Teko_DEBUG_SCOPE(
"MLPreconditionerFactory::initializeFromParameterList", 10);
149 coarseningParams_.clear();
152 blockRowCount_ = settings.get<
int>(
"Block Row Count");
156 mainParams_ = settings.sublist(
"Smoothing Parameters");
157 mainParams_.set<Teuchos::RCP<const Teko::InverseLibrary> >(
"smoother: teko inverse library",
162 const Teuchos::ParameterList &aggSublist = settings.sublist(
"Block Aggregation");
164 for (
int block = 0; block < blockRowCount_; block++) {
166 std::stringstream ss;
167 ss <<
"Block " << block;
168 std::string sublistName = ss.str();
171 RCP<Teuchos::ParameterList> userSpec =
172 rcp(
new Teuchos::ParameterList(aggSublist.sublist(sublistName)));
173 coarseningParams_.push_back(userSpec);
void setIsFilled(bool value)
Set if ML internals been constructed yet.
void fillMLPreconditionerState(const BlockedLinearOp &blo, MLPreconditionerState &mlState) const
Fills an ML preconditioner state object.
void initializeFromParameterList(const Teuchos::ParameterList &settings)
This function builds the internals of the preconditioner factory from a parameter list...
void setAggregationMatrices(const std::vector< Epetra_RowMatrix * > &diags)
Set matrices to build multigrid hierarcy from.
Contains operator internals need for ML.
An implementation of a state object for block preconditioners.
Teuchos::RCP< ML_Epetra::MultiLevelPreconditioner > constructMLPreconditioner(const Teuchos::ParameterList &mainList, const std::vector< Teuchos::RCP< const Teuchos::ParameterList > > &coarseningParams)
Build an ML preconditioner object using the set of coarsening parameters.
virtual LinearOp buildPreconditionerOperator(BlockedLinearOp &blo, BlockPreconditionerState &state) const
Function that is called to build the preconditioner for the linear operator that is passed in...
bool isFilled() const
Has this object been filled yet.
Teuchos::RCP< const InverseLibrary > getInverseLibrary() const
Get the inverse library used by this preconditioner factory.
void setMLComm(ML_Comm *comm)
set ML Comm pointer...it will be automatically cleaned up
void setMLOperator(ML_Operator *op)
set ML Operator pointer...it will be automatically cleaned up
virtual Teuchos::RCP< PreconditionerState > buildPreconditionerState() const
Function that permits the construction of an arbitrary PreconditionerState object.