From: Matthias Maier Date: Fri, 4 Sep 2015 04:01:11 +0000 (-0500) Subject: Bugfix: Tensor: Always store a tensor type internally X-Git-Tag: v8.4.0-rc2~466^2~19 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f9e55404f098ba85883e1289d171f1225b45115d;p=dealii.git Bugfix: Tensor: Always store a tensor type internally --- diff --git a/include/deal.II/base/point.h b/include/deal.II/base/point.h index 66c83dbfb8..575637d44d 100644 --- a/include/deal.II/base/point.h +++ b/include/deal.II/base/point.h @@ -19,7 +19,7 @@ #include #include -#include +#include #include DEAL_II_NAMESPACE_OPEN diff --git a/include/deal.II/base/tensor.h b/include/deal.II/base/tensor.h index 53c1314bca..a338636851 100644 --- a/include/deal.II/base/tensor.h +++ b/include/deal.II/base/tensor.h @@ -81,40 +81,6 @@ std::ostream &operator << (std::ostream &out, const Tensor<0,dim,Number> &p) } -/** - * 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: diff --git a/include/deal.II/base/tensor_base.h b/include/deal.II/base/tensor_base.h index 9ec99e4123..e9a263450e 100644 --- a/include/deal.II/base/tensor_base.h +++ b/include/deal.II/base/tensor_base.h @@ -17,12 +17,6 @@ #define dealii__tensor_base_h -// single this file out from tensor.h, since we want to derive -// Point from Tensor<1,dim,Number>. However, the point class will -// not need all the tensor stuff, so we don't want the whole tensor package to -// be included every time we use a point. - - #include #include #include @@ -115,14 +109,8 @@ public: typedef typename numbers::NumberTraits::real_type real_type; /** - * The tensor type this object represents. In the special case of a - * tensor or rank 0 we strip the tensor class and just store the scalar - * object. - */ - typedef Number tensor_type; - - /** - * Type of stored objects. This is a Number for a rank 0 tensor. + * Type of objects encapsulated by this container and returned by + * operator[](). This is a scalar number type for a rank 0 tensor. */ typedef Number value_type; @@ -158,19 +146,22 @@ public: Tensor (const OtherNumber initializer); /** - * Conversion to Number. Since rank-0 tensors are scalars, this is a natural - * operation. + * Return a reference to the encapsulated Number object. Since rank-0 + * tensors are scalars, this is a natural operation. + * + * This is the non-const conversion operator that returns a writable + * reference. */ - operator Number () const; + operator Number &(); /** - * Conversion to Number. Since rank-0 tensors are scalars, this is a natural - * operation. + * Return a reference to the encapsulated Number object. Since rank-0 + * tensors are scalars, this is a natural operation. * - * This is the non-const conversion operator that returns a writable + * This is the const conversion operator that returns a read-only * reference. */ - operator Number &(); + operator const Number &() const; /** * Copy assignment operator. @@ -279,6 +270,12 @@ public: << "dim must be positive, but was " << arg1); private: + /** + * Internal type declaration that is used to specialize the return type + * of operator[]() for Tensor<1,dim,Number> + */ + typedef Number tensor_type; + /** * The value of this scalar object. */ @@ -377,13 +374,9 @@ public: typedef typename numbers::NumberTraits::real_type real_type; /** - * The tensor type this object represents. - */ - typedef Tensor tensor_type; - - /** - * Type of stored objects (i.e., the object returned by operator[]()). - * This is a tensor of lower rank. + * Type of objects encapsulated by this container and returned by + * operator[](). This is a tensor of lower rank for a general tensor, and + * a scalar number type for Tensor<1,dim,Number>. */ typedef typename Tensor::tensor_type value_type; @@ -605,10 +598,16 @@ public: << "dim must be positive, but was " << arg1); private: + /** + * Internal type declaration that is used to specialize the return type + * of operator[]() for Tensor<1,dim,Number> + */ + typedef Tensor tensor_type; + /** * Array of tensors holding the subelements. */ - value_type values[(dim != 0) ? dim : 1]; + Tensor values[(dim != 0) ? dim : 1]; /** * Help function for unroll. @@ -678,7 +677,7 @@ Tensor<0,dim,Number>::Tensor (const Tensor<0,dim,OtherNumber> &p) template inline -Tensor<0,dim,Number>::operator Number () const +Tensor<0,dim,Number>::operator Number &() { return value; } @@ -686,7 +685,7 @@ Tensor<0,dim,Number>::operator Number () const template inline -Tensor<0,dim,Number>::operator Number &() +Tensor<0,dim,Number>::operator const Number &() const { return value; } @@ -1154,7 +1153,7 @@ Tensor::norm_square () const { real_type s = 0; for (unsigned int i=0; i >(values[i]).norm_square(); + s += values[i].norm_square(); return s; } @@ -1181,8 +1180,7 @@ Tensor::unroll_recursion (Vector &result, unsigned int &index) const { for (unsigned int i=0; i >(values[i]). - unroll_recursion(result, index); + values[i].unroll_recursion(result, index); } diff --git a/include/deal.II/fe/fe_nedelec.h b/include/deal.II/fe/fe_nedelec.h index 3b57774b4c..06f1c56458 100644 --- a/include/deal.II/fe/fe_nedelec.h +++ b/include/deal.II/fe/fe_nedelec.h @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include