29 #ifndef __Preconditioner_H
30 #define __Preconditioner_H 1
32 #include <boost/parameter.hpp>
34 #include <feel/feelcore/parameter.hpp>
36 #include <feel/feelalg/vector.hpp>
38 #include <feel/feelalg/enums.hpp>
42 template<
typename T>
class Backend;
43 typedef Backend<double> backend_type;
44 typedef boost::shared_ptr<Backend<double> > backend_ptrtype;
71 typedef boost::shared_ptr<Preconditioner<T> > preconditioner_ptrtype;
73 typedef boost::shared_ptr<MatrixSparse<T> > sparse_matrix_ptrtype;
74 typedef boost::shared_ptr<Vector<T> > vector_ptrtype;
84 Preconditioner( std::string
const& name =
"", WorldComm
const& worldComm=Environment::worldComm() );
96 M_mat_has_changed( o.M_mat_has_changed )
102 static preconditioner_ptrtype build( std::string
const& name =
"",
BackendType = BACKEND_PETSC, WorldComm
const& worldComm=Environment::worldComm() );
127 M_mat_has_changed = o.M_mat_has_changed;
152 WorldComm
const& worldComm()
const {
return M_worldComm; }
158 virtual void apply(
const Vector<T> & x, Vector<T> & y ) = 0;
164 void apply( vector_ptrtype
const& x, vector_ptrtype& y )
166 this->
apply( *x, *y );
184 virtual std::string name()
const {
return M_name; }
186 sparse_matrix_ptrtype
const& matrix()
const {
return M_matrix; }
194 virtual void setName( std::string
const& n ) {
M_name = n; }
199 void setMatrix( sparse_matrix_ptrtype mat );
268 typedef boost::shared_ptr<Preconditioner<double> > preconditioner_ptrtype;
271 template <
typename T>
276 M_worldComm(worldComm),
278 M_preconditioner_type ( ILU_PRECOND ),
279 M_matSolverPackage_type ( MATSOLVER_PETSC ),
281 M_is_initialized ( false ),
282 M_mat_has_changed ( false )
288 template <
typename T>
296 typedef boost::shared_ptr<preconditioner_type> preconditioner_ptrtype;
300 class PreconditionerManagerImpl:
301 public std::map<std::pair<backend_ptrtype,std::string>, preconditioner_ptrtype >,
302 public boost::noncopyable
305 typedef preconditioner_ptrtype value_type;
306 typedef std::pair<backend_ptrtype,std::string> key_type;
307 typedef std::map<key_type, value_type> preconditioner_manager_type;
312 struct PreconditionerManagerDeleterImpl
314 void operator()()
const
318 VLOG(2) <<
"[PreconditionerManagerDeleter] clear PreconditionerManager done\n";
325 BOOST_PARAMETER_MEMBER_FUNCTION( ( boost::shared_ptr<Preconditioner<double> > ),
330 ( backend, (backend_ptrtype) ) )
332 ( prefix, *( boost::is_convertible<mpl::_,std::string> ),
"" )
333 ( matrix,( d_sparse_matrix_ptrtype ),d_sparse_matrix_ptrtype() )
335 ( pcfactormatsolverpackage,( MatSolverPackageType ), MATSOLVER_DEFAULT )
336 ( worldcomm, *, Environment::worldComm() )
337 ( rebuild, (
bool),
false )
343 static bool observed=
false;
351 Feel::detail::ignore_unused_variable_warning( args );
357 VLOG(2) <<
"[preconditioner] found preconditioner name=" << prefix <<
" rebuild=" << rebuild <<
"\n";
364 preconditioner_ptrtype p = Preconditioner<double>::build( prefix, backend->type(), worldcomm );
366 p->setMatSolverPackageType( pcfactormatsolverpackage );
370 p->setMatrix( matrix );
372 VLOG(2) <<
"storing preconditionerin singleton" <<
"\n";
374 backend->addDeleteObserver( p );
Preconditioner & operator=(Preconditioner const &o)
copy operator
Definition: preconditioner.hpp:116
~Preconditioner()
destructor
Definition: preconditioner.hpp:290
PreconditionerType type() const
Definition: preconditioner.hpp:179
sparse_matrix_ptrtype M_matrix
Definition: preconditioner.hpp:243
PreconditionerType
Definition: feelalg/enums.hpp:114
PreconditionerType M_preconditioner_type
Definition: preconditioner.hpp:248
base class for preconditioner
Definition: preconditioner.hpp:54
WorldComm M_worldComm
Definition: preconditioner.hpp:237
void setPrecMatrixStructure(MatrixStructure mstruct)
Definition: preconditioner.cpp:94
static singleton_type & instance()
Definition: singleton.hpp:103
MatrixStructure
Definition: feelalg/enums.hpp:146
bool initialized() const
Definition: preconditioner.hpp:147
virtual void apply(const Vector< T > &x, Vector< T > &y)=0
void setMatrix(sparse_matrix_ptrtype mat)
Definition: preconditioner.cpp:54
void setMatSolverPackageType(const MatSolverPackageType mspt)
Definition: preconditioner.cpp:81
virtual void init()
Definition: preconditioner.hpp:107
Preconditioner(std::string const &name="", WorldComm const &worldComm=Environment::worldComm())
default constructor
Definition: preconditioner.hpp:273
void setType(const PreconditionerType pct)
Definition: preconditioner.cpp:68
virtual void clear()
Definition: preconditioner.hpp:172
implement the Singleton pattern
Definition: singleton.hpp:57
Preconditioner(Preconditioner const &o)
copy constructor
Definition: preconditioner.hpp:87
void apply(vector_ptrtype const &x, vector_ptrtype &y)
Definition: preconditioner.hpp:164
MatrixStructure M_prec_matrix_structure
Definition: preconditioner.hpp:258
BackendType
Definition: feelalg/enums.hpp:77
std::string M_name
Definition: preconditioner.hpp:232
bool M_is_initialized
Definition: preconditioner.hpp:263
MatSolverPackageType M_matSolverPackage_type
Definition: preconditioner.hpp:253