// <code>InverseMatrix</code> object is created. The member function
// <code>vmult</code> is, as in step-20, a multiplication with a vector,
// obtained by solving a linear system:
- template <class MatrixType, class Preconditioner>
+ template <class MatrixType, class PreconditionerType>
class InverseMatrix : public Subscriptor
{
public:
- InverseMatrix (const MatrixType &m,
- const Preconditioner &preconditioner);
+ InverseMatrix (const MatrixType &m,
+ const PreconditionerType &preconditioner);
void vmult (Vector<double> &dst,
const Vector<double> &src) const;
private:
const SmartPointer<const MatrixType> matrix;
- const SmartPointer<const Preconditioner> preconditioner;
+ const SmartPointer<const PreconditionerType> preconditioner;
};
- template <class MatrixType, class Preconditioner>
- InverseMatrix<MatrixType,Preconditioner>::InverseMatrix
- (const MatrixType &m,
- const Preconditioner &preconditioner)
+ template <class MatrixType, class PreconditionerType>
+ InverseMatrix<MatrixType,PreconditionerType>::InverseMatrix
+ (const MatrixType &m,
+ const PreconditionerType &preconditioner)
:
matrix (&m),
preconditioner (&preconditioner)
// inverse of the Laplace matrix – which is hence directly responsible
// for the accuracy of the solution itself, so we can't choose a too large
// tolerance, either.
- template <class MatrixType, class Preconditioner>
- void InverseMatrix<MatrixType,Preconditioner>::vmult (Vector<double> &dst,
- const Vector<double> &src) const
+ template <class MatrixType, class PreconditionerType>
+ void InverseMatrix<MatrixType,PreconditionerType>::vmult
+ (Vector<double> &dst,
+ const Vector<double> &src) const
{
SolverControl solver_control (src.size(), 1e-6*src.l2_norm());
SolverCG<> cg (solver_control);
// This class implements the Schur complement discussed in the introduction.
// It is in analogy to step-20. Though, we now call it with a template
- // parameter <code>Preconditioner</code> in order to access that when
+ // parameter <code>PreconditionerType</code> in order to access that when
// specifying the respective type of the inverse matrix class. As a
// consequence of the definition above, the declaration
// <code>InverseMatrix</code> now contains the second template parameter for
// a preconditioner class as above, which affects the
// <code>SmartPointer</code> object <code>m_inverse</code> as well.
- template <class Preconditioner>
+ template <class PreconditionerType>
class SchurComplement : public Subscriptor
{
public:
SchurComplement (const BlockSparseMatrix<double> &system_matrix,
- const InverseMatrix<SparseMatrix<double>, Preconditioner> &A_inverse);
+ const InverseMatrix<SparseMatrix<double>, PreconditionerType> &A_inverse);
void vmult (Vector<double> &dst,
const Vector<double> &src) const;
private:
const SmartPointer<const BlockSparseMatrix<double> > system_matrix;
- const SmartPointer<const InverseMatrix<SparseMatrix<double>, Preconditioner> > A_inverse;
+ const SmartPointer<const InverseMatrix<SparseMatrix<double>, PreconditionerType> > A_inverse;
mutable Vector<double> tmp1, tmp2;
};
- template <class Preconditioner>
- SchurComplement<Preconditioner>::
- SchurComplement (const BlockSparseMatrix<double> &system_matrix,
- const InverseMatrix<SparseMatrix<double>,Preconditioner> &A_inverse)
+ template <class PreconditionerType>
+ SchurComplement<PreconditionerType>::SchurComplement
+ (const BlockSparseMatrix<double> &system_matrix,
+ const InverseMatrix<SparseMatrix<double>,PreconditionerType> &A_inverse)
:
system_matrix (&system_matrix),
A_inverse (&A_inverse),
{}
- template <class Preconditioner>
- void SchurComplement<Preconditioner>::vmult (Vector<double> &dst,
- const Vector<double> &src) const
+ template <class PreconditionerType>
+ void SchurComplement<PreconditionerType>::vmult (Vector<double> &dst,
+ const Vector<double> &src) const
{
system_matrix->block(0,1).vmult (tmp1, src);
A_inverse->vmult (tmp2, tmp1);
// way as the corresponding class in step-22: when the product of an
// object of this class is requested, we solve a linear equation system
// with that matrix using the CG method, accelerated by a preconditioner
- // of (templated) class <code>Preconditioner</code>.
+ // of (templated) class <code>PreconditionerType</code>.
//
// In a minor deviation from the implementation of the same class in
// step-22 (and step-20), we make the <code>vmult</code> function take any
// run-time exception into an assertion that fails and triggers a call to
// <code>abort()</code>, allowing us to trace back in a debugger how we
// got to the current place.
- template <class MatrixType, class Preconditioner>
+ template <class MatrixType, class PreconditionerType>
class InverseMatrix : public Subscriptor
{
public:
InverseMatrix (const MatrixType &m,
- const Preconditioner &preconditioner);
+ const PreconditionerType &preconditioner);
template <typename VectorType>
private:
const SmartPointer<const MatrixType> matrix;
- const Preconditioner &preconditioner;
+ const PreconditionerType &preconditioner;
};
- template <class MatrixType, class Preconditioner>
- InverseMatrix<MatrixType,Preconditioner>::
- InverseMatrix (const MatrixType &m,
- const Preconditioner &preconditioner)
+ template <class MatrixType, class PreconditionerType>
+ InverseMatrix<MatrixType,PreconditionerType>::InverseMatrix
+ (const MatrixType &m,
+ const PreconditionerType &preconditioner)
:
matrix (&m),
preconditioner (preconditioner)
- template <class MatrixType, class Preconditioner>
+ template <class MatrixType, class PreconditionerType>
template <typename VectorType>
void
- InverseMatrix<MatrixType,Preconditioner>::
- vmult (VectorType &dst,
- const VectorType &src) const
+ InverseMatrix<MatrixType,PreconditionerType>::vmult
+ (VectorType &dst,
+ const VectorType &src) const
{
SolverControl solver_control (src.size(), 1e-7*src.l2_norm());
SolverCG<VectorType> cg (solver_control);
// Schur complement in step-20, with the difference that we need some more
// preconditioners in the constructor and that the matrices we use here
// are built upon Trilinos:
- template <class PreconditionerA, class PreconditionerMp>
+ template <class PreconditionerTypeA, class PreconditionerTypeMp>
class BlockSchurPreconditioner : public Subscriptor
{
public:
BlockSchurPreconditioner (
const TrilinosWrappers::BlockSparseMatrix &S,
const InverseMatrix<TrilinosWrappers::SparseMatrix,
- PreconditionerMp> &Mpinv,
- const PreconditionerA &Apreconditioner);
+ PreconditionerTypeMp> &Mpinv,
+ const PreconditionerTypeA &Apreconditioner);
void vmult (TrilinosWrappers::MPI::BlockVector &dst,
const TrilinosWrappers::MPI::BlockVector &src) const;
private:
const SmartPointer<const TrilinosWrappers::BlockSparseMatrix> stokes_matrix;
const SmartPointer<const InverseMatrix<TrilinosWrappers::SparseMatrix,
- PreconditionerMp > > m_inverse;
- const PreconditionerA &a_preconditioner;
+ PreconditionerTypeMp > > m_inverse;
+ const PreconditionerTypeA &a_preconditioner;
mutable TrilinosWrappers::MPI::Vector tmp;
};
// an IndexSet where every valid index is part of the set. Note that this
// program can only be run sequentially and will throw an exception if used
// in parallel.
- template <class PreconditionerA, class PreconditionerMp>
- BlockSchurPreconditioner<PreconditionerA, PreconditionerMp>::
- BlockSchurPreconditioner(const TrilinosWrappers::BlockSparseMatrix &S,
+ template <class PreconditionerTypeA, class PreconditionerTypeMp>
+ BlockSchurPreconditioner<PreconditionerTypeA, PreconditionerTypeMp>::
+ BlockSchurPreconditioner(const TrilinosWrappers::BlockSparseMatrix &S,
const InverseMatrix<TrilinosWrappers::SparseMatrix,
- PreconditionerMp> &Mpinv,
- const PreconditionerA &Apreconditioner)
+ PreconditionerTypeMp> &Mpinv,
+ const PreconditionerTypeA &Apreconditioner)
:
stokes_matrix (&S),
m_inverse (&Mpinv),
// vector and finally multiply by the inverse pressure mass matrix to get
// the final pressure vector, completing our work on the Stokes
// preconditioner:
- template <class PreconditionerA, class PreconditionerMp>
+ template <class PreconditionerTypeA, class PreconditionerTypeMp>
void
- BlockSchurPreconditioner<PreconditionerA, PreconditionerMp>::
- vmult (TrilinosWrappers::MPI::BlockVector &dst,
- const TrilinosWrappers::MPI::BlockVector &src) const
+ BlockSchurPreconditioner<PreconditionerTypeA, PreconditionerTypeMp>::vmult
+ (TrilinosWrappers::MPI::BlockVector &dst,
+ const TrilinosWrappers::MPI::BlockVector &src) const
{
a_preconditioner.vmult (dst.block(0), src.block(0));
stokes_matrix->block(1,0).residual(tmp, dst.block(0), src.block(1));
// discussion of composing solvers in step-20.
namespace LinearSolvers
{
- template <class PreconditionerA, class PreconditionerMp>
+ template <class PreconditionerTypeA, class PreconditionerTypeMp>
class BlockSchurPreconditioner : public Subscriptor
{
public:
- BlockSchurPreconditioner (const TrilinosWrappers::BlockSparseMatrix &S,
- const TrilinosWrappers::BlockSparseMatrix &Spre,
- const PreconditionerMp &Mppreconditioner,
- const PreconditionerA &Apreconditioner,
- const bool do_solve_A)
+ BlockSchurPreconditioner (const TrilinosWrappers::BlockSparseMatrix &S,
+ const TrilinosWrappers::BlockSparseMatrix &Spre,
+ const PreconditionerTypeMp &Mppreconditioner,
+ const PreconditionerTypeA &Apreconditioner,
+ const bool do_solve_A)
:
stokes_matrix (&S),
stokes_preconditioner_matrix (&Spre),
private:
const SmartPointer<const TrilinosWrappers::BlockSparseMatrix> stokes_matrix;
const SmartPointer<const TrilinosWrappers::BlockSparseMatrix> stokes_preconditioner_matrix;
- const PreconditionerMp &mp_preconditioner;
- const PreconditionerA &a_preconditioner;
+ const PreconditionerTypeMp &mp_preconditioner;
+ const PreconditionerTypeA &a_preconditioner;
const bool do_solve_A;
};
}
// darcy_matrix to match our problem.
namespace LinearSolvers
{
- template <class MatrixType, class Preconditioner>
+ template <class MatrixType, class PreconditionerType>
class InverseMatrix : public Subscriptor
{
public:
- InverseMatrix (const MatrixType &m,
- const Preconditioner &preconditioner);
+ InverseMatrix (const MatrixType &m,
+ const PreconditionerType &preconditioner);
template <typename VectorType>
private:
const SmartPointer<const MatrixType> matrix;
- const Preconditioner &preconditioner;
+ const PreconditionerType &preconditioner;
};
- template <class MatrixType, class Preconditioner>
- InverseMatrix<MatrixType,Preconditioner>::
- InverseMatrix (const MatrixType &m,
- const Preconditioner &preconditioner)
+ template <class MatrixType, class PreconditionerType>
+ InverseMatrix<MatrixType,PreconditionerType>::InverseMatrix
+ (const MatrixType &m,
+ const PreconditionerType &preconditioner)
:
matrix (&m),
preconditioner (preconditioner)
- template <class MatrixType, class Preconditioner>
+ template <class MatrixType, class PreconditionerType>
template <typename VectorType>
void
- InverseMatrix<MatrixType,Preconditioner>::
- vmult (VectorType &dst,
- const VectorType &src) const
+ InverseMatrix<MatrixType,PreconditionerType>::vmult
+ (VectorType &dst,
+ const VectorType &src) const
{
SolverControl solver_control (src.size(), 1e-7*src.l2_norm());
SolverCG<VectorType> cg (solver_control);
}
}
- template <class PreconditionerA, class PreconditionerMp>
+ template <class PreconditionerTypeA, class PreconditionerTypeMp>
class BlockSchurPreconditioner : public Subscriptor
{
public:
BlockSchurPreconditioner (
- const TrilinosWrappers::BlockSparseMatrix &S,
+ const TrilinosWrappers::BlockSparseMatrix &S,
const InverseMatrix<TrilinosWrappers::SparseMatrix,
- PreconditionerMp> &Mpinv,
- const PreconditionerA &Apreconditioner);
+ PreconditionerTypeMp> &Mpinv,
+ const PreconditionerTypeA &Apreconditioner);
void vmult (TrilinosWrappers::MPI::BlockVector &dst,
const TrilinosWrappers::MPI::BlockVector &src) const;
private:
const SmartPointer<const TrilinosWrappers::BlockSparseMatrix> darcy_matrix;
const SmartPointer<const InverseMatrix<TrilinosWrappers::SparseMatrix,
- PreconditionerMp > > m_inverse;
- const PreconditionerA &a_preconditioner;
+ PreconditionerTypeMp > > m_inverse;
+ const PreconditionerTypeA &a_preconditioner;
mutable TrilinosWrappers::MPI::Vector tmp;
};
- template <class PreconditionerA, class PreconditionerMp>
- BlockSchurPreconditioner<PreconditionerA, PreconditionerMp>::
- BlockSchurPreconditioner(const TrilinosWrappers::BlockSparseMatrix &S,
+ template <class PreconditionerTypeA, class PreconditionerTypeMp>
+ BlockSchurPreconditioner<PreconditionerTypeA, PreconditionerTypeMp>::
+ BlockSchurPreconditioner(const TrilinosWrappers::BlockSparseMatrix &S,
const InverseMatrix<TrilinosWrappers::SparseMatrix,
- PreconditionerMp> &Mpinv,
- const PreconditionerA &Apreconditioner)
+ PreconditionerTypeMp> &Mpinv,
+ const PreconditionerTypeA &Apreconditioner)
:
darcy_matrix (&S),
m_inverse (&Mpinv),
{}
- template <class PreconditionerA, class PreconditionerMp>
- void BlockSchurPreconditioner<PreconditionerA, PreconditionerMp>::vmult (
+ template <class PreconditionerTypeA, class PreconditionerTypeMp>
+ void BlockSchurPreconditioner<PreconditionerTypeA, PreconditionerTypeMp>::vmult (
TrilinosWrappers::MPI::BlockVector &dst,
const TrilinosWrappers::MPI::BlockVector &src) const
{
- template <class MatrixType, class Preconditioner>
+ template <class MatrixType, class PreconditionerType>
class InverseMatrix : public Subscriptor
{
public:
- InverseMatrix (const MatrixType &m,
- const Preconditioner &preconditioner,
- const IndexSet &locally_owned,
- const MPI_Comm &mpi_communicator);
+ InverseMatrix (const MatrixType &m,
+ const PreconditionerType &preconditioner,
+ const IndexSet &locally_owned,
+ const MPI_Comm &mpi_communicator);
void vmult (TrilinosWrappers::MPI::Vector &dst,
const TrilinosWrappers::MPI::Vector &src) const;
private:
const SmartPointer<const MatrixType> matrix;
- const SmartPointer<const Preconditioner> preconditioner;
+ const SmartPointer<const PreconditionerType> preconditioner;
const MPI_Comm *mpi_communicator;
mutable TrilinosWrappers::MPI::Vector tmp;
- template <class MatrixType, class Preconditioner>
- InverseMatrix<MatrixType,Preconditioner>::InverseMatrix
- (const MatrixType &m,
- const Preconditioner &preconditioner,
- const IndexSet &locally_owned,
- const MPI_Comm &mpi_communicator)
+ template <class MatrixType, class PreconditionerType>
+ InverseMatrix<MatrixType,PreconditionerType>::InverseMatrix
+ (const MatrixType &m,
+ const PreconditionerType &preconditioner,
+ const IndexSet &locally_owned,
+ const MPI_Comm &mpi_communicator)
:
matrix (&m),
preconditioner (&preconditioner),
- template <class MatrixType, class Preconditioner>
- void InverseMatrix<MatrixType,Preconditioner>::vmult
+ template <class MatrixType, class PreconditionerType>
+ void InverseMatrix<MatrixType,PreconditionerType>::vmult
(TrilinosWrappers::MPI::Vector &dst,
const TrilinosWrappers::MPI::Vector &src) const
{
- template <class Preconditioner>
+ template <class PreconditionerType>
class SchurComplement : public TrilinosWrappers::SparseMatrix
{
public:
- SchurComplement ( const TrilinosWrappers::BlockSparseMatrix &system_matrix,
- const InverseMatrix<TrilinosWrappers::SparseMatrix,
- Preconditioner> &A_inverse,
- const IndexSet &owned_pres,
- const MPI_Comm &mpi_communicator);
+ SchurComplement (const TrilinosWrappers::BlockSparseMatrix &system_matrix,
+ const InverseMatrix<TrilinosWrappers::SparseMatrix,
+ PreconditionerType> &A_inverse,
+ const IndexSet &owned_pres,
+ const MPI_Comm &mpi_communicator);
void vmult (TrilinosWrappers::MPI::Vector &dst,
const TrilinosWrappers::MPI::Vector &src) const;
private:
const SmartPointer<const TrilinosWrappers::BlockSparseMatrix> system_matrix;
const SmartPointer<const InverseMatrix<TrilinosWrappers::SparseMatrix,
- Preconditioner> > A_inverse;
+ PreconditionerType> > A_inverse;
mutable TrilinosWrappers::MPI::Vector tmp1, tmp2;
};
- template <class Preconditioner>
- SchurComplement<Preconditioner>::
+ template <class PreconditionerType>
+ SchurComplement<PreconditionerType>::
SchurComplement (const TrilinosWrappers::BlockSparseMatrix &system_matrix,
const InverseMatrix<TrilinosWrappers::SparseMatrix,
- Preconditioner> &A_inverse,
- const IndexSet &owned_vel,
- const MPI_Comm &mpi_communicator)
+ PreconditionerType> &A_inverse,
+ const IndexSet &owned_vel,
+ const MPI_Comm &mpi_communicator)
:
system_matrix (&system_matrix),
A_inverse (&A_inverse),
- template <class Preconditioner>
- void SchurComplement<Preconditioner>::vmult
+ template <class PreconditionerType>
+ void SchurComplement<PreconditionerType>::vmult
(TrilinosWrappers::MPI::Vector &dst,
const TrilinosWrappers::MPI::Vector &src) const
{