From 0544eb1552ebaf72ccc7db364c625d7ac5929983 Mon Sep 17 00:00:00 2001 From: guido Date: Tue, 13 Jul 1999 10:38:16 +0000 Subject: [PATCH] Quick mode for Vanka; Warning in Bicgstab removed git-svn-id: https://svn.dealii.org/trunk@1572 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/solver_bicgstab.h | 2 +- deal.II/lac/include/lac/sparse_vanka.h | 26 +++++++++++ .../lac/include/lac/sparse_vanka.templates.h | 44 ++++++++++++++++--- 3 files changed, 66 insertions(+), 6 deletions(-) diff --git a/deal.II/lac/include/lac/solver_bicgstab.h b/deal.II/lac/include/lac/solver_bicgstab.h index b0bbc428e1..6d294f2154 100644 --- a/deal.II/lac/include/lac/solver_bicgstab.h +++ b/deal.II/lac/include/lac/solver_bicgstab.h @@ -255,7 +255,7 @@ SolverBicgstab::solve(const Matrix &A, step = 0; - ReturnState state; + ReturnState state = breakdown; do { diff --git a/deal.II/lac/include/lac/sparse_vanka.h b/deal.II/lac/include/lac/sparse_vanka.h index 5162ad8673..3a75a7ef92 100644 --- a/deal.II/lac/include/lac/sparse_vanka.h +++ b/deal.II/lac/include/lac/sparse_vanka.h @@ -8,6 +8,7 @@ #include #include +#include /** * Point-wise Vanka preconditioning. @@ -49,6 +50,12 @@ class SparseVanka */ SparseVanka(const SparseMatrix& M, const bit_vector& selected); + /** + * Destructor. + * Delete all allocated matrices. + */ + ~SparseVanka(); + /** * Do the preconditioning. This * function contains a dispatch @@ -80,6 +87,17 @@ class SparseVanka */ template void backward(Vector& dst, const Vector& src) const; + /** + * Minimize memory consumption. + * Activating this option reduces + * memory needs of the Vanka object + * to nealy zero. You pay for this + * by a high increase of computing + * time, since all local matrices + * are built up and inverted every time. + */ + void conserve_memory(); + private: /** * Pointer to the matrix. @@ -91,6 +109,14 @@ class SparseVanka * multipliers. */ const bit_vector& selected; + /** + * Conserve memory flag. + */ + bool conserve_mem; + /** + * Array of inverse matrices. + */ + mutable vector > > inverses; }; template diff --git a/deal.II/lac/include/lac/sparse_vanka.templates.h b/deal.II/lac/include/lac/sparse_vanka.templates.h index fcf03faafd..3f100bcd72 100644 --- a/deal.II/lac/include/lac/sparse_vanka.templates.h +++ b/deal.II/lac/include/lac/sparse_vanka.templates.h @@ -10,24 +10,56 @@ template SparseVanka::SparseVanka(const SparseMatrix& M, const bit_vector& selected) : - matrix(&M), selected(selected) + matrix(&M), selected(selected), conserve_mem(false), inverses(M.m(),0) {} +template +SparseVanka::~SparseVanka() +{ + vector > >::iterator i; + for(i=inverses.begin();i!=inverses.end();++i) + { + FullMatrix* p = *i; + *i = 0; + if (p != 0) delete p; + } +} + + + template template void SparseVanka::forward(Vector& dst, const Vector& src) const { + FullMatrix local_matrix; for (unsigned int row=0; row< matrix->m() ; ++row) { + bool build_matrix = true; + if (!selected[row]) continue; - + + const SparseMatrixStruct& structure = matrix->get_sparsity_pattern(); unsigned int n = structure.row_length(row); - FullMatrix A(n); + if (!conserve_mem) + { + if (inverses[row] == 0) + { + FullMatrix* p = new FullMatrix; + inverses[row] = p; + } else { + build_matrix = false; + } + } + + FullMatrix& A = (conserve_mem) ? local_matrix : (*inverses[row]); + + if (build_matrix) A.reinit(n); + Vector b(n); Vector x(n); @@ -63,12 +95,14 @@ SparseVanka::forward(Vector& dst, { b(i) -= matrix->raw_entry(irow,j) * dst(col); } else { - A(i,js->second) = matrix->raw_entry(irow,j); + if (build_matrix) + A(i,js->second) = matrix->raw_entry(irow,j); } } } // Compute new values - A.gauss_jordan(); + if (build_matrix) + A.gauss_jordan(); A.vmult(x,b); // Distribute new values -- 2.39.5