]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Purge the block size template args from BlockSparseMatrix as well.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 1 Dec 2000 13:11:32 +0000 (13:11 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 1 Dec 2000 13:11:32 +0000 (13:11 +0000)
git-svn-id: https://svn.dealii.org/trunk@3519 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/dofs/dof_constraints.h
deal.II/deal.II/include/dofs/dof_constraints.templates.h
deal.II/deal.II/include/numerics/matrices.h
deal.II/deal.II/source/dofs/dof_constraints.cc
deal.II/deal.II/source/numerics/matrices.cc
deal.II/lac/include/lac/block_sparse_matrix.h
deal.II/lac/include/lac/block_sparse_matrix.templates.h
deal.II/lac/include/lac/block_sparsity_pattern.h
deal.II/lac/source/block_sparse_matrix.cc
tests/lac/block_matrices.cc

index 743b48809c65478d29e6f3ae0a40ff5dae84f69f..c713c048217864ce41674c66e6635d31be764387 100644 (file)
@@ -22,7 +22,7 @@
 class SparsityPattern;
 class BlockSparsityPattern;
 template <typename number> class SparseMatrix;
-template <typename number, int rows, int columns> class BlockSparseMatrix;
+template <typename number> class BlockSparseMatrix;
 class BlockIndices;
 
 /**
@@ -287,8 +287,8 @@ class ConstraintMatrix : public Subscriptor
                                      * condenses square block sparse
                                      * matrices.
                                      */
-    template <typename number, int blocks>
-    void condense (BlockSparseMatrix<number,blocks,blocks> &sparsity) const;
+    template <typename number>
+    void condense (BlockSparseMatrix<number> &matrix) const;
     
                                     /**
                                      * Condense the given vector @p{uncondensed}
index 20dcee477bd891dfbb1142237b6d5743b99847b9..e82c027bbd94eeaffb9654c248c0bfd1c1bed7cf 100644 (file)
@@ -262,10 +262,12 @@ ConstraintMatrix::condense (SparseMatrix<number> &uncondensed) const
 
 
 
-template <typename number, int blocks>
+template <typename number>
 void
-ConstraintMatrix::condense (BlockSparseMatrix<number,blocks,blocks> &uncondensed) const
+ConstraintMatrix::condense (BlockSparseMatrix<number> &uncondensed) const
 {
+  const unsigned int blocks = uncondensed.n_block_rows();
+  
   const BlockSparsityPattern &
     sparsity = uncondensed.get_sparsity_pattern ();
 
@@ -275,6 +277,8 @@ ConstraintMatrix::condense (BlockSparseMatrix<number,blocks,blocks> &uncondensed
          ExcMatrixNotSquare());
   Assert (sparsity.n_block_rows() == sparsity.n_block_cols(),
          ExcMatrixNotSquare());
+  Assert (sparsity.n_block_rows() == sparsity.n_block_cols(),
+         ExcMatrixNotSquare());
   Assert (sparsity.get_column_indices() == sparsity.get_row_indices(),
          ExcMatrixNotSquare());
 
index f623e2ed7135090249b4945b9e5b2c676b854e93..c8be9c7cb290a5cb1eacac760f032ad7d67d774a 100644 (file)
@@ -23,7 +23,7 @@ template<typename number> class Vector;
 template<typename number> class FullMatrix;
 template<typename number> class SparseMatrix;
 
-template <typename number, int rows, int columns  >  class BlockSparseMatrix;
+template <typename number> class BlockSparseMatrix;
 template <typename Number> class BlockVector;
 
 template <int dim> class DoFHandler;
@@ -457,13 +457,12 @@ class MatrixTools : public MatrixCreator<dim>
                                      * works for block sparse
                                      * matrices and block vectors
                                      */
-    template <int blocks>
     static void
     apply_boundary_values (const map<unsigned int,double> &boundary_values,
-                          BlockSparseMatrix<double,blocks,blocks> &matrix,
+                          BlockSparseMatrix<double> &matrix,
                           BlockVector<double> &solution,
                           BlockVector<double> &right_hand_side,
-                          const bool                  eliminate_columns = true);
+                          const bool           eliminate_columns = true);
     
                                     /**
                                      * Exception
index 44ef42930505187767f5ff876de5f825bd2298b7..07d40af78857ab4062e32fb9abf200291336aa6f 100644 (file)
@@ -689,11 +689,7 @@ matrix_functions_2;
 #undef MatrixType
 
 // block sparse matrices are only implemented for one of the two matrix functions
-#define MatrixType BlockSparseMatrix<double,2,2>
-matrix_functions_2;
-#undef MatrixType
-
-#define MatrixType BlockSparseMatrix<double,3,3>
+#define MatrixType BlockSparseMatrix<double>
 matrix_functions_2;
 #undef MatrixType
 
index 9b9172c178029e5d4975a6587ec8b82b78a30ffb..499cce06dee567f3840c9662ef64ed93a45d6999 100644 (file)
@@ -685,20 +685,23 @@ MatrixTools<dim>::apply_boundary_values (const map<unsigned int,double> &boundar
 
 
 template <int dim>
-template <int blocks>
 void
 MatrixTools<dim>::apply_boundary_values (const map<unsigned int,double> &boundary_values,
-                                        BlockSparseMatrix<double,blocks,blocks>  &matrix,
+                                        BlockSparseMatrix<double>  &matrix,
                                         BlockVector<double>   &solution,
                                         BlockVector<double>   &right_hand_side,
                                         const bool                    preserve_symmetry)
 {
+  const unsigned int blocks = matrix.n_block_rows();
+  
   Assert (matrix.n() == matrix.m(),
          ExcDimensionsDontMatch(matrix.n(), matrix.m()));
   Assert (matrix.n() == right_hand_side.size(),
          ExcDimensionsDontMatch(matrix.n(), right_hand_side.size()));
   Assert (matrix.n() == solution.size(),
          ExcDimensionsDontMatch(matrix.n(), solution.size()));
+  Assert (matrix.n_block_rows() == matrix.n_block_cols(),
+         ExcMatrixNotBlockSquare());
   Assert (matrix.get_sparsity_pattern().get_row_indices() == 
          matrix.get_sparsity_pattern().get_column_indices(),
          ExcMatrixNotBlockSquare());
@@ -1398,18 +1401,9 @@ template
 void
 MatrixTools<deal_II_dimension>::
 apply_boundary_values (const map<unsigned int,double> &,
-                      BlockSparseMatrix<double,2,2>  &,
-                      BlockVector<double>          &,
-                      BlockVector<double>          &,
-                      const bool);
-
-template
-void
-MatrixTools<deal_II_dimension>::
-apply_boundary_values (const map<unsigned int,double> &,
-                      BlockSparseMatrix<double,3,3>  &,
-                      BlockVector<double>          &,
-                      BlockVector<double>          &,
+                      BlockSparseMatrix<double>      &,
+                      BlockVector<double>            &,
+                      BlockVector<double>            &,
                       const bool);
 
 
index 82bd776c51e261fde7972426d6b1112d921ba5e9..c58032e848cf71b3f6f7450e44451065abf281eb 100644 (file)
@@ -35,6 +35,9 @@ template <typename Number> class BlockVector;
  * preconditioners, where each block belongs to a specific component
  * of the equation you are presently discretizing.
  *
+ * Note that the number of blocks and rows are implicitely determined
+ * by the sparsity pattern objects used.
+ *
  *
  * @sect2{On template instantiations}
  *
@@ -49,7 +52,7 @@ template <typename Number> class BlockVector;
  *
  * @author Wolfgang Bangerth, 2000
  */
