From ddc0b778409a64bc3b4d7ff6b74a8e1dedfdbfed Mon Sep 17 00:00:00 2001 From: guido Date: Fri, 2 Jul 1999 12:36:14 +0000 Subject: [PATCH] Vanka compiles git-svn-id: https://svn.dealii.org/trunk@1530 0785d39b-7218-0410-832d-ea1e28bc413d --- .../lac/include/lac/sparse_matrix.2.templates | 3 + deal.II/lac/include/lac/sparsevanka.h | 89 +++++++++++++++++++ .../lac/include/lac/sparsevanka.templates.h | 77 ++++++++++++++++ deal.II/lac/source/sparse_matrix.double.cc | 2 + deal.II/lac/source/sparse_matrix.float.cc | 2 + .../lac/source/sparse_matrix.long_double.cc | 2 + 6 files changed, 175 insertions(+) create mode 100644 deal.II/lac/include/lac/sparsevanka.h create mode 100644 deal.II/lac/include/lac/sparsevanka.templates.h diff --git a/deal.II/lac/include/lac/sparse_matrix.2.templates b/deal.II/lac/include/lac/sparse_matrix.2.templates index 9dbccff468..177b86395d 100644 --- a/deal.II/lac/include/lac/sparse_matrix.2.templates +++ b/deal.II/lac/include/lac/sparse_matrix.2.templates @@ -42,3 +42,6 @@ template void SparseMatrix::SSOR (Vector &, TYPEMAT) const; template void SparseMatrix::SOR_step (Vector &, const Vector &, TYPEMAT) const; template void SparseMatrix::TSOR_step (Vector &, const Vector &, TYPEMAT) const; template void SparseMatrix::SSOR_step (Vector &, const Vector &, TYPEMAT) const; + +template void SparseVanka::apply(Vector& dst) const; + diff --git a/deal.II/lac/include/lac/sparsevanka.h b/deal.II/lac/include/lac/sparsevanka.h new file mode 100644 index 0000000000..0a0664287a --- /dev/null +++ b/deal.II/lac/include/lac/sparsevanka.h @@ -0,0 +1,89 @@ +// $Id$ +// Copyright Guido Kanschat, 1999 + +#ifndef __lac_sparsematrix_H +#define __lac_sparsematrix_H + +#include +#include + +#include + +/** + * Point-wise Vanka preconditioning. + * This class does Vanka preconditioning on a point-wise base. + * Vanka preconditioners are used for saddle point problems. There the + * application of Jacobi or Gauß-Seidel methods is impossible, because + * the diagonal elements are zero in the rows of the Lagrange multiplier. + * + * It is constructed initializing a vector of indices to the degrees of + * freedom of the Lagrange multiplier. + * + * In the actual preconditioning method, these rows are traversed in + * original order. Since this is a Gauß-Seidel like procedure, + * remember to have a good ordering in advance. + * + * For each row, a local system of equations is built by the degree of + * freedom itself and all other values coupling immediately. The right + * hand side is augmented by all further couplings. + * + * This local system is solved and the values are updated into the + * destination vector. + * @author Guido Kanschat + */ +template +class SparseVanka +{ + public: + /** + * Constructor. + * Take a vector of the indices + * of the Lagrange multiplier as + * argument. A reference to this + * vector will be stored, so it + * must persist longer than the + * Vanka object. The same is true + * for the matrix. + */ + SparseVanka(const SparseMatrix& M, + const vector& indices); + /** + * Do the preconditioning. + */ + template + void operator() (Vector& dst, + const Vector& src) const; + + /** + * In-place application of the + * method. + */ + template + void apply(Vector& dst) const; + + private: + /** + * Pointer to the matrix. + */ + SmartPointer > matrix; + + /** + * Indices of Lagrange + * multipliers. + */ + const vector& indices; +}; + +template +template +inline +void +SparseVanka::operator() (Vector& dst, + const Vector& src) const +{ + dst = src; + apply(dst); +} + + +#endif diff --git a/deal.II/lac/include/lac/sparsevanka.templates.h b/deal.II/lac/include/lac/sparsevanka.templates.h new file mode 100644 index 0000000000..19e87b7d60 --- /dev/null +++ b/deal.II/lac/include/lac/sparsevanka.templates.h @@ -0,0 +1,77 @@ +// $Id$ +// Copyright Guido Kanschat, 1999 + +#include +#include + +#include + +template +SparseVanka::SparseVanka(const SparseMatrix& M, + const vector& indices) + : + matrix(&M), indices(indices) +{} + +template +template +void +SparseVanka::apply(Vector& dst) const +{ + for (unsigned int global_i=0; global_iget_sparsity_pattern(); + unsigned int n = structure.row_length(row); + + FullMatrix A(n); + Vector b(n); + Vector x(n); + + map local_index; + + // Build local index + + for (unsigned int i=0;i + (structure.column_number(row, i), i)); + + // Build local matrix + + for (map::iterator is=local_index.begin(); + is!=local_index.end();++is) + { + unsigned int irow = is->first; + unsigned int i = is->second; + unsigned int n = structure.row_length(irow); + + b(i) = dst(irow); + + for (unsigned int j=0;j::iterator js + = local_index.find(col); + if (js == local_index.end()) + { + b(i) -= matrix->raw_entry(irow,col) * dst(col); + } else { + A(i,j) = matrix->raw_entry(irow,col); + } + } + } + // Compute new values + A.gauss_jordan(); + A.vmult(x,b); + + // Distribute new values + for (map::iterator is=local_index.begin(); + is!=local_index.end();++is) + { + unsigned int irow = is->first; + unsigned int i = is->second; + dst(irow) = x(i); + } + } +} + diff --git a/deal.II/lac/source/sparse_matrix.double.cc b/deal.II/lac/source/sparse_matrix.double.cc index d129b74e99..d677b3275f 100644 --- a/deal.II/lac/source/sparse_matrix.double.cc +++ b/deal.II/lac/source/sparse_matrix.double.cc @@ -11,10 +11,12 @@ #include #include +#include #define TYPEMAT double template class SparseMatrix; +template class SparseVanka; #define TYPE2 float diff --git a/deal.II/lac/source/sparse_matrix.float.cc b/deal.II/lac/source/sparse_matrix.float.cc index f7d2f03495..32b2e0324e 100644 --- a/deal.II/lac/source/sparse_matrix.float.cc +++ b/deal.II/lac/source/sparse_matrix.float.cc @@ -11,10 +11,12 @@ #include #include +#include #define TYPEMAT float template class SparseMatrix; +template class SparseVanka; #define TYPE2 float diff --git a/deal.II/lac/source/sparse_matrix.long_double.cc b/deal.II/lac/source/sparse_matrix.long_double.cc index dbd0e62aa0..9afdba4530 100644 --- a/deal.II/lac/source/sparse_matrix.long_double.cc +++ b/deal.II/lac/source/sparse_matrix.long_double.cc @@ -11,10 +11,12 @@ #include #include +#include #define TYPEMAT long double template class SparseMatrix; +template class SparseVanka; #define TYPE2 float -- 2.39.5