From 9ddfe356913af8be44f8dadcdf08ae9cbb33642b Mon Sep 17 00:00:00 2001 From: kanschat Date: Thu, 26 Apr 2007 20:32:07 +0000 Subject: [PATCH] set up multigrid transfer by blocks git-svn-id: https://svn.dealii.org/trunk@14642 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/multigrid/mg_tools.h | 65 ++- .../deal.II/include/multigrid/mg_transfer.h | 523 +----------------- .../include/multigrid/mg_transfer.templates.h | 472 +--------------- .../include/multigrid/mg_transfer_block.h | 492 ++++++++++++++++ .../multigrid/mg_transfer_block.templates.h | 205 +++++++ .../include/multigrid/mg_transfer_component.h | 405 ++++++++++++++ .../mg_transfer_component.templates.h | 335 +++++++++++ .../deal.II/source/multigrid/mg_dof_tools.cc | 181 +++++- .../source/multigrid/mg_transfer_block.cc | 331 +++++------ .../source/multigrid/mg_transfer_component.cc | 437 +++++++++++++++ .../multigrid/multigrid.all_dimensions.cc | 88 ++- tests/multigrid/Makefile | 4 +- tests/multigrid/transfer.cc | 6 +- .../cmp/x86_64-unknown-linux-gnu+gcc3.3 | 11 + tests/multigrid/transfer_block.cc | 119 ++-- tests/multigrid/transfer_block/cmp/generic | 79 ++- tests/multigrid/transfer_block_select.cc | 155 ++++++ .../transfer_block_select/cmp/generic | 73 +++ tests/multigrid/transfer_select.cc | 4 +- 19 files changed, 2661 insertions(+), 1324 deletions(-) create mode 100644 deal.II/deal.II/include/multigrid/mg_transfer_block.h create mode 100644 deal.II/deal.II/include/multigrid/mg_transfer_block.templates.h create mode 100644 deal.II/deal.II/include/multigrid/mg_transfer_component.h create mode 100644 deal.II/deal.II/include/multigrid/mg_transfer_component.templates.h create mode 100644 deal.II/deal.II/source/multigrid/mg_transfer_component.cc create mode 100644 tests/multigrid/transfer_block_select.cc create mode 100644 tests/multigrid/transfer_block_select/cmp/generic diff --git a/deal.II/deal.II/include/multigrid/mg_tools.h b/deal.II/deal.II/include/multigrid/mg_tools.h index fbf7c86ac3..187b42f13b 100644 --- a/deal.II/deal.II/include/multigrid/mg_tools.h +++ b/deal.II/deal.II/include/multigrid/mg_tools.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2005, 2006 by the deal.II authors +// Copyright (C) 2005, 2006, 2007 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -267,6 +267,48 @@ class MGTools reinit_vector (const MGDoFHandler &mg_dof, MGLevelObject > &vector); + /** + * Ajust vectors on all levels to + * correct size. Here, we just + * count the numbers of degrees + * of freedom on each level and + * @p reinit each level vector + * to this length. + */ + template + static void + reinit_vector (const MGDoFHandler &mg_dof, + MGLevelObject > &vector); + + + /** + * Adjust block vectors on all + * levels to correct size. The + * degrees of freedom on each + * level are counted by block. + */ + template + static void + reinit_vector_by_blocks ( + const MGDoFHandler &mg_dof, + MGLevelObject > &v, + const std::vector &selected, + std::vector >& cached_sizes); + + /** + * Adjust block vectors on all + * levels to correct size. The + * degrees of freedom on each + * level are counted by block. + */ + template + static void + reinit_vector_by_blocks ( + const MGDoFHandler &mg_dof, + MGLevelObject > &v, + const std::vector &selected, + std::vector >& cached_sizes); + /** * Adjust block-vectors on all * levels to correct size. Count @@ -303,11 +345,11 @@ class MGTools */ template static void - reinit_vector (const MGDoFHandler& mg_dof, - MGLevelObject >& v, - const std::vector& selected = std::vector(), - const std::vector& target_component - = std::vector()); + reinit_vector_by_components (const MGDoFHandler& mg_dof, + MGLevelObject >& v, + const std::vector& selected, + const std::vector& target_component, + std::vector >& cached_sizes); /** * Adjust vectors on all levels * to correct size. Count the @@ -336,11 +378,12 @@ class MGTools */ template static void - reinit_vector (const MGDoFHandler &mg_dof, - MGLevelObject > &v, - const std::vector &selected, - const std::vector &target_component, - std::vector >& cached_sizes); + reinit_vector_by_components ( + const MGDoFHandler &mg_dof, + MGLevelObject > &v, + const std::vector &selected, + const std::vector &target_component, + std::vector >& cached_sizes); }; /*@}*/ diff --git a/deal.II/deal.II/include/multigrid/mg_transfer.h b/deal.II/deal.II/include/multigrid/mg_transfer.h index 7efcd83005..1500a037dd 100644 --- a/deal.II/deal.II/include/multigrid/mg_transfer.h +++ b/deal.II/deal.II/include/multigrid/mg_transfer.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -170,529 +170,8 @@ class MGTransferPrebuilt : public MGTransferBase }; -/** - * Implementation of matrix generation for MGTransferBlock and - * MGTransferSelect. - * - * @author Guido Kanschat, 2001-2003 - */ -class MGTransferBlockBase -{ - public: - /** - * Memory used by this object. - */ - unsigned int memory_consumption () const; - - - protected: - /** - * Actually build the prolongation - * matrices for each level. - * - * This function is only called - * by derived classes. These can - * also set the member variables - * #selected and #mg_selected to - * restrict the transfer matrices - * to certain components. - * Furthermore, they use - * #target_component and - * #mg_target_component for - * re-ordering and grouping of - * components. - */ - template - void build_matrices (const DoFHandler& dof, - const MGDoFHandler& mg_dof); - - /** - * Flag of selected components. - * - * The transfer operators only act - * on the components having a - * true entry here. If - * renumbering by - * #target_component is used, - * this refers to the - * renumbered components. - */ - std::vector selected; - - /** - * Flag of selected components. - * - * The transfer operators only act - * on the components having a - * true entry here. If - * renumbering by - * #mg_target_component is used, - * this refers to the - * renumbered components. - */ - std::vector mg_selected; - - /** - * Target component of the - * fine-level vector if - * renumbering is required. - */ - std::vector target_component; - - /** - * Target component if - * renumbering of level vectors - * is required. - */ - std::vector mg_target_component; - - /** - * Sizes of the multi-level vectors. - */ - mutable std::vector > sizes; - - /** - * Start index of each component. - */ - std::vector component_start; - - /** - * Start index of each component on - * all levels. - */ - std::vector > mg_component_start; - - /** - * Call build_matrices() - * function first. - */ - DeclException0(ExcMatricesNotBuilt); - - private: - std::vector > prolongation_sparsities; - - protected: - - /** - * The actual prolongation matrix. - * column indices belong to the - * dof indices of the mother cell, - * i.e. the coarse level. - * while row indices belong to the - * child cell, i.e. the fine level. - */ - std::vector > > prolongation_matrices; - - /** - * Unused now, but intended to - * hold the mapping for the - * copy_to/from_mg-functions. - */ - std::vector > - copy_to_and_from_indices; -}; - -//TODO:[GK] Update this class - -/** - * Implementation of the MGTransferBase interface for block - * matrices and block vectors. - * - * Warning! Due to additional requirements on MGTransferSelect, the - * implementation in the base class has changed. Therefore, this class - * is left in an untested state. If you use it and you encounter - * problems, please contact Guido Kanschat. - * - * In addition to the functionality of - * MGTransferPrebuilt, the operation may be restricted to - * certain blocks of the vector. - * - * If the restricted mode is chosen, block vectors used in the - * transfer routines may only have as many components as there are - * @p trues in the selected-field. - * - * See MGTransferBase to find out which of the transfer classes - * is best for your needs. - * - * @author Guido Kanschat, 2001, 2002 - */ -template -class MGTransferBlock : public MGTransferBase >, - private MGTransferBlockBase -{ - public: - /** - * Default constructor. - */ - MGTransferBlock(); - - /** - * Destructor. - */ - virtual ~MGTransferBlock (); - - /** - * Initialize additional #factors - * and #memory if the restriction - * of the components is to be - * weighted differently. - */ - void initialize (const std::vector& factors, - VectorMemory >& memory); - - /** - * Build the prolongation - * matrices for each level. - * - * This function is a front-end - * for the same function in - * MGTransferBlockBase. - * - * If mg_target_component is - * present, this refers to the - * renumbered components. - * - * @arg target_component: this - * argument allows grouping and - * renumbering of components in - * the fine-level vector (see - * DoFRenumbering::component_wise). - * - * @arg mg_target_component: this - * argument allows grouping and - * renumbering of components in - * the level vectors (see - * DoFRenumbering::component_wise). It - * also affects the behavior of - * the selected argument - */ - template - void build_matrices (const DoFHandler &dof, - const MGDoFHandler &mg_dof, - const std::vector& target_component - = std::vector(), - const std::vector& mg_target_component - =std::vector()); - - virtual void prolongate (const unsigned int to_level, - BlockVector &dst, - const BlockVector &src) const; - - virtual void restrict_and_add (const unsigned int from_level, - BlockVector &dst, - const BlockVector &src) const; - - /** - * Transfer from a vector on the - * global grid to a multilevel - * vector. - * - * The action for discontinuous - * elements is as follows: on an - * active mesh cell, the global - * vector entries are simply - * copied to the corresponding - * entries of the level - * vector. Then, these values are - * restricted down to the - * coarsest level. - * - * If the arguments - * target_component and - * mg_target_component - * was used in build_matrices(), - * then the blocks are shuffled - * around accordingly. - */ - 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 a multilevel - * vector into the respective - * positions of a global vector. - * - * If the arguments - * target_component and - * mg_target_component - * was used in build_matrices(), - * then the blocks are shuffled - * around accordingly. - */ - 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; - - MGTransferBlockBase::memory_consumption; - - private: - /** - * Optional multiplication - * factors for each - * component. Requires - * initialization of #memory. - */ - std::vector factors; - - /** - * Memory pool required if - * additional multiplication - * using #factors is desired. - */ - SmartPointer > > memory; -}; - - -//TODO:[GK] Update documentation for copy_* functions - -/** - * Implementation of the MGTransferBase interface for block - * matrices and simple vectors. This class uses MGTransferBlockBase - * selecting a single component or grouping several components into a - * single block. The transfer operators themselves are implemented for - * Vector and BlockVector objects. - * - * See MGTransferBase to find out which of the transfer classes - * is best for your needs. - * - * @author Guido Kanschat, 2001, 2002, 2003 - */ -template -class MGTransferSelect : public MGTransferBase >, - private MGTransferBlockBase -{ - public: - /** - * Destructor. - */ - virtual ~MGTransferSelect (); - - /** - * Actually build the prolongation - * matrices for grouped components. - * - * This function is a front-end - * for the same function in - * MGTransferBlockBase. - * - * @arg selected: Number of the - * component of the global vector - * to be copied from and to the - * multilevel vector. This number - * refers to the renumbering by - * target_component. - * - * @arg mg_selected: Number - * of the component for which the - * transfer matrices should be - * built. - * - * If mg_target_component is - * present, this refers to the - * renumbered components. - * - * @arg target_component: this - * argument allows grouping and - * renumbering of components in - * the fine-level vector (see - * DoFRenumbering::component_wise). - * - * @arg mg_target_component: this - * argument allows grouping and - * renumbering of components in - * the level vectors (see - * DoFRenumbering::component_wise). It - * also affects the behavior of - * the selected argument - */ - template - void build_matrices (const DoFHandler &dof, - const MGDoFHandler &mg_dof, - unsigned int selected, - unsigned int mg_selected, - const std::vector& target_component - = std::vector(), - const std::vector& mg_target_component - = std::vector()); - - /** - * Change selected - * component. Handle with care! - */ - void select (const unsigned int component, - const unsigned int mg_component = deal_II_numbers::invalid_unsigned_int); - - virtual void prolongate (const unsigned int to_level, - Vector &dst, - const Vector &src) const; - - virtual void restrict_and_add (const unsigned int from_level, - Vector &dst, - const Vector &src) const; - - /** - * Transfer from a vector on the - * global grid to a multilevel vector. - */ - template - void - copy_to_mg (const MGDoFHandler &mg_dof, - MGLevelObject > &dst, - const Vector &src) const; - - /** - * Transfer from multilevel vector to - * normal vector. - * - * Copies data from active - * portions of an multilevel - * vector into the respective - * positions of a Vector. - */ - template - void - copy_from_mg (const MGDoFHandler &mg_dof, - Vector &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, - Vector &dst, - const MGLevelObject > &src) const; - - /** - * Transfer from a vector on the - * global grid to multilevel vectors. - */ - template - void - copy_to_mg (const MGDoFHandler &mg_dof, - MGLevelObject > &dst, - const BlockVector &src) const; - - /** - * Transfer from multilevel vector to - * normal vector. - * - * Copies data from active - * portions of a multilevel - * vector into the respective - * positions of a global - * BlockVector. - */ - template - void - copy_from_mg (const MGDoFHandler &mg_dof, - BlockVector &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, - BlockVector &dst, - const MGLevelObject > &src) const; - - /** - * Memory used by this object. - */ - unsigned int memory_consumption () const; - - private: - /** - * Implementation of the public - * function. - */ - template - void - do_copy_from_mg (const MGDoFHandler &mg_dof, - OutVector &dst, - const MGLevelObject > &src, - const unsigned int offset) const; - - /** - * Implementation of the public - * function. - */ - template - void - do_copy_from_mg_add (const MGDoFHandler &mg_dof, - OutVector &dst, - const MGLevelObject > &src, - const unsigned int offset) const; - - /** - * Actual implementation of - * copy_to_mg(). - */ - template - void - do_copy_to_mg (const MGDoFHandler &mg_dof, - MGLevelObject > &dst, - const InVector &src, - const unsigned int offset) const; - /** - * Selected component of global vector. - */ - unsigned int selected_component; - /** - * Selected component inside multigrid. - */ - unsigned int mg_selected_component; -}; - /*@}*/ -//--------------------------------------------------------------------------- -template -inline void -MGTransferSelect::select(const unsigned int component, - const unsigned int mg_component) -{ - selected_component = component; - mg_selected_component = (mg_component == deal_II_numbers::invalid_unsigned_int) - ? component - : mg_component; -} DEAL_II_NAMESPACE_CLOSE 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 92306c1cd2..bef63bb128 100644 --- a/deal.II/deal.II/include/multigrid/mg_transfer.templates.h +++ b/deal.II/deal.II/include/multigrid/mg_transfer.templates.h @@ -2,7 +2,7 @@ // mg_transfer.templates.h,v 1.22 2006/01/29 15:03:55 guido Exp // Version: // -// Copyright (C) 2003, 2004, 2005, 2006 by the deal.II authors +// Copyright (C) 2003, 2004, 2005, 2006, 2007 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -211,476 +211,6 @@ MGTransferPrebuilt::memory_consumption () const return result; } -/* --------------------- MGTransferSelect -------------- */ - - - -template -template -void -MGTransferSelect::copy_to_mg ( - const MGDoFHandler &mg_dof_handler, - MGLevelObject > &dst, - const BlockVector &src) const -{ - do_copy_to_mg (mg_dof_handler, dst, src, 0); -} - - - -template -template -void -MGTransferSelect::copy_to_mg ( - const MGDoFHandler &mg_dof_handler, - MGLevelObject > &dst, - const Vector &src) const -{ - do_copy_to_mg (mg_dof_handler, dst, src, component_start[selected_component]); -} - - - -template -template -void -MGTransferSelect::do_copy_to_mg ( - const MGDoFHandler& mg_dof_handler, - MGLevelObject >& dst, - const InVector& src, - const unsigned int offset) const -{ - const FiniteElement& fe = mg_dof_handler.get_fe(); - - const unsigned int dofs_per_cell = fe.dofs_per_cell; - - // set the elements of the vectors - // on all levels to zero - unsigned int minlevel = dst.get_minlevel(); - unsigned int maxlevel = dst.get_maxlevel(); - - dst=0; - - Assert(sizes.size()==mg_dof_handler.get_tria().n_levels(), - ExcMatricesNotBuilt()); - - MGTools::reinit_vector(mg_dof_handler, dst, - mg_selected, mg_target_component, sizes); - - std::vector global_dof_indices (dofs_per_cell); - std::vector level_dof_indices (dofs_per_cell); - - // Build a vector of the selected - // indices, since traversing all - // indices on each cell is too - // slow. - std::vector selected_indices; - selected_indices.reserve(dofs_per_cell); - for (unsigned int i=0; i=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) - { - // get the dof numbers of - // this cell for the global - // and the level-wise - // numbering - level_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 - const unsigned int level_start - = mg_component_start[level][selected_component]; - const typename std::vector::const_iterator - end = selected_indices.end(); - - for (typename std::vector::const_iterator - i=selected_indices.begin(); - i != end; ++i) - { - dst[level](level_dof_indices[*i] - level_start) - = src(global_dof_indices[*i] - offset); - } - } - - // for that part of the level - // which is further refined: - // get the defect by - // restriction of the defect on - // one level higher - if (static_cast(level) < maxlevel) - { - restrict_and_add (level+1, dst[level], dst[level+1]); - } - }; -} - - - -template -template -void -MGTransferSelect::copy_from_mg ( - const MGDoFHandler& mg_dof_handler, - BlockVector& dst, - const MGLevelObject >& src) const -{ - do_copy_from_mg (mg_dof_handler, dst, src, 0); -} - - - -template -template -void -MGTransferSelect::copy_from_mg ( - const MGDoFHandler& mg_dof_handler, - Vector& dst, - const MGLevelObject >& src) const -{ - do_copy_from_mg (mg_dof_handler, dst, src, - component_start[selected_component]); -} - - - -template -template -void -MGTransferSelect::copy_from_mg_add ( - const MGDoFHandler& mg_dof_handler, - BlockVector& dst, - const MGLevelObject >& src) const -{ - do_copy_from_mg_add (mg_dof_handler, dst, src, 0); -} - - - -template -template -void -MGTransferSelect::copy_from_mg_add ( - const MGDoFHandler& mg_dof_handler, - Vector& dst, - const MGLevelObject >& src) const -{ - do_copy_from_mg_add (mg_dof_handler, dst, src, - component_start[selected_component]); -} - - - -template -template -void -MGTransferSelect::do_copy_from_mg ( - const MGDoFHandler &mg_dof_handler, - OutVector &dst, - const MGLevelObject > &src, - const unsigned int offset) 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 - - // Note that the level is - // monotonuosly increasing - for (; level_cell != endc; ++level_cell) - { - const unsigned int level = level_cell->level(); - - // get the dof numbers of - // this cell for the global - // and the level-wise - // numbering - level_cell->get_dof_indices (global_dof_indices); - level_cell->get_mg_dof_indices(level_dof_indices); - - // copy level-wise data to - // global vector - for (unsigned int i=0; i -template -void -MGTransferSelect::do_copy_from_mg_add ( - const MGDoFHandler &mg_dof_handler, - OutVector &dst, - const MGLevelObject > &src, - const unsigned int offset) 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 - - // Note that the level is - // monotonuosly increasing - for (; level_cell != endc; ++level_cell) - { - const unsigned int level = level_cell->level(); - - // get the dof numbers of - // this cell for the global - // and the level-wise - // numbering - level_cell->get_dof_indices (global_dof_indices); - level_cell->get_mg_dof_indices(level_dof_indices); - // copy level-wise data to - // global vector - for (unsigned int i=0; i -unsigned int -MGTransferSelect::memory_consumption () const -{ - return sizeof(int) + MGTransferBlockBase::memory_consumption(); -} - - -/* --------------------- MGTransferBlock -------------- */ - - - -template -template -void -MGTransferBlock::copy_to_mg ( - const MGDoFHandler &mg_dof_handler, - MGLevelObject > &dst, - const InVector &src) const -{ - const FiniteElement& fe = mg_dof_handler.get_fe(); - - const unsigned int dofs_per_cell = fe.dofs_per_cell; - - // set the elements of the vectors - // on all levels to zero - unsigned int minlevel = dst.get_minlevel(); - unsigned int maxlevel = dst.get_maxlevel(); - - dst=0; - - MGTools::reinit_vector(mg_dof_handler, dst, mg_selected, mg_target_component); - - std::vector global_dof_indices (dofs_per_cell); - std::vector level_dof_indices (dofs_per_cell); - - // 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) - { - // get the dof numbers of - // this cell for the global - // and the level-wise - // numbering - level_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]); - } - }; -} - - - - -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 - - // Note that level is monotonuosly - // increasing - for (; level_cell != endc; ++level_cell) - { - const unsigned int level = level_cell->level(); - // get the dof numbers of - // this cell for the global - // and the level-wise - // numbering - level_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 - - // Note that the level monotonuosly - // increasing - for (; level_cell != endc; ++level_cell) - { - const unsigned int level = level_cell->level(); - - // get the dof numbers of - // this cell for the global - // and the level-wise - // numbering - level_cell->get_dof_indices (global_dof_indices); - level_cell->get_mg_dof_indices(level_dof_indices); - // copy level-wise data to - // global vector - for (unsigned int i=0; i + +#include +#ifdef DEAL_PREFER_MATRIX_EZ +# include +# include +#else +# include +# include +#endif +#include + +#include +#include + + + +#include + +#include + + +DEAL_II_NAMESPACE_OPEN + + +template class MGDoFHandler; + +/* + * MGTransferBase is defined in mg_base.h + */ + +/*!@addtogroup mg */ +/*@{*/ + +/** + * Implementation of matrix generation for MGTransferBlock. + * + * This is the base class for MGTransfer objects for systems of + * equations where multigrid is applied only to one ore some blocks, + * where a @ref GlossBlock comprises all degrees of freedom generated + * by one base element. + * + * @author Guido Kanschat, 2001-2003 + */ +class MGTransferBlockBase +{ + public: + /** + * Memory used by this object. + */ + unsigned int memory_consumption () const; + + protected: + /** + * Actually build the prolongation + * matrices for each level. + * + * This function is only called + * by derived classes. These can + * also set the member variables + * #selected and #mg_selected to + * restrict the transfer matrices + * to certain blocks. + */ + template + void build_matrices (const DoFHandler& dof, + const MGDoFHandler& mg_dof); + + /** + * Flag of selected blocks. + * + * The transfer operators only act + * on the blocks having a + * true entry here. + */ + std::vector selected; + + /** + * For each block of the whole + * block vector, list to what + * block of the multigrid vector + * it is mapped. Since depending + * on #selected, there may be + * fewer mutlilevel blocks than + * original blocks, some of the + * entries may be illegal + * unsigned integers. + */ + std::vector mg_block; + + /** + * Sizes of the multi-level vectors. + */ + mutable std::vector > sizes; + + /** + * Start index of each block. + */ + std::vector block_start; + + /** + * Start index of each block on + * all levels. + */ + std::vector > mg_block_start; + + /** + * Call build_matrices() + * function first. + */ + DeclException0(ExcMatricesNotBuilt); + + private: + std::vector > prolongation_sparsities; + + protected: + + /** + * The actual prolongation matrix. + * column indices belong to the + * dof indices of the mother cell, + * i.e. the coarse level. + * while row indices belong to the + * child cell, i.e. the fine level. + */ + std::vector > > prolongation_matrices; + + /** + * Mapping for the + * copy_to/from_mg-functions. + * The indices into this vector + * are (in this order): global + * block number, level + * number. The data is first the + * global index inside the block, + * then the level index inside + * the block. + */ + std::vector > > + copy_indices; +}; + +/** + * Implementation of the MGTransferBase interface for block + * matrices and block vectors. + * + * @warning This class is in an untested state. If you use it and you + * encounter problems, please contact Guido Kanschat. + * + * In addition to the functionality of + * MGTransferPrebuilt, the operation may be restricted to + * certain blocks of the vector. + * + * If the restricted mode is chosen, block vectors used in the + * transfer routines may only have as many blocks as there are + * @p trues in the selected-field. + * + * See MGTransferBase to find out which of the transfer classes + * is best for your needs. + * + * @author Guido Kanschat, 2001, 2002 + */ +template +class MGTransferBlock : public MGTransferBase >, + private MGTransferBlockBase +{ + public: + /** + * Default constructor. + */ + MGTransferBlock(); + + /** + * Destructor. + */ + virtual ~MGTransferBlock (); + + /** + * Initialize additional #factors + * and #memory if the restriction + * of the blocks is to be + * weighted differently. + */ + void initialize (const std::vector& factors, + VectorMemory >& memory); + + /** + * Build the prolongation + * matrices for each level. + * + * This function is a front-end + * for the same function in + * MGTransferBlockBase. + */ + template + void build_matrices (const DoFHandler &dof, + const MGDoFHandler &mg_dof, + const std::vector& selected); + + virtual void prolongate (const unsigned int to_level, + BlockVector &dst, + const BlockVector &src) const; + + virtual void restrict_and_add (const unsigned int from_level, + BlockVector &dst, + const BlockVector &src) const; + + /** + * Transfer from a vector on the + * global grid to a multilevel + * vector. + * + * The action for discontinuous + * elements is as follows: on an + * active mesh cell, the global + * vector entries are simply + * copied to the corresponding + * entries of the level + * vector. Then, these values are + * restricted down to the + * coarsest level. + */ + template + void + copy_to_mg (const MGDoFHandler& mg_dof, + MGLevelObject >& dst, + const BlockVector& src) const; + + /** + * Transfer from multi-level vector to + * normal vector. + * + * Copies data from active + * portions of a multilevel + * vector into the respective + * positions of a global vector. + */ + template + void + copy_from_mg (const MGDoFHandler& mg_dof, + BlockVector& 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, + BlockVector& dst, + const MGLevelObject > &src) const; + + MGTransferBlockBase::memory_consumption; + + private: + /** + * Optional multiplication + * factors for each + * block. Requires + * initialization of #memory. + */ + std::vector factors; + + /** + * Memory pool required if + * additional multiplication + * using #factors is desired. + */ + SmartPointer > > memory; +}; + + +//TODO:[GK] Update documentation for copy_* functions + +/** + * Implementation of the MGTransferBase interface for block matrices + * and simple vectors. This class uses MGTransferBlockBase selecting a + * single block. The intergrid transfer operators are implemented for + * Vector objects, The copy functions between regular and multigrid + * vectors for Vector and BlockVector. + * + * See MGTransferBase to find out which of the transfer classes + * is best for your needs. + * + * @author Guido Kanschat, 2001, 2002, 2003 + */ +template +class MGTransferBlockSelect : public MGTransferBase >, + private MGTransferBlockBase +{ + public: + /** + * Destructor. + */ + virtual ~MGTransferBlockSelect (); + + /** + * Actually build the prolongation + * matrices for grouped blocks. + * + * This function is a front-end + * for the same function in + * MGTransferBlockBase. + * + * @arg selected: Number of the + * block of the global vector + * to be copied from and to the + * multilevel vector. + * + * @arg mg_selected: Number + * of the component for which the + * transfer matrices should be + * built. + */ + template + void build_matrices (const DoFHandler &dof, + const MGDoFHandler &mg_dof, + unsigned int selected); + + /** + * Change selected + * block. Handle with care! + */ + void select (const unsigned int block); + + virtual void prolongate (const unsigned int to_level, + Vector &dst, + const Vector &src) const; + + virtual void restrict_and_add (const unsigned int from_level, + Vector &dst, + const Vector &src) const; + + /** + * Transfer a single block from a + * vector on the global grid to a + * multilevel vector. + */ + template + void + copy_to_mg (const MGDoFHandler &mg_dof, + MGLevelObject > &dst, + const Vector &src) const; + + /** + * Transfer from multilevel vector to + * normal vector. + * + * Copies data from active + * portions of an multilevel + * vector into the respective + * positions of a Vector. + */ + template + void + copy_from_mg (const MGDoFHandler &mg_dof, + Vector &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, + Vector &dst, + const MGLevelObject > &src) const; + + /** + * Transfer a block from a vector + * on the global grid to + * multilevel vectors. Only the + * block selected is transfered. + */ + template + void + copy_to_mg (const MGDoFHandler &mg_dof, + MGLevelObject > &dst, + const BlockVector &src) const; + + /** + * Transfer from multilevel vector to + * normal vector. + * + * Copies data from active + * portions of a multilevel + * vector into the respective + * positions of a global + * BlockVector. + */ + template + void + copy_from_mg (const MGDoFHandler &mg_dof, + BlockVector &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, + BlockVector &dst, + const MGLevelObject > &src) const; + + /** + * Memory used by this object. + */ + unsigned int memory_consumption () const; + + private: + /** + * Implementation of the public + * function. + */ + template + void + do_copy_from_mg (const MGDoFHandler &mg_dof, + OutVector &dst, + const MGLevelObject > &src, + const unsigned int offset) const; + + /** + * Implementation of the public + * function. + */ + template + void + do_copy_from_mg_add (const MGDoFHandler &mg_dof, + OutVector &dst, + const MGLevelObject > &src, + const unsigned int offset) const; + + /** + * Actual implementation of + * copy_to_mg(). + */ + template + void + do_copy_to_mg (const MGDoFHandler &mg_dof, + MGLevelObject > &dst, + const InVector &src, + const unsigned int offset) const; + /** + * Selected block. + */ + unsigned int selected_block; +}; + +/*@}*/ + +//--------------------------------------------------------------------------- +template +inline void +MGTransferBlockSelect::select(const unsigned int block) +{ + selected_block = block; +} + +DEAL_II_NAMESPACE_CLOSE + +#endif diff --git a/deal.II/deal.II/include/multigrid/mg_transfer_block.templates.h b/deal.II/deal.II/include/multigrid/mg_transfer_block.templates.h new file mode 100644 index 0000000000..83b35992d5 --- /dev/null +++ b/deal.II/deal.II/include/multigrid/mg_transfer_block.templates.h @@ -0,0 +1,205 @@ +//--------------------------------------------------------------------------- +// mg_transfer.templates.h,v 1.22 2006/01/29 15:03:55 guido Exp +// Version: +// +// Copyright (C) 2003, 2004, 2005, 2006, 2007 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//--------------------------------------------------------------------------- + +#ifndef __deal2__mg_transfer_block_templates_h +#define __deal2__mg_transfer_block_templates_h + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +DEAL_II_NAMESPACE_OPEN + +/* --------------------- MGTransferBlockSelect -------------- */ + +// Simplify some things below +typedef std::map::const_iterator IT; + + + +template +template +void +MGTransferBlockSelect::copy_to_mg ( + const MGDoFHandler &mg_dof_handler, + MGLevelObject > &dst, + const BlockVector &src) const +{ + // For MGTransferBlockSelect, the + // multilevel block is always the + // first, since only one block is selected. + for (unsigned int level=0;levelsecond) = src.block(selected_block)(i->first); +} + + + +template +template +void +MGTransferBlockSelect::copy_to_mg ( + const MGDoFHandler &mg_dof_handler, + MGLevelObject > &dst, + const Vector &src) const +{ + // For MGTransferBlockSelect, the + // multilevel block is always the + // first, since only one block is selected. + for (unsigned int level=0;levelsecond) = src(i->first); +} + + + +template +template +void +MGTransferBlockSelect::copy_from_mg ( + const MGDoFHandler& mg_dof_handler, + BlockVector& dst, + const MGLevelObject >& src) const +{ + for (unsigned int level=0;levelfirst) = src[level](i->second); +} + + + +template +template +void +MGTransferBlockSelect::copy_from_mg ( + const MGDoFHandler& mg_dof_handler, + Vector& dst, + const MGLevelObject >& src) const +{ + for (unsigned int level=0;levelfirst) = src[level](i->second); +} + + + +template +template +void +MGTransferBlockSelect::copy_from_mg_add ( + const MGDoFHandler& mg_dof_handler, + BlockVector& dst, + const MGLevelObject >& src) const +{ + for (unsigned int level=0;levelfirst) = src[level](i->second); +} + + + +template +template +void +MGTransferBlockSelect::copy_from_mg_add ( + const MGDoFHandler& mg_dof_handler, + Vector& dst, + const MGLevelObject >& src) const +{ + for (unsigned int level=0;levelfirst) += src[level](i->second); +} + + + +template +unsigned int +MGTransferBlockSelect::memory_consumption () const +{ + return sizeof(int) + MGTransferBlockBase::memory_consumption(); +} + + +/* --------------------- MGTransferBlock -------------- */ + + + +template +template +void +MGTransferBlock::copy_to_mg ( + const MGDoFHandler& mg_dof_handler, + MGLevelObject >& dst, + const BlockVector& src) const +{ + for (unsigned int block=0;blocksecond) = src.block(block)(i->first); +} + + + + +template +template +void +MGTransferBlock::copy_from_mg ( + const MGDoFHandler& mg_dof_handler, + BlockVector& dst, + const MGLevelObject >& src) const +{ + for (unsigned int block=0;blockfirst) = src[level].block(mg_block[block])(i->second); +} + + + +template +template +void +MGTransferBlock::copy_from_mg_add ( + const MGDoFHandler& mg_dof_handler, + BlockVector& dst, + const MGLevelObject >& src) const +{ + for (unsigned int block=0;blockfirst) += src[level].block(mg_block[block])(i->second); +} + +DEAL_II_NAMESPACE_CLOSE + +#endif diff --git a/deal.II/deal.II/include/multigrid/mg_transfer_component.h b/deal.II/deal.II/include/multigrid/mg_transfer_component.h new file mode 100644 index 0000000000..a4b66e5e6a --- /dev/null +++ b/deal.II/deal.II/include/multigrid/mg_transfer_component.h @@ -0,0 +1,405 @@ +//--------------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//--------------------------------------------------------------------------- +#ifndef __deal2__mg_transfer_component_h +#define __deal2__mg_transfer_component_h + +#include + +#include +#ifdef DEAL_PREFER_MATRIX_EZ +# include +# include +#else +# include +# include +#endif +#include + +#include +#include + + + +#include + +#include + + +DEAL_II_NAMESPACE_OPEN + + +template class MGDoFHandler; + +/* + * MGTransferBase is defined in mg_base.h + */ + +/*!@addtogroup mg */ +/*@{*/ + +/** + * Implementation of matrix generation for component wise multigrid transfer. + * + * @note MGTransferBlockBase is probably the more logical + * class. Still eventually, a class should be developed allowing to + * select multiple components. + * + * @author Guido Kanschat, 2001-2003 + */ +class MGTransferComponentBase +{ + public: + /** + * Memory used by this object. + */ + unsigned int memory_consumption () const; + + + protected: + /** + * Actually build the prolongation + * matrices for each level. + * + * This function is only called + * by derived classes. These can + * also set the member variables + * #selected and #mg_selected to + * restrict the transfer matrices + * to certain components. + * Furthermore, they use + * #target_component and + * #mg_target_component for + * re-ordering and grouping of + * components. + */ + template + void build_matrices (const DoFHandler& dof, + const MGDoFHandler& mg_dof); + + /** + * Flag of selected components. + * + * The transfer operators only act + * on the components having a + * true entry here. If + * renumbering by + * #target_component is used, + * this refers to the + * renumbered components. + */ + std::vector selected; + + /** + * Flag of selected components. + * + * The transfer operators only act + * on the components having a + * true entry here. If + * renumbering by + * #mg_target_component is used, + * this refers to the + * renumbered components. + */ + std::vector mg_selected; + + /** + * Target component of the + * fine-level vector if + * renumbering is required. + */ + std::vector target_component; + + /** + * Target component if + * renumbering of level vectors + * is required. + */ + std::vector mg_target_component; + + /** + * Sizes of the multi-level vectors. + */ + mutable std::vector > sizes; + + /** + * Start index of each component. + */ + std::vector component_start; + + /** + * Start index of each component on + * all levels. + */ + std::vector > mg_component_start; + + /** + * Call build_matrices() + * function first. + */ + DeclException0(ExcMatricesNotBuilt); + + private: + std::vector > prolongation_sparsities; + + protected: + + /** + * The actual prolongation matrix. + * column indices belong to the + * dof indices of the mother cell, + * i.e. the coarse level. + * while row indices belong to the + * child cell, i.e. the fine level. + */ + std::vector > > prolongation_matrices; + + /** + * Unused now, but intended to + * hold the mapping for the + * copy_to/from_mg-functions. + */ + std::vector > + copy_to_and_from_indices; +}; + +//TODO:[GK] Update documentation for copy_* functions + +/** + * Implementation of the MGTransferBase interface for block + * matrices and simple vectors. This class uses MGTransferComponentBase + * selecting a single component or grouping several components into a + * single block. The transfer operators themselves are implemented for + * Vector and BlockVector objects. + * + * See MGTransferBase to find out which of the transfer classes + * is best for your needs. + * + * @author Guido Kanschat, 2001, 2002, 2003 + */ +template +class MGTransferSelect : public MGTransferBase >, + private MGTransferComponentBase +{ + public: + /** + * Destructor. + */ + virtual ~MGTransferSelect (); + + /** + * Actually build the prolongation + * matrices for grouped components. + * + * This function is a front-end + * for the same function in + * MGTransferComponentBase. + * + * @arg selected: Number of the + * component of the global vector + * to be copied from and to the + * multilevel vector. This number + * refers to the renumbering by + * target_component. + * + * @arg mg_selected: Number + * of the component for which the + * transfer matrices should be + * built. + * + * If mg_target_component is + * present, this refers to the + * renumbered components. + * + * @arg target_component: this + * argument allows grouping and + * renumbering of components in + * the fine-level vector (see + * DoFRenumbering::component_wise). + * + * @arg mg_target_component: this + * argument allows grouping and + * renumbering of components in + * the level vectors (see + * DoFRenumbering::component_wise). It + * also affects the behavior of + * the selected argument + */ + template + void build_matrices (const DoFHandler &dof, + const MGDoFHandler &mg_dof, + unsigned int selected, + unsigned int mg_selected, + const std::vector& target_component + = std::vector(), + const std::vector& mg_target_component + = std::vector()); + + /** + * Change selected + * component. Handle with care! + */ + void select (const unsigned int component, + const unsigned int mg_component = deal_II_numbers::invalid_unsigned_int); + + virtual void prolongate (const unsigned int to_level, + Vector &dst, + const Vector &src) const; + + virtual void restrict_and_add (const unsigned int from_level, + Vector &dst, + const Vector &src) const; + + /** + * Transfer from a vector on the + * global grid to a multilevel vector. + */ + template + void + copy_to_mg (const MGDoFHandler &mg_dof, + MGLevelObject > &dst, + const Vector &src) const; + + /** + * Transfer from multilevel vector to + * normal vector. + * + * Copies data from active + * portions of an multilevel + * vector into the respective + * positions of a Vector. + */ + template + void + copy_from_mg (const MGDoFHandler &mg_dof, + Vector &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, + Vector &dst, + const MGLevelObject > &src) const; + + /** + * Transfer from a vector on the + * global grid to multilevel vectors. + */ + template + void + copy_to_mg (const MGDoFHandler &mg_dof, + MGLevelObject > &dst, + const BlockVector &src) const; + + /** + * Transfer from multilevel vector to + * normal vector. + * + * Copies data from active + * portions of a multilevel + * vector into the respective + * positions of a global + * BlockVector. + */ + template + void + copy_from_mg (const MGDoFHandler &mg_dof, + BlockVector &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, + BlockVector &dst, + const MGLevelObject > &src) const; + + /** + * Memory used by this object. + */ + unsigned int memory_consumption () const; + + private: + /** + * Implementation of the public + * function. + */ + template + void + do_copy_from_mg (const MGDoFHandler &mg_dof, + OutVector &dst, + const MGLevelObject > &src, + const unsigned int offset) const; + + /** + * Implementation of the public + * function. + */ + template + void + do_copy_from_mg_add (const MGDoFHandler &mg_dof, + OutVector &dst, + const MGLevelObject > &src, + const unsigned int offset) const; + + /** + * Actual implementation of + * copy_to_mg(). + */ + template + void + do_copy_to_mg (const MGDoFHandler &mg_dof, + MGLevelObject > &dst, + const InVector &src, + const unsigned int offset) const; + /** + * Selected component of global vector. + */ + unsigned int selected_component; + /** + * Selected component inside multigrid. + */ + unsigned int mg_selected_component; +}; + +/*@}*/ + +//--------------------------------------------------------------------------- +template +inline void +MGTransferSelect::select(const unsigned int component, + const unsigned int mg_component) +{ + selected_component = component; + mg_selected_component = (mg_component == deal_II_numbers::invalid_unsigned_int) + ? component + : mg_component; +} + +DEAL_II_NAMESPACE_CLOSE + +#endif 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 new file mode 100644 index 0000000000..1c4667ecf7 --- /dev/null +++ b/deal.II/deal.II/include/multigrid/mg_transfer_component.templates.h @@ -0,0 +1,335 @@ +//--------------------------------------------------------------------------- +// mg_transfer.templates.h,v 1.22 2006/01/29 15:03:55 guido Exp +// Version: +// +// Copyright (C) 2003, 2004, 2005, 2006, 2007 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//--------------------------------------------------------------------------- + +#ifndef __deal2__mg_transfer_component_templates_h +#define __deal2__mg_transfer_component_templates_h + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +DEAL_II_NAMESPACE_OPEN + +/* --------------------- MGTransferSelect -------------- */ + + + +template +template +void +MGTransferSelect::copy_to_mg ( + const MGDoFHandler &mg_dof_handler, + MGLevelObject > &dst, + const BlockVector &src) const +{ + do_copy_to_mg (mg_dof_handler, dst, src, 0); +} + + + +template +template +void +MGTransferSelect::copy_to_mg ( + const MGDoFHandler &mg_dof_handler, + MGLevelObject > &dst, + const Vector &src) const +{ + do_copy_to_mg (mg_dof_handler, dst, src, component_start[selected_component]); +} + + + +template +template +void +MGTransferSelect::do_copy_to_mg ( + const MGDoFHandler& mg_dof_handler, + MGLevelObject >& dst, + const InVector& src, + const unsigned int offset) const +{ + const FiniteElement& fe = mg_dof_handler.get_fe(); + + const unsigned int dofs_per_cell = fe.dofs_per_cell; + + // set the elements of the vectors + // on all levels to zero + unsigned int minlevel = dst.get_minlevel(); + unsigned int maxlevel = dst.get_maxlevel(); + + dst=0; + + Assert(sizes.size()==mg_dof_handler.get_tria().n_levels(), + ExcMatricesNotBuilt()); + + MGTools::reinit_vector_by_components( + mg_dof_handler, dst, mg_selected, mg_target_component, sizes); + + std::vector global_dof_indices (dofs_per_cell); + std::vector level_dof_indices (dofs_per_cell); + + // Build a vector of the selected + // indices, since traversing all + // indices on each cell is too + // slow. + std::vector selected_indices; + selected_indices.reserve(dofs_per_cell); + for (unsigned int i=0; i=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) + { + // get the dof numbers of + // this cell for the global + // and the level-wise + // numbering + level_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 + const unsigned int level_start + = mg_component_start[level][selected_component]; + const typename std::vector::const_iterator + end = selected_indices.end(); + + for (typename std::vector::const_iterator + i=selected_indices.begin(); + i != end; ++i) + { + dst[level](level_dof_indices[*i] - level_start) + = src(global_dof_indices[*i] - offset); + } + } + + // for that part of the level + // which is further refined: + // get the defect by + // restriction of the defect on + // one level higher + if (static_cast(level) < maxlevel) + { + restrict_and_add (level+1, dst[level], dst[level+1]); + } + }; +} + + + +template +template +void +MGTransferSelect::copy_from_mg ( + const MGDoFHandler& mg_dof_handler, + BlockVector& dst, + const MGLevelObject >& src) const +{ + do_copy_from_mg (mg_dof_handler, dst, src, 0); +} + + + +template +template +void +MGTransferSelect::copy_from_mg ( + const MGDoFHandler& mg_dof_handler, + Vector& dst, + const MGLevelObject >& src) const +{ + do_copy_from_mg (mg_dof_handler, dst, src, + component_start[selected_component]); +} + + + +template +template +void +MGTransferSelect::copy_from_mg_add ( + const MGDoFHandler& mg_dof_handler, + BlockVector& dst, + const MGLevelObject >& src) const +{ + do_copy_from_mg_add (mg_dof_handler, dst, src, 0); +} + + + +template +template +void +MGTransferSelect::copy_from_mg_add ( + const MGDoFHandler& mg_dof_handler, + Vector& dst, + const MGLevelObject >& src) const +{ + do_copy_from_mg_add (mg_dof_handler, dst, src, + component_start[selected_component]); +} + + + +template +template +void +MGTransferSelect::do_copy_from_mg ( + const MGDoFHandler &mg_dof_handler, + OutVector &dst, + const MGLevelObject > &src, + const unsigned int offset) 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 + + // Note that the level is + // monotonuosly increasing + for (; level_cell != endc; ++level_cell) + { + const unsigned int level = level_cell->level(); + + // get the dof numbers of + // this cell for the global + // and the level-wise + // numbering + level_cell->get_dof_indices (global_dof_indices); + level_cell->get_mg_dof_indices(level_dof_indices); + + // copy level-wise data to + // global vector + for (unsigned int i=0; i +template +void +MGTransferSelect::do_copy_from_mg_add ( + const MGDoFHandler &mg_dof_handler, + OutVector &dst, + const MGLevelObject > &src, + const unsigned int offset) 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 + + // Note that the level is + // monotonuosly increasing + for (; level_cell != endc; ++level_cell) + { + const unsigned int level = level_cell->level(); + + // get the dof numbers of + // this cell for the global + // and the level-wise + // numbering + level_cell->get_dof_indices (global_dof_indices); + level_cell->get_mg_dof_indices(level_dof_indices); + // copy level-wise data to + // global vector + for (unsigned int i=0; i +unsigned int +MGTransferSelect::memory_consumption () const +{ + return sizeof(int) + MGTransferComponentBase::memory_consumption(); +} + + + +DEAL_II_NAMESPACE_CLOSE + +#endif 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 ff6badc4ab..4c5f2009e2 100644 --- a/deal.II/deal.II/source/multigrid/mg_dof_tools.cc +++ b/deal.II/deal.II/source/multigrid/mg_dof_tools.cc @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -1030,10 +1031,13 @@ MGTools::count_dofs_per_block ( const unsigned int n_blocks = fe.n_blocks(); const unsigned int n_levels = dof_handler.get_tria().n_levels(); - dofs_per_block.resize (n_levels, std::vector(n_blocks)); - for (unsigned int l=0;l &mg_dof, template void MGTools::reinit_vector (const MGDoFHandler &mg_dof, - MGLevelObject > &v, - const std::vector &sel, - const std::vector &target_comp) + MGLevelObject > &v) +{ + const unsigned int n_blocks = mg_dof.get_fe().n_blocks(); + std::vector > + ndofs(mg_dof.get_tria().n_levels(), + std::vector(n_blocks)); + count_dofs_per_block (mg_dof, ndofs); + + for (unsigned int level=v.get_minlevel(); + level<=v.get_maxlevel();++level) + { + v[level].reinit(ndofs[level]); + } +} + + +template +void +MGTools::reinit_vector_by_components ( + const MGDoFHandler &mg_dof, + MGLevelObject > &v, + const std::vector &sel, + const std::vector &target_comp, + std::vector >& ndofs) { std::vector selected=sel; std::vector target_component=target_comp; @@ -1351,11 +1376,14 @@ MGTools::reinit_vector (const MGDoFHandler &mg_dof, selected.end(), 0U); - std::vector > - ndofs(mg_dof.get_tria().n_levels(), - std::vector(target_component.size())); - - count_dofs_per_component (mg_dof, ndofs, true, target_component); + if (ndofs.size() == 0) + { + std::vector > + new_dofs(mg_dof.get_tria().n_levels(), + std::vector(target_component.size())); + std::swap(ndofs, new_dofs); + count_dofs_per_component (mg_dof, ndofs, true, target_component); + } for (unsigned int level=v.get_minlevel(); level<=v.get_maxlevel();++level) @@ -1376,11 +1404,12 @@ MGTools::reinit_vector (const MGDoFHandler &mg_dof, template void -MGTools::reinit_vector (const MGDoFHandler &mg_dof, - MGLevelObject > &v, - const std::vector &selected, - const std::vector &target_component, - std::vector >& ndofs) +MGTools::reinit_vector_by_components ( + const MGDoFHandler &mg_dof, + MGLevelObject > &v, + const std::vector &selected, + const std::vector &target_component, + std::vector >& ndofs) { Assert (selected.size() == target_component.size(), ExcDimensionMismatch(selected.size(), target_component.size())); @@ -1415,6 +1444,85 @@ MGTools::reinit_vector (const MGDoFHandler &mg_dof, } +template +void +MGTools::reinit_vector_by_blocks ( + const MGDoFHandler &mg_dof, + MGLevelObject > &v, + const std::vector &sel, + std::vector >& ndofs) +{ + std::vector selected=sel; + // Compute the number of blocks needed + const unsigned int n_selected + = std::accumulate(selected.begin(), + selected.end(), + 0U); + + if (ndofs.size() == 0) + { + std::vector > + new_dofs(mg_dof.get_tria().n_levels(), + std::vector(selected.size())); + std::swap(ndofs, new_dofs); + count_dofs_per_block (mg_dof, ndofs); + } + + for (unsigned int level=v.get_minlevel(); + level<=v.get_maxlevel();++level) + { + v[level].reinit(n_selected, 0); + unsigned int k=0; + for (unsigned int i=0;i +void +MGTools::reinit_vector_by_blocks ( + const MGDoFHandler &mg_dof, + MGLevelObject > &v, + const std::vector &selected, + std::vector >& ndofs) +{ + // Compute the number of blocks needed +#ifdef DEBUG + const unsigned int n_selected + = std::accumulate(selected.begin(), + selected.end(), + 0U); + Assert(n_selected == 1, ExcDimensionMismatch(n_selected, 1)); +#endif + + unsigned int selected_block = 0; + while (!selected[selected_block]) + ++selected_block; + + if (ndofs.size() == 0) + { + std::vector > + new_dofs(mg_dof.get_tria().n_levels(), + std::vector(selected.size())); + std::swap(ndofs, new_dofs); + count_dofs_per_block (mg_dof, ndofs); + } + + for (unsigned int level=v.get_minlevel(); + level<=v.get_maxlevel();++level) + { + v[level].reinit(ndofs[level][selected_block]); + } +} + + DEAL_II_NAMESPACE_CLOSE @@ -1460,29 +1568,60 @@ template void MGTools::reinit_vector ( MGLevelObject >&); template void MGTools::reinit_vector ( + const MGDoFHandler&, + MGLevelObject >&); +template void MGTools::reinit_vector ( + const MGDoFHandler&, + MGLevelObject >&); + +template void MGTools::reinit_vector_by_components ( const MGDoFHandler&, MGLevelObject >&, const std::vector &, - const std::vector &); -template void MGTools::reinit_vector ( + const std::vector &, + std::vector >&); +template void MGTools::reinit_vector_by_components ( const MGDoFHandler&, MGLevelObject >&, const std::vector &, - const std::vector &); + const std::vector &, + std::vector >&); -template void MGTools::reinit_vector ( +template void MGTools::reinit_vector_by_components ( const MGDoFHandler&, MGLevelObject >&, const std::vector&, const std::vector&, std::vector >&); -template void MGTools::reinit_vector ( +template void MGTools::reinit_vector_by_components ( const MGDoFHandler&, MGLevelObject >&, const std::vector&, const std::vector&, std::vector >&); +template void MGTools::reinit_vector_by_blocks ( + const MGDoFHandler&, + MGLevelObject >&, + const std::vector &, + std::vector >&); +template void MGTools::reinit_vector_by_blocks ( + const MGDoFHandler&, + MGLevelObject >&, + const std::vector &, + std::vector >&); + +template void MGTools::reinit_vector_by_blocks ( + const MGDoFHandler&, + MGLevelObject >&, + const std::vector&, + std::vector >&); +template void MGTools::reinit_vector_by_blocks ( + const MGDoFHandler&, + MGLevelObject >&, + const std::vector&, + std::vector >&); + template void MGTools::count_dofs_per_component ( const MGDoFHandler&, diff --git a/deal.II/deal.II/source/multigrid/mg_transfer_block.cc b/deal.II/deal.II/source/multigrid/mg_transfer_block.cc index c3a782ca01..9ff04129f6 100644 --- a/deal.II/deal.II/source/multigrid/mg_transfer_block.cc +++ b/deal.II/deal.II/source/multigrid/mg_transfer_block.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2003, 2004, 2005, 2006 by the deal.II authors +// Copyright (C) 2003, 2004, 2005, 2006, 2007 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -23,11 +23,12 @@ #include #include #include -#include -#include +#include +#include #include #include +#include DEAL_II_NAMESPACE_OPEN @@ -38,101 +39,66 @@ void MGTransferBlockBase::build_matrices ( const DoFHandler&, const MGDoFHandler& mg_dof) { - // Fill target component with - // standard values (identity) if it - // is empty - if (target_component.size() == 0) - { - target_component.resize(mg_dof.get_fe().n_components()); - for (unsigned int i=0;i& fe = mg_dof.get_fe(); - - // Effective number of components - // is the maximum entry in - // mg_target_component. This - // assumes that the values in that - // vector don't have holes. - const unsigned int n_components = - *std::max_element(mg_target_component.begin(), mg_target_component.end()) + 1; + const unsigned int n_blocks = fe.n_blocks(); const unsigned int dofs_per_cell = fe.dofs_per_cell; const unsigned int n_levels = mg_dof.get_tria().n_levels(); - Assert (mg_selected.size() == fe.n_components(), - ExcDimensionMismatch(mg_selected.size(), fe.n_components())); + Assert (selected.size() == n_blocks, + ExcDimensionMismatch(selected.size(), n_blocks)); + // Compute the mapping between real + // blocks and blocks used for + // multigrid computations. + mg_block.resize(n_blocks); + if (true) + { + unsigned int k=0; + for (unsigned int i=0;i&>(mg_dof), - component_start, true, target_component); + + block_start.resize(n_blocks); + DoFTools::count_dofs_per_block (static_cast&>(mg_dof), block_start); unsigned int k=0; - for (unsigned int i=0;ireinit (n_components, n_components); - for (unsigned int i=0; ireinit (n_blocks, n_blocks); + for (unsigned int i=0; iblock(i,j) .reinit(sizes[level+1][i], @@ -220,10 +186,10 @@ void MGTransferBlockBase::build_matrices ( if (prolongation(i,j) != 0) { const unsigned int icomp - = fe.system_to_component_index(i).first; + = fe.system_to_block_index(i).first; const unsigned int jcomp - = fe.system_to_component_index(j).first; - if ((icomp==jcomp) && mg_selected[mg_target_component[icomp]]) + = fe.system_to_block_index(j).first; + if ((icomp==jcomp) && selected[icomp]) prolongation_sparsities[level]->add(dof_indices_child[i], dof_indices_parent[j]); }; @@ -255,9 +221,9 @@ void MGTransferBlockBase::build_matrices ( for (unsigned int j=0; jset(dof_indices_child[i], dof_indices_parent[j], prolongation(i,j)); @@ -268,71 +234,79 @@ void MGTransferBlockBase::build_matrices ( } + template template -void MGTransferBlock::build_matrices ( +void MGTransferBlockSelect::build_matrices ( const DoFHandler &dof, const MGDoFHandler &mg_dof, - const std::vector& t_component, - const std::vector& mg_t_component) + unsigned int select) { - if (selected.size() == 0) - selected = std::vector (mg_dof.get_fe().n_components(), true); - if (mg_selected.size() == 0) - mg_selected = std::vector (mg_dof.get_fe().n_components(), true); - - target_component = t_component; - mg_target_component = mg_t_component; - + const FiniteElement& fe = mg_dof.get_fe(); + unsigned int n_blocks = mg_dof.get_fe().n_blocks(); + + selected_block = select; + selected.resize(n_blocks, false); + selected[select] = true; + MGTransferBlockBase::build_matrices (dof, mg_dof); + + 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) + { + typename MGDoFHandler::active_cell_iterator + level_cell = mg_dof.begin_active(level); + const typename MGDoFHandler::active_cell_iterator + level_end = mg_dof.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); + + for (unsigned int i=0; i template -void MGTransferSelect::build_matrices ( +void MGTransferBlock::build_matrices ( const DoFHandler &dof, const MGDoFHandler &mg_dof, - unsigned int select, - unsigned int mg_select, - const std::vector& t_component, - const std::vector& mg_t_component) + const std::vector& sel) { const FiniteElement& fe = mg_dof.get_fe(); - unsigned int ncomp = mg_dof.get_fe().n_components(); - - target_component = t_component; - mg_target_component = mg_t_component; + unsigned int n_blocks = mg_dof.get_fe().n_blocks(); - selected_component = select; - mg_selected_component = mg_select; - selected.resize(ncomp, false); - selected[select] = true; - mg_selected.resize(ncomp, false); - mg_selected[mg_select] = true; - // If components are renumbered, - // find the first original - // component corresponding to the - // target component. - for (unsigned int i=0;i (n_blocks, true); + MGTransferBlockBase::build_matrices (dof, mg_dof); -//TODO:[GK] Rewrite this to suit MGTransferBlock and move to base class std::vector global_dof_indices (fe.dofs_per_cell); std::vector level_dof_indices (fe.dofs_per_cell); @@ -357,17 +331,11 @@ void MGTransferSelect::build_matrices ( for (unsigned int i=0; i::build_matrices ( template void MGTransferBlock::build_matrices -(const DoFHandler &, - const MGDoFHandler &, - const std::vector&, - const std::vector&); - -template -void MGTransferSelect::build_matrices -(const DoFHandler &d, - const MGDoFHandler &, - unsigned int, unsigned int, - const std::vector&, - const std::vector&); +(const DoFHandler&, const MGDoFHandler&, + const std::vector&); template void MGTransferBlock::build_matrices -(const DoFHandler &, - const MGDoFHandler &, - const std::vector&, - const std::vector&); +(const DoFHandler&, const MGDoFHandler&, + const std::vector&); template -void MGTransferSelect::build_matrices -(const DoFHandler &, - const MGDoFHandler &, - unsigned int, unsigned int, - const std::vector&, - const std::vector&); +void MGTransferBlockSelect::build_matrices +(const DoFHandler&, const MGDoFHandler&, + const unsigned int); +template +void MGTransferBlockSelect::build_matrices +(const DoFHandler&, const MGDoFHandler&, + const unsigned int); -template void -MGTransferBlock::copy_to_mg ( - const MGDoFHandler&, - MGLevelObject >&, - const Vector&) const; template void MGTransferBlock::copy_to_mg ( const MGDoFHandler&, MGLevelObject >&, const BlockVector&) const; template void -MGTransferBlock::copy_from_mg ( - const MGDoFHandler&, - Vector&, - const MGLevelObject >&) const; -template void MGTransferBlock::copy_from_mg ( const MGDoFHandler&, BlockVector&, const MGLevelObject >&) const; template void -MGTransferBlock::copy_from_mg_add ( - const MGDoFHandler&, - Vector&, - const MGLevelObject >&) const; -template void MGTransferBlock::copy_from_mg_add ( const MGDoFHandler&, BlockVector&, const MGLevelObject >&) const; template void -MGTransferBlock::copy_to_mg ( - const MGDoFHandler&, - MGLevelObject >&, - const Vector&) const; -template void MGTransferBlock::copy_to_mg ( const MGDoFHandler&, MGLevelObject >&, const BlockVector&) const; template void -MGTransferBlock::copy_from_mg ( - const MGDoFHandler&, - Vector&, - const MGLevelObject >&) const; -template void MGTransferBlock::copy_from_mg ( const MGDoFHandler&, BlockVector&, const MGLevelObject >&) const; template void -MGTransferBlock::copy_from_mg_add ( - const MGDoFHandler&, - Vector&, - const MGLevelObject >&) const; -template void MGTransferBlock::copy_from_mg_add ( const MGDoFHandler&, BlockVector&, const MGLevelObject >&) const; template void -MGTransferSelect::copy_to_mg ( +MGTransferBlockSelect::copy_to_mg ( const MGDoFHandler&, MGLevelObject >&, const Vector&) const; template void -MGTransferSelect::copy_to_mg ( +MGTransferBlockSelect::copy_to_mg ( const MGDoFHandler&, MGLevelObject >&, const BlockVector&) const; template void -MGTransferSelect::copy_from_mg ( +MGTransferBlockSelect::copy_from_mg ( const MGDoFHandler&, Vector&, const MGLevelObject >&) const; template void -MGTransferSelect::copy_from_mg ( +MGTransferBlockSelect::copy_from_mg ( const MGDoFHandler&, BlockVector&, const MGLevelObject >&) const; template void -MGTransferSelect::copy_from_mg_add ( +MGTransferBlockSelect::copy_from_mg_add ( const MGDoFHandler&, Vector&, const MGLevelObject >&) const; template void -MGTransferSelect::copy_from_mg_add ( +MGTransferBlockSelect::copy_from_mg_add ( const MGDoFHandler&, BlockVector&, const MGLevelObject >&) const; template void -MGTransferSelect::copy_to_mg ( +MGTransferBlockSelect::copy_to_mg ( const MGDoFHandler&, MGLevelObject >&, const Vector&) const; template void -MGTransferSelect::copy_to_mg ( +MGTransferBlockSelect::copy_to_mg ( const MGDoFHandler&, MGLevelObject >&, const BlockVector&) const; template void -MGTransferSelect::copy_from_mg ( +MGTransferBlockSelect::copy_from_mg ( const MGDoFHandler&, Vector&, const MGLevelObject >&) const; template void -MGTransferSelect::copy_from_mg ( +MGTransferBlockSelect::copy_from_mg ( const MGDoFHandler&, BlockVector&, const MGLevelObject >&) const; template void -MGTransferSelect::copy_from_mg_add ( +MGTransferBlockSelect::copy_from_mg_add ( const MGDoFHandler&, Vector&, const MGLevelObject >&) const; template void -MGTransferSelect::copy_from_mg_add ( +MGTransferBlockSelect::copy_from_mg_add ( const MGDoFHandler&, BlockVector&, const MGLevelObject >&) const; diff --git a/deal.II/deal.II/source/multigrid/mg_transfer_component.cc b/deal.II/deal.II/source/multigrid/mg_transfer_component.cc new file mode 100644 index 0000000000..3c7411bea9 --- /dev/null +++ b/deal.II/deal.II/source/multigrid/mg_transfer_component.cc @@ -0,0 +1,437 @@ +//--------------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2003, 2004, 2005, 2006, 2007 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//--------------------------------------------------------------------------- + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +DEAL_II_NAMESPACE_OPEN + + + +template +void MGTransferComponentBase::build_matrices ( + const DoFHandler&, + const MGDoFHandler& mg_dof) +{ + // Fill target component with + // standard values (identity) if it + // is empty + if (target_component.size() == 0) + { + target_component.resize(mg_dof.get_fe().n_components()); + for (unsigned int i=0;i& fe = mg_dof.get_fe(); + + // Effective number of components + // is the maximum entry in + // mg_target_component. This + // assumes that the values in that + // vector don't have holes. + const unsigned int n_components = + *std::max_element(mg_target_component.begin(), mg_target_component.end()) + 1; + const unsigned int dofs_per_cell = fe.dofs_per_cell; + const unsigned int n_levels = mg_dof.get_tria().n_levels(); + + Assert (mg_selected.size() == fe.n_components(), + ExcDimensionMismatch(mg_selected.size(), fe.n_components())); + + // Compute the lengths of all blocks + sizes.resize(n_levels); + MGTools::count_dofs_per_component(mg_dof, sizes, true, mg_target_component); + + // Fill some index vectors + // for later use. + mg_component_start = sizes; + // Compute start indices from sizes + for (unsigned int l=0;l&>(mg_dof), + component_start, true, target_component); + + unsigned int k=0; + for (unsigned int i=0;i (new BlockSparsityPattern)); + prolongation_matrices + .push_back (boost::shared_ptr > (new BlockSparseMatrix)); + } + + // two fields which will store the + // indices of the multigrid dofs + // for a cell and one of its children + std::vector dof_indices_parent (dofs_per_cell); + std::vector dof_indices_child (dofs_per_cell); + + // for each level: first build the + // sparsity pattern of the matrices + // and then build the matrices + // themselves. note that we only + // need to take care of cells on + // the coarser level which have + // children + for (unsigned int level=0; levelreinit (n_components, n_components); + for (unsigned int i=0; iblock(i,j) + .reinit(sizes[level+1][i], + sizes[level][j], + dofs_per_cell+1, false); + else + prolongation_sparsities[level]->block(i,j) + .reinit(sizes[level+1][i], + sizes[level][j], + 0, false); + + prolongation_sparsities[level]->collect_sizes(); + + for (typename MGDoFHandler::cell_iterator cell=mg_dof.begin(level); + cell != mg_dof.end(level); ++cell) + if (cell->has_children()) + { + cell->get_mg_dof_indices (dof_indices_parent); + + for (unsigned int child=0; childn_children(); ++child) + { + // set an alias to the + // prolongation matrix for + // this child + const FullMatrix &prolongation + = mg_dof.get_fe().get_prolongation_matrix (child); + + cell->child(child)->get_mg_dof_indices (dof_indices_child); + + // now tag the entries in the + // matrix which will be used + // for this pair of parent/child + for (unsigned int i=0; iadd(dof_indices_child[i], + dof_indices_parent[j]); + }; + }; + }; + prolongation_sparsities[level]->compress (); + + prolongation_matrices[level]->reinit (*prolongation_sparsities[level]); + // now actually build the matrices + for (typename MGDoFHandler::cell_iterator cell=mg_dof.begin(level); + cell != mg_dof.end(level); ++cell) + if (cell->has_children()) + { + cell->get_mg_dof_indices (dof_indices_parent); + + for (unsigned int child=0; childn_children(); ++child) + { + // set an alias to the + // prolongation matrix for + // this child + const FullMatrix &prolongation + = mg_dof.get_fe().get_prolongation_matrix (child); + + cell->child(child)->get_mg_dof_indices (dof_indices_child); + + // now set the entries in the + // matrix + for (unsigned int i=0; iset(dof_indices_child[i], + dof_indices_parent[j], + prolongation(i,j)); + } + } + } + } +} + + +template +template +void MGTransferSelect::build_matrices ( + const DoFHandler &dof, + const MGDoFHandler &mg_dof, + unsigned int select, + unsigned int mg_select, + const std::vector& t_component, + const std::vector& mg_t_component) +{ + const FiniteElement& fe = mg_dof.get_fe(); + unsigned int ncomp = mg_dof.get_fe().n_components(); + + target_component = t_component; + mg_target_component = mg_t_component; + + selected_component = select; + mg_selected_component = mg_select; + selected.resize(ncomp, false); + selected[select] = true; + mg_selected.resize(ncomp, false); + mg_selected[mg_select] = true; + // If components are renumbered, + // find the first original + // component corresponding to the + // target component. + for (unsigned int i=0;i 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) + { + typename MGDoFHandler::active_cell_iterator + level_cell = mg_dof.begin_active(level); + const typename MGDoFHandler::active_cell_iterator + level_end = mg_dof.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); + + for (unsigned int i=0; i::build_matrices +(const DoFHandler &d, + const MGDoFHandler &, + unsigned int, unsigned int, + const std::vector&, + const std::vector&); + +template +void MGTransferSelect::build_matrices +(const DoFHandler &d, + const MGDoFHandler &, + unsigned int, unsigned int, + const std::vector&, + const std::vector&); + +template void +MGTransferSelect::copy_to_mg ( + const MGDoFHandler&, + MGLevelObject >&, + const Vector&) const; +template void +MGTransferSelect::copy_to_mg ( + const MGDoFHandler&, + MGLevelObject >&, + const BlockVector&) const; +template void +MGTransferSelect::copy_from_mg ( + const MGDoFHandler&, + Vector&, + const MGLevelObject >&) const; +template void +MGTransferSelect::copy_from_mg ( + const MGDoFHandler&, + BlockVector&, + const MGLevelObject >&) const; +template void +MGTransferSelect::copy_from_mg_add ( + const MGDoFHandler&, + Vector&, + const MGLevelObject >&) const; +template void +MGTransferSelect::copy_from_mg_add ( + const MGDoFHandler&, + BlockVector&, + const MGLevelObject >&) const; + +template void +MGTransferSelect::copy_to_mg ( + const MGDoFHandler&, + MGLevelObject >&, + const Vector&) const; +template void +MGTransferSelect::copy_to_mg ( + const MGDoFHandler&, + MGLevelObject >&, + const BlockVector&) const; +template void +MGTransferSelect::copy_from_mg ( + const MGDoFHandler&, + Vector&, + const MGLevelObject >&) const; +template void +MGTransferSelect::copy_from_mg ( + const MGDoFHandler&, + BlockVector&, + const MGLevelObject >&) const; +template void +MGTransferSelect::copy_from_mg_add ( + const MGDoFHandler&, + Vector&, + const MGLevelObject >&) const; +template void +MGTransferSelect::copy_from_mg_add ( + const MGDoFHandler&, + BlockVector&, + const MGLevelObject >&) const; + +DEAL_II_NAMESPACE_CLOSE 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 7e0cbfbc3c..d5871ad6ed 100644 --- a/deal.II/deal.II/source/multigrid/multigrid.all_dimensions.cc +++ b/deal.II/deal.II/source/multigrid/multigrid.all_dimensions.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors +// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -17,8 +17,12 @@ #include #include #include +#include +#include #include #include +#include +#include #include DEAL_II_NAMESPACE_OPEN @@ -165,14 +169,16 @@ void MGTransferBlock::prolongate ( { Assert ((to_level >= 1) && (to_level<=prolongation_matrices.size()), ExcIndexRange (to_level, 1, prolongation_matrices.size()+1)); - - unsigned int k=0; + Assert (src.n_blocks() == prolongation_matrices[to_level-1]->n_block_cols(), + ExcDimensionMismatch(src.n_blocks(), + prolongation_matrices[to_level-1]->n_block_cols())); + Assert (dst.n_blocks() == prolongation_matrices[to_level-1]->n_block_rows(), + ExcDimensionMismatch(dst.n_blocks(), + prolongation_matrices[to_level-1]->n_block_rows())); + for (unsigned int b=0; bblock(k,k).vmult (dst.block(b), src.block(b)); - ++k; + prolongation_matrices[to_level-1]->block(b,b).vmult (dst.block(b), src.block(b)); } } @@ -185,32 +191,48 @@ void MGTransferBlock::restrict_and_add ( { Assert ((from_level >= 1) && (from_level<=prolongation_matrices.size()), ExcIndexRange (from_level, 1, prolongation_matrices.size()+1)); + Assert (src.n_blocks() == prolongation_matrices[from_level-1]->n_block_rows(), + ExcDimensionMismatch(src.n_blocks(), + prolongation_matrices[from_level-1]->n_block_rows())); + Assert (dst.n_blocks() == prolongation_matrices[from_level-1]->n_block_cols(), + ExcDimensionMismatch(dst.n_blocks(), + prolongation_matrices[from_level-1]->n_block_cols())); - unsigned int k=0; for (unsigned int b=0; b* aux = memory->alloc(); aux->reinit(dst.block(b)); - prolongation_matrices[from_level-1]->block(k,k).Tvmult (*aux, src.block(b)); + prolongation_matrices[from_level-1]->block(b,b).Tvmult (*aux, src.block(b)); - dst.block(b).add(factors[k], *aux); + dst.block(b).add(factors[b], *aux); memory->free(aux); } else { - prolongation_matrices[from_level-1]->block(k,k).Tvmult_add (dst.block(b), + prolongation_matrices[from_level-1]->block(b,b).Tvmult_add (dst.block(b), src.block(b)); } - ++k; } } +//TODO:[GK] Add all those little vectors. +unsigned int +MGTransferComponentBase::memory_consumption () const +{ + unsigned int result = sizeof(*this); + result += sizeof(unsigned int) * sizes.size(); + for (unsigned int i=0;imemory_consumption() + + prolongation_sparsities[i]->memory_consumption(); + return result; +} + + //TODO:[GK] Add all those little vectors. unsigned int MGTransferBlockBase::memory_consumption () const @@ -276,6 +298,44 @@ MGSmootherContinuous::set_zero_interior_boundary ( } +//----------------------------------------------------------------------// + +template +MGTransferBlockSelect::~MGTransferBlockSelect () +{} + + +template +void MGTransferBlockSelect::prolongate ( + const unsigned int to_level, + Vector &dst, + const Vector &src) const +{ + Assert ((to_level >= 1) && (to_level<=prolongation_matrices.size()), + ExcIndexRange (to_level, 1, prolongation_matrices.size()+1)); + + prolongation_matrices[to_level-1]->block(selected_block, + selected_block) + .vmult (dst, src); +} + + +template +void MGTransferBlockSelect::restrict_and_add ( + const unsigned int from_level, + Vector &dst, + const Vector &src) const +{ + Assert ((from_level >= 1) && (from_level<=prolongation_matrices.size()), + ExcIndexRange (from_level, 1, prolongation_matrices.size()+1)); + + prolongation_matrices[from_level-1]->block(selected_block, + selected_block) + .Tvmult_add (dst, src); +} + + + // Explicit instantiations template class Multigrid >; @@ -291,6 +351,8 @@ template class MGTransferBlock; template class MGTransferBlock; template class MGTransferSelect; template class MGTransferSelect; +template class MGTransferBlockSelect; +template class MGTransferBlockSelect; template void MGSmootherContinuous >::set_zero_interior_boundary ( diff --git a/tests/multigrid/Makefile b/tests/multigrid/Makefile index eaee414c46..5210343b40 100644 --- a/tests/multigrid/Makefile +++ b/tests/multigrid/Makefile @@ -1,6 +1,6 @@ ############################################################ # $Id$ -# Copyright (C) 2000, 2001, 2002, 2003, 2005, 2006 by the deal.II authors +# Copyright (C) 2000, 2001, 2002, 2003, 2005, 2006, 2007 by the deal.II authors ############################################################ ############################################################ @@ -22,7 +22,7 @@ default: run-tests ############################################################ tests_x = cycles dof_* count_* boundary_* renumbering_* \ - transfer transfer_select transfer_block \ + transfer transfer_select transfer_block_select transfer_block \ smoother_block # from above list of regular expressions, generate the real set of diff --git a/tests/multigrid/transfer.cc b/tests/multigrid/transfer.cc index 40a8c977e4..44f12a9a7b 100644 --- a/tests/multigrid/transfer.cc +++ b/tests/multigrid/transfer.cc @@ -2,7 +2,7 @@ // transfer.cc,v 1.13 2005/12/30 16:07:03 guido Exp // Version: // -// Copyright (C) 2000 - 2006 by the deal.II authors +// Copyright (C) 2000 - 2007 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -90,7 +90,7 @@ void check_simple(const FiniteElement& fe) transfer.restrict_and_add(2,u1,u2); transfer.restrict_and_add(1,u0,u1); deallog << "u1\t" << (u1*u1+.5) << std::endl - << "u0\t" << (u0*u0+.5) << std::endl; + << "u0\t" << (u0*u0+.5) << std::endl; } @@ -111,7 +111,7 @@ int main() check_simple (FESystem<2>(FE_DGQ<2>(1), 2)); check_simple (FESystem<2>(FE_DGP<2>(1), 2, FE_DGQ<2>(1), 3)); -// check_simple (FE_RaviartThomas<2>(2)); + check_simple (FE_RaviartThomasNodal<2>(1)); // check_simple (FESystem<2>(FE_RaviartThomas<2>(1),1,FE_DGQ<2>(0),2)); check_simple (FE_DGQ<3>(1)); diff --git a/tests/multigrid/transfer/cmp/x86_64-unknown-linux-gnu+gcc3.3 b/tests/multigrid/transfer/cmp/x86_64-unknown-linux-gnu+gcc3.3 index 975e2d99ed..9126aedebc 100644 --- a/tests/multigrid/transfer/cmp/x86_64-unknown-linux-gnu+gcc3.3 +++ b/tests/multigrid/transfer/cmp/x86_64-unknown-linux-gnu+gcc3.3 @@ -87,6 +87,17 @@ DEAL::u1 7.11e+03 DEAL::u2 2.84e+04 DEAL::u1 1.14e+05 DEAL::u0 4.54e+05 +DEAL::FE_RaviartThomasNodal<2>(1) +DEAL::u0 12.5 +DEAL::u1 40.5 +DEAL::u2 144. +DEAL::u1 573. +DEAL::u0 2.21e+03 +DEAL::u0 506. +DEAL::u1 2.07e+03 +DEAL::u2 8.15e+03 +DEAL::u1 3.40e+04 +DEAL::u0 1.40e+05 DEAL::FE_DGQ<3>(1) DEAL::u0 8.50 DEAL::u1 64.5 diff --git a/tests/multigrid/transfer_block.cc b/tests/multigrid/transfer_block.cc index 396cdae1f2..886c6973e7 100644 --- a/tests/multigrid/transfer_block.cc +++ b/tests/multigrid/transfer_block.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2000 - 2006 by the deal.II authors +// Copyright (C) 2000 - 2007 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -23,9 +23,10 @@ #include #include #include +#include #include #include -#include +#include #include #include @@ -38,13 +39,14 @@ using namespace std; template void check_block(const FiniteElement& fe, - const vector& /*selected*/, - const vector& /*mg_selected*/, - const vector& factors, - std::vector target_component, - std::vector mg_target_component) + const vector& selected, + const vector& factors) { - deallog << fe.get_name() << std::endl; + deallog << fe.get_name() << std::endl << "selected "; + for (unsigned int i=0;i tr; GridGenerator::hyper_cube(tr); @@ -53,15 +55,14 @@ void check_block(const FiniteElement& fe, MGDoFHandler mgdof(tr); DoFHandler& dof=mgdof; mgdof.distribute_dofs(fe); - DoFRenumbering::component_wise(mgdof, target_component); - vector ndofs(fe.n_components()); - DoFTools::count_dofs_per_component(mgdof, ndofs, true, target_component); + DoFRenumbering::component_wise(mgdof); + vector ndofs(fe.n_blocks()); + DoFTools::count_dofs_per_block(mgdof, ndofs); for (unsigned int l=0;l > mg_ndofs(mgdof.get_tria().n_levels()); - MGTools::count_dofs_per_component(mgdof, mg_ndofs, true, mg_target_component); + MGTools::count_dofs_per_block(mgdof, mg_ndofs); deallog << "Global dofs:"; for (unsigned int i=0;i& fe, PrimitiveVectorMemory > mem; MGTransferBlock transfer; - transfer.build_matrices(dof, mgdof, target_component, mg_target_component); + transfer.build_matrices(dof, mgdof, selected); if (factors.size()>0) transfer.initialize(factors, mem); @@ -85,25 +86,30 @@ void check_block(const FiniteElement& fe, BlockVector u1(mg_ndofs[1]); BlockVector u0(mg_ndofs[0]); + // Prolongate a constant function + // twice u0 = 1; transfer.prolongate(1,u1,u0); transfer.prolongate(2,u2,u1); + // These outputs are just the + // number of dofs on each level deallog << "u0"; for (unsigned int b=0;b& fe, BlockVector u; u.reinit (ndofs); for (unsigned int i=0;i > v; - v.resize(2,2); - v[2].reinit(mg_ndofs[2]); + u(i) = i+1; + std::vector > cached_sizes; + MGLevelObject > v; + v.resize(0, tr.n_levels()-1); + MGTools::reinit_vector_by_blocks(mgdof, v, selected, cached_sizes); + transfer.copy_to_mg(mgdof, v, u); for (unsigned int i=0; i v1(4); - std::vector v2(4); - std::vector v3(4); - for (unsigned int i=0;i<4;++i) - { - v1[i] = i; - v2[i] = 0; - v3[i] = i; - } - v3[0] = 0; - v3[1] = 1; - v3[2] = 1; - v3[3] = 2; - std::vector factors; + + FE_DGQ<2> q0(0); + FE_DGQ<2> q1(1); + FE_RaviartThomasNodal<2> rt0(0); + FE_RaviartThomasNodal<2> rt1(1); - FESystem<2> fe1(FE_DGQ<2>(1), 4); - - vector s1(4, true); + FESystem<2> fe0(rt1, 1, q1, 1); + FESystem<2> fe1(rt0, 2, q0, 2); - deallog << "s1 s1 v1 v1" << std::endl; - check_block(fe1, s1, s1, factors, v1, v1); -// deallog << "s1 s1 v1 v2" << std::endl; -// check_block(fe1, s1, s1, factors, v1, v2); -// deallog << "s1 s1 v1 v3" << std::endl; -// check_block(fe1, s1, s1, factors, v1, v3); + vector s1(2, true); + deallog << "All" << std::endl; + check_block(fe0, s1, factors); + + s1[1] = false; + deallog << "Velocity" << std::endl; + check_block(fe0, s1, factors); - factors.resize(4, 1.); - factors[1] = 2.; - deallog << "s1 s1 v1 v1" << std::endl; - check_block(fe1, s1, s1, factors, v1, v1); -// deallog << "s1 s1 v1 v3" << std::endl; -// check_block(fe1, s1, s1, factors, v1, v3); + s1[1] = true; + s1[0] = false; + deallog << "Pressure" << std::endl; + check_block(fe0, s1, factors); + + s1.resize(4,true); + s1[0] = false; + s1[2] = false; + check_block(fe1, s1, factors); } diff --git a/tests/multigrid/transfer_block/cmp/generic b/tests/multigrid/transfer_block/cmp/generic index 85e4fda8ae..b08f070169 100644 --- a/tests/multigrid/transfer_block/cmp/generic +++ b/tests/multigrid/transfer_block/cmp/generic @@ -1,25 +1,56 @@ -DEAL::s1 s1 v1 v1 -DEAL::FESystem<2>[FE_DGQ<2>(1)^4] -DEAL::Global dofs: 64 64 64 64 -DEAL::Level 0 dofs: 4 4 4 4 -DEAL::Level 1 dofs: 16 16 16 16 -DEAL::Level 2 dofs: 64 64 64 64 -DEAL::u0 4 4 4 4 -DEAL::u1 16 16 16 16 -DEAL::u2 64 64 64 64 -DEAL::u1 256 256 256 256 -DEAL::u0 1024 1024 1024 1024 -DEAL:: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 -DEAL::s1 s1 v1 v1 -DEAL::FESystem<2>[FE_DGQ<2>(1)^4] -DEAL::Global dofs: 64 64 64 64 -DEAL::Level 0 dofs: 4 4 4 4 -DEAL::Level 1 dofs: 16 16 16 16 -DEAL::Level 2 dofs: 64 64 64 64 -DEAL::u0 4 4 4 4 -DEAL::u1 16 16 16 16 -DEAL::u2 64 64 64 64 -DEAL::u1 256 1024 256 256 -DEAL::u0 1024 16384 1024 1024 -DEAL:: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 +DEAL::All +DEAL::FESystem<2>[FE_RaviartThomasNodal<2>(1)-FE_DGQ<2>(1)] +DEAL::selected 0 1 +DEAL::Global dofs: 144 64 +DEAL::Level 0 dofs: 12 4 +DEAL::Level 1 dofs: 40 16 +DEAL::Level 2 dofs: 144 64 +DEAL::u0 12 4 +DEAL::u1 40 16 +DEAL::u2 144 64 +DEAL::u1 572 256 +DEAL::u0 2214 1024 +DEAL:: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 +DEAL:: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 +DEAL::Velocity +DEAL::FESystem<2>[FE_RaviartThomasNodal<2>(1)-FE_DGQ<2>(1)] +DEAL::selected 0 +DEAL::Global dofs: 144 64 +DEAL::Level 0 dofs: 12 4 +DEAL::Level 1 dofs: 40 16 +DEAL::Level 2 dofs: 144 64 +DEAL::u0 12 4 +DEAL::u1 40 0 +DEAL::u2 144 0 +DEAL::u1 572 0 +DEAL::u0 2214 0 +DEAL:: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 +DEAL:: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL::Pressure +DEAL::FESystem<2>[FE_RaviartThomasNodal<2>(1)-FE_DGQ<2>(1)] +DEAL::selected 1 +DEAL::Global dofs: 144 64 +DEAL::Level 0 dofs: 12 4 +DEAL::Level 1 dofs: 40 16 +DEAL::Level 2 dofs: 144 64 +DEAL::u0 12 4 +DEAL::u1 0 16 +DEAL::u2 0 64 +DEAL::u1 0 256 +DEAL::u0 0 1024 +DEAL:: 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 +DEAL:: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 +DEAL::FESystem<2>[FE_RaviartThomasNodal<2>(0)^2-FE_DGQ<2>(0)^2] +DEAL::selected 1 3 +DEAL::Global dofs: 40 40 16 16 +DEAL::Level 0 dofs: 4 4 1 1 +DEAL::Level 1 dofs: 12 12 4 4 +DEAL::Level 2 dofs: 40 40 16 16 +DEAL::u0 4 4 1 1 +DEAL::u1 0 12 0 4 +DEAL::u2 0 40 0 16 +DEAL::u1 0 136 0 64 +DEAL::u0 0 400 0 256 +DEAL:: 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 +DEAL:: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 diff --git a/tests/multigrid/transfer_block_select.cc b/tests/multigrid/transfer_block_select.cc new file mode 100644 index 0000000000..94d6996f07 --- /dev/null +++ b/tests/multigrid/transfer_block_select.cc @@ -0,0 +1,155 @@ +//---------------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2000 - 2007 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------------------------------------------------------- + + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +using namespace std; + +template +void check_select(const FiniteElement& fe, unsigned int selected) +{ + deallog << fe.get_name() + << " select " << selected << std::endl; + + Triangulation tr; + GridGenerator::hyper_cube(tr); + tr.refine_global(2); + + MGDoFHandler mgdof(tr); + DoFHandler& dof=mgdof; + mgdof.distribute_dofs(fe); + DoFRenumbering::component_wise(static_cast&>(mgdof)); + vector ndofs(fe.n_blocks()); + DoFTools::count_dofs_per_block(mgdof, ndofs); + + for (unsigned int l=0;l > mg_ndofs(mgdof.get_tria().n_levels()); + MGTools::count_dofs_per_block(mgdof, mg_ndofs); + + deallog << "Global dofs:"; + for (unsigned int i=0;i transfer; + transfer.build_matrices(dof, mgdof, selected); + + // First, prolongate the constant + // function from the coarsest mesh + // to the finer ones. Since this is + // the embedding, we obtain the + // constant one and the l2-norm is + // the number of degrees of freedom. + Vector u2(mg_ndofs[2][selected]); + Vector u1(mg_ndofs[1][selected]); + Vector u0(mg_ndofs[0][selected]); + + u0 = 1; + transfer.prolongate(1,u1,u0); + transfer.prolongate(2,u2,u1); + deallog << "u0\t" << (int) (u0*u0+.5) << std::endl + << "u1\t" << (int) (u1*u1+.5) << std::endl + << "u2\t" << (int) (u2*u2+.5) << std::endl; + // Now restrict the same vectors. + u1 = 0.; + u0 = 0.; + transfer.restrict_and_add(2,u1,u2); + transfer.restrict_and_add(1,u0,u1); + deallog << "u1\t" << (int) (u1*u1+.5) << std::endl + << "u0\t" << (int) (u0*u0+.5) << std::endl; + + // Fill a global vector by counting + // from one up + BlockVector u; + u.reinit (ndofs); + for (unsigned int i=0;i > v; + v.resize(2,2); + v[2].reinit(mg_ndofs[2][selected]); + + transfer.copy_to_mg(mgdof, v, u); + for (unsigned int i=0; i q0(0); + FE_DGQ<2> q1(1); + FE_RaviartThomasNodal<2> rt0(0); + FE_RaviartThomasNodal<2> rt1(1); + + FESystem<2> fe0(rt1, 1, q1, 1); + FESystem<2> fe1(rt0, 2, q0, 2); + + check_select(fe0, 0); + check_select(fe0, 1); + + check_select(fe1, 0); + check_select(fe1, 1); + check_select(fe1, 2); + check_select(fe1, 3); +} diff --git a/tests/multigrid/transfer_block_select/cmp/generic b/tests/multigrid/transfer_block_select/cmp/generic new file mode 100644 index 0000000000..1a7206b077 --- /dev/null +++ b/tests/multigrid/transfer_block_select/cmp/generic @@ -0,0 +1,73 @@ + +DEAL::FESystem<2>[FE_RaviartThomasNodal<2>(1)-FE_DGQ<2>(1)] select 0 +DEAL::Global dofs: 144 64 +DEAL::Level 0 dofs: 12 4 +DEAL::Level 1 dofs: 40 16 +DEAL::Level 2 dofs: 144 64 +DEAL::u0 12 +DEAL::u1 40 +DEAL::u2 144 +DEAL::u1 572 +DEAL::u0 2214 +DEAL:: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 +DEAL:: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL::FESystem<2>[FE_RaviartThomasNodal<2>(1)-FE_DGQ<2>(1)] select 1 +DEAL::Global dofs: 144 64 +DEAL::Level 0 dofs: 12 4 +DEAL::Level 1 dofs: 40 16 +DEAL::Level 2 dofs: 144 64 +DEAL::u0 4 +DEAL::u1 16 +DEAL::u2 64 +DEAL::u1 256 +DEAL::u0 1024 +DEAL:: 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 +DEAL:: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 +DEAL::FESystem<2>[FE_RaviartThomasNodal<2>(0)^2-FE_DGQ<2>(0)^2] select 0 +DEAL::Global dofs: 40 40 16 16 +DEAL::Level 0 dofs: 4 4 1 1 +DEAL::Level 1 dofs: 12 12 4 4 +DEAL::Level 2 dofs: 40 40 16 16 +DEAL::u0 4 +DEAL::u1 12 +DEAL::u2 40 +DEAL::u1 136 +DEAL::u0 400 +DEAL:: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 +DEAL:: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL::FESystem<2>[FE_RaviartThomasNodal<2>(0)^2-FE_DGQ<2>(0)^2] select 1 +DEAL::Global dofs: 40 40 16 16 +DEAL::Level 0 dofs: 4 4 1 1 +DEAL::Level 1 dofs: 12 12 4 4 +DEAL::Level 2 dofs: 40 40 16 16 +DEAL::u0 4 +DEAL::u1 12 +DEAL::u2 40 +DEAL::u1 136 +DEAL::u0 400 +DEAL:: 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 +DEAL:: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL::FESystem<2>[FE_RaviartThomasNodal<2>(0)^2-FE_DGQ<2>(0)^2] select 2 +DEAL::Global dofs: 40 40 16 16 +DEAL::Level 0 dofs: 4 4 1 1 +DEAL::Level 1 dofs: 12 12 4 4 +DEAL::Level 2 dofs: 40 40 16 16 +DEAL::u0 1 +DEAL::u1 4 +DEAL::u2 16 +DEAL::u1 64 +DEAL::u0 256 +DEAL:: 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 +DEAL:: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL::FESystem<2>[FE_RaviartThomasNodal<2>(0)^2-FE_DGQ<2>(0)^2] select 3 +DEAL::Global dofs: 40 40 16 16 +DEAL::Level 0 dofs: 4 4 1 1 +DEAL::Level 1 dofs: 12 12 4 4 +DEAL::Level 2 dofs: 40 40 16 16 +DEAL::u0 1 +DEAL::u1 4 +DEAL::u2 16 +DEAL::u1 64 +DEAL::u0 256 +DEAL:: 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 +DEAL:: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 diff --git a/tests/multigrid/transfer_select.cc b/tests/multigrid/transfer_select.cc index f8f71053d5..edbc45cd6c 100644 --- a/tests/multigrid/transfer_select.cc +++ b/tests/multigrid/transfer_select.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2000 - 2006 by the deal.II authors +// Copyright (C) 2000 - 2007 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include -- 2.39.5