]> https://gitweb.dealii.org/ - dealii.git/commitdiff
MGTransfer simplified for DG only
authorGuido Kanschat <dr.guido.kanschat@gmail.com>
Sun, 29 Jan 2006 15:00:32 +0000 (15:00 +0000)
committerGuido Kanschat <dr.guido.kanschat@gmail.com>
Sun, 29 Jan 2006 15:00:32 +0000 (15:00 +0000)
git-svn-id: https://svn.dealii.org/trunk@12201 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/multigrid/mg_transfer.h
deal.II/deal.II/include/multigrid/mg_transfer.templates.h

index b39a342e5337e5e3bd5b42067f11500b3f2d2a4a..3be072a0f3b3de4bacb3d195c5f90ff1bae43185 100644 (file)
@@ -2,7 +2,7 @@
 //    $Id$
 //    Version: $Name$
 //
-//    Copyright (C) 2001, 2002, 2003, 2004, 2005 by the deal.II authors
+//    Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 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 @@ class MGTransferPrebuilt : public MGTransferBase<VECTOR>
     void
     copy_to_mg (const MGDoFHandler<dim>& mg_dof,
                MGLevelObject<VECTOR>& dst,
-               const InVector&          src) const;
+               const InVector& src) const;
 
                                     /**
                                      * Transfer from multi-level vector to
@@ -106,8 +106,8 @@ class MGTransferPrebuilt : public MGTransferBase<VECTOR>
                                      */
     template <int dim, class OutVector>
     void
-    copy_from_mg (const MGDoFHandler<dim>              &mg_dof,
-                 OutVector                            &dst,
+    copy_from_mg (const MGDoFHandler<dim>mg_dof,
+                 OutVectordst,
                  const MGLevelObject<VECTOR> &src) const;
 
                                     /**
@@ -120,9 +120,9 @@ class MGTransferPrebuilt : public MGTransferBase<VECTOR>
                                      */
     template <int dim, class OutVector>
     void
-    copy_from_mg_add (const MGDoFHandler<dim>              &mg_dof,
-                     OutVector                            &dst,
-                     const MGLevelObject<VECTOR> &src) const;
+    copy_from_mg_add (const MGDoFHandler<dim>mg_dof,
+                     OutVectordst,
+                     const MGLevelObject<VECTOR>src) const;
 
                                     /**
                                      * Finite element does not
@@ -149,17 +149,6 @@ class MGTransferPrebuilt : public MGTransferBase<VECTOR>
                                    */
     std::vector<unsigned int> sizes;
 
-#ifdef DEAL_PREFER_MATRIX_EZ
-                                    /**
-                                     * 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<boost::shared_ptr<SparseMatrixEZ<double> > > prolongation_matrices;
-#else
                                     /**
                                      * Sparsity patterns for transfer
                                      * matrices.
@@ -174,56 +163,7 @@ class MGTransferPrebuilt : public MGTransferBase<VECTOR>
                                      * while row indices belong to the
                                      * child cell, i.e. the fine level.
                                      */
-    std::vector<boost::shared_ptr<SparseMatrix<double> > > prolongation_matrices;
-#endif
-
-                                    /**
-                                     * Structure that is used to
-                                     * disambiguate calls to
-                                     * @p copy_to_mg for 1d and
-                                     * non-1d. We provide two
-                                     * functions of @p copy_to_mg,
-                                     * where the 1d function takes an
-                                     * argument of type
-                                     * <tt>is_1d<true></tt> and the other
-                                     * one of type <tt>is_1d<false></tt>.
-                                     */
-    template <bool> struct is_1d {};
-    
-                                    /**
-                                     * Implementation of the
-                                     * copy_to_mg() function for
-                                     * 1d. We have to resort to some
-                                     * template trickery because we
-                                     * can't specialize template
-                                     * functions on the (outer)
-                                     * template of the class, without
-                                     * also fully specializing the
-                                     * inner (member function)
-                                     * template parameters. However,
-                                     * it can be done by adding the
-                                     * additional argument that
-                                     * converts template
-                                     * specialization into function
-                                     * overloading.
-                                     */
-    template <int dim, class InVector>
-    void
-    copy_to_mg (const MGDoFHandler<dim>        &mg_dof,
-               MGLevelObject<VECTOR> &dst,
-               const InVector                 &src,
-               const is_1d<true>              &) const;
-
-                                    /**
-                                     * Same for all other space
-                                     * dimensions.
-                                     */
-    template <int dim, class InVector>
-    void
-    copy_to_mg (const MGDoFHandler<dim>        &mg_dof,
-               MGLevelObject<VECTOR> &dst,
-               const InVector                 &src,
-               const is_1d<false>             &) const;
+    std::vector<boost::shared_ptr<SparseMatrix<double> > > prolongation_matrices;    
 };
 
 
