]> https://gitweb.dealii.org/ - dealii.git/commitdiff
One more reinit for dSMatrix
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 9 Mar 1998 18:32:33 +0000 (18:32 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 9 Mar 1998 18:32:33 +0000 (18:32 +0000)
git-svn-id: https://svn.dealii.org/trunk@51 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/dsmatrix.h
deal.II/lac/source/dsmatrix.cc

index 4588e46af190dca92b04ad642391d0949c4dfb1e..60db825da9fe023d06d4978d3424088a5033c100 100644 (file)
@@ -110,54 +110,61 @@ CLASS
    */
 class dSMatrix
 {
-  dSMatrixStruct& cols;
-  double* val;
-  int max_len;
- public:
-  //////////
-  void reinit();
-  //////////
-  dSMatrix(dSMatrixStruct& c)
-    : cols(c), val(0), max_len(0)
-    {
-      reinit();
-    }
-  //////////
-  ~dSMatrix()
-    {
-      delete[] val;
-    }
+    dSMatrixStruct * cols;
+    double* val;
+    int max_len;
+  public:
+                                    //
+    void reinit();
+                                    //
+    void reinit (dSMatrixStruct &);
+                                    //
+    dSMatrix(dSMatrixStruct& c)
+                   : cols(&c), val(0), max_len(0)
+      {
+       reinit();
+      }
+                                    //
+    ~dSMatrix()
+      {
+       delete[] val;
+      }
 
-  //////////
-  int m() const { return cols.rows; }
-  //////////
-  int n() const { return cols.cols; }
+                                    //
+    int m() const { return cols->rows; }
+                                    //
+    int n() const { return cols->cols; }
 
-  //////////
-  void set(int i,int j,double value) { val[cols(i,j)] = value; }
-  //////////
-  void add(int i,int j,double value) { val[cols(i,j)]+= value; }
+                                    //
+    void set(int i,int j,double value) { val[cols->operator()(i,j)] = value; }
+                                    //
+    void add(int i,int j,double value) { val[cols->operator()(i,j)]+= value; }
   
-  //////////
-  void vmult (dVector& dst,const dVector& src);
-  //////////
-  void Tvmult(dVector& dst,const dVector& src);
+                                    //
+    void vmult (dVector& dst,const dVector& src);
+                                    //
+    void Tvmult(dVector& dst,const dVector& src);
   
-  //////////
-  double residual (dVector& dst,const dVector& x,const dVector& b);
-  //////////
-  void Jacobi_precond(dVector& dst,const dVector& src,double om = 1.);
-  //////////
-  void SSOR_precond(dVector& dst,const dVector& src,double om = 1.);
-  //////////
-  void SOR_precond(dVector& dst,const dVector& src,double om = 1.);
-  //////////
-  void SSOR(dVector& dst,double om = 1.);
-  //////////
-  void SOR(dVector& dst,double om = 1.);
-  //////////
-  void precondition(dVector& dst,const dVector& src) { dst=src; }
+                                    //
+    double residual (dVector& dst,const dVector& x,const dVector& b);
+                                    //
+    void Jacobi_precond(dVector& dst,const dVector& src,double om = 1.);
+                                    //
+    void SSOR_precond(dVector& dst,const dVector& src,double om = 1.);
+                                    //
+    void SOR_precond(dVector& dst,const dVector& src,double om = 1.);
+                                    //
+    void SSOR(dVector& dst,double om = 1.);
+                                    //
+    void SOR(dVector& dst,double om = 1.);
+                                    //
+    void precondition(dVector& dst,const dVector& src) { dst=src; }
 
     void print (ostream &) const;
+
+                                    /**
+                                     * Exception
+                                     */
+    DeclException0 (ExcNotCompressed);
 };
 #endif
index b05430401c3457414390e3183644044f7f363aa5..d2e344f3f33bc8d909137276ad52356a79914465 100644 (file)
@@ -255,18 +255,6 @@ dSMatrixStruct::add_matrix(const iVector& rows, const iVector& cols)
       add(rows(i), cols(j));
 }
 
-void
-dSMatrix::reinit()
-{
-  if(max_len<cols.vec_len)
-  {
-    if (val) delete[] val;
-    val = new double[cols.vec_len];
-    max_len = cols.vec_len;
-  }
-//  memset(val, 0, sizeof(*val) * cols.vec_len);
-  for (int i = cols.vec_len-1 ; i>=0 ; i--) val[i] = 0;
-}
 
 void
 dSMatrixStruct::print_gnuplot (ostream &out) const
@@ -296,6 +284,34 @@ dSMatrixStruct::bandwidth () const
   return b;
 }
 
