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 );