@@ -324,25 +264,12 @@ class MGTransferBlockBase
                                      * function first.
                                      */
     DeclException0(ExcMatricesNotBuilt);
-
-#ifdef DEAL_PREFER_MATRIX_EZ
-  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<boost::shared_ptr<BlockSparseMatrixEZ<double> > > prolongation_matrices;
-#else
+    
   private:
     std::vector<boost::shared_ptr<BlockSparsityPattern> >   prolongation_sparsities;
-
+    
   protected:
-  
+    
                                     /**
                                      * The actual prolongation matrix.
                                      * column indices belong to the
@@ -352,8 +279,7 @@ class MGTransferBlockBase
                                      * child cell, i.e. the fine level.
                                      */
     std::vector<boost::shared_ptr<BlockSparseMatrix<double> > > prolongation_matrices;
-#endif
-
+    
                                     /**
                                      * Unused now, but intended to
                                      * hold the mapping for the
@@ -520,54 +446,6 @@ class MGTransferBlock : public MGTransferBase<BlockVector<number> >,
     MGTransferBlockBase::memory_consumption;
     
   private:
-                                    /**
-                                     * Structure that is used to
-                                     * disambiguate calls to
-                                     * @p copy_to_mg for 1d and
-                                     * non-1d. We provide two
-                                     * functions of @p copy_to_mg,
-                                     * where the 1d function takes an
-                                     * argument of type
-                                     * <tt>is_1d<true></tt> and the other
-                                     * one of type <tt>is_1d<false></tt>.
-                                     */
-    template <bool> struct is_1d {};
-
-                                    /**
-                                     * Implementation of the
-                                     * @p copy_to_mg function for
-                                     * 1d. We have to resort to some
-                                     * template trickery because we
-                                     * can't specialize template
-                                     * functions on the (outer)
-                                     * template of the class, without
-                                     * also fully specializing the
-                                     * inner (member function)
-                                     * template parameters. However,
-                                     * it can be done by adding the
-                                     * additional argument that
-                                     * converts template
-                                     * specialization into function
-                                     * overloading.
-                                     */
-    template <int dim, class InVector>
-    void
-    copy_to_mg (const MGDoFHandler<dim>             &mg_dof,
-               MGLevelObject<BlockVector<number> > &dst,
-               const InVector                      &src,
-               const is_1d<true>                   &) const;
-
-                                    /**
-                                     * Same for all other space
-                                     * dimensions.
-                                     */
-    template <int dim, class InVector>
-    void
-    copy_to_mg (const MGDoFHandler<dim>             &mg_dof,
-               MGLevelObject<BlockVector<number> > &dst,
-               const InVector                      &src,
-               const is_1d<false>                  &) const;    
-    
                                     /**
                                      * Optional multiplication
                                      * factors for each
@@ -671,19 +549,6 @@ class MGTransferSelect : public MGTransferBase<Vector<number> >,
     virtual void restrict_and_add (const unsigned int    from_level,
                                   Vector<number>       &dst,
                                   const Vector<number> &src) const;
-
-                                    /**
-                                     * Structure that is used to
-                                     * disambiguate calls to
-                                     * copy_to_mg() for 1d and
-                                     * non-1d. We provide two
-                                     * functions of copy_to_mg(),
-                                     * where the 1d function takes an
-                                     * argument of type
-                                     * <tt>is_1d<true></tt> and the other
-                                     * one of type <tt>is_1d<false></tt>}.
-                                     */
-    template <bool> struct is_1d {};
     
                                     /**
                                      * Transfer from a vector on the
@@ -793,43 +658,15 @@ class MGTransferSelect : public MGTransferBase<Vector<number> >,
                         const unsigned int offset) const;
 
                                     /**
-                                     * Implementation of the
-                                     * copy_to_mg() function for
-                                     * 1d. We have to resort to some
-                                     * template trickery because we
-                                     * can't specialize template
-                                     * functions on the (outer)
-                                     * template of the class, without
-                                     * also fully specializing the
-                                     * inner (member function)
-                                     * template parameters. However,
-                                     * it can be done by adding the
-                                     * additional argument that
-                                     * converts template
-                                     * specialization into function
-                                     * overloading.
+                                     * Actual implementation of
+                                     * copy_to_mg().
                                      */
     template <int dim, class InVector>
     void
     do_copy_to_mg (const MGDoFHandler<dim>        &mg_dof,
                   MGLevelObject<Vector<number> > &dst,
                   const InVector                 &src,
-                  const unsigned int              offset,
-                  const is_1d<true>              &) const;
-
-                                    /**
-                                     * Implementation of the
-                                     * copy_to_mg() function for
-                                     * higher dimensions.
-                                     */
-    template <int dim, class InVector>
-    void
-    do_copy_to_mg (const MGDoFHandler<dim>        &mg_dof,
-                  MGLevelObject<Vector<number> > &dst,
-                  const InVector                 &src,
-                  const unsigned int              offset,
-                  const is_1d<false>             &) const;
-
+                  const unsigned int              offset) const;
                                      /**
                                       * Selected component of global vector.
                                       */
