Reference documentation for deal.II version 9.6.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
Multigrid< VectorType > Class Template Reference

#include <deal.II/multigrid/multigrid.h>

Inheritance diagram for Multigrid< VectorType >:

Public Types

enum  Cycle { v_cycle , w_cycle , f_cycle }
 
using vector_type = VectorType
 
using const_vector_type = const VectorType
 

Public Member Functions

 Multigrid (const MGMatrixBase< VectorType > &matrix, const MGCoarseGridBase< VectorType > &coarse, const MGTransferBase< VectorType > &transfer, const MGSmootherBase< VectorType > &pre_smooth, const MGSmootherBase< VectorType > &post_smooth, const unsigned int minlevel=0, const unsigned int maxlevel=numbers::invalid_unsigned_int, Cycle cycle=v_cycle)
 
void reinit (const unsigned int minlevel, const unsigned int maxlevel)
 
void cycle ()
 
void vcycle ()
 
void set_edge_matrices (const MGMatrixBase< VectorType > &edge_out, const MGMatrixBase< VectorType > &edge_in)
 
void set_edge_in_matrix (const MGMatrixBase< VectorType > &edge_in)
 
void set_edge_flux_matrices (const MGMatrixBase< VectorType > &edge_down, const MGMatrixBase< VectorType > &edge_up)
 
unsigned int get_maxlevel () const
 
unsigned int get_minlevel () const
 
void set_maxlevel (const unsigned int)
 
void set_minlevel (const unsigned int level, bool relative=false)
 
void set_cycle (Cycle)
 
boost::signals2::connection connect_pre_smoother_step (const std::function< void(const bool, const unsigned int)> &slot)
 
boost::signals2::connection connect_residual_step (const std::function< void(const bool, const unsigned int)> &slot)
 
boost::signals2::connection connect_restriction (const std::function< void(const bool, const unsigned int)> &slot)
 
boost::signals2::connection connect_coarse_solve (const std::function< void(const bool, const unsigned int)> &slot)
 
boost::signals2::connection connect_prolongation (const std::function< void(const bool, const unsigned int)> &slot)
 
boost::signals2::connection connect_edge_prolongation (const std::function< void(const bool, const unsigned int)> &slot)
 
boost::signals2::connection connect_post_smoother_step (const std::function< void(const bool, const unsigned int)> &slot)
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 
Subscriptor functionality

Classes derived from Subscriptor provide a facility to subscribe to this object. This is mostly used by the SmartPointer class.

void subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
void unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
unsigned int n_subscriptions () const
 
template<typename StreamType >
void list_subscribers (StreamType &stream) const
 
void list_subscribers () const
 

Static Public Member Functions

static ::ExceptionBaseExcInUse (int arg1, std::string arg2, std::string arg3)
 
static ::ExceptionBaseExcNoSubscriber (std::string arg1, std::string arg2)
 

Public Attributes

MGLevelObject< VectorType > defect
 
MGLevelObject< VectorType > solution
 

Private Types

using map_value_type = decltype(counter_map)::value_type
 
using map_iterator = decltype(counter_map)::iterator
 

Private Member Functions

void level_v_step (const unsigned int level)
 
void level_step (const unsigned int level, Cycle cycle)
 
void check_no_subscribers () const noexcept
 

Private Attributes

mg::Signals signals
 
Cycle cycle_type
 
unsigned int minlevel
 
unsigned int maxlevel
 
MGLevelObject< VectorType > t
 
MGLevelObject< VectorType > defect2
 
SmartPointer< const MGMatrixBase< VectorType >, Multigrid< VectorType > > matrix
 
SmartPointer< const MGCoarseGridBase< VectorType >, Multigrid< VectorType > > coarse
 
SmartPointer< const MGTransferBase< VectorType >, Multigrid< VectorType > > transfer
 
SmartPointer< const MGSmootherBase< VectorType >, Multigrid< VectorType > > pre_smooth
 
SmartPointer< const MGSmootherBase< VectorType >, Multigrid< VectorType > > post_smooth
 
SmartPointer< const MGMatrixBase< VectorType > > edge_out
 
SmartPointer< const MGMatrixBase< VectorType > > edge_in
 
SmartPointer< const MGMatrixBase< VectorType >, Multigrid< VectorType > > edge_down
 
SmartPointer< const MGMatrixBase< VectorType >, Multigrid< VectorType > > edge_up
 
std::atomic< unsigned intcounter
 
