]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Quick mode for Vanka; Warning in Bicgstab removed
authorguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 13 Jul 1999 10:38:16 +0000 (10:38 +0000)
committerguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 13 Jul 1999 10:38:16 +0000 (10:38 +0000)
git-svn-id: https://svn.dealii.org/trunk@1572 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/solver_bicgstab.h
deal.II/lac/include/lac/sparse_vanka.h
deal.II/lac/include/lac/sparse_vanka.templates.h

index b0bbc428e1f0905cc256d93cd2002b11507b062b..6d294f21540a978552fe3322de2c0a173200db76 100644 (file)
@@ -255,7 +255,7 @@ SolverBicgstab<Matrix, Vector>::solve(const Matrix &A,
 
   step = 0;
 
-  ReturnState state;
+  ReturnState state = breakdown;
   
   do 
     {
index 5162ad8673d6b902cdadb91b861569c5a1b0bf06..3a75a7ef92ce721c02a1162e61e53174616c20a9 100644 (file)
@@ -8,6 +8,7 @@
 #include <lac/forward-declarations.h>
 
 #include <bvector.h>
+#include <vector>
 
 /**
  * Point-wise Vanka preconditioning.
@@ -49,6 +50,12 @@ class SparseVanka
                                      */
     SparseVanka(const SparseMatrix<number>& 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<typename number2>
     void backward(Vector<number2>& dst, const Vector<number2>& 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<SmartPointer<FullMatrix<float> > > inverses;
 };
 
 template<typename number>
index fcf03faafda0a4bf8e1e229d6436affe4e010428..3f100bcd729dfe40c7c85cbc0ac3c26c205ae25f 100644 (file)
@@ -10,24 +10,56 @@ template<typename number>
 SparseVanka<number>::SparseVanka(const SparseMatrix<number>& M,
                                 const bit_vector& selected)
                :
-               matrix(&M), selected(selected)
+               matrix(&M), selected(selected), conserve_mem(false), inverses(M.m(),0)
 {}
 
+template<typename number>
+SparseVanka<number>::~SparseVanka()
+{
+  vector<SmartPointer<FullMatrix<float> > >::iterator i;
+  for(i=inverses.begin();i!=inverses.end();++i)
+    {
+      FullMatrix<float>* p = *i;
+      *i = 0;
+      if (p != 0) delete p;
+    }
+}
+
+
+
 template<typename number>
 template<typename number2>
 void
 SparseVanka<number>::forward(Vector<number2>& dst,
                           const Vector<number2>& src) const
 {
+  FullMatrix<float> 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<float> A(n);
+      if (!conserve_mem)
+       {
+         if (inverses[row] == 0)
+           {
+             FullMatrix<float>* p = new FullMatrix<float>;
+             inverses[row] = p;
+           } else {
+             build_matrix = false;
+           }
+       }
+
+      FullMatrix<float>& A = (conserve_mem) ? local_matrix : (*inverses[row]);
+
+      if (build_matrix) A.reinit(n);
+      
       Vector<float> b(n);
       Vector<float> x(n);
       
@@ -63,12 +95,14 @@ SparseVanka<number>::forward(Vector<number2>& 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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.