From beed3f9ba108e4046a94239a8c61a7dc91dd9f8b Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 3 Feb 2015 09:18:57 -0600 Subject: [PATCH] Add missing copy constructors for the specializations of class Tensor. Also add a changelog entry. --- doc/news/changes.h | 7 ++++ include/deal.II/base/tensor_base.h | 56 ++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/doc/news/changes.h b/doc/news/changes.h index 6a3a881977..66902ba442 100644 --- a/doc/news/changes.h +++ b/doc/news/changes.h @@ -316,6 +316,13 @@ inconvenience this causes.

Specific improvements

    +
  1. New: The Tensor classes now have copy constructors and copy + operators that allow assignment from other tensors with different + underlying scalar types. +
    + (Denis Davydov, 2015/02/03) +
  2. +
  3. New: Class hp::DoFHandler can now also be serialized.
    (Lukas Korous, 2015/01/31) diff --git a/include/deal.II/base/tensor_base.h b/include/deal.II/base/tensor_base.h index bf2d7c68ae..db9e55b9c8 100644 --- a/include/deal.II/base/tensor_base.h +++ b/include/deal.II/base/tensor_base.h @@ -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 + 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 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 + Tensor (const Tensor<1,dim,OtherNumber> &); + /** * Read access to the indexth 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 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 +template +inline +Tensor<0,dim,Number>::Tensor (const Tensor<0,dim,OtherNumber> &p) +{ + Assert (dim>0, ExcDimTooSmall(dim)); + + value = Number(p.value); +} + + template inline @@ -640,7 +677,7 @@ template 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 +template +inline +Tensor<1,dim,Number>::Tensor (const Tensor<1,dim,OtherNumber> &p) +{ + Assert (dim>0, ExcDimTooSmall(dim)); + + for (unsigned int i=0; i 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