]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Introduced non-default copy constructor and operator= for Tensor class
authorDenis Davydov <davydden@gmail.com>
Tue, 3 Feb 2015 13:10:59 +0000 (14:10 +0100)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 3 Feb 2015 15:21:29 +0000 (09:21 -0600)
include/deal.II/base/tensor.h
include/deal.II/base/tensor_base.h

index 7d8b9f11c40c2449ba10f1c0f5962dfb7bbde7d9..1425289e158b651ef80eada0e3f50ef9da4d62c4 100644 (file)
@@ -102,6 +102,13 @@ public:
    */
   Tensor (const array_type &initializer);
 
+  /**
+   * Copy constructor taking a tesnor of another base data type
+   */
+  template <typename OtherNumber>
+  explicit
+  Tensor (const Tensor<rank_,dim,OtherNumber> &);
+
   /**
    * Conversion operator from tensor of tensors.
    */
@@ -137,6 +144,9 @@ public:
    */
   Tensor &operator = (const Tensor<rank_,dim,Number> &);
 
+  template <typename OtherNumber>
+  Tensor &operator = (const Tensor<rank_,dim,OtherNumber> &);
+
   /**
    * 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
@@ -403,6 +413,26 @@ Tensor<rank_,dim,Number>::operator = (const Tensor<rank_,dim,Number> &t)
 
 
 
+template <int rank_, int dim, typename Number>
+template <typename OtherNumber>
+inline
+Tensor<rank_,dim,Number> &
+Tensor<rank_,dim,Number>::operator = (const Tensor<rank_,dim,OtherNumber> &t)
+{
+  for (unsigned int i=0; i<dim; ++i)
+    subtensor[i] = t.subtensor[i];
+  return *this;
+}
+
+template <int rank_, int dim, typename Number>
+template <typename OtherNumber>
+Tensor<rank_,dim,Number>::Tensor (const Tensor<rank_,dim,OtherNumber> &t)
+{
+  *this = t;
+}
+
+
+
 template <int rank_, int dim, typename Number>
 inline
 Tensor<rank_,dim,Number> &
index 1f7b39ed360bfd069f5d6947dbc01984d01f7c11..bf2d7c68aeabf133ccb581077c2dfeb25cbac4fc 100644 (file)
@@ -135,6 +135,9 @@ public:
    */
   Tensor<0,dim,Number> &operator = (const Tensor<0,dim,Number> &);
 
+  template <typename OtherNumber>
+  Tensor<0,dim,Number> &operator = (const Tensor<0,dim,OtherNumber> &);
+
   /**
    * Assignment operator.
    */
@@ -369,6 +372,9 @@ public:
    */
   Tensor<1,dim,Number> &operator = (const Tensor<1,dim,Number> &);
 
+  template <typename OtherNumber>
+  Tensor<1,dim,Number> &operator = (const Tensor<1,dim,OtherNumber> &);
+
   /**
    * 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
@@ -629,6 +635,14 @@ Tensor<0,dim,Number> &Tensor<0,dim,Number>::operator = (const Tensor<0,dim,Numbe
   return *this;
 }
 
+template <int dim, typename Number>
+template <typename OtherNumber>
+inline
+Tensor<0,dim,Number> &Tensor<0,dim,Number>::operator = (const Tensor<0,dim,OtherNumber> &p)
+{
+  value = p.value;
+  return *this;
+}
 
 
 template <int dim, typename Number>
@@ -901,6 +915,20 @@ Tensor<1,dim,Number>::operator = (const Tensor<1,dim,Number> &p)
 
 
 
+template <int dim, typename Number>
+template <typename OtherNumber>
+inline
+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];
+
+  return *this;
+}
+
+
+
 template <int dim, typename Number>
 inline
 Tensor<1,dim,Number> &Tensor<1,dim,Number>::operator = (const Number d)

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.