std::map< std::string, unsigned intcounter_map
 
std::vector< std::atomic< bool > * > validity_pointers
 
const std::type_info * object_info
 

Static Private Attributes

static std::mutex mutex
 

Friends

template<int dim, typename OtherVectorType , typename TransferType >
class PreconditionMG
 

Detailed Description

template<typename VectorType>
class Multigrid< VectorType >

Implementation of the multigrid method. The implementation supports both continuous and discontinuous elements and follows the procedure described in the multigrid paper by Janssen and Kanschat.

The function which starts a multigrid cycle on the finest level is cycle(). Depending on the cycle type chosen with the constructor (see enum Cycle), this function triggers one of the cycles level_v_step() or level_step(), where the latter one can do different types of cycles.

Using this class, it is expected that the right hand side has been converted from a vector living on the locally finest level to a multilevel vector. This is a nontrivial operation, usually initiated automatically by the class PreconditionMG and performed by the classes derived from MGTransferBase.

Definition at line 162 of file multigrid.h.

Member Typedef Documentation

◆ vector_type

template<typename VectorType >
using Multigrid< VectorType >::vector_type = VectorType

Definition at line 178 of file multigrid.h.

◆ const_vector_type

template<typename VectorType >
using Multigrid< VectorType >::const_vector_type = const VectorType

Definition at line 179 of file multigrid.h.

◆ map_value_type

using Subscriptor::map_value_type = decltype(counter_map)::value_type
privateinherited

The data type used in counter_map.

Definition at line 229 of file subscriptor.h.

◆ map_iterator

using Subscriptor::map_iterator = decltype(counter_map)::iterator
privateinherited

The iterator type used in counter_map.

Definition at line 234 of file subscriptor.h.

Member Enumeration Documentation

◆ Cycle

template<typename VectorType >
enum Multigrid::Cycle

List of implemented cycle types.

Enumerator
v_cycle 

The V-cycle.

w_cycle 

The W-cycle.

f_cycle 

The F-cycle.

Definition at line 168 of file multigrid.h.

Constructor & Destructor Documentation

◆ Multigrid()

template<typename VectorType >
Multigrid< VectorType >::Multigrid ( const MGMatrixBase< VectorType > & matrix,
const MGCoarseGridBase< VectorType > & coarse,
const MGTransferBase< VectorType > & transfer,
const MGSmootherBase< VectorType > & pre_smooth,
const MGSmootherBase< VectorType > & post_smooth,
const unsigned int minlevel = 0,
const unsigned int maxlevel = numbers::invalid_unsigned_int,
Cycle cycle = v_cycle )

Constructor. transfer is an object performing prolongation and restriction. For levels in [minlevel, maxlevel] matrix has to contain valid matrices. By default the maxlevel is set to the maximal valid level.

This function already initializes the vectors which will be used later in the course of the computations. You should therefore create objects of this type as late as possible.

Member Function Documentation

◆ reinit()

template<typename VectorType >
void Multigrid< VectorType >::reinit ( const unsigned int minlevel,
const unsigned int maxlevel )

Reinit this class according to minlevel and maxlevel.

◆ cycle()

template<typename VectorType >
void Multigrid< VectorType >::cycle ( )

Execute one multigrid cycle. The type of cycle is selected by the constructor argument cycle. See the enum Cycle for available types.

◆ vcycle()

template<typename VectorType >
void Multigrid< VectorType >::vcycle ( )

Execute one step of the V-cycle algorithm. This function assumes, that the multilevel vector defect is filled with the residual of an outer defect correction scheme. This is usually taken care of by PreconditionMG). After vcycle(), the result is in the multilevel vector solution. See copy_*_mg in the MGTools namespace if you want to use these vectors yourself.

The actual work for this function is done in level_v_step().

◆ set_edge_matrices()

template<typename VectorType >
void Multigrid< VectorType >::set_edge_matrices ( const MGMatrixBase< VectorType > & edge_out,
const MGMatrixBase< VectorType > & edge_in )

Set additional matrices to correct residual computation at refinement edges. Since we only smoothen in the interior of the refined part of the mesh, the coupling across the refinement edge is missing. This coupling is provided by these two matrices.

Note
While edge_out.vmult is used, for the second argument, we use edge_in.Tvmult. Thus, edge_in should be assembled in transposed form. This saves a second sparsity pattern for edge_in. In particular, for symmetric operators, both arguments can refer to the same matrix, saving assembling of one of them.

