/**
* Constructor, where the data is copied from a C-style array.
*/
- Tensor (const value_type &initializer);
+ template <typename OtherNumber>
+ Tensor (const OtherNumber initializer);
/**
* Conversion to Number. Since rank-0 tensors are scalars, this is a natural
template <int dim, typename Number>
+template <typename OtherNumber>
inline
-Tensor<0,dim,Number>::Tensor (const value_type &initializer)
+Tensor<0,dim,Number>::Tensor (const OtherNumber initializer)
{
Assert (dim>0, ExcDimTooSmall(dim));
typename = typename EnableIfScalar<OtherNumber>::type>
inline
Tensor<0,dim,typename ProductType<OtherNumber, Number>::type>
-operator * (const Number factor,
- const Tensor<0,dim,OtherNumber> &t)
+operator * (const OtherNumber factor,
+ const Tensor<0,dim,Number> &t)
{
return factor * static_cast<Number>(t);
}
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 1998 - 2015 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+#include "../tests.h"
+#include <deal.II/base/tensor.h>
+
+#include<complex>
+
+int main ()
+{
+ initlog();
+
+ {
+ dealii::Tensor<0,3,float> f = 2.;
+ dealii::Tensor<0,3,double> d = 4.;
+ dealii::Tensor<0,3,std::complex<double> > c = 8.;
+
+ deallog << f + d << std::endl;
+ deallog << f - d << std::endl;
+ deallog << f * d << std::endl;
+
+ deallog << d + c << std::endl;
+ deallog << d - c << std::endl;
+ deallog << d * c << std::endl;
+
+ float f_scalar = 10.;
+ deallog << (d * f_scalar) << std::endl;
+ deallog << (d / f_scalar) << std::endl;
+ deallog << (f_scalar * d) << std::endl;
+ deallog << (d *= f_scalar) << std::endl;
+ deallog << (d /= f_scalar) << std::endl;
+
+ double d_scalar = 10.;
+ deallog << (c * d_scalar) << std::endl;
+ deallog << (c / d_scalar) << std::endl;
+ deallog << (d_scalar * c) << std::endl;
+ deallog << (c *= d_scalar) << std::endl;
+ deallog << (c /= d_scalar) << std::endl;
+ }
+
+ {
+ dealii::Tensor<1,2,float> f = { {1., 2.} };
+ dealii::Tensor<1,2,double> d = { {4., 8.} };
+ dealii::Tensor<1,2,std::complex<double> > c = { {16., 32.} };
+
+ deallog << f + d << std::endl;
+ deallog << f - d << std::endl;
+ deallog << f * d << std::endl;
+
+ deallog << d + c << std::endl;
+ deallog << d - c << std::endl;
+ deallog << d * c << std::endl;
+
+ float f_scalar = 10.;
+ deallog << (d * f_scalar) << std::endl;
+ deallog << (d / f_scalar) << std::endl;
+ deallog << (f_scalar * d) << std::endl;
+ deallog << (d *= f_scalar) << std::endl;
+ deallog << (d /= f_scalar) << std::endl;
+
+ double d_scalar = 10.;
+ deallog << (c * d_scalar) << std::endl;
+ deallog << (c / d_scalar) << std::endl;
+ deallog << (d_scalar * c) << std::endl;
+ deallog << (c *= d_scalar) << std::endl;
+ deallog << (c /= d_scalar) << std::endl;
+ }
+
+ {
+ dealii::Tensor<1,3,float> f = { {1., 2., 4.} };
+ dealii::Tensor<1,3,double> d = { {4., 8., 16.} };
+ dealii::Tensor<1,3,std::complex<double> > c = { {32., 64., 128.} };
+
+ deallog << f + d << std::endl;
+ deallog << f - d << std::endl;
+ deallog << f * d << std::endl;
+
+ deallog << d + c << std::endl;
+ deallog << d - c << std::endl;
+ deallog << d * c << std::endl;
+
+ float f_scalar = 10.;
+ deallog << (d * f_scalar) << std::endl;
+ deallog << (d / f_scalar) << std::endl;
+ deallog << (f_scalar * d) << std::endl;
+ deallog << (d *= f_scalar) << std::endl;
+ deallog << (d /= f_scalar) << std::endl;
+
+ double d_scalar = 10.;
+ deallog << (c * d_scalar) << std::endl;
+ deallog << (c / d_scalar) << std::endl;
+ deallog << (d_scalar * c) << std::endl;
+ deallog << (c *= d_scalar) << std::endl;
+ deallog << (c /= d_scalar) << std::endl;
+ }
+
+ deallog << "OK!" << std::endl;
+}
--- /dev/null
+
+DEAL::6.00000
+DEAL::-2.00000
+DEAL::8.00000
+DEAL::(12.0000,0.00000)
+DEAL::(-4.00000,0.00000)
+DEAL::(32.0000,0.00000)
+DEAL::40.0000
+DEAL::0.400000
+DEAL::40.0000
+DEAL::40.0000
+DEAL::4.00000
+DEAL::(80.0000,0.00000)
+DEAL::(0.800000,0.00000)
+DEAL::(80.0000,0.00000)
+DEAL::(80.0000,0.00000)
+DEAL::(8.00000,0.00000)
+DEAL::5.00000 10.0000
+DEAL::-3.00000 -6.00000
+DEAL::20.0000
+DEAL::(20.0000,0.00000) (40.0000,0.00000)
+DEAL::(-12.0000,0.00000) (-24.0000,0.00000)
+DEAL::(320.000,0.00000)
+DEAL::40.0000 80.0000
+DEAL::0.400000 0.800000
+DEAL::40.0000 80.0000
+DEAL::40.0000 80.0000
+DEAL::4.00000 8.00000
+DEAL::(160.000,0.00000) (320.000,0.00000)
+DEAL::(1.60000,0.00000) (3.20000,0.00000)
+DEAL::(160.000,0.00000) (320.000,0.00000)
+DEAL::(160.000,0.00000) (320.000,0.00000)
+DEAL::(16.0000,0.00000) (32.0000,0.00000)
+DEAL::OK!