]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
More tensor work.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 7 Nov 1998 02:13:12 +0000 (02:13 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 7 Nov 1998 02:13:12 +0000 (02:13 +0000)
git-svn-id: https://svn.dealii.org/trunk@654 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/function.h
deal.II/base/include/base/tensor.h
deal.II/base/include/base/tensor_base.h
deal.II/base/source/function.cc

index c7a568791736b02403a918a92028649112e87f1a..f992406d9c0f7cc7d3ae5f980517a9f2c0f04cc1 100644 (file)
@@ -116,7 +116,7 @@ class Function {
                                      * Return the gradient of the function
                                      * at the given point.
                                      */
-    virtual Point<dim> gradient (const Point<dim> &p) const;
+    virtual Tensor<1,dim> gradient (const Point<dim> &p) const;
 
                                     /**
                                      * Set #gradients# to the gradients of
@@ -126,7 +126,7 @@ class Function {
                                      * the same size as the #points# array.
                                      */
     virtual void gradient_list (const vector<Point<dim> > &points,
-                               vector<Point<dim> >       &gradients) const;
+                               vector<Tensor<1,dim> >    &gradients) const;
 
                                     /**
                                      * Return the value of the time variable/
@@ -203,7 +203,7 @@ class ZeroFunction : public Function<dim> {
                                      * Return the gradient of the function
                                      * at the given point.
                                      */
-    virtual Point<dim> gradient (const Point<dim> &p) const;
+    virtual Tensor<1,dim> gradient (const Point<dim> &p) const;
 
                                     /**
                                      * Set #gradients# to the gradients of
@@ -213,7 +213,7 @@ class ZeroFunction : public Function<dim> {
                                      * the same size as the #points# array.
                                      */
     virtual void gradient_list (const vector<Point<dim> > &points,
-                               vector<Point<dim> >       &gradients) const;
+                               vector<Tensor<1,dim> >    &gradients) const;
 };
 
 
index de90959cdf98176e53a0a786c4badd896dfe9e59..ac90f9920b8a18aab5fb0f5baeab36a8bebb5d2e 100644 (file)
@@ -97,6 +97,20 @@ class Tensor {
                                      */
     Tensor<rank_,dim> & operator /= (const double &factor);
 
+                                    /**
+                                     *  Add two tensors. If possible, use
+                                     *  #operator +=# instead since this does not
+                                     *  need to copy a point at least once.
+                                     */
+    Tensor<rank_,dim>   operator + (const Tensor<rank_,dim> &) const;
+
+                                    /**
+                                     *  Subtract two tensors. If possible, use
+                                     *  #operator +=# instead since this does not
+                                     *  need to copy a point at least once.
+                                     */
+    Tensor<rank_,dim>   operator - (const Tensor<rank_,dim> &) const;
+
                                     /**
                                      * Reset all values to zero.
                                      */
@@ -212,6 +226,34 @@ Tensor<rank_,dim> & Tensor<rank_,dim>::operator /= (const double &s) {
 
 
 
+template <int rank_, int dim>
+inline
+Tensor<rank_,dim>
+Tensor<rank_,dim>::operator + (const Tensor<rank_,dim> &t) const {
+  Tensor<rank_,dim> tmp(*this);
+  
+  for (unsigned int i=0; i<dim; ++i)
+    tmp.subtensor[i] += t.subtensor[i];
+
+  return tmp;
+};
+
+
+
+template <int rank_, int dim>
+inline
+Tensor<rank_,dim>
+Tensor<rank_,dim>::operator - (const Tensor<rank_,dim> &t) const {
+  Tensor<rank_,dim> tmp(*this);
+  
+  for (unsigned int i=0; i<dim; ++i)
+    tmp.subtensor[i] -= t.subtensor[i];
+
+  return tmp;
+};
+
+
+
 template <int rank_, int dim>
 inline
 void Tensor<rank_,dim>::clear () {
index 077c722c53217d39cd6fa250cfc6576cf4659423..51f42ee7b0722bfc9d817222dd250fa512930cd1 100644 (file)
@@ -126,7 +126,21 @@ class Tensor<1,dim> {
                                     /**
                                      *  Returns the scalar product of two vectors.
                                      */
-    double              operator * (const Tensor<1,dim> &) const;
+    double          operator * (const Tensor<1,dim> &) const;
+
+                                    /**
+                                     *  Add two tensors. If possible, use
+                                     *  #operator +=# instead since this does not
+                                     *  need to copy a point at least once.
+                                     */
+    Tensor<1,dim>   operator + (const Tensor<1,dim> &) const;
+
+                                    /**
+                                     *  Subtract two tensors. If possible, use
+                                     *  #operator +=# instead since this does not
+                                     *  need to copy a point at least once.
+                                     */
+    Tensor<1,dim>   operator - (const Tensor<1,dim> &) const;
 
                                     /**
                                      * Reset all values to zero.
@@ -285,6 +299,22 @@ double Tensor<1,dim>::operator * (const Tensor<1,dim> &p) const {
 
 
 
+template <int dim>
+inline
+Tensor<1,dim> Tensor<1,dim>::operator + (const Tensor<1,dim> &p) const {
+  return (Tensor<1,dim>(*this) += p);
+};
+
+
+
+template <int dim>
+inline
+Tensor<1,dim> Tensor<1,dim>::operator - (const Tensor<1,dim> &p) const {
+  return (Tensor<1,dim>(*this) -= p);
+};
+
+
+
 template <int dim>
 inline
 void Tensor<1,dim>::clear () {
index a88413d6775af5ff747061597eb60b9af636026a..3b7a77494be7080c8d1fc1c97e4f326e67897a11 100644 (file)
@@ -38,7 +38,7 @@ void Function<dim>::value_list (const vector<Point<dim> > &points,
 
 
 template <int dim>
-Point<dim> Function<dim>::gradient (const Point<dim> &) const {
+Tensor<1,dim> Function<dim>::gradient (const Point<dim> &) const {
   Assert (false, ExcPureFunctionCalled());
   return Point<dim>();
 };
@@ -47,7 +47,7 @@ Point<dim> Function<dim>::gradient (const Point<dim> &) const {
 
 template <int dim>
 void Function<dim>::gradient_list (const vector<Point<dim> > &points,
-                                  vector<Point<dim> >       &gradients) const {
+                                  vector<Tensor<1,dim> >    &gradients) const {
   Assert (gradients.size() == points.size(),
          ExcVectorHasWrongSize(gradients.size(), points.size()));
 
@@ -104,19 +104,19 @@ void ZeroFunction<dim>::value_list (const vector<Point<dim> > &points,
 
 
 template <int dim>
-Point<dim> ZeroFunction<dim>::gradient (const Point<dim> &) const {
-  return Point<dim>();
+Tensor<1,dim> ZeroFunction<dim>::gradient (const Point<dim> &) const {
+  return Tensor<1,dim>();
 };
 
 
 
 template <int dim>
 void ZeroFunction<dim>::gradient_list (const vector<Point<dim> > &points,
-                                      vector<Point<dim> >       &gradients) const {
+                                      vector<Tensor<1,dim> >    &gradients) const {
   Assert (gradients.size() == points.size(),
          ExcVectorHasWrongSize(gradients.size(), points.size()));
 
-  fill_n (gradients.begin(), points.size(), Point<dim>());
+  gradients.clear ();
 };
 
 

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.