From: kronbichler Date: Tue, 9 Feb 2010 11:21:29 +0000 (+0000) Subject: Update copy_indices - use std::vector instead of std::map. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=71f8352da851fc2b7423125836172c7c82379b1f;p=dealii-svn.git Update copy_indices - use std::vector instead of std::map. git-svn-id: https://svn.dealii.org/trunk@20526 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/multigrid/mg_transfer.h b/deal.II/deal.II/include/multigrid/mg_transfer.h index 61ad98b3d5..8c63dc237a 100644 --- a/deal.II/deal.II/include/multigrid/mg_transfer.h +++ b/deal.II/deal.II/include/multigrid/mg_transfer.h @@ -223,7 +223,7 @@ class MGTransferPrebuilt : public MGTransferBase * The data is first the global * index, then the level index. */ - std::vector > + std::vector > > copy_indices; /** diff --git a/deal.II/deal.II/include/multigrid/mg_transfer.templates.h b/deal.II/deal.II/include/multigrid/mg_transfer.templates.h index ac3e9308d8..0aad386f8b 100644 --- a/deal.II/deal.II/include/multigrid/mg_transfer.templates.h +++ b/deal.II/deal.II/include/multigrid/mg_transfer.templates.h @@ -49,7 +49,7 @@ MGTransferPrebuilt::copy_from_mg( dst = 0; for (unsigned int level=0;level::const_iterator IT; + typedef std::vector >::const_iterator IT; for (IT i= copy_indices[level].begin(); i != copy_indices[level].end();++i) dst(i->first) = src[level](i->second); @@ -77,7 +77,7 @@ MGTransferPrebuilt::copy_from_mg_add ( // functions for (unsigned int level=0;level::const_iterator IT; + typedef std::vector >::const_iterator IT; for (IT i= copy_indices[level].begin(); i != copy_indices[level].end();++i) dst(i->first) += src[level](i->second); diff --git a/deal.II/deal.II/include/multigrid/mg_transfer_component.h b/deal.II/deal.II/include/multigrid/mg_transfer_component.h index ea98f0b957..2e32e71067 100644 --- a/deal.II/deal.II/include/multigrid/mg_transfer_component.h +++ b/deal.II/deal.II/include/multigrid/mg_transfer_component.h @@ -170,7 +170,7 @@ class MGTransferComponentBase * The data is first the global * index, then the level index. */ - std::vector > + std::vector > > copy_to_and_from_indices; /** diff --git a/deal.II/deal.II/include/multigrid/mg_transfer_component.templates.h b/deal.II/deal.II/include/multigrid/mg_transfer_component.templates.h index 301c987de5..a8abc20625 100644 --- a/deal.II/deal.II/include/multigrid/mg_transfer_component.templates.h +++ b/deal.II/deal.II/include/multigrid/mg_transfer_component.templates.h @@ -86,15 +86,15 @@ MGTransferSelect::copy_from_mg ( do_copy_from_mg (mg_dof_handler, dst, src); if (constraints != 0) { - //If we were given constraints - //apply them to the dst that goes + //If we were given constraints + //apply them to the dst that goes //back now to the linear solver. //Since constraints are globally //defined create a global vector here - //and copy dst to the right component, - //apply the constraints then and copy + //and copy dst to the right component, + //apply the constraints then and copy //the block back to dst. - const unsigned int n_blocks = + const unsigned int n_blocks = *std::max_element(target_component.begin(), target_component.end()) + 1; std::vector dofs_per_block (n_blocks); DoFTools::count_dofs_per_block (mg_dof_handler, dofs_per_block, target_component); @@ -166,7 +166,7 @@ MGTransferSelect::do_copy_from_mg ( for (; level_cell != endc; ++level_cell) { const unsigned int level = level_cell->level(); - typedef std::map::const_iterator IT; + typedef std::vector >::const_iterator IT; for (IT i=copy_to_and_from_indices[level].begin(); i != copy_to_and_from_indices[level].end(); ++i) dst(i->first) = src[level](i->second); @@ -203,7 +203,7 @@ MGTransferSelect::do_copy_from_mg_add ( for (; level_cell != endc; ++level_cell) { const unsigned int level = level_cell->level(); - typedef std::map::const_iterator IT; + typedef std::vector >::const_iterator IT; for (IT i=copy_to_and_from_indices[level].begin(); i != copy_to_and_from_indices[level].end(); ++i) dst(i->first) += src[level](i->second); diff --git a/deal.II/deal.II/source/multigrid/mg_transfer_component.cc b/deal.II/deal.II/source/multigrid/mg_transfer_component.cc index c30c638a8a..b358e07d96 100644 --- a/deal.II/deal.II/source/multigrid/mg_transfer_component.cc +++ b/deal.II/deal.II/source/multigrid/mg_transfer_component.cc @@ -247,19 +247,20 @@ MGTransferSelect::do_copy_to_mg ( for (unsigned int level=mg_dof_handler.get_tria().n_levels(); level!=0;) { --level; + Vector &dst_level = dst[level]; - typedef std::map::const_iterator IT; - for (IT i=copy_to_and_from_indices[level].begin(); - i != copy_to_and_from_indices[level].end(); ++i) - dst[level](i->second) = src(i->first); + typedef std::vector >::const_iterator IT; + for (IT i=copy_to_and_from_indices[level].begin(); + i != copy_to_and_from_indices[level].end(); ++i) + dst_level(i->second) = src(i->first); // for that part of the level // which is further refined: // get the defect by // restriction of the defect on // one level higher - if(!first) - restrict_and_add (level+1, dst[level], dst[level+1]); - first = false; + if(!first) + restrict_and_add (level+1, dst[level], dst[level+1]); + first = false; } } @@ -610,6 +611,9 @@ void MGTransferSelect::build_matrices ( interface_dofs[l].resize(mg_dof.n_dofs(l)); MGTools::extract_inner_interface_dofs(mg_dof, interface_dofs); + // use a temporary vector to create the + // relation between global and level dofs + std::vector temp_copy_indices; std::vector global_dof_indices (fe.dofs_per_cell); std::vector level_dof_indices (fe.dofs_per_cell); for (int level=dof.get_tria().n_levels()-1; level>=0; --level) @@ -620,6 +624,9 @@ void MGTransferSelect::build_matrices ( const typename MGDoFHandler::active_cell_iterator level_end = mg_dof.end_active(level); + temp_copy_indices.resize (0); + temp_copy_indices.resize (mg_dof.n_dofs(level), numbers::invalid_unsigned_int); + // Compute coarse level right hand side // by restricting from fine level. for (; level_cell!=level_end; ++level_cell) @@ -644,10 +651,8 @@ void MGTransferSelect::build_matrices ( = mg_component_start[level][mg_target_component[component]]; const unsigned int global_start = component_start[target_component[component]]; - copy_to_and_from_indices[level].insert( - std::make_pair(global_dof_indices[i] - global_start - /*- component_start[target_component[selected_component]]*/, - level_dof_indices[i]-level_start)); + temp_copy_indices[level_dof_indices[i]-level_start] = + global_dof_indices[i]-global_start; deallog << "global " << global_dof_indices[i] - component_start[target_component[selected_component]] << " lokal " << level_dof_indices[i]-level_start << std::endl; @@ -659,6 +664,20 @@ void MGTransferSelect::build_matrices ( } } } + + // write indices from vector into the map from + // global to level dofs + const unsigned int n_active_dofs = + std::count_if (temp_copy_indices.begin(), temp_copy_indices.end(), + std::bind2nd(std::not_equal_to(), + numbers::invalid_unsigned_int)); + copy_to_and_from_indices[level].resize (n_active_dofs); + unsigned int counter = 0; + for (unsigned int i=0; i (temp_copy_indices[i], i); + Assert (counter == n_active_dofs, ExcInternalError()); } } diff --git a/deal.II/deal.II/source/multigrid/mg_transfer_prebuilt.cc b/deal.II/deal.II/source/multigrid/mg_transfer_prebuilt.cc index 5f2b214a01..fd3d1b05b2 100644 --- a/deal.II/deal.II/source/multigrid/mg_transfer_prebuilt.cc +++ b/deal.II/deal.II/source/multigrid/mg_transfer_prebuilt.cc @@ -121,12 +121,12 @@ MGTransferPrebuilt::copy_to_mg ( for (unsigned int level=mg_dof_handler.get_tria().n_levels();level != 0;) { --level; -// VECTOR& dst_level = dst[level]; + VECTOR& dst_level = dst[level]; - typedef std::map::const_iterator IT; + typedef std::vector >::const_iterator IT; for (IT i= copy_indices[level].begin(); i != copy_indices[level].end();++i) - dst[level](i->second) = src(i->first); + dst_level(i->second) = src(i->first); // For non-DG: degrees of // freedom in the refinement @@ -329,7 +329,7 @@ void MGTransferPrebuilt::build_matrices ( MGTools::extract_inner_interface_dofs (mg_dof, interface_dofs); copy_indices.resize(n_levels); -// std::vector temp_copy_indices; + std::vector temp_copy_indices; std::vector global_dof_indices (dofs_per_cell); std::vector level_dof_indices (dofs_per_cell); for (int level=mg_dof.get_tria().n_levels()-1; level>=0; --level) @@ -340,8 +340,8 @@ void MGTransferPrebuilt::build_matrices ( const typename MGDoFHandler::active_cell_iterator level_end = mg_dof.end_active(level); -// temp_copy_indices.resize (0); -// temp_copy_indices.resize (mg_dof.n_dofs(level), numbers::invalid_unsigned_int); + temp_copy_indices.resize (0); + temp_copy_indices.resize (mg_dof.n_dofs(level), numbers::invalid_unsigned_int); // Compute coarse level right hand side // by restricting from fine level. @@ -357,12 +357,8 @@ void MGTransferPrebuilt::build_matrices ( for (unsigned int i=0; i::build_matrices ( // copy_indices object. Then, insert the pairs // of global index and level index into // copy_indices. -// const unsigned int n_active_dofs = -// std::count_if (temp_copy_indices.begin(), temp_copy_indices.end(), -// std::bind2nd(std::not_equal_to(), -// numbers::invalid_unsigned_int)); -// copy_indices[level].resize (n_active_dofs); -// unsigned int counter = 0; -// for (unsigned int i=0; i (temp_copy_indices[i], i); -// Assert (counter == n_active_dofs, ExcInternalError()); + const unsigned int n_active_dofs = + std::count_if (temp_copy_indices.begin(), temp_copy_indices.end(), + std::bind2nd(std::not_equal_to(), + numbers::invalid_unsigned_int)); + copy_indices[level].resize (n_active_dofs); + unsigned int counter = 0; + for (unsigned int i=0; i (temp_copy_indices[i], i); + Assert (counter == n_active_dofs, ExcInternalError()); } }