◆ set_edge_in_matrix()

template<typename VectorType >
void Multigrid< VectorType >::set_edge_in_matrix ( const MGMatrixBase< VectorType > & edge_in)

Similar to the function above: however, only edge_in is set. This is useful if the matrix attached to this class ignores the edge constraints during vmult(), which is only used during the computation of the residual.

◆ set_edge_flux_matrices()

template<typename VectorType >
void Multigrid< VectorType >::set_edge_flux_matrices ( const MGMatrixBase< VectorType > & edge_down,
const MGMatrixBase< VectorType > & edge_up )

Set additional matrices to correct residual computation at refinement edges. These matrices originate from discontinuous Galerkin methods (see FE_DGQ etc.), where they correspond to the edge fluxes at the refinement edge between two levels.

Note
While edge_down.vmult is used, for the second argument, we use edge_up.Tvmult. Thus, edge_up should be assembled in transposed form. This saves a second sparsity pattern for edge_up. In particular, for symmetric operators, both arguments can refer to the same matrix, saving assembling of one of them.

◆ get_maxlevel()

template<typename VectorType >
unsigned int Multigrid< VectorType >::get_maxlevel ( ) const

Return the finest level for multigrid.

◆ get_minlevel()

template<typename VectorType >
unsigned int Multigrid< VectorType >::get_minlevel ( ) const

Return the coarsest level for multigrid.

◆ set_maxlevel()

template<typename VectorType >
void Multigrid< VectorType >::set_maxlevel ( const unsigned int )

Set the highest level for which the multilevel method is performed. By default, this is the finest level of the Triangulation. Accepted are values not smaller than the current minlevel.

◆ set_minlevel()

template<typename VectorType >
void Multigrid< VectorType >::set_minlevel ( const unsigned int level,
bool relative = false )

Set the coarsest level for which the multilevel method is performed. By default, this is zero. Accepted are non-negative values not larger than the current maxlevel.

If relative is true, then this function determines the number of levels used, that is, it sets minlevel to maxlevel-level.

Note
The mesh on the coarsest level must cover the whole domain. There may not be hanging nodes on minlevel.
If minlevel is set to a nonzero value, do not forget to adjust your coarse grid solver!

◆ set_cycle()

template<typename VectorType >
void Multigrid< VectorType >::set_cycle ( Cycle )

Chance cycle_type used in cycle().

◆ connect_pre_smoother_step()

template<typename VectorType >
boost::signals2::connection Multigrid< VectorType >::connect_pre_smoother_step ( const std::function< void(const bool, const unsigned int)> & slot)

Connect a function to mg::Signals::pre_smoother_step.

◆ connect_residual_step()

template<typename VectorType >
boost::signals2::connection Multigrid< VectorType >::connect_residual_step ( const std::function< void(const bool, const unsigned int)> & slot)

Connect a function to mg::Signals::residual_step.

◆ connect_restriction()

template<typename VectorType >
boost::signals2::connection Multigrid< VectorType >::connect_restriction ( const std::function< void(const bool, const unsigned int)> & slot)

Connect a function to mg::Signals::restriction.

◆ connect_coarse_solve()

template<typename VectorType >
boost::signals2::connection Multigrid< VectorType >::connect_coarse_solve ( const std::function< void(const bool, const unsigned int)> & slot)

Connect a function to mg::Signals::coarse_solve.

◆ connect_prolongation()

template<typename VectorType >
boost::signals2::connection Multigrid< VectorType >::connect_prolongation ( const std::function< void(const bool, const unsigned int)> & slot)

Connect a function to mg::Signals::prolongation.

◆ connect_edge_prolongation()

template<typename VectorType >
boost::signals2::connection Multigrid< VectorType >::connect_edge_prolongation ( const std::function< void(const bool, const unsigned int)> & slot)

Connect a function to mg::Signals::edge_prolongation.

◆ connect_post_smoother_step()

template<typename VectorType >
boost::signals2::connection Multigrid< VectorType >::connect_post_smoother_step ( const std::function< void(const bool, const unsigned int)> & slot)

Connect a function to mg::Signals::post_smoother_step.

◆ level_v_step()

template<typename VectorType >
void Multigrid< VectorType >::level_v_step ( const unsigned int level)
private

The V-cycle multigrid method. level is the level the function starts on. It will usually be called for the highest level from outside, but will then call itself recursively for level-1, unless we are on minlevel where the coarse grid solver solves the problem exactly.

