]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add some norms to the dVector class.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 7 Apr 1998 13:55:28 +0000 (13:55 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 7 Apr 1998 13:55:28 +0000 (13:55 +0000)
git-svn-id: https://svn.dealii.org/trunk@152 0785d39b-7218-0410-832d-ea1e28bc413d

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

index cc78b2cc8d537137ae3651f23630b7e1a18ebca5..33a08d319b8ad92151f6c2340b3f8288f7dc1a9d 100644 (file)
@@ -95,9 +95,29 @@ class dVector : public VectorBase
     double operator* (const dVector& V) const;
 
                                     /**
-                                     * Return square of the norm.
+                                     * Return square of the l2-norm.
                                      */
     double norm_sqr () const;
+
+                                    /**
+                                     * Return the mean value of the elements of
+                                     * this vector.
+                                     */
+    double mean_value () const;
+
+                                    /**
+                                     * Return the l1-norm of the vector, i.e.
+                                     * the sum of the absolute values.
+                                     */
+    double l1_norm () const;
+
+                                    /**
+                                     * Return the l2-norm of the vector, i.e.
+                                     * the square root of the sum of the
+                                     * squares of the elements.
+                                     */
+    double l2_norm () const;
+    
     
                                     /**
                                      * Change  Dimension. <p>
index d39bb93f53f0b391d16019cc47bf9ba6f16856d8..9ede32ce1bf09040a973ae0e442f64106387b48d 100644 (file)
@@ -144,7 +144,87 @@ double dVector::norm_sqr () const
     sum0 += val[i] * val[i];
   
   return sum0+sum1+sum2+sum3;
-}
+};
+
+
+
+double dVector::mean_value () const
+{
+  double sum0 = 0,
+        sum1 = 0,
+        sum2 = 0,
+        sum3 = 0;
+
+                                  // use modern processors better by
+                                  // allowing pipelined commands to be
+                                  // executed in parallel
+  for (unsigned int i=0; i<(dim/4); ++i) 
+    {
+      sum0 += val[4*i];
+      sum1 += val[4*i+1];
+      sum2 += val[4*i+2];
+      sum3 += val[4*i+3];
+    };
+                                  // add up remaining elements
+  for (unsigned int i=(dim/4)*4; i<dim; ++i)
+    sum0 += val[i];
+  
+  return (sum0+sum1+sum2+sum3)/n();
+};
+
+
+
+double dVector::l1_norm () const
+{
+  double sum0 = 0,
+        sum1 = 0,
+        sum2 = 0,
+        sum3 = 0;
+
+                                  // use modern processors better by
+                                  // allowing pipelined commands to be
+                                  // executed in parallel
+  for (unsigned int i=0; i<(dim/4); ++i) 
+    {
+      sum0 += fabs(val[4*i]);
+      sum1 += fabs(val[4*i+1]);
+      sum2 += fabs(val[4*i+2]);
+      sum3 += fabs(val[4*i+3]);
+    };
+                                  // add up remaining elements
+  for (unsigned int i=(dim/4)*4; i<dim; ++i)
+    sum0 += fabs(val[i]);
+  
+  return sum0+sum1+sum2+sum3;
+};
+
+
+
+double dVector::l2_norm () const
+{
+  double sum0 = 0,
+        sum1 = 0,
+        sum2 = 0,
+        sum3 = 0;
+
+                                  // use modern processors better by
+                                  // allowing pipelined commands to be
+                                  // executed in parallel
+  for (unsigned int i=0; i<(dim/4); ++i) 
+    {
+      sum0 += val[4*i] * val[4*i];
+      sum1 += val[4*i+1] * val[4*i+1];
+      sum2 += val[4*i+2] * val[4*i+2];
+      sum3 += val[4*i+3] * val[4*i+3];
+    };
+                                  // add up remaining elements
+  for (unsigned int i=(dim/4)*4; i<dim; ++i)
+    sum0 += val[i] * val[i];
+  
+  return sqrt(sum0+sum1+sum2+sum3);
+};
+
+
 
 
 

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.