From: guido Date: Tue, 27 Aug 2002 19:53:25 +0000 (+0000) Subject: copy to/from mg for BlockVector X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0f07a74624738da22c693fd4b3bdd468a060f550;p=dealii-svn.git copy to/from mg for BlockVector git-svn-id: https://svn.dealii.org/trunk@6341 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/multigrid/mg_tools.templates.h b/deal.II/deal.II/include/multigrid/mg_tools.templates.h index abc271eb36..acd675a32c 100644 --- a/deal.II/deal.II/include/multigrid/mg_tools.templates.h +++ b/deal.II/deal.II/include/multigrid/mg_tools.templates.h @@ -484,4 +484,199 @@ MGTransferSelect::copy_from_mg_add( } +#if deal_II_dimension == 1 + +template +template +void +MGTransferBlock::copy_to_mg ( + const MGDoFHandler&, + MGLevelObject >&, + const InVector&) const +{ + Assert(false, ExcNotImplemented()); +} + +#else + + +template +template +void +MGTransferBlock::copy_to_mg ( + const MGDoFHandler& mg_dof_handler, + MGLevelObject >& dst, + const InVector& src) const +{ + // Make src a real finite element function +// InVector src = osrc; +// constraints->distribute(src); + + const FiniteElement& fe = mg_dof_handler.get_fe(); + const unsigned int dofs_per_cell = fe.dofs_per_cell; + const unsigned int dofs_per_face = fe.dofs_per_face; + + // set the elements of the vectors + // on all levels to zero + unsigned int minlevel = dst.get_minlevel(); + unsigned int maxlevel = dst.get_maxlevel(); + + dst.clear(); + +//TODO:[GK] Make sure dst is not too large ans sizes is filled + for (unsigned int l=minlevel;l<=maxlevel;++l) + dst[l].reinit(sizes[l]); + + std::vector global_dof_indices (dofs_per_cell); + std::vector level_dof_indices (dofs_per_cell); + std::vector level_face_indices (dofs_per_face); + + // traverse the grid top-down + // (i.e. starting with the most + // refined grid). this way, we can + // always get that part of one + // level of the output vector which + // corresponds to a region which is + // more refined, by restriction of + // the respective vector on the + // next finer level, which we then + // already have built. + for (int level=maxlevel; level>=static_cast(minlevel); --level) + { + typename MGDoFHandler::active_cell_iterator + level_cell = mg_dof_handler.begin_active(level); + const typename MGDoFHandler::active_cell_iterator + level_end = mg_dof_handler.end_active(level); + + // Compute coarse level right hand side + // by restricting from fine level. + for (; level_cell!=level_end; ++level_cell) + { + DoFObjectAccessor& global_cell = *level_cell; + // get the dof numbers of + // this cell for the global + // and the level-wise + // numbering + global_cell.get_dof_indices(global_dof_indices); + level_cell->get_mg_dof_indices (level_dof_indices); + + // transfer the global + // defect in the vector + // into the level-wise one + for (unsigned int i=0; i(level) < maxlevel) + { + restrict_and_add (level+1, dst[level], dst[level+1]); + } + }; +}; + +#endif + + +template +template +void +MGTransferBlock::copy_from_mg( + const MGDoFHandler& mg_dof_handler, + OutVector &dst, + const MGLevelObject > &src) const +{ + + const FiniteElement& fe = mg_dof_handler.get_fe(); + const unsigned int dofs_per_cell = fe.dofs_per_cell; + + std::vector global_dof_indices (dofs_per_cell); + std::vector level_dof_indices (dofs_per_cell); + + typename MGDoFHandler::active_cell_iterator + level_cell = mg_dof_handler.begin_active(); + const typename MGDoFHandler::active_cell_iterator + endc = mg_dof_handler.end(); + // traverse all cells and copy the + // data appropriately to the output + // vector + + // Is the level monotonuosly increasing? + + for (; level_cell != endc; ++level_cell) + { + DoFObjectAccessor& global_cell = *level_cell; + const unsigned int level = level_cell->level(); + // get the dof numbers of + // this cell for the global + // and the level-wise + // numbering + global_cell.get_dof_indices (global_dof_indices); + level_cell->get_mg_dof_indices(level_dof_indices); + + // copy level-wise data to + // global vector +//TODO:[GK] Does this work with selected components? + for (unsigned int i=0; i +template +void +MGTransferBlock::copy_from_mg_add( + const MGDoFHandler& mg_dof_handler, + OutVector &dst, + const MGLevelObject > &src) const +{ + + const FiniteElement& fe = mg_dof_handler.get_fe(); + const unsigned int dofs_per_cell = fe.dofs_per_cell; + + std::vector global_dof_indices (dofs_per_cell); + std::vector level_dof_indices (dofs_per_cell); + + typename MGDoFHandler::active_cell_iterator + level_cell = mg_dof_handler.begin_active(); + const typename MGDoFHandler::active_cell_iterator + endc = mg_dof_handler.end(); + + // traverse all cells and copy the + // data appropriately to the output + // vector + + // Is the level monotonuosly increasing? + for (; level_cell != endc; ++level_cell) + { + DoFObjectAccessor& global_cell = *level_cell; + const unsigned int level = level_cell->level(); + + // get the dof numbers of + // this cell for the global + // and the level-wise + // numbering + global_cell.get_dof_indices (global_dof_indices); + level_cell->get_mg_dof_indices(level_dof_indices); + +//TODO:[GK] Probably wrong for continuous elements + + // copy level-wise data to + // global vector + for (unsigned int i=0; i >, BlockVector &dst, const BlockVector &src) const; - protected: + /** + * Transfer from a vector on the + * global grid to vectors defined + * on each of the levels + * separately, i.a. an @p{MGVector}. + */ + template + void + copy_to_mg (const MGDoFHandler& mg_dof, + MGLevelObject >& dst, + const InVector& src) const; + + /** + * Transfer from multi-level vector to + * normal vector. + * + * Copies data from active + * portions of an MGVector into + * the respective positions of a + * @p{Vector}. In order to + * keep the result consistent, + * constrained degrees of freedom + * are set to zero. + */ + template + void + copy_from_mg (const MGDoFHandler& mg_dof, + OutVector& dst, + const MGLevelObject >& src) const; + + /** + * Add a multi-level vector to a + * normal vector. + * + * Works as the previous + * function, but probably not for + * continuous elements. + */ + template + void + copy_from_mg_add (const MGDoFHandler& mg_dof, + OutVector& dst, + const MGLevelObject >& src) const; }; diff --git a/deal.II/deal.II/source/multigrid/mg_dof_tools.cc b/deal.II/deal.II/source/multigrid/mg_dof_tools.cc index 80843d7cba..d63d3b7ae7 100644 --- a/deal.II/deal.II/source/multigrid/mg_dof_tools.cc +++ b/deal.II/deal.II/source/multigrid/mg_dof_tools.cc @@ -511,57 +511,6 @@ template void MGTools::reinit_vector (const MGDoFHandler >&); -// template void MGTools::copy_to_mg (const MGDoFHandler&, -// const MGTransfer >&, -// MGLevelObject >&, -// const Vector&); - -// template void MGTools::copy_from_mg(const MGDoFHandler&, -// Vector&, -// const MGLevelObject >&); - -// template void MGTools::copy_from_mg_add(const MGDoFHandler&, -// Vector&, -// const MGLevelObject >&); - -// template void MGTools::copy_to_mg (const MGDoFHandler&, -// const MGTransfer >&, -// MGLevelObject >&, -// const Vector&); - -// template void MGTools::copy_from_mg(const MGDoFHandler&, -// Vector&, -// const MGLevelObject >&); - -// template void MGTools::copy_from_mg_add(const MGDoFHandler&, -// Vector&, -// const MGLevelObject >&); - -// template void MGTools::copy_to_mg (const MGDoFHandler&, -// const MGTransfer >&, -// MGLevelObject >&, -// const BlockVector&); - -// template void MGTools::copy_from_mg(const MGDoFHandler&, -// BlockVector&, -// const MGLevelObject >&); - -// template void MGTools::copy_from_mg_add(const MGDoFHandler&, -// BlockVector&, -// const MGLevelObject >&); - -// template void MGTools::copy_to_mg (const MGDoFHandler&, -// const MGTransfer >&, -// MGLevelObject >&, -// const BlockVector&); - -// template void MGTools::copy_from_mg(const MGDoFHandler&, -// BlockVector&, -// const MGLevelObject >&); - -// template void MGTools::copy_from_mg_add(const MGDoFHandler&, -// BlockVector&, -// const MGLevelObject >&); template void MGTools::count_dofs_per_component (const MGDoFHandler&, std::vector >&);