]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
preparation for local multigrid
authorguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 22 Aug 2002 15:14:55 +0000 (15:14 +0000)
committerguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 22 Aug 2002 15:14:55 +0000 (15:14 +0000)
git-svn-id: https://svn.dealii.org/trunk@6338 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/multigrid/mg_base.h
deal.II/deal.II/include/multigrid/mg_dof_tools.h
deal.II/deal.II/include/multigrid/mg_tools.templates.h
deal.II/deal.II/include/multigrid/multigrid.h
deal.II/deal.II/include/multigrid/multigrid.templates.h
deal.II/deal.II/source/multigrid/mg_dof_tools.cc
deal.II/deal.II/source/multigrid/multigrid.all_dimensions.cc

index c858ae747e17527dc17e9a6835c21510bf9922cf..968e55b58548b04c1c1c32feb8d42bb66c1f4b2b 100644 (file)
@@ -130,6 +130,29 @@ class MGMatrixBase : public Subscriptor
                                    */
   virtual void vmult(unsigned int level, VECTOR& dst,
                     const VECTOR& src) const = 0;
+
+                                  /**
+                                   * Adding matrix-vector-multiplication on
+                                   * a certain level.
+                                   */
+  virtual void vmult_add(unsigned int level, VECTOR& dst,
+                    const VECTOR& src) const = 0;
+
+                                  /**
+                                   * Transpose
+                                   * matrix-vector-multiplication on
+                                   * a certain level.
+                                   */
+  virtual void Tvmult(unsigned int level, VECTOR& dst,
+                    const VECTOR& src) const = 0;
+
+                                  /**
+                                   * Adding transpose
+                                   * matrix-vector-multiplication on
+                                   * a certain level.
+                                   */
+  virtual void Tvmult_add(unsigned int level, VECTOR& dst,
+                    const VECTOR& src) const = 0;
 };
 
 
@@ -159,6 +182,28 @@ class MGMatrix : public MGMatrixBase<VECTOR>,
     virtual void vmult(unsigned int level, VECTOR& dst,
                       const VECTOR& src) const;
     
+                                  /**
+                                   * Adding matrix-vector-multiplication on
+                                   * a certain level.
+                                   */
+  virtual void vmult_add(unsigned int level, VECTOR& dst,
+                    const VECTOR& src) const;
+
+                                  /**
+                                   * Transpose
+                                   * matrix-vector-multiplication on
+                                   * a certain level.
+                                   */
+  virtual void Tvmult(unsigned int level, VECTOR& dst,
+                    const VECTOR& src) const;
+
+                                  /**
+                                   * Adding transpose
+                                   * matrix-vector-multiplication on
+                                   * a certain level.
+                                   */
+  virtual void Tvmult_add(unsigned int level, VECTOR& dst,
+                    const VECTOR& src) const;    
 };
 
 
@@ -373,6 +418,39 @@ MGMatrix<MATRIX, VECTOR>::vmult (unsigned int level,
 }
 
 
+template <class MATRIX, class VECTOR>
+void
+MGMatrix<MATRIX, VECTOR>::vmult_add (unsigned int level,
+                                VECTOR& dst,
+                                const VECTOR& src) const
+{
+  const MGLevelObject<MATRIX>& m = **this;
+  m[level].vmult_add(dst, src);
+}
+
+
+template <class MATRIX, class VECTOR>
+void
+MGMatrix<MATRIX, VECTOR>::Tvmult (unsigned int level,
+                                VECTOR& dst,
+                                const VECTOR& src) const
+{
+  const MGLevelObject<MATRIX>& m = **this;
+  m[level].Tvmult(dst, src);
+}
+
+
+template <class MATRIX, class VECTOR>
+void
+MGMatrix<MATRIX, VECTOR>::Tvmult_add (unsigned int level,
+                                VECTOR& dst,
+                                const VECTOR& src) const
+{
+  const MGLevelObject<MATRIX>& m = **this;
+  m[level].Tvmult_add(dst, src);
+}
+
+
 /*----------------------------   mgbase.h     ---------------------------*/
 
 #endif
index a7d2233fb494972485fa04f677f2959f07bd1966..54ea5318aa1d3a6ed9f1a9ec2b1929e8b96a4641 100644 (file)
@@ -62,7 +62,7 @@ class MGTools
                                      * Make a sparsity pattern including fluxes
                                      * of discontinuous Galerkin methods.
                                      * @ref make_sparsity_pattern