-template <typename number, int  rows, int columns=rows>
+template <typename number>
 class BlockSparseMatrix : public Subscriptor
 {
   public:
@@ -60,19 +63,25 @@ class BlockSparseMatrix : public Subscriptor
     typedef number value_type;
     
                                     /**
-                                     * Constructor; initializes the matrix to
-                                     * be empty, without any structure, i.e.
-                                     * the matrix is not usable at all. This
-                                     * constructor is therefore only useful
-                                     * for matrices which are members of a
-                                     * class. All other matrices should be
-                                     * created at a point in the data flow
-                                     * where all necessary information is
+                                     * Constructor; initializes the
+                                     * matrix to be empty, without
+                                     * any structure, i.e.  the
+                                     * matrix is not usable at
+                                     * all. This constructor is
+                                     * therefore only useful for
+                                     * matrices which are members of
+                                     * a class. All other matrices
+                                     * should be created at a point
+                                     * in the data flow where all
+                                     * necessary information is
                                      * available.
                                      *
-                                     * You have to initialize
-                                     * the matrix before usage with
-                                     * @p{reinit(BlockSparsityPattern)}.
+                                     * You have to initialize the
+                                     * matrix before usage with
+                                     * @p{reinit(BlockSparsityPattern)}. The
+                                     * number of blocks per row and
+                                     * column are then determined by
+                                     * that function.
                                      */
     BlockSparseMatrix ();
 
@@ -99,15 +108,21 @@ class BlockSparseMatrix : public Subscriptor
                                      */
     BlockSparseMatrix (const BlockSparsityPattern &sparsity);
 
+                                    /**
+                                     * Destructor.
+                                     */
+    virtual ~BlockSparseMatrix ();
+    
     
 
                                     /** 
                                      * Pseudo operator only copying
-                                     * empty objects.
+                                     * empty objects. The sizes of
+                                     * the block matrices need to be
+                                     * the same.
                                      */
-    BlockSparseMatrix<number,rows,columns> &
-    operator = (const BlockSparseMatrix<number,rows,columns> &);
-
+    BlockSparseMatrix<number> &
+    operator = (const BlockSparseMatrix<number> &);
 
                                     /**
                                      * Reinitialize the object but
@@ -116,8 +131,10 @@ class BlockSparseMatrix : public Subscriptor
                                      * necessary if you @p{reinit}'d
                                      * the sparsity structure and
                                      * want to update the size of the
-                                     * matrix. It only calls @p{reinit}
-                                     * on the sub-matrices.
+                                     * matrix. It only calls
+                                     * @p{reinit} on the
+                                     * sub-matrices. The size of this
+                                     * matrix is unchanged.
                                      *
                                      * If the sparsity pattern has
                                      * not changed, then the effect
@@ -179,14 +196,18 @@ class BlockSparseMatrix : public Subscriptor
     virtual void clear ();
     
                                     /**
-                                     * Return the number of blocks in a
-                                     * column.
+                                     * Return the number of blocks in
+                                     * a column. Returns zero if no
+                                     * sparsity pattern is presently
+                                     * associated to this matrix.
                                      */
     unsigned int n_block_rows () const;
     
                                     /**
-                                     * Return the number of blocks in a
-                                     * row.
+                                     * Return the number of blocks in
+                                     * a row. Returns zero if no
+                                     * sparsity pattern is presently
+                                     * associated to this matrix.
                                      */
     unsigned int n_block_cols () const;
   
@@ -276,8 +297,8 @@ class BlockSparseMatrix : public Subscriptor
                                      * reference to @p{this}.
                                      */
     template <typename somenumber>
-    BlockSparseMatrix<number,rows,columns> &
-    copy_from (const BlockSparseMatrix<somenumber,rows,columns> &source);
+    BlockSparseMatrix<number> &
+    copy_from (const BlockSparseMatrix<somenumber> &source);
 
                                     /**
                                      * Add @p{matrix} scaled by
@@ -296,7 +317,7 @@ class BlockSparseMatrix : public Subscriptor
                                      */
     template <typename somenumber>
     void add_scaled (const number factor,
-                    const BlockSparseMatrix<somenumber,rows,columns> &matrix);
+                    const BlockSparseMatrix<somenumber> &matrix);
     
                                     /**
                                      * Return the value of the entry (i,j).
@@ -307,7 +328,8 @@ class BlockSparseMatrix : public Subscriptor
                                      * throws an exception if the wanted
                                      * element does not exist in the matrix.
                                      */