◆ level_step()

template<typename VectorType >
void Multigrid< VectorType >::level_step ( const unsigned int level,
Cycle cycle )
private

The actual W-cycle or F-cycle multigrid method. level is the level the function starts on. It will usually be called for the highest level from outside, but will then call itself recursively for level-1, unless we are on minlevel where the coarse grid solver solves the problem exactly.

◆ subscribe()

void Subscriptor::subscribe ( std::atomic< bool > *const validity,
const std::string & identifier = "" ) const
inherited

Subscribes a user of the object by storing the pointer validity. The subscriber may be identified by text supplied as identifier.

Definition at line 135 of file subscriptor.cc.

◆ unsubscribe()

void Subscriptor::unsubscribe ( std::atomic< bool > *const validity,
const std::string & identifier = "" ) const
inherited

Unsubscribes a user from the object.

Note
The identifier and the validity pointer must be the same as the one supplied to subscribe().

Definition at line 155 of file subscriptor.cc.

◆ n_subscriptions()

unsigned int Subscriptor::n_subscriptions ( ) const
inlineinherited

Return the present number of subscriptions to this object. This allows to use this class for reference counted lifetime determination where the last one to unsubscribe also deletes the object.

Definition at line 300 of file subscriptor.h.

◆ list_subscribers() [1/2]

template<typename StreamType >
void Subscriptor::list_subscribers ( StreamType & stream) const
inlineinherited

List the subscribers to the input stream.

Definition at line 317 of file subscriptor.h.

◆ list_subscribers() [2/2]

void Subscriptor::list_subscribers ( ) const
inherited

List the subscribers to deallog.

Definition at line 203 of file subscriptor.cc.

◆ serialize()

template<class Archive >
void Subscriptor::serialize ( Archive & ar,
const unsigned int version )
inlineinherited

Read or write the data of this object to or from a stream for the purpose of serialization using the BOOST serialization library.

This function does not actually serialize any of the member variables of this class. The reason is that what this class stores is only who subscribes to this object, but who does so at the time of storing the contents of this object does not necessarily have anything to do with who subscribes to the object when it is restored. Consequently, we do not want to overwrite the subscribers at the time of restoring, and then there is no reason to write the subscribers out in the first place.

Definition at line 309 of file subscriptor.h.

◆ check_no_subscribers()

void Subscriptor::check_no_subscribers ( ) const
privatenoexceptinherited

Check that there are no objects subscribing to this object. If this check passes then it is safe to destroy the current object. It this check fails then this function will either abort or print an error message to deallog (by using the AssertNothrow mechanism), but will not throw an exception.

Note
Since this function is just a consistency check it does nothing in release mode.
If this function is called when there is an uncaught exception then, rather than aborting, this function prints an error message to the standard error stream and returns.

Definition at line 52 of file subscriptor.cc.

Friends And Related Symbol Documentation

◆ PreconditionMG

template<typename VectorType >
template<int dim, typename OtherVectorType , typename TransferType >
friend class PreconditionMG
friend

Definition at line 481 of file multigrid.h.

Member Data Documentation

◆ signals

template<typename VectorType >
mg::Signals Multigrid< VectorType >::signals
private

Signals for the various actions that the Multigrid algorithm uses.

Definition at line 362 of file multigrid.h.

◆ cycle_type

template<typename VectorType >
Cycle Multigrid< VectorType >::cycle_type
private

Cycle type performed by the method cycle().

Definition at line 386 of file multigrid.h.

◆ minlevel

template<typename VectorType >
unsigned int Multigrid< VectorType >::minlevel
private

Level for coarse grid solution.

Definition at line 391 of file multigrid.h.

◆ maxlevel

template<typename VectorType >
unsigned int Multigrid< VectorType >::maxlevel
private

Highest level of cells.

Definition at line 396 of file multigrid.h.

◆ defect

template<typename VectorType >
MGLevelObject<VectorType> Multigrid< VectorType >::defect

Input vector for the cycle. Contains the defect of the outer method projected to the multilevel vectors.

Definition at line 403 of file multigrid.h.

◆ solution

template<typename VectorType >
MGLevelObject<VectorType> Multigrid< VectorType >::solution

The solution update after the multigrid step.

Definition at line 408 of file multigrid.h.

◆ t

template<typename VectorType >
MGLevelObject<VectorType> Multigrid< VectorType >::t
private

