From 70ee2e77d47fc84324a6a62db68bca5bf0adff7f Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Tue, 1 Sep 2015 18:37:21 -0500 Subject: [PATCH] Tensor<0,dim>: Use cast instead of friend declaration to access value --- include/deal.II/base/tensor_base.h | 97 +++++++++++++----------------- 1 file changed, 42 insertions(+), 55 deletions(-) diff --git a/include/deal.II/base/tensor_base.h b/include/deal.II/base/tensor_base.h index d8c29c411f..29a551be5f 100644 --- a/include/deal.II/base/tensor_base.h +++ b/include/deal.II/base/tensor_base.h @@ -267,21 +267,6 @@ private: * The value of this scalar object. */ Number value; - - template - friend Tensor<0, dim2, typename ProductType::type> - operator*(const Tensor<0, dim2, Number2> &, - const Tensor<0, dim2, OtherNumber> &); - - template - friend Tensor<0, dim2, typename ProductType::type> - operator+(const Tensor<0, dim2, Number2> &, - const Tensor<0, dim2, OtherNumber> &); - - template - friend Tensor<0, dim2, typename ProductType::type> - operator-(const Tensor<0, dim2, Number2> &, - const Tensor<0, dim2, OtherNumber> &); }; @@ -832,7 +817,7 @@ template inline void Tensor<0,dim,Number>::clear () { - value = 0; + value = value_type(); } @@ -847,45 +832,6 @@ void Tensor<0,dim,Number>::serialize(Archive &ar, const unsigned int) -/** - * Returns the product of two Tensors of rank 0. - */ -template -inline -Tensor<0, dim, typename ProductType::type> -operator* (const Tensor<0,dim,Number> &p, const Tensor<0,dim,OtherNumber> &q) -{ - return p.value * q.value; -} - - - -/** - * Add two tensors of rank 0. - */ -template -inline -Tensor<0, dim, typename ProductType::type> -operator+ (const Tensor<0,dim,Number> &p, const Tensor<0,dim,OtherNumber> &q) -{ - return p.value + q.value; -} - - - -/** - * Subtract two tensors of rank 0. - */ -template -inline -Tensor<0, dim, typename ProductType::type> -operator- (const Tensor<0,dim,Number> &p, const Tensor<0,dim,OtherNumber> &q) -{ - return p.value - q.value; -} - - - #ifndef DEAL_II_WITH_CXX11 template @@ -964,6 +910,47 @@ operator / (const Tensor<0,dim,Number> &t, +/** + * Add two tensors of rank 0. + */ +template +inline +Tensor<0, dim, typename ProductType::type> +operator+ (const Tensor<0,dim,Number> &p, const Tensor<0,dim,OtherNumber> &q) +{ + return static_cast(p) + static_cast(q); +} + + + +/** + * Subtract two tensors of rank 0. + */ +template +inline +Tensor<0, dim, typename ProductType::type> +operator- (const Tensor<0,dim,Number> &p, const Tensor<0,dim,OtherNumber> &q) +{ + return static_cast(p) - static_cast(q); +} + + + +/** + * Returns the contraction of two Tensors of rank 0. + * + * @relates Tensor + */ +template +inline +typename ProductType::type +operator* (const Tensor<0,dim,Number> &p, const Tensor<0,dim,OtherNumber> &q) +{ + return static_cast(p) * static_cast(q); +} + + + /*---------------------- Inline functions: Tensor<1,dim> ---------------------*/ -- 2.39.5