-                                     * $see DoFTools
+                                     * @ref DoFTools
                                      */
     template <int dim, class SparsityPattern>
     static void
@@ -73,9 +73,12 @@ class MGTools
                                     /**
                                      * Create sparsity pattern for
                                      * the fluxes at refinement
-                                     * edges. 
+                                     * edges. The matrix maps a
+                                     * function of the fine level
+                                     * space @p{level} to the coarser
+                                     * space.
+                                     *
                                      * @ref{make_flux_sparsity_pattern}
-                                     * @ref{DoFTools}
                                      */
     template <int dim, class SparsityPattern>
     static void
index efeb9e2f15b2801a08c02daecdfb2282e50d2bd0..abc271eb36e84daca6c977c04da23805cdda47c2 100644 (file)
@@ -16,7 +16,7 @@
 
 #include <dofs/dof_constraints.h>
 #include <numerics/data_out.h>
-#include <multigrid/multigrid.h>
+#include <multigrid/mg_base.h>
 #include <algorithm>
 #include <fstream>
 
index 7a787fbc9dc316ad57b3fcaef0bdb96d8173171f..ad3afd36436e5d79cac6103c7922466a1a105dcc 100644 (file)
@@ -195,7 +195,15 @@ class Multigrid : public Subscriptor
                                      */
     SmartPointer<const MGSmoother<VECTOR> > post_smooth;
     
-    
+                                    /**
+                                     * Edge matrix from fine to coarse.
+                                     */
+    SmartPointer<const MGMatrixBase<VECTOR> > edge_down;
+
+                                    /**
+                                     * Transpose edge matrix from coarse to fine.
+                                     */
+    SmartPointer<const MGMatrixBase<VECTOR> > edge_up;
 
                                     /**
                                      * Exception.
@@ -290,142 +298,9 @@ class PreconditionMG : public Subscriptor
 };
 
 
-
-
 /* --------------------------- inline functions --------------------- */
 
 
