]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add missing copy constructors for the specializations of class Tensor.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 3 Feb 2015 15:18:57 +0000 (09:18 -0600)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 3 Feb 2015 15:21:30 +0000 (09:21 -0600)
Also add a changelog entry.

doc/news/changes.h
include/deal.II/base/tensor_base.h

index 6a3a88197705e572c32df22c903fef4fa8e91b54..66902ba442243b0490cb975f4b18348b80586680 100644 (file)
@@ -316,6 +316,13 @@ inconvenience this causes.
 <h3>Specific improvements</h3>
 
 <ol>
+  <li> New: The Tensor classes now have copy constructors and copy
+  operators that allow assignment from other tensors with different
+  underlying scalar types.
+  <br>
+  (Denis Davydov, 2015/02/03)
+  </li>
+
   <li> New: Class hp::DoFHandler can now also be serialized.
   <br>
   (Lukas Korous, 2015/01/31)
index bf2d7c68aeabf133ccb581077c2dfeb25cbac4fc..db9e55b9c835676e1500e64e84c2ae980bc3dbe7 100644 (file)
@@ -1,6 +1,6 @@
 // ---------------------------------------------------------------------
 //
-// Copyright (C) 1998 - 2014 by the deal.II authors
+// Copyright (C) 1998 - 2015 by the deal.II authors
 //
 // This file is part of the deal.II library.
 //
@@ -115,6 +115,14 @@ public:
    */
   Tensor (const Tensor<0,dim,Number> &);
 
+  /**
+   * Copy constructor from tensors with different underlying scalar
+   * type. This obviously requires that the @p OtherNumber type is
+   * convertible to @p Number.
+   */
+  template <typename OtherNumber>
+  Tensor (const Tensor<0,dim,OtherNumber> &);
+  
   /**
    * Conversion to Number. Since rank-0 tensors are scalars, this is a natural
    * operation.
@@ -135,6 +143,11 @@ public:
    */
   Tensor<0,dim,Number> &operator = (const Tensor<0,dim,Number> &);
 
+  /**
+   * Assignment operator from tensors with different underlying scalar
+   * type. This obviously requires that the @p OtherNumber type is
+   * convertible to @p Number.
+   */
   template <typename OtherNumber>
   Tensor<0,dim,Number> &operator = (const Tensor<0,dim,OtherNumber> &);
 
@@ -341,6 +354,14 @@ public:
    */
   Tensor (const Tensor<1,dim,Number> &);
 
+  /**
+   * Copy constructor from tensors with different underlying scalar
+   * type. This obviously requires that the @p OtherNumber type is
+   * convertible to @p Number.
+   */
+  template <typename OtherNumber>
+  Tensor (const Tensor<1,dim,OtherNumber> &);
+  
   /**
    * Read access to the <tt>index</tt>th coordinate.
    *
@@ -372,6 +393,11 @@ public:
    */
   Tensor<1,dim,Number> &operator = (const Tensor<1,dim,Number> &);
 
+  /**
+   * Assignment operator from tensors with different underlying scalar
+   * type. This obviously requires that the @p OtherNumber type is
+   * convertible to @p Number.
+   */
   template <typename OtherNumber>
   Tensor<1,dim,Number> &operator = (const Tensor<1,dim,OtherNumber> &);
 
@@ -608,6 +634,17 @@ Tensor<0,dim,Number>::Tensor (const Tensor<0,dim,Number> &p)
 
 
 
+template <int dim, typename Number>
+template <typename OtherNumber>
+inline
+Tensor<0,dim,Number>::Tensor (const Tensor<0,dim,OtherNumber> &p)
+{
+  Assert (dim>0, ExcDimTooSmall(dim));
+
+  value = Number(p.value);
+}
+
+
 
 template <int dim, typename Number>
 inline
@@ -640,7 +677,7 @@ template <typename OtherNumber>
 inline
 Tensor<0,dim,Number> &Tensor<0,dim,Number>::operator = (const Tensor<0,dim,OtherNumber> &p)
 {
-  value = p.value;
+  value = Number(p.value);
   return *this;
 }
 
@@ -829,6 +866,19 @@ Tensor<1,dim,Number>::Tensor (const Tensor<1,dim,Number> &p)
 
 
 
+template <int dim, typename Number>
+template <typename OtherNumber>
+inline
+Tensor<1,dim,Number>::Tensor (const Tensor<1,dim,OtherNumber> &p)
+{
+  Assert (dim>0, ExcDimTooSmall(dim));
+
+  for (unsigned int i=0; i<dim; ++i)
+    values[i] = Number(p.values[i]);
+}
+
+
+
 template <>
 inline
 Tensor<1,0,double>::Tensor (const Tensor<1,0,double> &)
@@ -922,7 +972,7 @@ Tensor<1,dim,Number> &
 Tensor<1,dim,Number>::operator = (const Tensor<1,dim,OtherNumber> &p)
 {
   for (unsigned int i=0; i<dim; ++i)
-    values[i] = p.values[i];
+    values[i] = Number(p.values[i]);
 
   return *this;
 }

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.