index 6931906f31f96cbc9ae878707698962ab02d9233..100b9d00d2909e776b26e5f6a9f7effbac6e7447 100644 (file)
@@ -2,7 +2,7 @@
 //    $Id$
 //    Version: $Name$
 //
-//    Copyright (C) 2003, 2004, 2005 by the deal.II authors
+//    Copyright (C) 2003, 2004, 2005, 2006 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -38,40 +38,11 @@ MGTransferPrebuilt<VECTOR>::copy_to_mg (
   MGLevelObject<VECTOR> &dst,
   const InVector                 &src) const
 {
-                                  // forward to the correct
-                                  // specialization
-  copy_to_mg (mg_dof_handler, dst, src, is_1d<(dim==1)>());
-}
-
-
-template <class VECTOR>
-template <int dim, class InVector>
-void
-MGTransferPrebuilt<VECTOR>::copy_to_mg (
-  const MGDoFHandler<dim>        &,
-  MGLevelObject<VECTOR> &,
-  const InVector                 &,
-  const is_1d<true>              &) const
-{
-  Assert(false, ExcNotImplemented());
-}
-
-
-template <class VECTOR>
-template <int dim, class InVector>
-void
-MGTransferPrebuilt<VECTOR>::copy_to_mg (
-  const MGDoFHandler<dim>& mg_dof_handler,
-  MGLevelObject<VECTOR>& dst,
-  const InVector&          src,
-  const is_1d<false>&) const
-{
-                                  // Make src a real finite element function
-//  InVector src = osrc;
-//  constraints->distribute(src);
-  const unsigned int dofs_per_cell = mg_dof_handler.get_fe().dofs_per_cell;
-  const unsigned int dofs_per_face = mg_dof_handler.get_fe().dofs_per_face;
-
+  const FiniteElement<dim>& fe = mg_dof_handler.get_fe();
+  Assert (fe.dofs_per_face == 0, ExcDimensionMismatch(fe.dofs_per_face, 0));
+  
+  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();
@@ -86,8 +57,7 @@ MGTransferPrebuilt<VECTOR>::copy_to_mg (
   
   std::vector<unsigned int> global_dof_indices (dofs_per_cell);
   std::vector<unsigned int> level_dof_indices  (dofs_per_cell);
-  std::vector<unsigned int> level_face_indices (dofs_per_face);
-
+  
                                   // traverse the grid top-down
                                   // (i.e. starting with the most
                                   // refined grid). this way, we can
@@ -105,10 +75,6 @@ MGTransferPrebuilt<VECTOR>::copy_to_mg (
       const typename MGDoFHandler<dim>::active_cell_iterator
        level_end  = mg_dof_handler.end_active(level);
 
-//TODO:[?] Treat hanging nodes properly
-// The single-level vector is not an FE-function, because the values at
-// hanging nodes are set to zero. This should be treated before the restriction.
-
                                       // Compute coarse level right hand side
                                       // by restricting from fine level.
       for (; level_cell!=level_end; ++level_cell)
@@ -125,24 +91,7 @@ MGTransferPrebuilt<VECTOR>::copy_to_mg (
                                           // into the level-wise one
          for (unsigned int i=0; i<dofs_per_cell; ++i)
            dst[level](level_dof_indices[i]) = src(global_dof_indices[i]);
-
-         for (unsigned int face_n=0; face_n<GeometryInfo<dim>::faces_per_cell; ++face_n)
-           {
-             const typename MGDoFHandler<dim>::face_iterator
-               face = level_cell->face(face_n);
-             if (face->has_children())
-               {
-                 face->get_mg_dof_indices(level_face_indices);
-
-
-                                                  // Delete values on refinement edge,
-                                                  // since restriction will add them again.
-                 for (unsigned int i=0; i<dofs_per_face; ++i)
-                   dst[level](level_face_indices[i])
-                     = 0.;
-               };
-           };
-       };
+       }
                                       // for that part of the level
                                       // which is further refined:
                                       // get the defect by
@@ -152,7 +101,7 @@ MGTransferPrebuilt<VECTOR>::copy_to_mg (
        {
          restrict_and_add (level+1, dst[level], dst[level+1]);
        }
-    };
+    }
 }
 
 
