1 #include "Teko_MLPreconditionerFactory.hpp"
3 #include "Teko_MLLinearOp.hpp"
5 #include "ml_include.h"
6 #include "ml_MultiLevelPreconditioner.h"
7 #include "ml_epetra_utils.h"
8 #include "ml_RowMatrix.h"
10 #include "Thyra_get_Epetra_Operator.hpp"
18 MLPreconditionerState::MLPreconditionerState() : isFilled_(false) {}
21 mlComm_ = Teuchos::rcpWithDealloc(comm, Teuchos::deallocFunctorDelete<ML_Comm>(cleanup_ML_Comm));
26 Teuchos::rcpWithDealloc(op, Teuchos::deallocFunctorDelete<ML_Operator>(cleanup_ML_Operator));
33 void MLPreconditionerState::cleanup_ML_Comm(ML_Comm *mlComm) { ML_Comm_Destroy(&mlComm); }
35 void MLPreconditionerState::cleanup_ML_Operator(ML_Operator *mlOp) { ML_Operator_Destroy(&mlOp); }
42 const Teuchos::ParameterList &mainList,
43 const std::vector<Teuchos::RCP<const Teuchos::ParameterList> > &coarseningParams) {
45 std::vector<Teuchos::ParameterList> cpls(coarseningParams.size());
46 for (std::size_t i = 0; i < coarseningParams.size(); i++) cpls[i] = *coarseningParams[i];
48 mlPreconditioner_ = rcp(
new ML_Epetra::MultiLevelPreconditioner(
49 &*mlOp_, mainList, &diagonalOps_[0], &cpls[0], diagonalOps_.size()));
51 return mlPreconditioner_;
58 MLPreconditionerFactory::MLPreconditionerFactory() {}
67 Teuchos::RCP<ML_Epetra::MultiLevelPreconditioner> mlPrecOp =
71 return Teuchos::rcp(
new MLLinearOp(mlPrecOp));
80 TEUCHOS_ASSERT(not mlState.
isFilled());
82 EpetraExt::CrsMatrix_SolverMap RowMatrixColMapTrans;
84 int rowCnt = blockRowCount(blo);
85 int colCnt = blockRowCount(blo);
89 ML_Comm_Create(&mlComm);
92 ML_Operator *mlBlkMat = ML_Operator_Create(mlComm);
93 ML_Operator_BlkMatInit(mlBlkMat, mlComm, rowCnt, colCnt, ML_DESTROY_EVERYTHING);
95 std::vector<Epetra_RowMatrix *> aggMats;
96 for (
int r = 0; r < rowCnt; r++) {
97 for (
int c = 0; c < colCnt; c++) {
99 Epetra_RowMatrix *EMat = 0;
100 std::stringstream ss;
102 ss <<
"fine_" << r <<
"_" << c;
105 Teuchos::RCP<Epetra_CrsMatrix> crsMat = Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(
106 Thyra::get_Epetra_Operator(*blo->getNonconstBlock(r, c)));
107 EMat = ML_Epetra::ModifyEpetraMatrixColMap(*crsMat, RowMatrixColMapTrans, ss.str().c_str());
109 aggMats.push_back(EMat);
112 tmp = ML_Operator_Create(mlComm);
113 ML_Operator_WrapEpetraMatrix(EMat, tmp);
116 ML_Operator_BlkMatInsert(mlBlkMat, tmp, r, c);
119 ML_Operator_BlkMatFinalize(mlBlkMat);
137 Teko_DEBUG_SCOPE(
"MLPreconditionerFactory::initializeFromParameterList", 10);
140 coarseningParams_.clear();
143 blockRowCount_ = settings.get<
int>(
"Block Row Count");
147 mainParams_ = settings.sublist(
"Smoothing Parameters");
148 mainParams_.set<Teuchos::RCP<const Teko::InverseLibrary> >(
"smoother: teko inverse library",
153 const Teuchos::ParameterList &aggSublist = settings.sublist(
"Block Aggregation");
155 for (
int block = 0; block < blockRowCount_; block++) {
157 std::stringstream ss;
158 ss <<
"Block " << block;
159 std::string sublistName = ss.str();
162 RCP<Teuchos::ParameterList> userSpec =
163 rcp(
new Teuchos::ParameterList(aggSublist.sublist(sublistName)));
164 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.