}
-/**
- * Output operator for tensors of rank 1. Print the elements consecutively,
- * with a space in between.
- *
- * @relates Tensor<1,dim,Number>
- */
-template <int dim, typename Number>
-inline
-std::ostream &operator << (std::ostream &out, const Tensor<1,dim,Number> &p)
-{
- for (unsigned int i=0; i<dim-1; ++i)
- out << p[i] << ' ';
- out << p[dim-1];
-
- return out;
-}
-
-
-/**
- * Output operator for tensors of rank 1 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<1,dim,Number>
- */
-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:
#define dealii__tensor_base_h
-// single this file out from tensor.h, since we want to derive
-// Point<dim,Number> 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 <deal.II/base/config.h>
#include <deal.II/base/exceptions.h>
#include <deal.II/base/table_indices.h>
typedef typename numbers::NumberTraits<Number>::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;
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.
<< "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.
*/
typedef typename numbers::NumberTraits<Number>::real_type real_type;
/**
- * The tensor type this object represents.
- */
- typedef Tensor<rank_,dim,Number> 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<rank_-1,dim,Number>::tensor_type value_type;
<< "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<rank_, dim, Number> tensor_type;
+
/**
* Array of tensors holding the subelements.
*/
- value_type values[(dim != 0) ? dim : 1];
+ Tensor<rank_-1, dim, Number> values[(dim != 0) ? dim : 1];
/**
* Help function for unroll.
template <int dim, typename Number>
inline
-Tensor<0,dim,Number>::operator Number () const
+Tensor<0,dim,Number>::operator Number &()
{
return value;
}
template <int dim, typename Number>
inline
-Tensor<0,dim,Number>::operator Number &()
+Tensor<0,dim,Number>::operator const Number &() const
{
return value;
}
{
real_type s = 0;
for (unsigned int i=0; i<dim; ++i)
- s += static_cast<Tensor<rank_-1,dim,Number> >(values[i]).norm_square();
+ s += values[i].norm_square();
return s;
}
unsigned int &index) const
{
for (unsigned int i=0; i<dim; ++i)
- static_cast<Tensor<rank_ - 1, dim, Number> >(values[i]).
- unroll_recursion(result, index);
+ values[i].unroll_recursion(result, index);
}