]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Don't use vector<SparseMatrix> (or SparsityPattern, or their block counterparts)...
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 21 May 2003 21:19:16 +0000 (21:19 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 21 May 2003 21:19:16 +0000 (21:19 +0000)
git-svn-id: https://svn.dealii.org/trunk@7663 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/multigrid/mg_transfer.h
deal.II/deal.II/source/multigrid/multigrid.all_dimensions.cc
deal.II/deal.II/source/multigrid/multigrid.cc

index c4588bf89530b294d2235f9a0c0af19b31d80779..98d58c34cd545547fdb922dce24a79b0d518b793 100644 (file)
@@ -25,6 +25,9 @@
 #include <multigrid/mg_base.h>
 #include <multigrid/mg_level_object.h>
 
+#include <boost_local/shared_ptr.hpp>
+
+
 template <int dim> class MGDoFHandler;
 
 /*
@@ -179,13 +182,13 @@ class MGTransferPrebuilt : public MGTransferBase<Vector<number> >
                                      * while row indices belong to the
                                      * child cell, i.e. the fine level.
                                      */
-    std::vector<SparseMatrixEZ<double> > prolongation_matrices;
+    std::vector<boost::shared_ptr<SparseMatrixEZ<double> > > prolongation_matrices;
 #else
                                     /**
                                      * Sparsity patterns for transfer
                                      * matrices.
                                      */
-    std::vector<SparsityPattern>   prolongation_sparsities;
+    std::vector<boost::shared_ptr<SparsityPattern> >   prolongation_sparsities;
 
                                     /**
                                      * The actual prolongation matrix.
@@ -195,7 +198,7 @@ class MGTransferPrebuilt : public MGTransferBase<Vector<number> >
                                      * while row indices belong to the
                                      * child cell, i.e. the fine level.
                                      */
-    std::vector<SparseMatrix<double> > prolongation_matrices;
+    std::vector<boost::shared_ptr<SparseMatrix<double> > > prolongation_matrices;
 #endif
 };
 
@@ -261,10 +264,10 @@ class MGTransferBlockBase
                                      * while row indices belong to the
                                      * child cell, i.e. the fine level.
                                      */
-    std::vector<BlockSparseMatrixEZ<double> > prolongation_matrices;
+    std::vector<boost::shared_ptr<BlockSparseMatrixEZ<double> > > prolongation_matrices;
 #else
   private:
-    std::vector<BlockSparsityPattern>   prolongation_sparsities;
+    std::vector<boost::shared_ptr<BlockSparsityPattern> >   prolongation_sparsities;
 
   protected:
   
@@ -276,7 +279,7 @@ class MGTransferBlockBase
                                      * while row indices belong to the
                                      * child cell, i.e. the fine level.
                                      */
-    std::vector<BlockSparseMatrix<double> > prolongation_matrices;
+    std::vector<boost::shared_ptr<BlockSparseMatrix<double> > > prolongation_matrices;
 #endif
 };
 
index b634c62f5eed85b467771b5c9828abafb48abb19..093099414af8ac9777d1a69c0c07464780dd5a8d 100644 (file)
@@ -104,7 +104,7 @@ void MGTransferPrebuilt<number>::prolongate (
   Assert ((to_level >= 1) && (to_level<=prolongation_matrices.size()),
          ExcIndexRange (to_level, 1, prolongation_matrices.size()+1));
 
-  prolongation_matrices[to_level-1].vmult (dst, src);
+  prolongation_matrices[to_level-1]->vmult (dst, src);
 }
 
 
@@ -117,7 +117,7 @@ void MGTransferPrebuilt<number>::restrict_and_add (
   Assert ((from_level >= 1) && (from_level<=prolongation_matrices.size()),
          ExcIndexRange (from_level, 1, prolongation_matrices.size()+1));
 
-  prolongation_matrices[from_level-1].Tvmult_add (dst, src);
+  prolongation_matrices[from_level-1]->Tvmult_add (dst, src);
 }
 
 
@@ -143,7 +143,7 @@ void MGTransferBlock<number>::prolongate (
     {
       if (!selected[k])
        ++k;
-      prolongation_matrices[to_level-1].block(k,k).vmult (dst.block(b), src.block(b));
+      prolongation_matrices[to_level-1]->block(k,k).vmult (dst.block(b), src.block(b));
       ++k;
     }
 }
@@ -163,7 +163,7 @@ void MGTransferBlock<number>::restrict_and_add (
     {
       if (!selected[k])
        ++k;
-      prolongation_matrices[from_level-1].block(k,k).Tvmult_add (dst.block(b), src.block(b));
+      prolongation_matrices[from_level-1]->block(k,k).Tvmult_add (dst.block(b), src.block(b));
       ++k;
     }
 }
@@ -185,7 +185,7 @@ void MGTransferSelect<number>::prolongate (
   Assert ((to_level >= 1) && (to_level<=prolongation_matrices.size()),
          ExcIndexRange (to_level, 1, prolongation_matrices.size()+1));
 
-      prolongation_matrices[to_level-1].block(selected, selected)
+      prolongation_matrices[to_level-1]->block(selected, selected)
        .vmult (dst, src);
 }
 
@@ -199,7 +199,7 @@ void MGTransferSelect<number>::restrict_and_add (
   Assert ((from_level >= 1) && (from_level<=prolongation_matrices.size()),
          ExcIndexRange (from_level, 1, prolongation_matrices.size()+1));
 
-  prolongation_matrices[from_level-1].block(selected, selected)
+  prolongation_matrices[from_level-1]->block(selected, selected)
     .Tvmult_add (dst, src);
 }
 
index d238ba7037c43d6dfc9eea39a71c2748af0a771b..01fa606dab1cee0fb519a0438bf326123d801eb7 100644 (file)
@@ -41,21 +41,34 @@ void MGTransferPrebuilt<number>::build_matrices (
   for (unsigned int l=0;l<n_levels;++l)
     sizes[l] = mg_dof.n_dofs(l);
   
-                                  // Reset the size of the array of
-                                  // matrices. Call resize(0) first,
+                                  // reset the size of the array of
+                                  // matrices. call resize(0) first,
                                   // in order to delete all elements
-                                  // as otherwise the copy
-                                  // constructor of SparseMatrix and
-                                  // SparsityPattern is called what
-                                  // throws an error if existing
-                                  // SparseMatrices/SparsityPatterns
-                                  // have a size greater zero.
+                                  // and clear their memory. then
+                                  // repopulate these arrays
+                                  //
+                                  // note that on resize(0), the
+                                  // shared_ptr class takes care of
+                                  // deleting the object it points to
+                                  // by itself
   prolongation_matrices.resize (0);
-  prolongation_matrices.resize (n_levels-1);
 #ifndef DEAL_PREFER_MATRIX_EZ
   prolongation_sparsities.resize (0);
-  prolongation_sparsities.resize (n_levels-1);
 #endif
+
+  for (unsigned int i=0; i<n_levels-1; ++i)
+    {
+#ifndef DEAL_PREFER_MATRIX_EZ
+      prolongation_sparsities
+       .push_back (boost::shared_ptr<SparsityPattern> (new SparsityPattern));
+      prolongation_matrices
+       .push_back (boost::shared_ptr<SparseMatrix<double> > (new SparseMatrix<double>));
+#else
+      prolongation_matrices
+       .push_back (boost::shared_ptr<SparseMatrix<double> > (new SparseMatrixEZ<double>));
+#endif
+    }
+  
                                   // two fields which will store the
                                   // indices of the multigrid dofs
                                   // for a cell and one of its children
@@ -77,16 +90,16 @@ void MGTransferPrebuilt<number>::build_matrices (
                                       // number of degrees of freedom per
                                       // cell
 #ifdef DEAL_PREFER_MATRIX_EZ      
-      prolongation_matrices[level].reinit (sizes[level+1],
-                                          sizes[level],
-                                          dofs_per_cell);
+      prolongation_matrices[level]->reinit (sizes[level+1],
+                                           sizes[level],
+                                           dofs_per_cell);
 #else
                                       // increment dofs_per_cell
                                       // since a useless diagonal
                                       // element will be stored
-      prolongation_sparsities[level].reinit (sizes[level+1],
-                                            sizes[level],
-                                            dofs_per_cell+1);
+      prolongation_sparsities[level]->reinit (sizes[level+1],
+                                             sizes[level],
+                                             dofs_per_cell+1);
       
       for (typename MGDoFHandler<dim>::cell_iterator cell=mg_dof.begin(level);
           cell != mg_dof.end(level); ++cell)
@@ -114,15 +127,14 @@ void MGTransferPrebuilt<number>::build_matrices (
                  for (unsigned int j=0; j<dofs_per_cell; ++j)
                    if (prolongation(i,j) != 0)
                      {
-                       prolongation_sparsities[level].add
-                         (dof_indices_child[i],
-                          dof_indices_parent[j]);
+                       prolongation_sparsities[level]->add (dof_indices_child[i],
+                                                            dof_indices_parent[j]);
                      };
              };
          };
-      prolongation_sparsities[level].compress ();
+      prolongation_sparsities[level]->compress ();
 
-      prolongation_matrices[level].reinit (prolongation_sparsities[level]);
+      prolongation_matrices[level]->reinit (*prolongation_sparsities[level]);
 #endif
 
                                       // now actually build the matrices
@@ -148,12 +160,9 @@ void MGTransferPrebuilt<number>::build_matrices (
                for (unsigned int i=0; i<dofs_per_cell; ++i)
                  for (unsigned int j=0; j<dofs_per_cell; ++j)
                    if (prolongation(i,j) != 0)
-                     {
-                       prolongation_matrices[level].set
-                         (dof_indices_child[i],
-                          dof_indices_parent[j],
-                          prolongation(i,j));
-                     };
+                     prolongation_matrices[level]->set (dof_indices_child[i],
+                                                        dof_indices_parent[j],
+                                                        prolongation(i,j));
              };
          };
     };
@@ -182,13 +191,32 @@ void MGTransferBlockBase::build_matrices (
   MGTools::count_dofs_per_component(mg_dof, sizes);
   
                                   // reset the size of the array of
-                                  // matrices
-  prolongation_matrices.clear();
+                                  // matrices. call resize(0) first,
+                                  // in order to delete all elements
+                                  // and clear their memory. then
+                                  // repopulate these arrays
+                                  //
+                                  // note that on resize(0), the
+                                  // shared_ptr class takes care of
+                                  // deleting the object it points to
+                                  // by itself
+  prolongation_matrices.resize (0);
+#ifndef DEAL_PREFER_MATRIX_EZ
+  prolongation_sparsities.resize (0);
+#endif
+
+  for (unsigned int i=0; i<n_levels-1; ++i)
+    {
 #ifndef DEAL_PREFER_MATRIX_EZ
-  prolongation_sparsities.clear();
-  prolongation_sparsities.resize (n_levels-1);
+      prolongation_sparsities
+       .push_back (boost::shared_ptr<BlockSparsityPattern> (new BlockSparsityPattern));
+      prolongation_matrices
+       .push_back (boost::shared_ptr<BlockSparseMatrix<double> > (new BlockSparseMatrix<double>));
+#else
+      prolongation_matrices
+       .push_back (boost::shared_ptr<BlockSparseMatrix<double> > (new BlockSparseMatrixEZ<double>));
 #endif
-  prolongation_matrices.resize (n_levels-1);
+    }
 
                                   // two fields which will store the
                                   // indices of the multigrid dofs
@@ -220,35 +248,35 @@ void MGTransferBlockBase::build_matrices (
 // row-lengths, this should be used here to specify the length of
 // every single row.
 
-      prolongation_matrices[level].reinit (n_components, n_components);
+      prolongation_matrices[level]->reinit (n_components, n_components);
       for (unsigned int i=0;i<n_components;++i)
        for (unsigned int j=0;j<n_components;++j)
          if (i==j)
-           prolongation_matrices[level].block(i,j).reinit(
-             sizes[level+1][i],
-             sizes[level][j], dofs_per_cell, 0);
+           prolongation_matrices[level]->block(i,j)
+             .reinit(sizes[level+1][i],
+                     sizes[level][j], dofs_per_cell, 0);
          else
-           prolongation_matrices[level].block(i,j).reinit(
-             sizes[level+1][i],
-             sizes[level][j], 0);
-      prolongation_matrices[level].collect_sizes();
+           prolongation_matrices[level]->block(i,j)
+             .reinit(sizes[level+1][i],
+                     sizes[level][j], 0);
+      prolongation_matrices[level]->collect_sizes();
 #else
-      prolongation_sparsities[level].reinit (n_components, n_components);
-      for (unsigned int i=0;i<n_components;++i)
-       for (unsigned int j=0;j<n_components;++j)
+      prolongation_sparsities[level]->reinit (n_components, n_components);
+      for (unsigned int i=0; i<n_components; ++i)
+       for (unsigned int j=0; j<n_components; ++j)
          if (i==j)
-           prolongation_sparsities[level].block(i,j).reinit(
-             sizes[level+1][i],
-             sizes[level][j],
+           prolongation_sparsities[level]->block(i,j)
+             .reinit(sizes[level+1][i],
+                     sizes[level][j],
 //TODO:[GK] Split this by component to save memory
-             dofs_per_cell+1);
+                     dofs_per_cell+1);
          else
-           prolongation_sparsities[level].block(i,j).reinit(
-             sizes[level+1][i],
-             sizes[level][j],
-             0);
+           prolongation_sparsities[level]->block(i,j)
+             .reinit(sizes[level+1][i],
+                     sizes[level][j],
+                     0);
 
-      prolongation_sparsities[level].collect_sizes();
+      prolongation_sparsities[level]->collect_sizes();
       
       for (typename MGDoFHandler<dim>::cell_iterator cell=mg_dof.begin(level);
           cell != mg_dof.end(level); ++cell)
@@ -277,15 +305,14 @@ void MGTransferBlockBase::build_matrices (
                        const unsigned int icomp = fe.system_to_component_index(i).first;
                        const unsigned int jcomp = fe.system_to_component_index(j).first;
                        if ((icomp==jcomp) && selected[icomp])
-                         prolongation_sparsities[level].add
-                           (dof_indices_child[i],
-                            dof_indices_parent[j]);
+                         prolongation_sparsities[level]->add(dof_indices_child[i],
+                                                             dof_indices_parent[j]);
                      };
              };
          };
