]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Test commitment to pass changes to Guido.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 8 Apr 1999 15:48:39 +0000 (15:48 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 8 Apr 1999 15:48:39 +0000 (15:48 +0000)
git-svn-id: https://svn.dealii.org/trunk@1101 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/multigrid/multigrid.h
deal.II/deal.II/include/numerics/multigrid.h
deal.II/deal.II/source/multigrid/multigrid.cc
deal.II/deal.II/source/numerics/multigrid.cc

index 4c00b24dc26e86c35b1513ca80b627c071a3e231..f9c6b52f2cf09d40f7e6225eb2d73944d1e8371a 100644 (file)
@@ -4,14 +4,17 @@
 #define __multigrid_H
 /*----------------------------   multigrid.h     ---------------------------*/
 
-#include <vector>
-#include <base/smartpointer.h>
+#include <base/subscriptor.h>
 #include <lac/forward-declarations.h>
+#include <basic/forward-declarations.h>
+#include <lac/sparsematrix.h>
 #include <lac/vector.h>
 
+#include <vector>
 class MGTransferBase;
 
 
+
 /**
  * Basic matrix class for multigrid preconditioning.
  *
@@ -183,22 +186,135 @@ class MultiGridBase
 };
 
 
-class MGTransferBase
-  :
-  public Subscriptor
+
+/**
+ * Base class used to declare the operations needed by a concrete class
+ * implementing prolongation and restriction of vectors in the multigrid
+ * context. This class is an abstract one and has no implementations of
+ * possible algorithms for these operations.
+ *
+ * @author Wolfgang Bangerth, Guido Kanschat, 1999
+ */
+class MGTransferBase  :  public Subscriptor
 {
   public:
+                                    /**
+                                     * Destructor. Does nothing here, but
+                                     * needs to be declared virtual anyway.
+                                     */
     virtual ~MGTransferBase();
 
-    virtual void prolongate(unsigned l,
-                           Vector<float>& dst,
-                           const Vector<float>& src) const = 0;
-    virtual void restrict(unsigned l,
-                         Vector<float>& dst,
-                         const Vector<float>& src) const = 0;
+                                    /**
+                                     * Prolongate a vector from level
+                                     * #to_level-1# to level #to_level#.
+                                     *
+                                     * #src# is assumed to be a vector with
+                                     * as many elements as there are degrees
+                                     * of freedom on the coarser level of
+                                     * the two involved levels, while #src#
+                                     * shall have as many elements as there
+                                     * are degrees of freedom on the finer
+                                     * level.
+                                     */
+    virtual void prolongate (const unsigned int   to_level,
+                            Vector<float>       &dst,
+                            const Vector<float> &src) const = 0;
+
+                                    /**
+                                     * Restrict a vector from level
+                                     * #from_level# to level
+                                     * #from_level-1#.
+                                     *
+                                     * #src# is assumed to be a vector with
+                                     * as many elements as there are degrees
+                                     * of freedom on the finer level of
+                                     * the two involved levels, while #src#
+                                     * shall have as many elements as there
+                                     * are degrees of freedom on the coarser
+                                     * level.
+                                     */
+    virtual void restrict (const unsigned int   from_level,
+                          Vector<float>       &dst,
+                          const Vector<float> &src) const = 0;
 };
 
 
+
+/**
+ * Implementation of the #MGTransferBase# interface for which the transfer
+ * operations are prebuilt upon construction of the object of this class as
+ * matrices. This is the fast way, since it only needs to build the operation
+ * once by looping over all cells and storing the result in a matrix for
+ * each level, but requires additional memory.
+ *
+ * @author Wolfgang Bangerth, Guido Kanschat, 1999
+ */
+class MGTransferPrebuilt : public MGTransferBase 
+{
+  public:
+
+                                    /**
+                                     * Destructor.
+                                     */
+    virtual ~MGTransferPrebuilt ();
+    
+                                    /**
+                                     * Actually build the prolongation
+                                     * matrices for each level.
+                                     */
+    template <int dim>
+    void build_matrices (const MGDoFHandler<dim> &mg_dof);
+
+                                    /**
+                                     * Prolongate a vector from level
+                                     * #to_level-1# to level #to_level#.
+                                     *
+                                     * #src# is assumed to be a vector with
+                                     * as many elements as there are degrees
+                                     * of freedom on the coarser level of
+                                     * the two involved levels, while #src#
+                                     * shall have as many elements as there
+                                     * are degrees of freedom on the finer
+                                     * level.
+                                     */
+    virtual void prolongate (const unsigned int  to_level,
+                            Vector<float>       &dst,
+                            const Vector<float> &src) const = 0;
+
+                                    /**
+                                     * Restrict a vector from level
+                                     * #from_level# to level
+                                     * #from_level-1#.
+                                     *
+                                     * #src# is assumed to be a vector with
+                                     * as many elements as there are degrees
+                                     * of freedom on the finer level of
+                                     * the two involved levels, while #src#
+                                     * shall have as many elements as there
+                                     * are degrees of freedom on the coarser
+                                     * level.
+                                     */
+    virtual void restrict (const unsigned int   from_level,
+                          Vector<float>       &dst,
+                          const Vector<float> &src) const = 0;
+
+  private:
+
+    vector<SparseMatrixStruct>   prolongation_sparsities;
+
+                                        /**
+                                         * 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.
+                                         */
+    vector<SparseMatrix<float> > prolongation_matrices;
+};
+
+
+
 /*----------------------------   multigrid.h     ---------------------------*/
 /* end of #ifndef __multigrid_H */
 #endif
index 4c00b24dc26e86c35b1513ca80b627c071a3e231..f9c6b52f2cf09d40f7e6225eb2d73944d1e8371a 100644 (file)
@@ -4,14 +4,17 @@
 #define __multigrid_H
 /*----------------------------   multigrid.h     ---------------------------*/
 
-#include <vector>
-#include <base/smartpointer.h>
+#include <base/subscriptor.h>
 #include <lac/forward-declarations.h>
+#include <basic/forward-declarations.h>
+#include <lac/sparsematrix.h>
 #include <lac/vector.h>
 
+#include <vector>
 class MGTransferBase;
 
 
+
 /**
  * Basic matrix class for multigrid preconditioning.
  *
@@ -183,22 +186,135 @@ class MultiGridBase
 };
 
 
-class MGTransferBase
-  :
-  public Subscriptor
+
+/**
+ * Base class used to declare the operations needed by a concrete class
+ * implementing prolongation and restriction of vectors in the multigrid
+ * context. This class is an abstract one and has no implementations of
+ * possible algorithms for these operations.
+ *
+ * @author Wolfgang Bangerth, Guido Kanschat, 1999
+ */
+class MGTransferBase  :  public Subscriptor
 {
   public:
+                                    /**
+                                     * Destructor. Does nothing here, but
+                                     * needs to be declared virtual anyway.
+                                     */
     virtual ~MGTransferBase();
 
-    virtual void prolongate(unsigned l,
-                           Vector<float>& dst,
-                           const Vector<float>& src) const = 0;
-    virtual void restrict(unsigned l,
-                         Vector<float>& dst,
-                         const Vector<float>& src) const = 0;
+                                    /**
+                                     * Prolongate a vector from level
+                                     * #to_level-1# to level #to_level#.
+                                     *
+                                     * #src# is assumed to be a vector with
+                                     * as many elements as there are degrees
+                                     * of freedom on the coarser level of
+                                     * the two involved levels, while #src#
+                                     * shall have as many elements as there
+                                     * are degrees of freedom on the finer
+                                     * level.
+                                     */
+    virtual void prolongate (const unsigned int   to_level,
+                            Vector<float>       &dst,
+                            const Vector<float> &src) const = 0;
+
+                                    /**
+                                     * Restrict a vector from level
+                                     * #from_level# to level
+                                     * #from_level-1#.
+                                     *
+                                     * #src# is assumed to be a vector with
+                                     * as many elements as there are degrees
+                                     * of freedom on the finer level of
+                                     * the two involved levels, while #src#
+                                     * shall have as many elements as there
+                                     * are degrees of freedom on the coarser
+                                     * level.
+                                     */
+    virtual void restrict (const unsigned int   from_level,
+                          Vector<float>       &dst,
+                          const Vector<float> &src) const = 0;
 };
 
 
+
+/**
+ * Implementation of the #MGTransferBase# interface for which the transfer
+ * operations are prebuilt upon construction of the object of this class as
+ * matrices. This is the fast way, since it only needs to build the operation
+ * once by looping over all cells and storing the result in a matrix for
+ * each level, but requires additional memory.
+ *
+ * @author Wolfgang Bangerth, Guido Kanschat, 1999
+ */
+class MGTransferPrebuilt : public MGTransferBase 
+{
+  public:
+
+                                    /**
+                                     * Destructor.
+                                     */
+    virtual ~MGTransferPrebuilt ();
+    
+                                    /**
+                                     * Actually build the prolongation
+                                     * matrices for each level.
+                                     */
+    template <int dim>
+    void build_matrices (const MGDoFHandler<dim> &mg_dof);
+
+                                    /**
+                                     * Prolongate a vector from level
+                                     * #to_level-1# to level #to_level#.
+                                     *
+                                     * #src# is assumed to be a vector with
+                                     * as many elements as there are degrees
+                                     * of freedom on the coarser level of
+                                     * the two involved levels, while #src#
+                                     * shall have as many elements as there
+                                     * are degrees of freedom on the finer
+                                     * level.
+                                     */
+    virtual void prolongate (const unsigned int  to_level,
+                            Vector<float>       &dst,
+                            const Vector<float> &src) const = 0;
+
+                                    /**
+                                     * Restrict a vector from level
+                                     * #from_level# to level
+                                     * #from_level-1#.
+                                     *
+                                     * #src# is assumed to be a vector with
+                                     * as many elements as there are degrees
+                                     * of freedom on the finer level of
+                                     * the two involved levels, while #src#
+                                     * shall have as many elements as there
+                                     * are degrees of freedom on the coarser
+                                     * level.
+                                     */
+    virtual void restrict (const unsigned int   from_level,
+                          Vector<float>       &dst,
+                          const Vector<float> &src) const = 0;
+
+  private:
+
+    vector<SparseMatrixStruct>   prolongation_sparsities;
+
+                                        /**
+                                         * 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.
+                                         */
+    vector<SparseMatrix<float> > prolongation_matrices;
+};
+
+
+
 /*----------------------------   multigrid.h     ---------------------------*/
 /* end of #ifndef __multigrid_H */
 #endif
index c0fa498bf354b276db548886fe1cc2824dd0b0cd..5d2a69805fbbefd147562bf453d5adcef2ae1a3a 100644 (file)
@@ -1,9 +1,15 @@
 // $Id$
 // Copyright Guido Kanschat, Universitaet Heidelberg, 1999
 
+#include <grid/tria.h>
+#include <grid/mg_dof.h>
+#include <grid/mg_dof_accessor.h>
+#include <grid/tria_iterator.h>
+#include <fe/fe.h>
 #include <numerics/multigrid.h>
 #include <lac/vector.h>
 
+
 MultiGridBase::MultiGridBase(MGTransferBase& transfer,
                             unsigned maxlevel, unsigned minlevel,
                             unsigned pre_smooth, unsigned post_smooth)
@@ -13,6 +19,7 @@ MultiGridBase::MultiGridBase(MGTransferBase& transfer,
                n_pre_smooth(pre_smooth), n_post_smooth(post_smooth)
 {}
 
+
 void
 MultiGridBase::level_mgstep(unsigned level)
 {
@@ -48,6 +55,8 @@ MultiGridBase::post_smooth(unsigned level,
   smooth(level, dst, src, steps);
 }
 
+
+
 void
 MultiGridBase::coarse_grid_solution(unsigned level,
                          Vector<float>& dst,
@@ -56,5 +65,133 @@ MultiGridBase::coarse_grid_solution(unsigned level,
   smooth(level, dst, src, 10 * (n_pre_smooth + n_post_smooth));
 }
 
+
+
+
 // ab hier Wolfgang
 
+
+
+/* ------------------------------ MGTransferBase --------------------------- */
+
+MGTransferBase::~MGTransferBase () 
+{};
+
+
+
+/* ----------------------------- MGTransferPrebuilt ------------------------ */
+
+
+<<<<<<< multigrid.cc
+/*
+MGTransferPrebuilt::~MGTransferPrebuilt () 
+{};
+
+
+
+template <int dim>
+void MGTransferPrebuilt::build_matrices (const MGDoFHandler<dim> &mg_dof) 
+{
+  const unsigned int n_levels      = mg_dof.get_tria().n_levels();
+  const unsigned int dofs_per_cell = mg_dof.get_fe().total_dofs;
+  
+                                  // reset the size of the array of
+                                  // matrices
+  prolongation_sparsities.clear ();
+  prolongation_matrices.clear ();
+  prolongation_sparsities.reserve (n_levels-1);
+  prolongation_matrices.reserve (n_levels-1);
+  
+
+                                  // two fields which will store the
+                                  // indices of the multigrid dofs
+                                  // for a cell and one of its children
+  vector<int> dof_indices_mother (dofs_per_cell);
+  vector<int> 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; level<n_levels-1; ++level)
+    {
+      prolongation_sparsities.push_back (SparseMatrixStruct());
+      
+      for (typename MGDoFHandler<dim>::cell_iterator cell=mg_dof.begin(level);
+          cell != mg_dof.end(level); ++cell)
+       if (cell->has_children())
+         {
+           cell->get_mg_dof_indices (dof_indices_mother);
+
+           for (unsigned int child=0;
+                child<GeometryInfo<dim>::children_per_cell; ++child)
+             {
+                                                // set an alias to the
+                                                // prolongation matrix for
+                                                // this child
+               const FullMatrix<double> &prolongation
+                 = mg_dof.get_fe().prolongate(child);
+           
+               cell->child(child)->get_dof_indices (dof_indices_child);
+
+                                                // now tag the entries in the
+                                                // matrix which will be used
+                                                // for this pair of mother/child
+               for (unsigned int i=0; i<dofs_per_cell; ++i)
+                 for (unsigned int j=0; j<dofs_per_cell; ++j)
+                   if (prolongation(i,j) != 0)
+                     {
+                       prolongation_sparsities[level].add
+                         (dof_indices_child[i],
+                          dof_indices_mother[j]);
+                     };
+             };
+         };
+
+      prolongation_matrices[level].matrix.reinit (prolongation_matrices[level].sparsity);
+
+
+                                      // now actually build the matrices
+      for (MGDoFHandler<dim>::cell_iterator cell=mg_dof.begin(level);
+          cell != mg_dof.end(level); ++cell)
+       if (cell->has_children())
+         {
+           cell->get_mg_dof_indices (dof_indices_mother);
+
+           for (unsigned int child=0;
+                child<GeometryInfo<dim>::children_per_cell; ++child)
+             {
+                                                // set an alias to the
+                                                // prolongation matrix for
+                                                // this child
+               const FullMatrix<double> &prolongation
+                 = mg_dof.get_fe().prolongate(child);
+           
+               cell->child(child)->get_dof_indices (dof_indices_child);
+
+                                                // now set the entries in the
+                                                // matrix
+               for (unsigned int i=0; i<dofs_per_cell; ++i)
+                 for (unsigned int j=0; j<dofs_per_cell; ++j)
+                   if (prolongation(i,j) != 0)
+                     {
+                       prolongation_matrices[level]
+                         (dof_indices_child[i],
+                          dof_indices_mother[j],
+                          prolongation(i,j));
+                     };
+             };
+         };
+    };
+};
+
+
+
+
+
+// explicit instatations
+template
+void MGTransferPrebuilt::build_matrices (const MGDoFHandler<deal_II_dimension> &mg_dof);
+
+*/
index c0fa498bf354b276db548886fe1cc2824dd0b0cd..5d2a69805fbbefd147562bf453d5adcef2ae1a3a 100644 (file)
@@ -1,9 +1,15 @@
 // $Id$
 // Copyright Guido Kanschat, Universitaet Heidelberg, 1999
 
+#include <grid/tria.h>
+#include <grid/mg_dof.h>
+#include <grid/mg_dof_accessor.h>
+#include <grid/tria_iterator.h>
+#include <fe/fe.h>
 #include <numerics/multigrid.h>
 #include <lac/vector.h>
 
+
 MultiGridBase::MultiGridBase(MGTransferBase& transfer,
                             unsigned maxlevel, unsigned minlevel,
                             unsigned pre_smooth, unsigned post_smooth)
@@ -13,6 +19,7 @@ MultiGridBase::MultiGridBase(MGTransferBase& transfer,
                n_pre_smooth(pre_smooth), n_post_smooth(post_smooth)
 {}
 
+
 void
 MultiGridBase::level_mgstep(unsigned level)
 {
@@ -48,6 +55,8 @@ MultiGridBase::post_smooth(unsigned level,
   smooth(level, dst, src, steps);
 }
 
+
+
 void
 MultiGridBase::coarse_grid_solution(unsigned level,
                          Vector<float>& dst,
@@ -56,5 +65,133 @@ MultiGridBase::coarse_grid_solution(unsigned level,
   smooth(level, dst, src, 10 * (n_pre_smooth + n_post_smooth));
 }
 
+
+
+
 // ab hier Wolfgang
 
+
+
+/* ------------------------------ MGTransferBase --------------------------- */
+
+MGTransferBase::~MGTransferBase () 
+{};
+
+
+
+/* ----------------------------- MGTransferPrebuilt ------------------------ */
+
+
+<<<<<<< multigrid.cc
+/*
+MGTransferPrebuilt::~MGTransferPrebuilt () 
+{};
+
+
+
+template <int dim>
+void MGTransferPrebuilt::build_matrices (const MGDoFHandler<dim> &mg_dof) 
+{
+  const unsigned int n_levels      = mg_dof.get_tria().n_levels();
+  const unsigned int dofs_per_cell = mg_dof.get_fe().total_dofs;
+  
+                                  // reset the size of the array of
+                                  // matrices
+  prolongation_sparsities.clear ();
+  prolongation_matrices.clear ();
+  prolongation_sparsities.reserve (n_levels-1);
+  prolongation_matrices.reserve (n_levels-1);
+  
+
+                                  // two fields which will store the
+                                  // indices of the multigrid dofs
+                                  // for a cell and one of its children
+  vector<int> dof_indices_mother (dofs_per_cell);
+  vector<int> 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; level<n_levels-1; ++level)
+    {
+      prolongation_sparsities.push_back (SparseMatrixStruct());
+      
+      for (typename MGDoFHandler<dim>::cell_iterator cell=mg_dof.begin(level);
+          cell != mg_dof.end(level); ++cell)
+       if (cell->has_children())
+         {
+           cell->get_mg_dof_indices (dof_indices_mother);
+
+           for (unsigned int child=0;
+                child<GeometryInfo<dim>::children_per_cell; ++child)
+             {
+                                                // set an alias to the
+                                                // prolongation matrix for
+                                                // this child
+               const FullMatrix<double> &prolongation
+                 = mg_dof.get_fe().prolongate(child);
+           
+               cell->child(child)->get_dof_indices (dof_indices_child);
+
+                                                // now tag the entries in the
+                                                // matrix which will be used
+                                                // for this pair of mother/child
+               for (unsigned int i=0; i<dofs_per_cell; ++i)
+                 for (unsigned int j=0; j<dofs_per_cell; ++j)
+                   if (prolongation(i,j) != 0)
+                     {
+                       prolongation_sparsities[level].add
+                         (dof_indices_child[i],
+                          dof_indices_mother[j]);
+                     };
+             };
+         };
+
+      prolongation_matrices[level].matrix.reinit (prolongation_matrices[level].sparsity);
+
+
+                                      // now actually build the matrices
+      for (MGDoFHandler<dim>::cell_iterator cell=mg_dof.begin(level);
+          cell != mg_dof.end(level); ++cell)
+       if (cell->has_children())
+         {
+           cell->get_mg_dof_indices (dof_indices_mother);
+
+           for (unsigned int child=0;
+                child<GeometryInfo<dim>::children_per_cell; ++child)
+             {
+                                                // set an alias to the
+                                                // prolongation matrix for
+                                                // this child
+               const FullMatrix<double> &prolongation
+                 = mg_dof.get_fe().prolongate(child);
+           
+               cell->child(child)->get_dof_indices (dof_indices_child);
+
+                                                // now set the entries in the
+                                                // matrix
+               for (unsigned int i=0; i<dofs_per_cell; ++i)
+                 for (unsigned int j=0; j<dofs_per_cell; ++j)
+                   if (prolongation(i,j) != 0)
+                     {
+                       prolongation_matrices[level]
+                         (dof_indices_child[i],
+                          dof_indices_mother[j],
+                          prolongation(i,j));
+                     };
+             };
+         };
+    };
+};
+
+
+
+
+
+// explicit instatations
+template
+void MGTransferPrebuilt::build_matrices (const MGDoFHandler<deal_II_dimension> &mg_dof);
+
+*/

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.