@@ -165,8 +114,10 @@ MGTransferPrebuilt<VECTOR>::copy_from_mg(
   OutVector&                     dst,
   const MGLevelObject<VECTOR>& src) const
 {
-  const unsigned int dofs_per_cell = mg_dof_handler.get_fe().dofs_per_cell;
-
+  const FiniteElement<dim>& fe = mg_dof_handler.get_fe();
+  Assert (fe.dofs_per_face == 0, ExcDimensionMismatch(fe.dofs_per_face, 0));
+  
+  const unsigned int dofs_per_cell = fe.dofs_per_cell;
   std::vector<unsigned int> global_dof_indices (dofs_per_cell);
   std::vector<unsigned int> level_dof_indices (dofs_per_cell);
 
@@ -212,8 +163,10 @@ MGTransferPrebuilt<VECTOR>::copy_from_mg_add (
   OutVector                            &dst,
   const MGLevelObject<VECTOR> &src) const
 {
-  const unsigned int dofs_per_cell = mg_dof_handler.get_fe().dofs_per_cell;
-
+  const FiniteElement<dim>& fe = mg_dof_handler.get_fe();
+  Assert (fe.dofs_per_face == 0, ExcDimensionMismatch(fe.dofs_per_face, 0));
+  
+  const unsigned int dofs_per_cell = fe.dofs_per_cell;
   std::vector<unsigned int> global_dof_indices (dofs_per_cell);
   std::vector<unsigned int> level_dof_indices (dofs_per_cell);
 
@@ -283,11 +236,7 @@ MGTransferSelect<number>::copy_to_mg (
   MGLevelObject<Vector<number> > &dst,
   const BlockVector<number2>     &src) const
 {
-                                  // forward to the correct
-                                  // specialization
-  do_copy_to_mg (mg_dof_handler, dst, src,
-                0, //component_start[selected_component],
-                is_1d<(dim==1)>());
+  do_copy_to_mg (mg_dof_handler, dst, src, 0);
 }
 
 
@@ -300,26 +249,7 @@ MGTransferSelect<number>::copy_to_mg (
   MGLevelObject<Vector<number> > &dst,
   const Vector<number2>          &src) const
 {
-                                  // forward to the correct
-                                  // specialization
-  do_copy_to_mg (mg_dof_handler, dst, src,
-                component_start[selected_component],
-                is_1d<(dim==1)>());
-}
-
-
-
-template <typename number>
-template <int dim, class InVector>
-void
-MGTransferSelect<number>::do_copy_to_mg (
-  const MGDoFHandler<dim>&,
-  MGLevelObject<Vector<number> >&,
-  const InVector&,
-  const unsigned int,
-  const is_1d<true>&) const
-{
-  Assert(false, ExcNotImplemented());
+  do_copy_to_mg (mg_dof_handler, dst, src, component_start[selected_component]);
 }
 
 
@@ -331,17 +261,13 @@ MGTransferSelect<number>::do_copy_to_mg (
   const MGDoFHandler<dim>&        mg_dof_handler,
   MGLevelObject<Vector<number> >& dst,
   const InVector&                 src,
-  const unsigned int              offset,
-  const is_1d<false>&) const
+  const unsigned int              offset) const
 {
-                                  // Make src a real finite element function
-//  InVector src = osrc;
-//  constraints->distribute(src);
-
   const FiniteElement<dim>& fe = mg_dof_handler.get_fe();
+  Assert (fe.dofs_per_face == 0, ExcDimensionMismatch(fe.dofs_per_face, 0));
+  
   const unsigned int dofs_per_cell = fe.dofs_per_cell;
-  const unsigned int dofs_per_face = fe.dofs_per_face;
-
+  
                                   // set the elements of the vectors
                                   // on all levels to zero
   unsigned int minlevel = dst.get_minlevel();
@@ -357,8 +283,7 @@ MGTransferSelect<number>::do_copy_to_mg (
   
   std::vector<unsigned int> global_dof_indices (dofs_per_cell);
   std::vector<unsigned int> level_dof_indices  (dofs_per_cell);
-  std::vector<unsigned int> level_face_indices (dofs_per_face);
-
+  
                                   // Build a vector of the selected
                                   // indices, since traversing all
                                   // indices on each cell is too
@@ -498,10 +423,10 @@ MGTransferSelect<number>::do_copy_from_mg (
   const MGLevelObject<Vector<number> > &src,
   const unsigned int offset) const
 {
-
   const FiniteElement<dim>& fe = mg_dof_handler.get_fe();
+  Assert (fe.dofs_per_face == 0, ExcDimensionMismatch(fe.dofs_per_face, 0));
+  
   const unsigned int dofs_per_cell = fe.dofs_per_cell;
-
   std::vector<unsigned int> global_dof_indices (dofs_per_cell);
   std::vector<unsigned int> level_dof_indices (dofs_per_cell);
 
@@ -558,8 +483,8 @@ MGTransferSelect<number>::do_copy_from_mg_add (
   const MGLevelObject<Vector<number> > &src,
   const unsigned int offset) const
 {
-
   const FiniteElement<dim>& fe = mg_dof_handler.get_fe();
+  Assert (fe.dofs_per_face == 0, ExcDimensionMismatch(fe.dofs_per_face, 0));
   const unsigned int dofs_per_cell = fe.dofs_per_cell;
 
   std::vector<unsigned int> global_dof_indices (dofs_per_cell);
@@ -629,44 +554,10 @@ MGTransferBlock<number>::copy_to_mg (
   MGLevelObject<BlockVector<number> > &dst,
   const InVector                      &src) const
 {
-                                  // forward to the correct
-                                  // specialization
-  copy_to_mg (mg_dof_handler, dst, src, is_1d<(dim==1)>());
-}
-
-
-
-template <typename number>
-template <int dim, class InVector>
-void
-MGTransferBlock<number>::copy_to_mg (
-  const MGDoFHandler<dim>             &,
-  MGLevelObject<BlockVector<number> > &,
-  const InVector                      &,
-  const is_1d<true>                   &) const
-{
-  Assert(false, ExcNotImplemented());
-}
-
-
-
-template <typename number>
-template <int dim, class InVector>
-void
-MGTransferBlock<number>::copy_to_mg (
-  const MGDoFHandler<dim>             &mg_dof_handler,
-  MGLevelObject<BlockVector<number> > &dst,
-  const InVector                      &src,
-  const is_1d<false>                  &) const
-{
-                                  // Make src a real finite element
-                                  // function
-//  InVector src = osrc;
-//  constraints->distribute(src);
-
   const FiniteElement<dim>& fe = mg_dof_handler.get_fe();
+  Assert (fe.dofs_per_face == 0, ExcDimensionMismatch(fe.dofs_per_face, 0));
+  
   const unsigned int dofs_per_cell = fe.dofs_per_cell;
-  const unsigned int dofs_per_face = fe.dofs_per_face;
 
                                   // set the elements of the vectors
                                   // on all levels to zero
@@ -679,8 +570,7 @@ MGTransferBlock<number>::copy_to_mg (
   
   std::vector<unsigned int> global_dof_indices (dofs_per_cell);
   std::vector<unsigned int> level_dof_indices  (dofs_per_cell);
-  std::vector<unsigned int> level_face_indices (dofs_per_face);
-
+  
                                   // traverse the grid top-down
                                   // (i.e. starting with the most
                                   // refined grid). this way, we can
@@ -718,7 +608,6 @@ MGTransferBlock<number>::copy_to_mg (
              dst[level](level_dof_indices[i])
                = src(global_dof_indices[i]);
            }
-//TODO: Special treatment of faces? Copy from MGTransferPrebuilt when done there.
        }
                                       // for that part of the level
                                       // which is further refined:
@@ -743,10 +632,10 @@ MGTransferBlock<number>::copy_from_mg (
   OutVector                                 &dst,
   const MGLevelObject<BlockVector<number> > &src) const
 {
-
   const FiniteElement<dim>& fe = mg_dof_handler.get_fe();
+  Assert (fe.dofs_per_face == 0, ExcDimensionMismatch(fe.dofs_per_face, 0));
+  
   const unsigned int dofs_per_cell = fe.dofs_per_cell;
-
   std::vector<unsigned int> global_dof_indices (dofs_per_cell);
   std::vector<unsigned int> level_dof_indices (dofs_per_cell);
 
@@ -790,8 +679,9 @@ MGTransferBlock<number>::copy_from_mg_add (
   const MGLevelObject<BlockVector<number> > &src) const
 {
   const FiniteElement<dim>& fe = mg_dof_handler.get_fe();
+  Assert (fe.dofs_per_face == 0, ExcDimensionMismatch(fe.dofs_per_face, 0));
+  
   const unsigned int dofs_per_cell = fe.dofs_per_cell;
-
   std::vector<unsigned int> global_dof_indices (dofs_per_cell);
   std::vector<unsigned int> level_dof_indices (dofs_per_cell);
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.