]> https://gitweb.dealii.org/ - dealii.git/commitdiff
allow contraction of tensors of different base type 631/head
authorDenis Davydov <davydden@gmail.com>
Wed, 4 Feb 2015 14:20:03 +0000 (15:20 +0100)
committerDenis Davydov <davydden@gmail.com>
Mon, 2 Mar 2015 17:01:39 +0000 (18:01 +0100)
include/deal.II/base/tensor.h

index cabc4643fe3d0bb9f47ce8875dd68090259d0a99..c0a24c90990d7a26ecb3917ed799a0e3ade2d45d 100644 (file)
@@ -761,12 +761,13 @@ std::ostream &operator << (std::ostream &out, const Tensor<rank_,1> &p)
  * @relates Tensor
  * @author Guido Kanschat, 2000
  */
-template <int dim, typename Number>
+template <int dim, typename Number, typename OtherNumber>
 inline
-Number contract (const Tensor<1,dim,Number> &src1,
-                 const Tensor<1,dim,Number> &src2)
+typename ProductType<Number,OtherNumber>::type
+contract (const Tensor<1,dim,Number> &src1,
+          const Tensor<1,dim,OtherNumber> &src2)
 {
-  Number res = 0.;
+  typename ProductType<Number,OtherNumber>::type res = typename ProductType<Number,OtherNumber>::type();
   for (unsigned int i=0; i<dim; ++i)
     res += src1[i] * src2[i];
 
@@ -789,11 +790,11 @@ Number contract (const Tensor<1,dim,Number> &src1,
  * @relates Tensor
  * @author Wolfgang Bangerth, 2005
  */
-template <int dim, typename Number>
+template <int dim, typename Number, typename OtherNumber>
 inline
-Number
+typename ProductType<Number,OtherNumber>::type
 operator * (const Tensor<1,dim,Number> &src1,
-            const Tensor<1,dim,Number> &src2)
+            const Tensor<1,dim,OtherNumber> &src2)
 {
   return contract(src1, src2);
 }

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.