]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Allow tensors to be reset to zero by writing t=0
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Fri, 24 Mar 2006 19:21:29 +0000 (19:21 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Fri, 24 Mar 2006 19:21:29 +0000 (19:21 +0000)
git-svn-id: https://svn.dealii.org/trunk@12672 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/symmetric_tensor.h
deal.II/base/include/base/tensor.h
deal.II/base/include/base/tensor_base.h
deal.II/doc/news/changes.html

index 24369e595328f1fec1c23c2b6b3c8315ab13f8a0..ad1c2eb7b73e09e7452c1bdf31f899cbb3411335 100644 (file)
@@ -2,7 +2,7 @@
 //    $Id$
 //    Version: $Name$
 //
-//    Copyright (C) 2005 by the deal.II authors
+//    Copyright (C) 2005, 2006 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -656,6 +656,20 @@ class SymmetricTensor
                                      */
     SymmetricTensor & operator = (const SymmetricTensor &);
 
+                                    /**
+                                     * This operator assigns a scalar
+                                     * to a tensor. To avoid
+                                     * confusion with what exactly it
+                                     * means to assign a scalar value
+                                     * to a tensor, zero is the only
+                                     * value allowed for <tt>d</tt>,
+                                     * allowing the intuitive
+                                     * notation <tt>t=0</tt> to reset
+                                     * all elements of the tensor to
+                                     * zero.
+                                     */
+    SymmetricTensor & operator = (const double d);
+
                                      /**
                                       * Convert the present symmetric tensor
                                       * into a full tensor with the same
@@ -1020,6 +1034,20 @@ SymmetricTensor<rank,dim>::operator = (const SymmetricTensor<rank,dim> &t)
 
 
 
+template <int rank, int dim>
+inline
+SymmetricTensor<rank,dim> &
+SymmetricTensor<rank,dim>::operator = (const double d)
+{
+  Assert (d==0, ExcMessage ("Only assignment with zero is allowed"));
+
+  data = 0;
+  
+  return *this;
+}
+
+
+
 template <>
 inline
 SymmetricTensor<2,1>::
index 54888b2b04b7f059021d58458075aa2355863d52..d452bfe2480abc8dadefb665007e3612f657d92a 100644 (file)
@@ -2,7 +2,7 @@
 //    $Id$
 //    Version: $Name$
 //
-//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 by the deal.II authors
+//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -106,7 +106,21 @@ class Tensor
                                      */
     Tensor & operator = (const Tensor<rank_,dim> &);
 
-                                    /**
+                                    /**
+                                     * This operator assigns a scalar
+                                     * to a tensor. To avoid
+                                     * confusion with what exactly it
+                                     * means to assign a scalar value
+                                     * to a tensor, zero is the only
+                                     * value allowed for <tt>d</tt>,
+                                     * allowing the intuitive
+                                     * notation <tt>t=0</tt> to reset
+                                     * all elements of the tensor to
+                                     * zero.
+                                     */
+    Tensor<rank_,dim> & operator = (const double d);
+
+                                    /**
                                      *  Test for equality of two tensors.
                                      */
     bool operator == (const Tensor<rank_,dim> &) const;
@@ -312,6 +326,21 @@ Tensor<rank_,dim>::operator = (const Tensor<rank_,dim> &t)
 }
 
 
+
+template <int rank_, int dim>
+inline
+Tensor<rank_,dim> &
+Tensor<rank_,dim>::operator = (const double d)
+{
+  Assert (d==0, ExcMessage ("Only assignment with zero is allowed"));
+
+  for (unsigned int i=0; i<dim; ++i)
+    subtensor[i] = 0;
+  return *this;
+}
+
+
+
 template <int rank_, int dim>
 inline
 bool
index 11d1f269ada49995f802cdc6717f4b139916fa41..800e41e79fe2adb780d9bdd80b7f515f25639591 100644 (file)
@@ -2,7 +2,7 @@
 //    $Id$
 //    Version: $Name$
 //
-//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 by the deal.II authors
+//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -161,6 +161,20 @@ class Tensor<1,dim>
                                      */
     Tensor<1,dim> & operator = (const Tensor<1,dim> &);
 
+                                    /**
+                                     * This operator assigns a scalar
+                                     * to a tensor. To avoid
+                                     * confusion with what exactly it
+                                     * means to assign a scalar value
+                                     * to a tensor, zero is the only
+                                     * value allowed for <tt>d</tt>,
+                                     * allowing the intuitive
+                                     * notation <tt>t=0</tt> to reset
+                                     * all elements of the tensor to
+                                     * zero.
+                                     */
+    Tensor<1,dim> & operator = (const double d);
+
                                     /**
                                      * Test for equality of two
                                      * tensors.
@@ -516,6 +530,20 @@ Tensor<1,dim> & Tensor<1,dim>::operator = (const Tensor<1,dim> &p)
 
 
 
+template <int dim>
+inline
+Tensor<1,dim> & Tensor<1,dim>::operator = (const double d)
+{
+  Assert (d==0, ExcMessage ("Only assignment with zero is allowed"));
+  
+  for (unsigned int i=0; i<dim; ++i)
+    values[i] = 0;
+  
+  return *this;
+}
+
+
+
 template <int dim>
 inline
 bool Tensor<1,dim>::operator == (const Tensor<1,dim> &p) const
index 6333745ddf117f95ffa2e2608fed74e06e56db39..07da107116a20b1ef366e6edffef88e4de6c6afa 100644 (file)
@@ -267,6 +267,13 @@ inconvenience this causes.
 
 <ol>
 
+  <li> <p> New: The various tensor classes can now effectively be reset to zero
+       by simply writing <code>t=0;</code> as has long been allowed for
+       matrices and vectors.
+       <br>
+       (WB 2006/03/24)
+       </p>
+
   <li> <p> New: The new <code
        class="member">deal_II_numbers::is_finite</code> function can
        be used to check whether a floating point number is finite,

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.