+
+
+void
+dSMatrix::reinit()
+{
+  Assert (cols->compressed, ExcNotCompressed());
+  
+  if(max_len<cols->vec_len)
+  {
+    if (val) delete[] val;
+    val = new double[cols->vec_len];
+    max_len = cols->vec_len;
+  }
+//  memset(val, 0, sizeof(*val) * cols->vec_len);
+  for (int i = cols->vec_len-1 ; i>=0 ; i--) val[i] = 0;
+}
+
+
+
+void
+dSMatrix::reinit (dSMatrixStruct &sparsity) {
+  cols = &sparsity;
+  reinit ();
+};
+
+
+
+
 void
 dSMatrix::vmult(dVector& dst,const dVector& src)
 {
@@ -305,9 +321,9 @@ dSMatrix::vmult(dVector& dst,const dVector& src)
   for (int i=0;i<m();i++)
     {
       double s = 0.;
-      for (int j=cols.rowstart[i]; j < cols.rowstart[i+1] ;j++) 
+      for (int j=cols->rowstart[i]; j < cols->rowstart[i+1] ;j++) 
        {
-         int p = cols.colnums[j];
+         int p = cols->colnums[j];
          s += val[j] * src(p);
        }
       dst(i) = s;
@@ -326,9 +342,9 @@ dSMatrix::Tvmult(dVector& dst,const dVector& src)
   
   for (i=0;i<m();i++)
     {
-      for (int j=cols.rowstart[i]; j<cols.rowstart[i+1] ;j++)
+      for (int j=cols->rowstart[i]; j<cols->rowstart[i+1] ;j++)
        {
-         int p = cols.colnums[j];
+         int p = cols->colnums[j];
          dst(p) += val[j] * src(i);
        }
     }
@@ -345,9 +361,9 @@ dSMatrix::residual(dVector& dst,const dVector& u,const dVector& b)
   for (int i=0;i<m();i++)
     {
       s = b(i);
-      for (int j=cols.rowstart[i]; j<cols.rowstart[i+1] ;j++)
+      for (int j=cols->rowstart[i]; j<cols->rowstart[i+1] ;j++)
        {
-         int p = cols.colnums[j];
+         int p = cols->colnums[j];
          s -= val[j] * u(p);
        }
       dst(i) = s;
@@ -363,7 +379,7 @@ dSMatrix::Jacobi_precond(dVector& dst,const dVector& src,double om)
 
   for (int i=0;i<n;++i)
     {
-      dst(i) = om * src(i) * val[cols.rowstart[i]];
+      dst(i) = om * src(i) * val[cols->rowstart[i]];
     }
 }
 
@@ -376,23 +392,23 @@ dSMatrix::SSOR_precond(dVector& dst,const dVector& src,double om)
   for (i=0;i<n;i++)
     {
       dst(i) = src(i);
-      for (j=cols.rowstart[i]; j<cols.rowstart[i+1] ;j++)
+      for (j=cols->rowstart[i]; j<cols->rowstart[i+1] ;j++)
        {
-         p = cols.colnums[j];
+         p = cols->colnums[j];
          if (p<i) dst(i) -= om* val[j] * dst(p);
        }
-      dst(i) /= val[cols.rowstart[i]];
+      dst(i) /= val[cols->rowstart[i]];
     }
-  for (i=0;i<n;i++) dst(i) *= (2.-om)*val[cols.rowstart[i]];
+  for (i=0;i<n;i++) dst(i) *= (2.-om)*val[cols->rowstart[i]];
   
   for (i=n-1;i>=0;i--)
     {
-      for (j=cols.rowstart[i];j<cols.rowstart[i+1];j++)
+      for (j=cols->rowstart[i];j<cols->rowstart[i+1];j++)
        {
-         p = cols.colnums[j];
+         p = cols->colnums[j];
          if (p>i) dst(i) -= om* val[j] * dst(p);
        }
-      dst(i) /= val[cols.rowstart[i]];
+      dst(i) /= val[cols->rowstart[i]];
     }
 }
 
@@ -412,13 +428,13 @@ dSMatrix::SOR(dVector& dst, double om)
   for (int i=0;i<m();i++)
     {
       double s = dst(i);
-      for (int j=cols.rowstart[i]; j<cols.rowstart[i+1] ;j++)
+      for (int j=cols->rowstart[i]; j<cols->rowstart[i+1] ;j++)
        {
-         int p = cols.colnums[j];
+         int p = cols->colnums[j];
          if (p<i)
            s -= val[j] * dst(p);
        }
-      dst(i) = s * om / val[cols.rowstart[i]];
+      dst(i) = s * om / val[cols->rowstart[i]];
     }
 }
 
@@ -432,36 +448,36 @@ dSMatrix::SSOR(dVector& dst, double om)
   for (i=0;i<n;i++)
     {
       s = 0.;
-      for (j=cols.rowstart[i]; j<cols.rowstart[i+1] ;j++)
+      for (j=cols->rowstart[i]; j<cols->rowstart[i+1] ;j++)
        {
-         p = cols.colnums[j];
+         p = cols->colnums[j];
          if (p>=0)
            {
              if (i>j) s += val[j] * dst(p);
            }
        }
       dst(i) -= s * om;
-      dst(i) /= val[cols.rowstart[i]];
+      dst(i) /= val[cols->rowstart[i]];
     }
 
   for (i=n-1;i>=0;i--)
     {
       s = 0.;
-      for (j=cols.rowstart[i]; j<cols.rowstart[i+1] ;j++)
+      for (j=cols->rowstart[i]; j<cols->rowstart[i+1] ;j++)
        {
-         p = cols.colnums[j];
+         p = cols->colnums[j];
          if (p>=0)
            {
              if (i<j) s += val[j] * dst(p);
            }
        }
-      dst(i) -= s * om / val[cols.rowstart[i]];
+      dst(i) -= s * om / val[cols->rowstart[i]];
     }
 }
 
 
 void dSMatrix::print (ostream &out) const {
-  for (int i=0; i<cols.rows; ++i)
-    for (int j=cols.rowstart[i]; j<cols.rowstart[i+1]; ++j)
-      out << "(" << i << "," << cols.colnums[j] << ") " << val[j] << endl;
+  for (int i=0; i<cols->rows; ++i)
+    for (int j=cols->rowstart[i]; j<cols->rowstart[i+1]; ++j)
+      out << "(" << i << "," << cols->colnums[j] << ") " << val[j] << endl;
 };

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.