libMesh
Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | Static Private Member Functions | List of all members
libMesh::PetscPreconditioner< T > Class Template Reference

This class provides an interface to the suite of preconditioners available from PETSc. More...

#include <petsc_preconditioner.h>

Inheritance diagram for libMesh::PetscPreconditioner< T >:
[legend]

Public Member Functions

 PetscPreconditioner (const libMesh::Parallel::Communicator &comm_in)
 Constructor. More...
 
virtual ~PetscPreconditioner ()
 Destructor. More...
 
virtual void apply (const NumericVector< T > &x, NumericVector< T > &y) override
 Computes the preconditioned vector y based on input vector x. More...
 
virtual void clear () override
 Release all memory and clear data structures. More...
 
virtual void init () override
 Initialize data structures if not done so already. More...
 
PC pc ()
 
bool initialized () const
 
virtual void setup ()
 This is called every time the "operator might have changed". More...
 
void set_matrix (SparseMatrix< Number > &mat)
 Sets the matrix to be preconditioned. More...
 
PreconditionerType type () const
 
void set_type (const PreconditionerType pct)
 Sets the type of preconditioner to use. More...
 
const Parallel::Communicatorcomm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static void set_petsc_preconditioner_type (const PreconditionerType &preconditioner_type, PC &pc)
 Tells PETSc to use the user-specified preconditioner. More...
 