Auxiliary vector.

Definition at line 414 of file multigrid.h.

◆ defect2

template<typename VectorType >
MGLevelObject<VectorType> Multigrid< VectorType >::defect2
private

Auxiliary vector for W- and F-cycles. Left uninitialized in V-cycle.

Definition at line 419 of file multigrid.h.

◆ matrix

template<typename VectorType >
SmartPointer<const MGMatrixBase<VectorType>, Multigrid<VectorType> > Multigrid< VectorType >::matrix
private

The matrix for each level.

Definition at line 425 of file multigrid.h.

◆ coarse

template<typename VectorType >
SmartPointer<const MGCoarseGridBase<VectorType>, Multigrid<VectorType> > Multigrid< VectorType >::coarse
private

The matrix for each level.

Definition at line 431 of file multigrid.h.

◆ transfer

template<typename VectorType >
SmartPointer<const MGTransferBase<VectorType>, Multigrid<VectorType> > Multigrid< VectorType >::transfer
private

Object for grid transfer.

Definition at line 437 of file multigrid.h.

◆ pre_smooth

template<typename VectorType >
SmartPointer<const MGSmootherBase<VectorType>, Multigrid<VectorType> > Multigrid< VectorType >::pre_smooth
private

The pre-smoothing object.

Definition at line 443 of file multigrid.h.

◆ post_smooth

template<typename VectorType >
SmartPointer<const MGSmootherBase<VectorType>, Multigrid<VectorType> > Multigrid< VectorType >::post_smooth
private

The post-smoothing object.

Definition at line 449 of file multigrid.h.

◆ edge_out

template<typename VectorType >
SmartPointer<const MGMatrixBase<VectorType> > Multigrid< VectorType >::edge_out
private

Edge matrix from the interior of the refined part to the refinement edge.

Note
Only vmult is used for these matrices.

Definition at line 456 of file multigrid.h.

◆ edge_in

template<typename VectorType >
SmartPointer<const MGMatrixBase<VectorType> > Multigrid< VectorType >::edge_in
private

Transpose edge matrix from the refinement edge to the interior of the refined part.

Note
Only Tvmult is used for these matrices.

Definition at line 464 of file multigrid.h.

◆ edge_down

template<typename VectorType >
SmartPointer<const MGMatrixBase<VectorType>, Multigrid<VectorType> > Multigrid< VectorType >::edge_down
private

Edge matrix from fine to coarse.

Note
Only vmult is used for these matrices.

Definition at line 471 of file multigrid.h.

◆ edge_up

template<typename VectorType >
SmartPointer<const MGMatrixBase<VectorType>, Multigrid<VectorType> > Multigrid< VectorType >::edge_up
private

Transpose edge matrix from coarse to fine.

Note
Only Tvmult is used for these matrices.

Definition at line 478 of file multigrid.h.

◆ counter

std::atomic<unsigned int> Subscriptor::counter
mutableprivateinherited

Store the number of objects which subscribed to this object. Initially, this number is zero, and upon destruction it shall be zero again (i.e. all objects which subscribed should have unsubscribed again).

The creator (and owner) of an object is counted in the map below if HE manages to supply identification.

We use the mutable keyword in order to allow subscription to constant objects also.

This counter may be read from and written to concurrently in multithreaded code: hence we use the std::atomic class template.

Definition at line 218 of file subscriptor.h.

◆ counter_map

std::map<std::string, unsigned int> Subscriptor::counter_map
mutableprivateinherited

In this map, we count subscriptions for each different identification string supplied to subscribe().

Definition at line 224 of file subscriptor.h.

◆ validity_pointers

std::vector<std::atomic<bool> *> Subscriptor::validity_pointers
mutableprivateinherited

In this vector, we store pointers to the validity bool in the SmartPointer objects that subscribe to this class.

Definition at line 240 of file subscriptor.h.

◆ object_info

const std::type_info* Subscriptor::object_info
mutableprivateinherited

Pointer to the typeinfo object of this object, from which we can later deduce the class name. Since this information on the derived class is neither available in the destructor, nor in the constructor, we obtain it in between and store it here.

Definition at line 248 of file subscriptor.h.

◆ mutex

std::mutex Subscriptor::mutex
staticprivateinherited

A mutex used to ensure data consistency when accessing the mutable members of this class. This lock is used in the subscribe() and unsubscribe() functions, as well as in list_subscribers().

Definition at line 271 of file subscriptor.h.


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