From f9690e9c4e3cc47d466e4bb8e777c7fddc82e6ad Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Wed, 2 Sep 2015 17:17:06 -0500 Subject: [PATCH] Restructure declarations in tensor_base.h and tensor.h Move everything that isn't necessary from tensor_base.h to tensor.h --- include/deal.II/base/tensor.h | 220 ++++++++++++++++++++++++++++- include/deal.II/base/tensor_base.h | 218 +--------------------------- 2 files changed, 220 insertions(+), 218 deletions(-) diff --git a/include/deal.II/base/tensor.h b/include/deal.II/base/tensor.h index 224e3fc5fd..738be73325 100644 --- a/include/deal.II/base/tensor.h +++ b/include/deal.II/base/tensor.h @@ -23,10 +23,12 @@ DEAL_II_NAMESPACE_OPEN - /* ----------------- Non-member functions operating on tensors. ------------ */ - +/** + * @name Output functions for Tensor objects + */ +//@{ /** * Output operator for tensors. Print the elements consecutively, with a space @@ -46,10 +48,13 @@ std::ostream &operator << (std::ostream &out, const Tensor &p) return out; } -#ifndef DOXYGEN /** - * Specialization for 1D. + * Output operator for tensors and dimension 1. This is implemented + * specialized from the general template in order to avoid a compiler + * warning that the loop is empty. + * + * @relates Tensor */ template inline @@ -60,7 +65,212 @@ std::ostream &operator << (std::ostream &out, const Tensor &p) return out; } -#endif // DOXYGEN + +/** + * Output operator for tensors of rank 0. Since such tensors are scalars, we + * simply print this one value. + * + * @relates Tensor<0,dim,Number> + */ +template +inline +std::ostream &operator << (std::ostream &out, const Tensor<0,dim,Number> &p) +{ + out << static_cast(p); + return out; +} + + +/** + * Output operator for tensors of rank 1. Print the elements consecutively, + * with a space in between. + * + * @relates Tensor<1,dim,Number> + */ +template +inline +std::ostream &operator << (std::ostream &out, const Tensor<1,dim,Number> &p) +{ + for (unsigned int i=0; i + */ +inline +std::ostream &operator << (std::ostream &out, const Tensor<1,1,double> &p) +{ + out << p[0]; + + return out; +} + + +//@} +/** + * @name Vector space operations on Tensor objects: + */ +//@{ + +/** + * Scalar multiplication of a tensor of rank 0 with a scalar from the left. + * + * @relates Tensor<0,dim,Number> + * @relates EnableIfScalar + */ +template ::type> +inline +Tensor<0,dim,typename ProductType::type> +operator * (const OtherNumber factor, + const Tensor<0,dim,Number> &t) +{ + return factor * static_cast(t); +} + + +/** + * Scalar multiplication of a tensor of rank 0 with a scalar from the right. + * + * @relates Tensor<0,dim,Number> + * @relates EnableIfScalar + */ +template ::type> +inline +Tensor<0,dim,typename ProductType::type> +operator * (const Tensor<0,dim,Number> &t, + const OtherNumber factor) +{ + return static_cast(t) * factor; +} + + +/** + * Division of a tensor of rank 0 with a scalar number. + * + * @relates Tensor<0,dim,Number> + * @relates EnableIfScalar + */ +template ::type> +inline +Tensor<0,dim,typename ProductType::type> +operator / (const Tensor<0,dim,Number> &t, + const OtherNumber factor) +{ + return static_cast(t) / factor; +} + + +/** + * Add two tensors of rank 0. + * + * @relates Tensor<0,dim,Number> + */ +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. + * + * @relates Tensor<0,dim,Number> + */ +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); +} + + +//@} +/** + * @name Contraction operations on Tensors + */ +//@{ + +/** + * Returns the contraction of two Tensors of rank 0. + * + * @relates Tensor<0,dim,Number> + */ +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); +} + +//@} + + +/** + * Contract a tensor of rank 1 with a tensor of rank 1. The result is + * sum_j src1[j] src2[j]. + * + * @relates Tensor + */ +template +inline +typename ProductType::type +contract (const Tensor<1,dim,Number> &src1, + const Tensor<1,dim,OtherNumber> &src2) +{ + typename ProductType::type res + = typename ProductType::type(); + for (unsigned int i=0; icontract function, + * but returns the result as a return value, rather than writing it into the + * reference given as the first argument to the contract function. + * + * Note that for the Tensor class, the multiplication operator only + * performs a contraction over a single pair of indices. This is in contrast + * to the multiplication operator for symmetric tensors, which does the double + * contraction. + * + * @relates Tensor + */ +template +inline +typename ProductType::type +operator * (const Tensor<1,dim,Number> &src1, + const Tensor<1,dim,OtherNumber> &src2) +{ + return contract(src1, src2); +} /** diff --git a/include/deal.II/base/tensor_base.h b/include/deal.II/base/tensor_base.h index ada55ccbd8..08a1d022dd 100644 --- a/include/deal.II/base/tensor_base.h +++ b/include/deal.II/base/tensor_base.h @@ -633,12 +633,10 @@ private: }; - #ifndef DOXYGEN /*---------------------- Inline functions: Tensor<0,dim> ---------------------*/ - template inline Tensor<0,dim,Number>::Tensor () @@ -1258,9 +1256,7 @@ Tensor::serialize(Archive &ar, const unsigned int) /* ----------------- Non-member functions operating on tensors. ------------- */ - #ifndef DEAL_II_WITH_CXX11 - template struct ProductType > { @@ -1272,171 +1268,16 @@ struct ProductType,U> { typedef Tensor::type> type; }; - #endif - -/** - * TODO - * - * @relates Tensor - * @relates EnableIfScalar - */ -template ::type> -inline -Tensor<0,dim,typename ProductType::type> -operator * (const OtherNumber factor, - const Tensor<0,dim,Number> &t) -{ - return factor * static_cast(t); -} - - - -/** - * TODO - * - * @relates Tensor - * @relates EnableIfScalar - */ -template ::type> -inline -Tensor<0,dim,typename ProductType::type> -operator * (const Tensor<0,dim,Number> &t, - const OtherNumber factor) -{ - return static_cast(t) * factor; -} - - - -/** - * TODO - * - * @relates Tensor - * @relates EnableIfScalar - */ -template ::type> -inline -Tensor<0,dim,typename ProductType::type> -operator / (const Tensor<0,dim,Number> &t, - const OtherNumber factor) -{ - return static_cast(t) / factor; -} - - - -/** - * Add two tensors of rank 0. - * - * @relates Tensor - */ -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. - * - * @relates Tensor - */ -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); -} - - -// TODO: - - -/** - * Output operator for tensors of rank 0. Since such tensors are scalars, we - * simply print this one value. - * - * @relates Tensor<0,dim,Number> - */ -template -inline -std::ostream &operator << (std::ostream &out, const Tensor<0,dim,Number> &p) -{ - out << static_cast(p); - return out; -} - - - /** - * Output operator for tensors of rank 1. Print the elements consecutively, - * with a space in between. - * - * @relates Tensor<1,dim,Number> + * @name Vector space operations on Tensor objects: */ -template -inline -std::ostream &operator << (std::ostream &out, const Tensor<1,dim,Number> &p) -{ - for (unsigned int i=0; i - */ -inline -std::ostream &operator << (std::ostream &out, const Tensor<1,1,double> &p) -{ - out << p[0]; - - return out; -} - - - -/** - * Multiplication of a tensor of rank with a scalar number from the right. + * Multiplication of a tensor of general rank with a scalar number from the + * right. * * The purpose of this operator is to enable only multiplication of a tensor * by a scalar number (i.e., a floating point number, a complex floating point @@ -1477,7 +1318,6 @@ operator * (const Tensor &t, } - /** * Multiplication of a tensor of general rank with a scalar number from the * left. See the discussion with the operator with switched arguments for more @@ -1500,7 +1340,6 @@ operator * (const Number factor, } - /** * Division of a tensor of general rank with a scalar number. See the * discussion on operator*() above for more information about template @@ -1526,7 +1365,6 @@ operator / (const Tensor &t, } - /** * Addition of two tensors of general @tparam rank. * @@ -1546,7 +1384,6 @@ operator+ (const Tensor &p, const Tensor } - /** * Subtraction of two tensors of general @tparam rank. * @@ -1565,52 +1402,7 @@ operator- (const Tensor &p, const Tensor return tmp; } - - -/** - * Contract a tensor of rank 1 with a tensor of rank 1. The result is - * sum_j src1[j] src2[j]. - * - * @relates Tensor - */ -template -inline -typename ProductType::type -contract (const Tensor<1,dim,Number> &src1, - const Tensor<1,dim,OtherNumber> &src2) -{ - typename ProductType::type res - = typename ProductType::type(); - for (unsigned int i=0; icontract function, - * but returns the result as a return value, rather than writing it into the - * reference given as the first argument to the contract function. - * - * Note that for the Tensor class, the multiplication operator only - * performs a contraction over a single pair of indices. This is in contrast - * to the multiplication operator for symmetric tensors, which does the double - * contraction. - * - * @relates Tensor - */ -template -inline -typename ProductType::type -operator * (const Tensor<1,dim,Number> &src1, - const Tensor<1,dim,OtherNumber> &src2) -{ - return contract(src1, src2); -} - +//@} DEAL_II_NAMESPACE_CLOSE -- 2.39.5