-/**
- * Multiplication of a tensor of general rank with a scalar Number from the
- * right.
- *
- * @relates Tensor
- */
-template <int rank, int dim, typename Number>
-inline
-Tensor<rank,dim,Number>
-operator * (const Tensor<rank,dim,Number> &t,
- const Number factor)
-{
- Tensor<rank,dim,Number> tt = t;
- tt *= factor;
- return tt;
-}
-
-
-
-/**
- * Multiplication of a tensor of general rank with a scalar Number from the
- * left.
- *
- * @relates Tensor
- */
-template <int rank, int dim, typename Number>
-inline
-Tensor<rank,dim,Number>
-operator * (const Number factor,
- const Tensor<rank,dim,Number> &t)
-{
- Tensor<rank,dim,Number> tt = t;
- tt *= factor;
- return tt;
-}
-
-
-#ifndef DEAL_II_WITH_CXX11
-
-template <typename T, typename U, int rank, int dim>
-struct ProductType<T,Tensor<rank,dim,U> >
-{
- typedef Tensor<rank,dim,typename ProductType<T,U>::type> type;
-};
-
-template <typename T, typename U, int rank, int dim>
-struct ProductType<Tensor<rank,dim,T>,U>
-{
- typedef Tensor<rank,dim,typename ProductType<T,U>::type> type;
-};
-
-#endif
-
-
-/**
- * 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
- * number, etc.). The function is written in a way that only allows the
- * compiler to consider the function if the second argument is indeed a scalar
- * number -- in other words, @p OtherNumber will not match, for example
- * <code>std::vector@<double@></code> as the product of a tensor and a vector
- * clearly would make no sense. The mechanism by which the compiler is
- * prohibited of considering this operator for multiplication with non-scalar
- * types are explained in the documentation of the EnableIfScalar class.
- *
- * The return type of the function is chosen so that it matches the types of
- * both the tensor and the scalar argument. For example, if you multiply a
- * <code>Tensor@<1,dim,double@></code> by <code>std::complex@<double@></code>,
- * then the result will be a
- * <code>Tensor@<1,dim,std::complex@<double@>@></code>. In other words, the
- * type with which the returned tensor stores its components equals the type
- * you would get if you multiplied an individual component of the input tensor
- * by the scalar factor.
- *
- * @relates Tensor
- * @relates EnableIfScalar
- */
-template <int rank, int dim, typename Number, typename OtherNumber>
-inline
-Tensor<rank,dim,typename ProductType<Number,typename EnableIfScalar<OtherNumber>::type>::type>
-operator * (const Tensor<rank,dim,Number> &t,
- const OtherNumber factor)
-{
- // recurse over the base objects
- Tensor<rank,dim,typename ProductType<Number,OtherNumber>::type> tt;
- for (unsigned int d=0; d<dim; ++d)
- tt[d] = t[d] * factor;
- return tt;
-}
-
-
-
-/**
- * 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
- * information about template arguments and the return type.
- *
- * @relates Tensor
- * @relates EnableIfScalar
- */
-template <int rank, int dim, typename Number, typename OtherNumber>
-inline
-Tensor<rank,dim,typename ProductType<Number,typename EnableIfScalar<OtherNumber>::type>::type>
-operator * (const Number factor,
- const Tensor<rank,dim,OtherNumber> &t)
-{
- // simply forward to the operator above
- return t * factor;
-}
-
-
-
-/**
- * Division of a tensor of general rank by a scalar Number.
- *
- * @relates Tensor
- */
-template <int rank, int dim, typename Number>
-inline
-Tensor<rank,dim,Number>
-operator / (const Tensor<rank,dim,Number> &t,
- const Number factor)
-{
- Tensor<rank,dim,Number> tt = t;
- tt /= factor;
- return tt;
-}
-
-
-
-
-/**
- * Multiplication of a tensor of general rank with a scalar double from the
- * right.
- *
- * @relates Tensor
- */
-template <int rank, int dim>
-inline
-Tensor<rank,dim>
-operator * (const Tensor<rank,dim> &t,
- const double factor)
-{
- Tensor<rank,dim> tt = t;
- tt *= factor;
- return tt;
-}
-
-
-
-/**
- * Multiplication of a tensor of general rank with a scalar double from the
- * left.
- *
- * @relates Tensor
- */
-template <int rank, int dim>
-inline
-Tensor<rank,dim>
-operator * (const double factor,
- const Tensor<rank,dim> &t)
-{
- Tensor<rank,dim> tt = t;
- tt *= factor;
- return tt;
-}
-
-
-
-/**
- * Division of a tensor of general rank by a scalar double.
- *
- * @relates Tensor
- */
-template <int rank, int dim>
-inline
-Tensor<rank,dim>
-operator / (const Tensor<rank,dim> &t,
- const double factor)
-{
- Tensor<rank,dim> tt = t;
- tt /= factor;
- return tt;
-}
-
-
-
-/**
- * Multiplication of a tensor of general rank by a scalar complex<double> from
- * the left.
- *
- * @relates Tensor
- */
-template <int rank, int dim>
-inline
-Tensor<rank,dim,std::complex<double> >
-operator * (const std::complex<double> factor,
- const Tensor<rank,dim> &t)
-{
- Tensor<rank,dim,std::complex<double> > tt;
- for (unsigned int d=0; d<dim; ++d)
- tt[d] = factor * t[d];
- return tt;
-}
-
-
-
-/**
- * Multiplication of a tensor of general rank by a scalar complex<double> from
- * the right.
- *
- * @relates Tensor
- */
-template <int rank, int dim>
-inline
-Tensor<rank,dim,std::complex<double> >
-operator * (const Tensor<rank,dim> &t,
- const std::complex<double> factor)
-{
- Tensor<rank,dim,std::complex<double> > tt;
- for (unsigned int d=0; d<dim; ++d)
- tt[d] = t[d] * factor;
- return tt;
-}
-
-
-
DEAL_II_NAMESPACE_CLOSE
#endif
}
+
template <int dim, typename Number>
template <class Archive>
inline
#endif // DOXYGEN
+
/**
* Output operator for tensors of rank 0. Since such tensors are scalars, we
* simply print this one value.
-/**
- * Multiplication of a tensor of rank 1 with a scalar Number from the right.
- *
- * @relates Tensor<1,dim,Number>
- */
-template <int dim, typename Number>
-inline
-Tensor<1,dim,Number>
-operator * (const Tensor<1,dim,Number> &t,
- const Number factor)
-{
- Tensor<1,dim,Number> tt (false);
- for (unsigned int d=0; d<dim; ++d)
- tt[d] = t[d] * factor;
- return tt;
-}
-
-
-
-/**
- * Multiplication of a tensor of rank 1 with a scalar Number from the left.
- *
- * @relates Tensor<1,dim,Number>
- */
-template <int dim, typename Number>
-inline
-Tensor<1,dim,Number>
-operator * (const Number factor,
- const Tensor<1,dim,Number> &t)
-{
- Tensor<1,dim,Number> tt (false);
- for (unsigned int d=0; d<dim; ++d)
- tt[d] = t[d] * factor;
- return tt;
-}
-
-
#ifndef DEAL_II_WITH_CXX11
-template <typename T, typename U, int dim>
-struct ProductType<T,Tensor<1,dim,U> >
+template <typename T, typename U, int rank, int dim>
+struct ProductType<T,Tensor<rank,dim,U> >
{
- typedef Tensor<1,dim,typename ProductType<T,U>::type> type;
+ typedef Tensor<rank,dim,typename ProductType<T,U>::type> type;
};
-template <typename T, typename U, int dim>
-struct ProductType<Tensor<1,dim,T>,U>
+template <typename T, typename U, int rank, int dim>
+struct ProductType<Tensor<rank,dim,T>,U>
{
- typedef Tensor<1,dim,typename ProductType<T,U>::type> type;
+ typedef Tensor<rank,dim,typename ProductType<T,U>::type> type;
};
#endif
+
+
/**
- * Multiplication of a tensor of rank 1 with a scalar number from the right.
+ * Multiplication of a tensor of 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
* you would get if you multiplied an individual component of the input tensor
* by the scalar factor.
*
- * @relates Tensor<1,dim,Number>
- * @relates EnableIfScalar
- */
-template <int dim, typename Number, typename OtherNumber>
-inline
-Tensor<1,dim,typename ProductType<Number,typename EnableIfScalar<OtherNumber>::type>::type>
-operator * (const Tensor<1,dim,Number> &t,
- const OtherNumber factor)
-{
- // form the product. we have to convert the two factors into the final
- // type via explicit casts because, for awkward reasons, the C++
- // standard committee saw it fit to not define an
- // operator*(float,std::complex<double>)
- // (as well as with switched arguments and double<->float).
- typedef typename ProductType<Number,OtherNumber>::type product_type;
- Tensor<1,dim,product_type> tt (false);
- for (unsigned int d=0; d<dim; ++d)
- tt[d] = product_type(t[d]) * product_type(factor);
- return tt;
-}
-
-
-
-/**
- * Multiplication of a tensor of rank 1 with a scalar number from the left.
- * See the discussion with the operator with switched arguments for more
- * information about template arguments and the return type.
- *
- * @relates Tensor<1,dim,Number>
+ * @relates Tensor
* @relates EnableIfScalar
*/
-template <int dim, typename Number, typename OtherNumber>
+template <int rank, int dim,
+ typename Number,
+ typename OtherNumber,
+ typename = typename EnableIfScalar<OtherNumber>::type>
inline
-Tensor<1,dim,typename ProductType<Number,typename EnableIfScalar<OtherNumber>::type>::type>
-operator * (const Number factor,
- const Tensor<1,dim,OtherNumber> &t)
+Tensor<rank,dim,typename ProductType<Number, OtherNumber>::type>
+operator * (const Tensor<rank,dim,Number> &t,
+ const OtherNumber factor)
{
- // simply forward to the other operator with switched arguments
- return (t*factor);
-}
-
-
-
-/**
- * Division of a tensor of rank 1 by a scalar Number.
- *
- * @relates Tensor<1,dim,Number>
- */
-template <int dim, typename Number>
-inline
-Tensor<1,dim,Number>
-operator / (const Tensor<1,dim,Number> &t,
- const Number factor)
-{
- Tensor<1,dim,Number> tt (false);
- for (unsigned int d=0; d<dim; ++d)
- tt[d] = t[d] / factor;
- return tt;
-}
-
-
-
-/**
- * Multiplication of a tensor of rank 1 with a scalar double from the right.
- *
- * @relates Tensor<1,dim,Number>
- */
-template <int dim>
-inline
-Tensor<1,dim>
-operator * (const Tensor<1,dim> &t,
- const double factor)
-{
- Tensor<1,dim> tt (false);
+ // recurse over the base objects
+ Tensor<rank,dim,typename ProductType<Number,OtherNumber>::type> tt;
for (unsigned int d=0; d<dim; ++d)
tt[d] = t[d] * factor;
return tt;
/**
- * Multiplication of a tensor of rank 1 with a scalar double from the left.
+ * 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
+ * information about template arguments and the return type.
*
- * @relates Tensor<1,dim,Number>
+ * @relates Tensor
+ * @relates EnableIfScalar
*/
-template <int dim>
+template <int rank, int dim,
+ typename Number,
+ typename OtherNumber,
+ typename = typename EnableIfScalar<OtherNumber>::type>
inline
-Tensor<1,dim>
-operator * (const double factor,
- const Tensor<1,dim> &t)
+Tensor<rank,dim,typename ProductType<Number, OtherNumber>::type>
+operator * (const Number factor,
+ const Tensor<rank,dim,OtherNumber> &t)
{
- Tensor<1,dim> tt (false);
- for (unsigned int d=0; d<dim; ++d)
- tt[d] = t[d] * factor;
- return tt;
+ // simply forward to the operator above
+ return t * factor;
}
/**
- * Division of a tensor of rank 1 by a scalar double.
+ * Division of a tensor of general rank with a scalar number. See the
+ * discussion on operator*() above for more information about template
+ * arguments and the return type.
*
- * @relates Tensor<1,dim,Number>
+ * @relates Tensor
+ * @relates EnableIfScalar
*/
-template <int dim>
+template <int rank, int dim,
+ typename Number,
+ typename OtherNumber,
+ typename = typename EnableIfScalar<OtherNumber>::type>
inline
-Tensor<1,dim>
-operator / (const Tensor<1,dim> &t,
- const double factor)
+Tensor<rank,dim,typename ProductType<Number, OtherNumber>::type>
+operator / (const Tensor<rank,dim,Number> &t,
+ const OtherNumber factor)
{
- Tensor<1,dim> tt (false);
+ // recurse over the base objects
+ Tensor<rank,dim,typename ProductType<Number,OtherNumber>::type> tt;
for (unsigned int d=0; d<dim; ++d)
tt[d] = t[d] / factor;
return tt;
-/**
- * Multiplication of a tensor of rank 1 by a scalar complex<double> from the
- * right.
- *
- * @relates Tensor<1,dim,Number>
- */
-template <int dim>
-inline
-Tensor<1,dim,std::complex<double> >
-operator * (const Tensor<1,dim> &t,
- const std::complex<double> factor)
-{
- Tensor<1,dim,std::complex<double> > tt (false);
- for (unsigned int d=0; d<dim; ++d)
- tt[d] = t[d] * factor;
- return tt;
-}
-
-
-
-/**
- * Multiplication of a tensor of rank 1 by a scalar complex<double> from the
- * left.
- *
- * @relates Tensor<1,dim,Number>
- */
-template <int dim>
-inline
-Tensor<1,dim,std::complex<double> >
-operator * (const std::complex<double> factor,
- const Tensor<1,dim> &t)
-{
- Tensor<1,dim,std::complex<double> > tt (false);
- for (unsigned int d=0; d<dim; ++d)
- tt[d] = t[d] * factor;
- return tt;
-}
-
-
-
DEAL_II_NAMESPACE_CLOSE
#endif