static std::unique_ptr< Preconditioner< T > > build_preconditioner (const libMesh::Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
 Builds a Preconditioner using the linear solver package specified by solver_package, returning the result wrapped in a std::unique_ptr for safety. More...
 
static Preconditioner< T > * build (const libMesh::Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
 Builds a Preconditioner using the linear solver package specified by solver_package. More...
 
static std::string get_info ()
 Gets a string containing the reference information. More...
 
static void print_info (std::ostream &out=libMesh::out)
 Prints the reference information, by default to libMesh::out. More...
 
static unsigned int n_objects ()
 Prints the number of outstanding (created, but not yet destroyed) objects. More...
 
static void enable_print_counter_info ()
 Methods to enable/disable the reference counter output from print_info() More...
 
static void disable_print_counter_info ()
 

Protected Types

typedef std::map< std::string, std::pair< unsigned int, unsigned int > > Counts
 Data structure to log the information. More...
 

Protected Member Functions

void increment_constructor_count (const std::string &name)
 Increments the construction counter. More...
 
void increment_destructor_count (const std::string &name)
 Increments the destruction counter. More...
 

Protected Attributes

PC _pc
 Preconditioner context. More...
 
Mat _mat
 PETSc Mat pulled out of the _matrix object during init(). More...
 
SparseMatrix< T > * _matrix
 The matrix P... More...
 
PreconditionerType _preconditioner_type
 Enum stating with type of preconditioner to use. More...
 
bool _is_initialized
 Flag indicating if the data structures have been initialized. More...
 
const Parallel::Communicator_communicator
 

Static Protected Attributes

static Counts _counts
 Actually holds the data. More...
 
static Threads::atomic< unsigned int > _n_objects
 The number of objects. More...
 
static Threads::spin_mutex _mutex
 Mutual exclusion object to enable thread-safe reference counting. More...
 
static bool _enable_print_counter
 Flag to control whether reference count information is printed when print_info is called. More...
 

Static Private Member Functions

static void set_petsc_subpreconditioner_type (PCType type, PC &pc)
 Some PETSc preconditioners (ILU, LU) don't work in parallel. More...
 
static void set_petsc_subpreconditioner_type (const PCType type, PC &pc)
 

Detailed Description

template<typename T>
class libMesh::PetscPreconditioner< T >

This class provides an interface to the suite of preconditioners available from PETSc.

All overridden virtual functions are documented in preconditioner.h.

Author
Derek Gaston
Date
2009

Definition at line 63 of file petsc_preconditioner.h.

Member Typedef Documentation

◆ Counts

typedef std::map<std::string, std::pair<unsigned int, unsigned int> > libMesh::ReferenceCounter::Counts
protectedinherited

Data structure to log the information.

The log is identified by the class name.

Definition at line 117 of file reference_counter.h.

Constructor & Destructor Documentation

◆ PetscPreconditioner()

template<typename T >
libMesh::PetscPreconditioner< T >::PetscPreconditioner ( const libMesh::Parallel::Communicator comm_in)

Constructor.

Initializes PetscPreconditioner data structures

Definition at line 129 of file petsc_preconditioner.h.

129  :
130  Preconditioner<T>(comm_in),
131  _pc(PETSC_NULL)
132 {
133 }
PC _pc
Preconditioner context.

◆ ~PetscPreconditioner()

template<typename T >
libMesh::PetscPreconditioner< T >::~PetscPreconditioner ( )
virtual

Destructor.

Definition at line 139 of file petsc_preconditioner.h.

140 {
141  this->clear ();
142 }
virtual void clear() override
Release all memory and clear data structures.

Member Function Documentation

◆ apply()

template<typename T >
virtual void libMesh::PetscPreconditioner< T >::apply ( const NumericVector< T > &  x,
NumericVector< T > &  y 
)
overridevirtual

Computes the preconditioned vector y based on input vector x.

This is usually done by solving $ Py=x $ to get the action of $ P^-1 x $.

Implements libMesh::Preconditioner< T >.

◆ build()

template<typename T>
static Preconditioner<T>* libMesh::Preconditioner< T >::build ( const libMesh::Parallel::Communicator comm,
const SolverPackage  solver_package = libMesh::default_solver_package() 
)
staticinherited

Builds a Preconditioner using the linear solver package specified by solver_package.

Deprecated:
Use build_preconditioner() instead.

◆ build_preconditioner()

template<typename T>
static std::unique_ptr<Preconditioner<T> > libMesh::Preconditioner< T >::build_preconditioner ( const libMesh::Parallel::Communicator comm,
const SolverPackage  solver_package = libMesh::default_solver_package() 
)
staticinherited

Builds a Preconditioner using the linear solver package specified by solver_package, returning the result wrapped in a std::unique_ptr for safety.

◆ clear()

template<typename T >
virtual void libMesh::PetscPreconditioner< T >::clear ( )
overridevirtual

Release all memory and clear data structures.

Reimplemented from libMesh::Preconditioner< T >.

◆ comm()

const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const
inherited

◆ disable_print_counter_info()

static void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

◆ enable_print_counter_info()

static void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

Methods to enable/disable the reference counter output from print_info()

◆ get_info()

static std::string libMesh::ReferenceCounter::get_info ( )
staticinherited

Gets a string containing the reference information.

◆ increment_constructor_count()

void libMesh::ReferenceCounter::increment_constructor_count ( const std::string &  name)
protectedinherited

Increments the construction counter.

Should be called in the constructor of any derived class that will be reference counted.

Definition at line 181 of file reference_counter.h.

References libMesh::ReferenceCounter::_counts, libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::ReferenceCountedObject().

182 {
183  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
184  std::pair<unsigned int, unsigned int> & p = _counts[name];
185 
186  p.first++;
187 }
std::string name(const ElemQuality q)
static Counts _counts
Actually holds the data.
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.

◆ increment_destructor_count()

void libMesh::ReferenceCounter::increment_destructor_count ( const std::string &  name)
protectedinherited

Increments the destruction counter.

Should be called in the destructor of any derived class that will be reference counted.

Definition at line 194 of file reference_counter.h.

References libMesh::ReferenceCounter::_counts, libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::~ReferenceCountedObject().

195 {
196  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
197  std::pair<unsigned int, unsigned int> & p = _counts[name];
198 
199  p.second++;
200 }
std::string name(const ElemQuality q)
static Counts _counts
Actually holds the data.
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.

◆ init()

template<typename T >
virtual void libMesh::PetscPreconditioner< T >::init ( )
overridevirtual

Initialize data structures if not done so already.

Note
This MUST be called before the preconditioning object is used.

Reimplemented from libMesh::Preconditioner< T >.

◆ initialized()

template<typename T>
bool libMesh::Preconditioner< T >::initialized ( ) const
inherited
Returns
true if the data structures are initialized, false otherwise.

Definition at line 106 of file preconditioner.h.

106 { return _is_initialized; }
bool _is_initialized
Flag indicating if the data structures have been initialized.

◆ n_objects()

static unsigned int libMesh::ReferenceCounter::n_objects ( )
staticinherited

Prints the number of outstanding (created, but not yet destroyed) objects.

Definition at line 83 of file reference_counter.h.

References libMesh::ReferenceCounter::_n_objects.

84  { return _n_objects; }
static Threads::atomic< unsigned int > _n_objects
The number of objects.

◆ n_processors()

processor_id_type libMesh::ParallelObject::n_processors ( ) const
inherited
Returns
The number of processors in the group.

Definition at line 93 of file parallel_object.h.

References libMesh::ParallelObject::_communicator, and libMesh::Parallel::Communicator::size().

Referenced by libMesh::MeshBase::partition().

94  { return cast_int<processor_id_type>(_communicator.size()); }
processor_id_type size() const
Definition: communicator.h:175
const Parallel::Communicator & _communicator

◆ pc()

template<typename T >
PC libMesh::PetscPreconditioner< T >::pc ( )
Returns
The PETSc PC object. Can be useful for implementing more advanced algorithms.

Definition at line 87 of file petsc_preconditioner.h.

References libMesh::PetscPreconditioner< T >::_pc.

87 { return _pc; }
PC _pc
Preconditioner context.

◆ print_info()

static void libMesh::ReferenceCounter::print_info ( std::ostream &  out = libMesh::out)
staticinherited

Prints the reference information, by default to libMesh::out.

◆ processor_id()

processor_id_type libMesh::ParallelObject::processor_id ( ) const
inherited

◆ set_matrix()

template<typename T >
void libMesh::Preconditioner< T >::set_matrix ( SparseMatrix< Number > &  mat)
inherited

Sets the matrix to be preconditioned.

Definition at line 181 of file preconditioner.h.

182 {
183  //If the matrix is changing then we (probably) need to reinitialize.
184  _is_initialized = false;
185  _matrix = &mat;
186 }
bool _is_initialized
Flag indicating if the data structures have been initialized.
SparseMatrix< T > * _matrix
The matrix P...

◆ set_petsc_preconditioner_type()

template<typename T >
static void libMesh::PetscPreconditioner< T >::set_petsc_preconditioner_type ( const PreconditionerType preconditioner_type,
PC &  pc 
)
static

Tells PETSc to use the user-specified preconditioner.

◆ set_petsc_subpreconditioner_type() [1/2]

template<typename T >
static void libMesh::PetscPreconditioner< T >::set_petsc_subpreconditioner_type ( PCType  type,
PC &  pc 
)
staticprivate

Some PETSc preconditioners (ILU, LU) don't work in parallel.

This function is called from set_petsc_preconditioner_type() to set additional options for those so-called sub-preconditioners. This method ends up being static so that it can be called from set_petsc_preconditioner_type(). Not sure why set_petsc_preconditioner_type() needs to be static though...

◆ set_petsc_subpreconditioner_type() [2/2]

template<typename T >
static void libMesh::PetscPreconditioner< T >::set_petsc_subpreconditioner_type ( const PCType  type,
PC &  pc 
)
staticprivate

◆ set_type()

template<typename T >
void libMesh::Preconditioner< T >::set_type ( const PreconditionerType  pct)
inherited

Sets the type of preconditioner to use.

Definition at line 190 of file preconditioner.h.

191 {
192  //If the preconditioner type changes we (probably) need to reinitialize.
193  _is_initialized = false;
194  _preconditioner_type = pct;
195 }
PreconditionerType _preconditioner_type
Enum stating with type of preconditioner to use.
bool _is_initialized
Flag indicating if the data structures have been initialized.

◆ setup()

template<typename T>
virtual void libMesh::Preconditioner< T >::setup ( )
virtualinherited

This is called every time the "operator might have changed".

This is where you need to fill in your preconditioning matrix.

Definition at line 132 of file preconditioner.h.

132 {}

◆ type()

template<typename T>
PreconditionerType libMesh::Preconditioner< T >::type ( ) const
inherited
Returns
The type of preconditioner to use.

Definition at line 142 of file preconditioner.h.

142 { return _preconditioner_type; }
PreconditionerType _preconditioner_type
Enum stating with type of preconditioner to use.

Member Data Documentation

◆ _communicator

const Parallel::Communicator& libMesh::ParallelObject::_communicator
protectedinherited

◆ _counts

Counts libMesh::ReferenceCounter::_counts
staticprotectedinherited

◆ _enable_print_counter

bool libMesh::ReferenceCounter::_enable_print_counter
staticprotectedinherited

Flag to control whether reference count information is printed when print_info is called.

Definition at line 141 of file reference_counter.h.

◆ _is_initialized

template<typename T>
bool libMesh::Preconditioner< T >::_is_initialized
protectedinherited

Flag indicating if the data structures have been initialized.

Definition at line 165 of file preconditioner.h.

Referenced by libMesh::Preconditioner< Number >::initialized().

◆ _mat

template<typename T >
Mat libMesh::PetscPreconditioner< T >::_mat
protected

PETSc Mat pulled out of the _matrix object during init().

Definition at line 104 of file petsc_preconditioner.h.

◆ _matrix

template<typename T>
SparseMatrix<T>* libMesh::Preconditioner< T >::_matrix
protectedinherited

The matrix P...

ie the matrix to be preconditioned. This is often the actual system matrix of a linear system.

Definition at line 155 of file preconditioner.h.

◆ _mutex

Threads::spin_mutex libMesh::ReferenceCounter::_mutex
staticprotectedinherited

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 135 of file reference_counter.h.

◆ _n_objects

Threads::atomic<unsigned int> libMesh::ReferenceCounter::_n_objects
staticprotectedinherited

The number of objects.

Print the reference count information when the number returns to 0.

Definition at line 130 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::n_objects(), libMesh::ReferenceCounter::ReferenceCounter(), and libMesh::ReferenceCounter::~ReferenceCounter().

◆ _pc

template<typename T >
PC libMesh::PetscPreconditioner< T >::_pc
protected

Preconditioner context.

Definition at line 99 of file petsc_preconditioner.h.

Referenced by libMesh::PetscPreconditioner< T >::pc().

◆ _preconditioner_type

template<typename T>
PreconditionerType libMesh::Preconditioner< T >::_preconditioner_type
protectedinherited

Enum stating with type of preconditioner to use.

Definition at line 160 of file preconditioner.h.

Referenced by libMesh::Preconditioner< Number >::type().


The documentation for this class was generated from the following file: