From 34761eaf3a3bab874ce6e255de57a0939ac5f185 Mon Sep 17 00:00:00 2001 From: wolf Date: Wed, 21 May 2003 21:19:16 +0000 Subject: [PATCH] Don't use vector (or SparsityPattern, or their block counterparts), since these objects can't really be copied and std::vector requires this. Rather, use boost::shared_ptr for that. git-svn-id: https://svn.dealii.org/trunk@7663 0785d39b-7218-0410-832d-ea1e28bc413d --- .../deal.II/include/multigrid/mg_transfer.h | 15 +- .../multigrid/multigrid.all_dimensions.cc | 12 +- deal.II/deal.II/source/multigrid/multigrid.cc | 150 ++++++++++-------- 3 files changed, 103 insertions(+), 74 deletions(-) diff --git a/deal.II/deal.II/include/multigrid/mg_transfer.h b/deal.II/deal.II/include/multigrid/mg_transfer.h index c4588bf895..98d58c34cd 100644 --- a/deal.II/deal.II/include/multigrid/mg_transfer.h +++ b/deal.II/deal.II/include/multigrid/mg_transfer.h @@ -25,6 +25,9 @@ #include #include +#include + + template class MGDoFHandler; /* @@ -179,13 +182,13 @@ class MGTransferPrebuilt : public MGTransferBase > * while row indices belong to the * child cell, i.e. the fine level. */ - std::vector > prolongation_matrices; + std::vector > > prolongation_matrices; #else /** * Sparsity patterns for transfer * matrices. */ - std::vector prolongation_sparsities; + std::vector > prolongation_sparsities; /** * The actual prolongation matrix. @@ -195,7 +198,7 @@ class MGTransferPrebuilt : public MGTransferBase > * while row indices belong to the * child cell, i.e. the fine level. */ - std::vector > prolongation_matrices; + std::vector > > prolongation_matrices; #endif }; @@ -261,10 +264,10 @@ class MGTransferBlockBase * while row indices belong to the * child cell, i.e. the fine level. */ - std::vector > prolongation_matrices; + std::vector > > prolongation_matrices; #else private: - std::vector prolongation_sparsities; + std::vector > prolongation_sparsities; protected: @@ -276,7 +279,7 @@ class MGTransferBlockBase * while row indices belong to the * child cell, i.e. the fine level. */ - std::vector > prolongation_matrices; + std::vector > > prolongation_matrices; #endif }; diff --git a/deal.II/deal.II/source/multigrid/multigrid.all_dimensions.cc b/deal.II/deal.II/source/multigrid/multigrid.all_dimensions.cc index b634c62f5e..093099414a 100644 --- a/deal.II/deal.II/source/multigrid/multigrid.all_dimensions.cc +++ b/deal.II/deal.II/source/multigrid/multigrid.all_dimensions.cc @@ -104,7 +104,7 @@ void MGTransferPrebuilt::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::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::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::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::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::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); } diff --git a/deal.II/deal.II/source/multigrid/multigrid.cc b/deal.II/deal.II/source/multigrid/multigrid.cc index d238ba7037..01fa606dab 100644 --- a/deal.II/deal.II/source/multigrid/multigrid.cc +++ b/deal.II/deal.II/source/multigrid/multigrid.cc @@ -41,21 +41,34 @@ void MGTransferPrebuilt::build_matrices ( for (unsigned int l=0;l (new SparsityPattern)); + prolongation_matrices + .push_back (boost::shared_ptr > (new SparseMatrix)); +#else + prolongation_matrices + .push_back (boost::shared_ptr > (new SparseMatrixEZ)); +#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::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::cell_iterator cell=mg_dof.begin(level); cell != mg_dof.end(level); ++cell) @@ -114,15 +127,14 @@ void MGTransferPrebuilt::build_matrices ( for (unsigned int j=0; jadd (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::build_matrices ( for (unsigned int i=0; iset (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 (new BlockSparsityPattern)); + prolongation_matrices + .push_back (boost::shared_ptr > (new BlockSparseMatrix)); +#else + prolongation_matrices + .push_back (boost::shared_ptr > (new BlockSparseMatrixEZ)); #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;iblock(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;ireinit (n_components, n_components); + for (unsigned int i=0; iblock(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::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::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 -- 2.39.5