-    number operator () (const unsigned int i, const unsigned int j) const;
+    number operator () (const unsigned int i,
+                       const unsigned int j) const;
 
 
                                     /**
@@ -316,7 +338,7 @@ class BlockSparseMatrix : public Subscriptor
                                      * being this matrix.
                                      */
     template <typename somenumber>
-    void vmult (BlockVector<somenumber>          &dst,
+    void vmult (BlockVector<somenumber>       &dst,
                const BlockVector<somenumber> &src) const;
     
                                     /**
@@ -328,7 +350,7 @@ class BlockSparseMatrix : public Subscriptor
                                      * transposed matrix.
                                      */
     template <typename somenumber>
-    void Tvmult (BlockVector<somenumber>    &dst,
+    void Tvmult (BlockVector<somenumber>       &dst,
                 const BlockVector<somenumber> &src) const;
   
                                     /**
@@ -338,7 +360,7 @@ class BlockSparseMatrix : public Subscriptor
                                      * matrix.
                                      */
     template <typename somenumber>
-    void vmult_add (BlockVector<somenumber>          &dst,
+    void vmult_add (BlockVector<somenumber>       &dst,
                    const BlockVector<somenumber> &src) const;
     
                                     /**
@@ -350,7 +372,7 @@ class BlockSparseMatrix : public Subscriptor
                                      * the transposed matrix.
                                      */
     template <typename somenumber>
-    void Tvmult_add (BlockVector<somenumber>    &dst,
+    void Tvmult_add (BlockVector<somenumber>       &dst,
                     const BlockVector<somenumber> &src) const;
   
                                     /**
@@ -386,7 +408,7 @@ class BlockSparseMatrix : public Subscriptor
                                      */    
     template <typename somenumber>
     somenumber
-    matrix_scalar_product (const BlockVector<somenumber>    &u,
+    matrix_scalar_product (const BlockVector<somenumber> &u,
                           const BlockVector<somenumber> &v) const;
     
                                     /**
@@ -400,9 +422,9 @@ class BlockSparseMatrix : public Subscriptor
                                      * into @p{dst}.
                                      */
     template <typename somenumber>
-    somenumber residual (BlockVector<somenumber>          &dst,
+    somenumber residual (BlockVector<somenumber>       &dst,
                         const BlockVector<somenumber> &x,
-                        const BlockVector<somenumber>    &b) const;
+                        const BlockVector<somenumber> &b) const;
 
                                     /**
                                      * Apply the Jacobi
@@ -418,9 +440,9 @@ class BlockSparseMatrix : public Subscriptor
                                      * for this operation.
                                      */
     template <typename somenumber>
-    void precondition_Jacobi (BlockVector<somenumber>          &dst,
+    void precondition_Jacobi (BlockVector<somenumber>       &dst,
                              const BlockVector<somenumber> &src,
-                             const number                           omega = 1.) const;
+                             const number                   omega = 1.) const;
 
                                     /**
                                      * Return a (constant) reference
@@ -448,8 +470,33 @@ class BlockSparseMatrix : public Subscriptor
                                      * Exception
                                      */
     DeclException0 (ExcMatrixNotBlockSquare);
+
+                                    /**
+                                     * Exception.
+                                     */
+    DeclException0 (ExcIncompatibleObjects);
     
   private:
+                                    /**
+                                     * Number of block rows in this
+                                     * matrix. Is set by default to
+                                     * zero, and is only changed if a
+                                     * sparsity pattern is given to
+                                     * the constructor or the
+                                     * @p{reinit} function.
+                                     */
+    unsigned int rows;
+
+                                    /**
+                                     * Number of block columns in this
+                                     * matrix. Is set by default to
+                                     * zero, and is only changed if a
+                                     * sparsity pattern is given to
+                                     * the constructor or the
+                                     * @p{reinit} function.
+                                     */
+    unsigned int columns;
+    
                                     /**
                                      * Pointer to the block sparsity
                                      * pattern used for this
@@ -464,7 +511,7 @@ class BlockSparseMatrix : public Subscriptor
                                     /**
                                      * Array of sub-matrices.
                                      */
-    SparseMatrix<number> sub_objects[rows][columns];
+    vector<vector<SmartPointer<SparseMatrix<number> > > > sub_objects;
 };
 
 
@@ -473,60 +520,60 @@ class BlockSparseMatrix : public Subscriptor
 /* ------------------------- Template functions ---------------------- */
 
 
-template <typename number, int rows, int columns>
+template <typename number>
 inline
 SparseMatrix<number> &
-BlockSparseMatrix<number,rows,columns>::block (const unsigned int row,
-                                              const unsigned int column)
+BlockSparseMatrix<number>::block (const unsigned int row,
+                                 const unsigned int column)
 {
   Assert (row<rows, ExcIndexRange (row, 0, rows));
   Assert (column<columns, ExcIndexRange (column, 0, columns));
   
-  return sub_objects[row][column];
+  return *sub_objects[row][column];
 };
 
 
 
-template <typename number, int rows, int columns>
+template <typename number>
 inline
 const SparseMatrix<number> &
-BlockSparseMatrix<number,rows,columns>::block (const unsigned int row,
-                                              const unsigned int column) const
+BlockSparseMatrix<number>::block (const unsigned int row,
+                                 const unsigned int column) const
 {
   Assert (row<rows, ExcIndexRange (row, 0, rows));
   Assert (column<columns, ExcIndexRange (column, 0, columns));
   
-  return sub_objects[row][column];
+  return *sub_objects[row][column];
 };
 
 
 
-template <typename number, int  rows, int columns>
+template <typename number>
 inline
 unsigned int
-BlockSparseMatrix<number,rows,columns>::m () const
+BlockSparseMatrix<number>::m () const
 {
   return sparsity_pattern->n_rows();
 };
 
 
 
-template <typename number, int  rows, int columns>
+template <typename number>
 inline
 unsigned int
-BlockSparseMatrix<number,rows,columns>::n () const
+BlockSparseMatrix<number>::n () const
 {
   return sparsity_pattern->n_cols();
 };
 
 
 
-template <typename number, int  rows, int columns>
+template <typename number>
 inline
 void
-BlockSparseMatrix<number,rows,columns>::set (const unsigned int i,
-                                            const unsigned int j,
-                                            const number value)
+BlockSparseMatrix<number>::set (const unsigned int i,
+                               const unsigned int j,
+                               const number value)
 {
   const pair<unsigned int,unsigned int>
     row_index = sparsity_pattern->row_indices.global_to_local (i),
@@ -538,12 +585,12 @@ BlockSparseMatrix<number,rows,columns>::set (const unsigned int i,
 
 
 
-template <typename number, int  rows, int columns>
+template <typename number>
 inline
 void
-BlockSparseMatrix<number,rows,columns>::add (const unsigned int i,
-                                            const unsigned int j,
-                                            const number value)
+BlockSparseMatrix<number>::add (const unsigned int i,
+                               const unsigned int j,
+                               const number value)
 {
   const pair<unsigned int,unsigned int>
     row_index = sparsity_pattern->row_indices.global_to_local (i),
@@ -555,11 +602,11 @@ BlockSparseMatrix<number,rows,columns>::add (const unsigned int i,
 
 
 
-template <typename number, int  rows, int columns>
+template <typename number>
 inline
 number
-BlockSparseMatrix<number,rows,columns>::operator () (const unsigned int i,
-                                                    const unsigned int j) const
+BlockSparseMatrix<number>::operator () (const unsigned int i,
+                                       const unsigned int j) const
 {
   const pair<unsigned int,unsigned int>
     row_index = sparsity_pattern->row_indices.global_to_local (i),
@@ -571,11 +618,11 @@ BlockSparseMatrix<number,rows,columns>::operator () (const unsigned int i,
 
 
 
-template <typename number, int  rows, int columns>
+template <typename number>
 template <typename somenumber>
-BlockSparseMatrix<number,rows,columns> &
-BlockSparseMatrix<number,rows,columns>::
-copy_from (const BlockSparseMatrix<somenumber,rows,columns> &source)
+BlockSparseMatrix<number> &
+BlockSparseMatrix<number>::
+copy_from (const BlockSparseMatrix<somenumber> &source)
 {
   for (unsigned int r=0; r<rows; ++r)
     for (unsigned int c=0; c<columns; ++c)
@@ -586,12 +633,12 @@ copy_from (const BlockSparseMatrix<somenumber,rows,columns> &source)
 
 
 
-template <typename number, int  rows, int columns>
+template <typename number>
 template <typename somenumber>
 void
-BlockSparseMatrix<number,rows,columns>::
+BlockSparseMatrix<number>::
 add_scaled (const number factor,
-           const BlockSparseMatrix<somenumber,rows,columns> &matrix)
+           const BlockSparseMatrix<somenumber> &matrix)
 {
   for (unsigned int r=0; r<rows; ++r)
     for (unsigned int c=0; c<columns; ++c)
@@ -601,12 +648,11 @@ add_scaled (const number factor,
 
 
 
-template <typename number, int  rows, int columns>
+template <typename number>
 template <typename somenumber>
 void
-BlockSparseMatrix<number,rows,columns>::
-vmult (BlockVector<somenumber>          &dst,
-       const BlockVector<somenumber> &src) const
+BlockSparseMatrix<number>::vmult (BlockVector<somenumber>       &dst,
+                                 const BlockVector<somenumber> &src) const
 {
   Assert (dst.n_blocks() == rows,
          ExcDimensionMismatch(dst.n_blocks(), rows));
@@ -618,19 +664,18 @@ vmult (BlockVector<somenumber>          &dst,
       block(row,0).vmult (dst.block(row),
                          src.block(0));
       for (unsigned int col=1; col<columns; ++col)
-      block(row,col).vmult_add (dst.block(row),
-                               src.block(col));
+       block(row,col).vmult_add (dst.block(row),
+                                 src.block(col));
     };
 };
 
 
 
-template <typename number, int  rows, int columns>
+template <typename number>
 template <typename somenumber>
 void
-BlockSparseMatrix<number,rows,columns>::
-vmult_add (BlockVector<somenumber>          &dst,
-          const BlockVector<somenumber> &src) const
+BlockSparseMatrix<number>::vmult_add (BlockVector<somenumber>       &dst,
+                                     const BlockVector<somenumber> &src) const
 {
   Assert (dst.n_blocks() == rows,
          ExcDimensionMismatch(dst.n_blocks(), rows));
@@ -642,20 +687,19 @@ vmult_add (BlockVector<somenumber>          &dst,
       block(row,0).vmult_add (dst.block(row),
                              src.block(0));
       for (unsigned int col=1; col<columns; ++col)
-      block(row,col).vmult_add (dst.block(row),
-                               src.block(col));
+       block(row,col).vmult_add (dst.block(row),
+                                 src.block(col));
     };
 };
 
 
 
 
-template <typename number, int  rows, int columns>
+template <typename number>
 template <typename somenumber>
 void
-BlockSparseMatrix<number,rows,columns>::
-Tvmult (BlockVector<somenumber>   &/*dst*/,
-       const BlockVector<somenumber> &/*src*/) const
+BlockSparseMatrix<number>::Tvmult (BlockVector<somenumber>   &/*dst*/,
+                                  const BlockVector<somenumber> &/*src*/) const
 {
                                   // presently not
                                   // implemented. should be simple,
@@ -666,12 +710,11 @@ Tvmult (BlockVector<somenumber>   &/*dst*/,
 
 
 
-template <typename number, int  rows, int columns>
+template <typename number>
 template <typename somenumber>
 void
-BlockSparseMatrix<number,rows,columns>::
-Tvmult_add (BlockVector<somenumber>    &/*dst*/,
-           const BlockVector<somenumber> &/*src*/) const
+BlockSparseMatrix<number>::Tvmult_add (BlockVector<somenumber>    &/*dst*/,
+                                      const BlockVector<somenumber> &/*src*/) const
 {
                                   // presently not
                                   // implemented. should be simple,
@@ -682,11 +725,10 @@ Tvmult_add (BlockVector<somenumber>    &/*dst*/,
 
 
 
-template <typename number, int  rows, int columns>
+template <typename number>
 template <typename somenumber>
 somenumber
-BlockSparseMatrix<number,rows,columns>::
-matrix_norm_square (const BlockVector<somenumber> &v) const
+BlockSparseMatrix<number>::matrix_norm_square (const BlockVector<somenumber> &v) const
 {
   Assert (rows == columns, ExcMatrixNotBlockSquare());
   Assert (v.n_blocks() == rows,
@@ -705,10 +747,10 @@ matrix_norm_square (const BlockVector<somenumber> &v) const
 
 
 
-template <typename number, int  rows, int columns>
+template <typename number>
 template <typename somenumber>
 somenumber
-BlockSparseMatrix<number,rows,columns>::
+BlockSparseMatrix<number>::
 matrix_scalar_product (const BlockVector<somenumber>    &u,
                       const BlockVector<somenumber> &v) const
 {
@@ -727,10 +769,10 @@ matrix_scalar_product (const BlockVector<somenumber>    &u,
 
 
 
-template <typename number, int  rows, int columns>
+template <typename number>
 template <typename somenumber>
 somenumber
-BlockSparseMatrix<number,rows,columns>::
+BlockSparseMatrix<number>::
 residual (BlockVector<somenumber>          &dst,
          const BlockVector<somenumber> &x,
          const BlockVector<somenumber>    &b) const
@@ -780,10 +822,10 @@ residual (BlockVector<somenumber>          &dst,
 
 
 
-template <typename number, int  rows, int columns>
+template <typename number>
 template <typename somenumber>
 void
-BlockSparseMatrix<number,rows,columns>::
+BlockSparseMatrix<number>::
 precondition_Jacobi (BlockVector<somenumber>          &dst,
                     const BlockVector<somenumber> &src,
                     const number                           omega) const
@@ -801,23 +843,23 @@ precondition_Jacobi (BlockVector<somenumber>          &dst,
 };
 
 
-template <typename number, int rows, int columns>
+template <typename number>
 inline
 unsigned int
-BlockSparseMatrix<number,rows,columns>::n_block_cols () const
+BlockSparseMatrix<number>::n_block_cols () const
 {
   return columns;
-}
+};
 
 
 
-template <typename number, int rows, int columns>
+template <typename number>
 inline
 unsigned int
-BlockSparseMatrix<number,rows,columns>::n_block_rows () const
+BlockSparseMatrix<number>::n_block_rows () const
 {
   return rows;
-}
+};
 
 
 #endif    // __deal2__block_sparse_matrix_h
index 52abe1a3df79872818ece692c1799e235ebe05ea..672c1c3e6b3224c5d1740b9aab702b68fc176bc4 100644 (file)
 
 
 
-template <typename number, int  rows, int columns>
-BlockSparseMatrix<number,rows,columns>::BlockSparseMatrix () :
+template <typename number>
+BlockSparseMatrix<number>::BlockSparseMatrix () :
+               rows (0),
+               columns (0),
                sparsity_pattern (0)
 {};
 
 
 
-template <typename number, int  rows, int columns>
-BlockSparseMatrix<number,rows,columns>::
-BlockSparseMatrix (const BlockSparsityPattern &sparsity)
+template <typename number>
+BlockSparseMatrix<number>::
+BlockSparseMatrix (const BlockSparsityPattern &sparsity) :
+               rows (0),
+               columns (0)
 {
   reinit (sparsity);
 };
 
 
 
-template <typename number, int  rows, int columns>
-BlockSparseMatrix<number,rows,columns> &
-BlockSparseMatrix<number,rows,columns>::
-operator = (const BlockSparseMatrix<number,rows,columns> &m) 
+template <typename number>
+BlockSparseMatrix<number>::~BlockSparseMatrix ()
 {
+                                  // delete previous content of
+                                  // the subobjects array
+  for (unsigned int r=0; r<rows; ++r)
+    for (unsigned int c=0; c<columns; ++c)
+      {
+       SparseMatrix<number> *p = sub_objects[r][c];
+       sub_objects[r][c] = 0;
+       delete p;
+      };
+};
+
+
+
+template <typename number>
+BlockSparseMatrix<number> &
+BlockSparseMatrix<number>::
+operator = (const BlockSparseMatrix<number> &m) 
+{
+  Assert (rows == m.rows, ExcIncompatibleObjects());
+  Assert (columns == m.columns, ExcIncompatibleObjects());
                                   // this operator does not do
                                   // anything except than checking
                                   // whether the base objects want to
@@ -52,9 +74,9 @@ operator = (const BlockSparseMatrix<number,rows,columns> &m)
 
  
 
-template <typename number, int  rows, int columns>
+template <typename number>
 void
-BlockSparseMatrix<number,rows,columns>::reinit ()
+BlockSparseMatrix<number>::reinit ()
 {
   for (unsigned int r=0; r<rows; ++r)
     for (unsigned int c=0; c<columns; ++c)
@@ -63,23 +85,44 @@ BlockSparseMatrix<number,rows,columns>::reinit ()
 
 
 
-template <typename number, int  rows, int columns>
+template <typename number>
 void
-BlockSparseMatrix<number,rows,columns>::
+BlockSparseMatrix<number>::
 reinit (const BlockSparsityPattern &sparsity)
 {
+                                  // first delete previous content of
+                                  // the subobjects array
+  for (unsigned int r=0; r<rows; ++r)
+    for (unsigned int c=0; c<columns; ++c)
+      {
+       SparseMatrix<number> *p = sub_objects[r][c];
+       sub_objects[r][c] = 0;
+       delete p;
+      };
+  sub_objects.clear ();
+
+                                  // then associate new sparsity
+                                  // pattern and resize
   sparsity_pattern = &sparsity;
-  
+  rows = sparsity.n_block_rows();
+  columns = sparsity.n_block_cols();
+  sub_objects = vector<vector<SmartPointer<SparseMatrix<number> > > >
+               (rows, vector<SmartPointer<SparseMatrix<number> > > (columns, 0));
+
+                                  // and reinitialize the blocks
   for (unsigned int r=0; r<rows; ++r)
     for (unsigned int c=0; c<columns; ++c)
-      block(r,c).reinit (sparsity.block(r,c));
+      {
+       sub_objects[r][c] = new SparseMatrix<number>();
+       block(r,c).reinit (sparsity.block(r,c));
+      };
 };
 
 
 
-template <typename number, int  rows, int columns>
+template <typename number>
 void
-BlockSparseMatrix<number,rows,columns>::clear () 
+BlockSparseMatrix<number>::clear () 
 {
   sparsity_pattern = 0;
   for (unsigned int r=0; r<rows; ++r)
@@ -89,9 +132,9 @@ BlockSparseMatrix<number,rows,columns>::clear ()
 
 
 
-template <typename number, int  rows, int columns>
+template <typename number>
 bool
-BlockSparseMatrix<number,rows,columns>::empty () const
+BlockSparseMatrix<number>::empty () const
 {
   for (unsigned int r=0; r<rows; ++r)
     for (unsigned int c=0; c<columns; ++c)
@@ -103,32 +146,33 @@ BlockSparseMatrix<number,rows,columns>::empty () const
 
 
 
-template <typename number, int  rows, int columns>
+template <typename number>
 unsigned int
-BlockSparseMatrix<number,rows,columns>::n_nonzero_elements () const
+BlockSparseMatrix<number>::n_nonzero_elements () const
 {
   return sparsity_pattern->n_nonzero_elements ();
 };
 
 
 
-template <typename number, int  rows, int columns>
+template <typename number>
 const BlockSparsityPattern &
-BlockSparseMatrix<number,rows,columns>::get_sparsity_pattern () const
+BlockSparseMatrix<number>::get_sparsity_pattern () const
 {
   return *sparsity_pattern;
 };
 
 
 
-template <typename number, int  rows, int columns>
+template <typename number>
 unsigned int
-BlockSparseMatrix<number,rows,columns>::memory_consumption () const
+BlockSparseMatrix<number>::memory_consumption () const
 {
   unsigned int mem = sizeof(*this);
+  mem += MemoryConsumption::memory_consumption (sub_objects);
   for (unsigned int r=0; r<rows; ++r)
     for (unsigned int c=0; c<columns; ++c)
-      mem += MemoryConsumption::memory_consumption(sub_objects[r][c]);
+      mem += MemoryConsumption::memory_consumption(*sub_objects[r][c]);
   return mem;
 };
 
index bd9655893ec9b8c0da34da5677cee1cee5c9dbbc..49ba448a9eae8d52ad780033fc6cadf75e3a9c09 100644 (file)
@@ -385,7 +385,7 @@ class BlockSparsityPattern : public Subscriptor
                                      * @p{row_indices} and
                                      * @p{column_indices} objects.
                                      */
-    template <typename number, int r, int c>
+    template <typename number>
     friend class BlockSparseMatrix;
 };
 
index 504d7c5bfccbe447bc2af0b41995375b2bfb91f0..6be484a4333a08435763983436b1302f4e53e961 100644 (file)
 #include <lac/block_sparse_matrix.templates.h>
 
 // explicit instantiations
-template class BlockSparseMatrix<double,2,2>;
-template class BlockSparseMatrix<double,2,3>;
-
-template class BlockSparseMatrix<double,3,2>;
-template class BlockSparseMatrix<double,3,3>;
-
-
-
-template class BlockSparseMatrix<float,2,2>;
-template class BlockSparseMatrix<float,2,3>;
-
-template class BlockSparseMatrix<float,3,2>;
-template class BlockSparseMatrix<float,3,3>;
-
+template class BlockSparseMatrix<double>;
+template class BlockSparseMatrix<float>;
index dee86931f3917a356b0b6587881ee3cea28fa3d9..acb06007408fd5217483536055068361207ea707 100644 (file)
@@ -124,7 +124,7 @@ void test ()
   
                                   // now make a matrix with this
                                   // sparsity pattern
-  BlockSparseMatrix<double,3,2> bsm (bsp);
+  BlockSparseMatrix<double> bsm (bsp);
   deallog << total_nonzero_elements << "=="
          << bsm.n_nonzero_elements()
          << endl;

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.