-template <class VECTOR>
-template <int dim>
-Multigrid<VECTOR>::Multigrid (const MGDoFHandler<dim>& mg_dof_handler,
-                             const MGMatrixBase<VECTOR>& matrix,
-                             const MGCoarseGrid<VECTOR>& coarse,
-                             const MGTransfer<VECTOR>& transfer,
-                             const MGSmoother<VECTOR>& pre_smooth,
-                             const MGSmoother<VECTOR>& post_smooth,
-                             const unsigned int min_level,
-                             const unsigned int max_level)
-               :
-               minlevel(min_level),
-               maxlevel(std::min(mg_dof_handler.get_tria().n_levels()-1,
-                                 max_level)),
-               defect(minlevel,maxlevel),
-               solution(minlevel,maxlevel),
-               t(minlevel,maxlevel),
-               matrix(&matrix),
-               coarse(&coarse),
-               transfer(&transfer),
-               pre_smooth(&pre_smooth),
-               post_smooth(&post_smooth)
-{
-};
-
-
-template <class VECTOR>
-void
-Multigrid<VECTOR>::level_mgstep(const unsigned int level)
-{
-#ifdef MG_DEBUG
-  char *name = new char[100];
-  sprintf(name, "MG%d-defect",level);
-  print_vector(level, defect[level], name);
-#endif
-
-  solution[level] = 0.;
-  
-  if (level == minlevel)
-    {
-      (*coarse)(level, solution[level], defect[level]);
-#ifdef MG_DEBUG
-      sprintf(name, "MG%d-solution",level);
-      print_vector(level, solution[level], name);
-#endif
-      return;
-    }
-
-                          // smoothing of the residual by modifying s
-  pre_smooth->smooth(level, solution[level], defect[level]);
-
-#ifdef MG_DEBUG
-  sprintf(name, "MG%d-pre",level);
-  print_vector(level, solution[level], name);
-#endif
-  
-                                  // t = -A*solution[level]
-  matrix->vmult(level, t[level], solution[level]);
-  t[level].scale(-1);
-  
-                                  // make t rhs of lower level
-                                  // The non-refined parts of the
-                                  // coarse-level defect already contain
-                                  // the global defect, the refined parts
-                                  // its restriction.
-  for (unsigned int l = level;l>minlevel;--l)
-    {
-      t[l-1] = 0.;
-      transfer->restrict_and_add (l, t[l-1], t[l]);
-      defect[l-1] += t[l-1];
-    }
-
-                                  // add additional DG contribution
-//  edge_vmult(level, defect[level-1], defect[level]);
-  
-                                  // do recursion
-  level_mgstep(level-1);
-
-                                  // reset size of the auxiliary
-                                  // vector, since it has been
-                                  // resized in the recursive call to
-                                  // level_mgstep directly above
-  t[level] = 0.;
-
-                                  // do coarse grid correction
-
-  transfer->prolongate(level, t[level], solution[level-1]);
-
-#ifdef MG_DEBUG
-  sprintf(name, "MG%d-cgc",level);
-  print_vector(level, t, name);
-#endif
-
-  solution[level] += t[level];
-  
-                                  // post-smoothing
-  post_smooth->smooth(level, solution[level], defect[level]);
-
-#ifdef MG_DEBUG
-  sprintf(name, "MG%d-post",level);
-  print_vector(level, solution[level], name);
-
-  delete[] name;
-#endif
-}
-
-
-template <class VECTOR>
-void
-Multigrid<VECTOR>::vcycle()
-{
-                                  // The defect vector has been
-                                  // initialized by copy_to_mg. Now
-                                  // adjust the other vectors.
-  solution.resize(minlevel, maxlevel);
-  t.resize(minlevel, maxlevel);
-  
-  for (unsigned int level=minlevel; level<=maxlevel;++level)
-    {
-      solution[level].reinit(defect[level]);
-      t[level].reinit(defect[level]);
-    }
-
-  level_mgstep (maxlevel);
-//  abort ();
-}
-
-
-/* ------------------------------------------------------------------- */
-
-
 template<int dim, class VECTOR, class TRANSFER>
 PreconditionMG<dim, VECTOR, TRANSFER>
 ::PreconditionMG(const MGDoFHandler<dim>&      mg_dof_handler,
index c23bf90d5d485539f51adce4c90f16332a8fe792..dbd9e42384e07b7379d8c41c648e4e7e41cb7037 100644 (file)
 #define __deal2__multigrid_templates_h
 
 
-#include <dofs/dof_constraints.h>
-//#include <numerics/data_out.h>
 #include <multigrid/multigrid.h>
-#include <algorithm>
-#include <fstream>
 
-#include <lac/sparse_matrix.h>
+/* --------------------------- inline functions --------------------- */
 
 
+template <class VECTOR>
 template <int dim>
+Multigrid<VECTOR>::Multigrid (const MGDoFHandler<dim>& mg_dof_handler,
+                             const MGMatrixBase<VECTOR>& matrix,
+                             const MGCoarseGrid<VECTOR>& coarse,
+                             const MGTransfer<VECTOR>& transfer,
+                             const MGSmoother<VECTOR>& pre_smooth,
+                             const MGSmoother<VECTOR>& post_smooth,
+                             const unsigned int min_level,
+                             const unsigned int max_level)
+               :
+               minlevel(min_level),
+               maxlevel(std::min(mg_dof_handler.get_tria().n_levels()-1,
+                                 max_level)),
+               defect(minlevel,maxlevel),
+               solution(minlevel,maxlevel),
+               t(minlevel,maxlevel),
+               matrix(&matrix),
+               coarse(&coarse),
+               transfer(&transfer),
+               pre_smooth(&pre_smooth),
+               post_smooth(&post_smooth)
+{
+};
+
+
+template <class VECTOR>
+void
+Multigrid<VECTOR>::level_mgstep(const unsigned int level)
+{
+#ifdef MG_DEBUG
+  char *name = new char[100];
+  sprintf(name, "MG%d-defect",level);
+  print_vector(level, defect[level], name);
+#endif
+
+  solution[level] = 0.;
+  
+  if (level == minlevel)
+    {
+      (*coarse)(level, solution[level], defect[level]);
+#ifdef MG_DEBUG
+      sprintf(name, "MG%d-solution",level);
+      print_vector(level, solution[level], name);
+#endif
+      return;
+    }
+
+                          // smoothing of the residual by modifying s
+  pre_smooth->smooth(level, solution[level], defect[level]);
+
+#ifdef MG_DEBUG
+  sprintf(name, "MG%d-pre",level);
+  print_vector(level, solution[level], name);
+#endif
+  
+                                  // t = -A*solution[level]
+  matrix->vmult(level, t[level], solution[level]);
+  t[level].scale(-1);
+  
+                                  // make t rhs of lower level
+                                  // The non-refined parts of the
+                                  // coarse-level defect already contain
+                                  // the global defect, the refined parts
+                                  // its restriction.
+  for (unsigned int l = level;l>minlevel;--l)
+    {
+      t[l-1] = 0.;
+      transfer->restrict_and_add (l, t[l-1], t[l]);
+      defect[l-1] += t[l-1];
+    }
+
+                                  // add additional DG contribution
+//  edge_vmult(level, defect[level-1], defect[level]);
+  
+                                  // do recursion
+  level_mgstep(level-1);
+
+                                  // reset size of the auxiliary
+                                  // vector, since it has been
+                                  // resized in the recursive call to
+                                  // level_mgstep directly above
+  t[level] = 0.;
+
+                                  // do coarse grid correction
+
+  transfer->prolongate(level, t[level], solution[level-1]);
+
+#ifdef MG_DEBUG
+  sprintf(name, "MG%d-cgc",level);
+  print_vector(level, t, name);
+#endif
+
+  solution[level] += t[level];
+  
+                                  // post-smoothing
+  post_smooth->smooth(level, solution[level], defect[level]);
+
+#ifdef MG_DEBUG
+  sprintf(name, "MG%d-post",level);
+  print_vector(level, solution[level], name);
+
+  delete[] name;
+#endif
+}
+
+
+template <class VECTOR>
 void
-Multigrid<dim>::print_vector (const unsigned int /*level*/,
-                             const Vector<double>& /*v*/,
-                             const char* /*name*/) const
+Multigrid<VECTOR>::vcycle()
 {
+                                  // The defect vector has been
+                                  // initialized by copy_to_mg. Now
+                                  // adjust the other vectors.
+  solution.resize(minlevel, maxlevel);
+  t.resize(minlevel, maxlevel);
+  
+  for (unsigned int level=minlevel; level<=maxlevel;++level)
+    {
+      solution[level].reinit(defect[level]);
+      t[level].reinit(defect[level]);
+    }
+
+  level_mgstep (maxlevel);
+//  abort ();
+}
+
+
+
+// template <int dim>
+// void
+// Multigrid<dim>::print_vector (const unsigned int /*level*/,
+//                           const Vector<double>& /*v*/,
+//                           const char* /*name*/) const
+// {
 //    if (level!=maxlevel)
 //      return;
   
@@ -71,6 +196,6 @@ Multigrid<dim>::print_vector (const unsigned int /*level*/,
 //    out.add_data_vector(out_vector, "v");
 //    out.build_patches(5);
 //    out.write_gnuplot(out_file);
-}
+//}
 
 #endif
index c3bc1ba9da89d8d0cce3881caea5c86c3d32c874..80843d7cbaa7cf846af0808cc58be59c44b8d187 100644 (file)
@@ -121,8 +121,8 @@ MGTools::make_flux_sparsity_pattern (const MGDoFHandler<dim> &dof,
 template<int dim, class SparsityPattern>
 void
 MGTools::make_flux_sparsity_pattern_edge (const MGDoFHandler<dim> &dof,
-                                            SparsityPattern       &sparsity,
-                                            const unsigned int level)
+                                         SparsityPattern       &sparsity,
+                                         const unsigned int level)
 {
   Assert ((level>=1) && (level<dof.get_tria().n_levels()),
          ExcIndexRange(level, 1, dof.get_tria().n_levels()));
index 84108e0ae5f326683c611376e350781e2653aed1..a20703198d4d8f187d5b1ed0ca1de0127d128597 100644 (file)
@@ -17,6 +17,7 @@
 #include <lac/sparse_matrix.h>
 #include <lac/block_sparse_matrix.h>
 #include <multigrid/mg_transfer.h>
+#include <multigrid/multigrid.templates.h>
 
 
 template <typename number>
@@ -135,6 +136,11 @@ void MGTransferSelect<number>::restrict_and_add (
 
 // Explicit instantiations
 
+template class Multigrid<Vector<float> >;
+template class Multigrid<Vector<double> >;
+template class Multigrid<BlockVector<float> >;
+template class Multigrid<BlockVector<double> >;
+
 template class MGTransferPrebuilt<float>;
 template class MGTransferPrebuilt<double>;
 template class MGTransferBlock<float>;

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.