-      prolongation_sparsities[level].compress ();
+      prolongation_sparsities[level]->compress ();
 
-      prolongation_matrices[level].reinit (prolongation_sparsities[level]);
+      prolongation_matrices[level]->reinit (*prolongation_sparsities[level]);
 #endif
                                       // now actually build the matrices
       for (typename MGDoFHandler<dim>::cell_iterator cell=mg_dof.begin(level);
@@ -314,10 +341,9 @@ void MGTransferBlockBase::build_matrices (
                        const unsigned int icomp = fe.system_to_component_index(i).first;
                        const unsigned int jcomp = fe.system_to_component_index(j).first;
                        if ((icomp==jcomp) && selected[icomp])
-                         prolongation_matrices[level].set
-                           (dof_indices_child[i],
-                            dof_indices_parent[j],
-                            prolongation(i,j));
+                         prolongation_matrices[level]->set(dof_indices_child[i],
+                                                           dof_indices_parent[j],
+                                                           prolongation(i,j));
                      };
              };
          };
@@ -356,7 +382,7 @@ void MGTransferBlockBase::build_matrices (
          deallog << "level " << level
                  << " block " << i << ' ' << j << std::endl;
          
-         prolongation_matrices[level].block(i,j).print_statistics(deallog,true);
+         prolongation_matrices[level]->block(i,j).print_statistics(deallog,true);
        }
   deallog.pop();
 #endif  

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.