Commit efea9816 authored by malossi's avatar malossi
Browse files

Adding preconditionerCreated() method to verify if the preconditioner has been...

Adding preconditionerCreated() method to verify if the preconditioner has been created. This is necessary for AztecOO preconditioner that is not an Epetra_Operator.

Plus some cleaning in all the preconditioner classes.
parent 6cfb35f5
......@@ -29,17 +29,14 @@
#include "EpetraPreconditioner.hpp"
namespace LifeV
{
// namespace Epetra
// {
namespace LifeV {
EpetraPreconditioner::EpetraPreconditioner(const Epetra_Comm* comm):
M_displayer(comm),
M_overlapLevel(0),
M_Oper(),
M_List()
M_List(),
M_preconditionerCreated( false )
{
}
......@@ -47,11 +44,11 @@ EpetraPreconditioner::EpetraPreconditioner( EpetraPreconditioner& P, const Epet
M_displayer(comm),
M_overlapLevel(P.getOverlapLevel()),
M_Oper(P.M_Oper),
M_List(P.getList())
M_List(P.getList()),
M_preconditionerCreated( P.M_preconditionerCreated )
{
}
EpetraPreconditioner::~EpetraPreconditioner()
{
}
......@@ -74,5 +71,10 @@ EpetraPreconditioner::getOverlapLevel() const
return M_overlapLevel;
}
// } // namespace Epetra
bool
EpetraPreconditioner::preconditionerCreated()
{
return M_preconditionerCreated;
}
} // namespace LifeV
......@@ -79,12 +79,7 @@ public:
EpetraPreconditioner(EpetraPreconditioner& P, const Epetra_Comm* comm=0);
//! constructor from matrix A.
//! @param A EpetraMatrix<double> matrix upon which construct the preconditioner
// EpetraPreconditioner(operator_type& A);
//! default virtual destructor
virtual ~EpetraPreconditioner();
//@}
......@@ -116,35 +111,28 @@ public:
virtual void setSolver( SolverTrilinos& /*solver*/ ) {}
// Teuchos list management
void setList(Teuchos::ParameterList list);
const Teuchos::ParameterList& getList() const;
const int& getOverlapLevel() const;
protected:
Displayer M_displayer;
//! Return if the preconditioner has been created
/*!
* @return true if the preconditioner has been created.
*/
bool preconditionerCreated();
int M_overlapLevel;
protected:
Displayer M_displayer;
int M_overlapLevel;
operator_raw_type::matrix_ptrtype M_Oper;
Teuchos::ParameterList M_List;
private:
Teuchos::ParameterList M_List;
bool M_preconditionerCreated;
};
// } // namespace Epetra
//typedef boost::shared_ptr<EpetraPreconditioner> prec_ptr;
typedef singleton<factory<EpetraPreconditioner, std::string> > PRECFactory;
} // namespace LifeV
#endif
......@@ -29,11 +29,7 @@
#include "IfpackPreconditioner.hpp"
namespace LifeV
{
namespace LifeV {
IfpackPreconditioner::IfpackPreconditioner():
super (),
......@@ -44,13 +40,10 @@ IfpackPreconditioner::IfpackPreconditioner():
IfpackPreconditioner::~IfpackPreconditioner()
{}
void
IfpackPreconditioner::setDataFromGetPot( const GetPot& dataFile,
const std::string& section )
{
//! See http://trilinos.sandia.gov/packages/docs/r9.0/packages/ifpack/doc/html/index.html
//! for more informations on the parameters
......@@ -58,7 +51,6 @@ IfpackPreconditioner::setDataFromGetPot( const GetPot& dataFile,
M_overlapLevel = this->M_List.get("overlap level", -1);
M_precType = this->M_List.get("prectype", "Amesos");
}
int
......@@ -75,23 +67,25 @@ IfpackPreconditioner::buildPreconditioner(operator_type& oper)
// M_Prec.reset(new prec_type(&A.getEpetraMatrix(), OverlapLevel));
if ( !M_Prec.get() )
{ //! if not filled, I do not know how to diagonalize.
ERROR_MSG( "Preconditioner not set, something went wrong in its computation\n" );
}
{ //! if not filled, I do not know how to diagonalize.
ERROR_MSG( "Preconditioner not set, something went wrong in its computation\n" );
}
IFPACK_CHK_ERR(M_Prec->SetParameters(this->M_List));
IFPACK_CHK_ERR(M_Prec->Initialize());
IFPACK_CHK_ERR(M_Prec->Compute());
return EXIT_SUCCESS;
}
this->M_preconditionerCreated = true;
return ( EXIT_SUCCESS );
}
double
Real
IfpackPreconditioner::Condest()
{
return M_Prec->Condest();
}
EpetraPreconditioner::prec_raw_type*
IfpackPreconditioner::getPrec()
{
......@@ -103,9 +97,9 @@ IfpackPreconditioner::precReset()
{
M_Oper.reset();
M_Prec.reset();
}
this->M_preconditionerCreated = false;
}
void
createIfpackList( const GetPot& dataFile,
......@@ -122,8 +116,6 @@ createIfpackList( const GetPot& dataFile,
list.set("overlap level", overlapLevel);
bool displayList = dataFile((section + "/displayList").data(), false);
// std::cout << section + "/displayList " << displayList <<std::endl;
std::string relaxationType = dataFile((section + "/ifpack/relaxation/type").data(), "Jacobi");
int relaxationSweeps = dataFile((section + "/ifpack/relaxation/sweeps").data(), 1);
......@@ -137,7 +129,6 @@ createIfpackList( const GetPot& dataFile,
list.set("relaxation: min diagonal value", relaxationMinDiagValue);
list.set("relaxation: zero starting solution", relaxationZeroStartSolution);
std::string partitionerType = dataFile((section + "/ifpack/partitioner/type").data(), "metis");
int partitionerOverlap = dataFile((section + "/ifpack/partitioner/overlap").data(), 0);
int partitionerLocalParts = dataFile((section + "/ifpack/partitioner/local_parts").data(), 1);
......@@ -150,7 +141,6 @@ createIfpackList( const GetPot& dataFile,
list.set("partitioner: root node", partitionerRootNode);
list.set("partitioner: use symmetric graph", partitionerUseSymmGraph);
std::string amesosSolverType = dataFile((section + "/ifpack/amesos/solvertype").data(), "Amesos_KLU");
list.set("amesos: solver type", amesosSolverType);
......@@ -162,7 +152,6 @@ createIfpackList( const GetPot& dataFile,
double relaxValue = dataFile((section + "/ifpack/fact/relax_value").data(), 0.);
double dropTolerance = dataFile((section + "/ifpack/fact/drop_tolerance").data(), 1e-5);
list.set("fact: drop tolerance", dropTolerance);
list.set("fact: level-of-fill", levelOfFill);
list.set("fact: ilut level-of-fill", ILUTlevelOfFill);
......@@ -194,7 +183,6 @@ createIfpackList( const GetPot& dataFile,
schwarzCombineMode = Zero;
}
bool schwarzComputeCondest = dataFile((section + "/ifpack/schwarz/compute_condest").data(), true);
std::string schwarzReorderingType = dataFile((section + "/ifpack/schwarz/reordering_type").data(), "none");
bool schwarzFilterSingletons = dataFile((section + "/ifpack/schwarz/filter_singletons").data(), true);
......@@ -207,27 +195,4 @@ createIfpackList( const GetPot& dataFile,
if (displayList) list.print(std::cout);
}
// void
// IfpackPreconditioner::createList( const GetPot& /*dataFile*/ )
// {
// }
// namespace
// {
// EpetraPreconditioner* createIfpack(){ std::cout << "*******************"<< std::endl;return new IfpackPreconditioner(); }
// static bool reg = (PRECFactory::instance().registerProduct( "Ifpack", &createIfpack )
// && (std::cout << "*************** SIMONE" << std::endl) ) ;
// }
//} // namespace Epetra
} // namespace LifeV
......@@ -44,10 +44,7 @@
#include <life/lifearray/EpetraMatrix.hpp>
#include <life/lifealg/EpetraPreconditioner.hpp>
namespace LifeV
{
// namespace Epetra
// {
namespace LifeV {
class IfpackPreconditioner:
public EpetraPreconditioner
......@@ -59,9 +56,6 @@ public:
//@{
typedef EpetraPreconditioner super;
// typedef super::prec_raw_type prec_raw_type;
// typedef super::prec_type prec_type;
typedef Ifpack_Preconditioner prec_raw_type;
typedef boost::shared_ptr<prec_raw_type> prec_type;
......@@ -81,21 +75,15 @@ public:
// IfpackPreconditioner(operator_type& A);
//! default destructor
~IfpackPreconditioner();
//@}
/** @name Methods
*/
void setDataFromGetPot ( const GetPot& dataFile,
const std::string& section );
// void createList( const GetPot& dataFile,
// const std::string& section,
// Teuchos::ParameterList& list);
const std::string& section );
double Condest ();
......@@ -115,30 +103,11 @@ public:
protected:
prec_type M_Prec;
// operator_type M_Oper;
// Teuchos::ParameterList M_List;
std::string M_precType;
// int M_overlapLevel;
// static EpetraPreconditioner createIfpack()
// { std::cout << "*******************"<< std::endl;return new IfpackPreconditioner(); }
private:
// static bool regIfpack;
// static bool reg;
};
void
createIfpackList( const GetPot& dataFile,
const std::string& section,
......@@ -150,6 +119,6 @@ namespace
static bool registerIF = PRECFactory::instance().registerProduct( "Ifpack", &createIfpack );
}
// } // namespace Epetra
} // namespace LifeV
#endif
......@@ -28,11 +28,8 @@
*/
#include "MLPreconditioner.hpp"
//#ifdef HAVE_TRILINOS_ML
namespace LifeV
{
namespace LifeV {
MLPreconditioner::MLPreconditioner():
super(),
......@@ -44,16 +41,6 @@ MLPreconditioner::MLPreconditioner():
MLPreconditioner::~MLPreconditioner()
{}
// MLPreconditioner::MLPreconditioner(operator_type& oper):
// M_Prec(),
// M_Oper()
// {
// buildPreconditioner(oper);
// }
void
MLPreconditioner::setDataFromGetPot( const GetPot& dataFile,
const std::string& section)
......@@ -67,11 +54,8 @@ MLPreconditioner::setDataFromGetPot( const GetPot& dataFile,
Teuchos::ParameterList& SmootherIFSubList = M_List.sublist("smoother: ifpack list");
createIfpackList(dataFile, section, SmootherIFSubList);
}
int
MLPreconditioner::buildPreconditioner(operator_type& oper)
{
......@@ -81,27 +65,27 @@ MLPreconditioner::buildPreconditioner(operator_type& oper)
M_Prec.reset(new prec_raw_type(*M_Oper, this->getList(), true));
if (M_analyze)
{
ML_Epetra::MultiLevelPreconditioner* prec;
prec = dynamic_cast<ML_Epetra::MultiLevelPreconditioner*> (M_Prec.get());
int NumPreCycles = 5;
int NumPostCycles = 1;
int NumMLCycles = 10;
prec->AnalyzeHierarchy(true, NumPreCycles, NumPostCycles, NumMLCycles);
//prec->TestSmoothers();
}
// ML_CHK_ERR(M_Prec->SetParameters(M_List));
{
ML_Epetra::MultiLevelPreconditioner* prec;
prec = dynamic_cast<ML_Epetra::MultiLevelPreconditioner*> (M_Prec.get());
int NumPreCycles = 5;
int NumPostCycles = 1;
int NumMLCycles = 10;
prec->AnalyzeHierarchy(true, NumPreCycles, NumPostCycles, NumMLCycles);
//prec->TestSmoothers();
}
// ML_CHK_ERR(M_Prec->SetParameters(M_List));
// M_Prec->Initialize();
// M_Prec->Compute();
return EXIT_SUCCESS;
this->M_preconditionerCreated = true;
return ( EXIT_SUCCESS );
}
double
Real
MLPreconditioner::Condest()
{
return 0.;
......@@ -118,22 +102,15 @@ MLPreconditioner::precReset()
{
M_Oper.reset();
M_Prec.reset();
}
this->M_preconditionerCreated = false;
}
void
createMLList( const GetPot& dataFile,
const std::string& section,
Teuchos::ParameterList& list)
{
list.setName("ML paramters list");
std::string defList = dataFile((section + "/ML/default_parameter_list").data(), "SA");
......@@ -298,7 +275,6 @@ createMLList( const GetPot& dataFile,
// Load-balancing Options
int RepartitionEnable = dataFile((section + "/ML/repartition/enable").data(), 0, found);
if (found) list.set("repartition: enable", RepartitionEnable);
......@@ -323,13 +299,11 @@ createMLList( const GetPot& dataFile,
if (MLPrintParameterList)
{
std::cout << " Parameters List: " << std::endl;
list.print(std::cout);
std::cout << std::endl;
}
{
std::cout << " Parameters List: " << std::endl;
list.print(std::cout);
std::cout << std::endl;
}
}
} // namespace LifeV
//#endif //#ifdef HAVE_TRILINOS_ML
......@@ -31,8 +31,6 @@
#ifndef _MLPRECONDITIONER_HPP_
#define _MLPRECONDITIONER_HPP_
//#ifdef HAVE_TRILINOS_ML
#include <boost/shared_ptr.hpp>
// #include <Ifpack_config.h>
......@@ -44,15 +42,12 @@
#include <ml_MultiLevelPreconditioner.h>
#include <life/lifecore/GetPot.hpp>
#include <life/lifearray/EpetraMatrix.hpp>
#include <life/lifealg/EpetraPreconditioner.hpp>
#include <life/lifealg/IfpackPreconditioner.hpp>
namespace LifeV
{
namespace LifeV{
class MLPreconditioner:
public EpetraPreconditioner
......@@ -141,5 +136,4 @@ namespace
} // namespace LifeV
//#endif // HAVE_TRILINOS_ML
#endif
......@@ -303,7 +303,7 @@ SolverTrilinos::printStatus()
bool
SolverTrilinos::isPrecSet() const
{
return ( M_prec.get() !=0 && M_prec->getPrec() != 0 );
return ( M_prec.get() !=0 && M_prec->preconditionerCreated() );
}
void SolverTrilinos::buildPreconditioner( matrix_ptrtype& prec)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment