--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 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.
+//
+// ---------------------------------------------------------------------
+
+#ifndef dealii__sacado_product_type_h
+#define dealii__sacado_product_type_h
+
+#include <deal.II/base/config.h>
+#include <deal.II/base/template_constraints.h>
+
+#ifdef DEAL_II_WITH_TRILINOS
+#include "Sacado.hpp"
+
+DEAL_II_NAMESPACE_OPEN
+
+template <typename T>
+struct ProductType<Sacado::Fad::DFad<T>, float>
+{
+ typedef Sacado::Fad::DFad<T> type;
+};
+
+template <typename T>
+struct ProductType<float, Sacado::Fad::DFad<T> >
+{
+ typedef Sacado::Fad::DFad<T> type;
+};
+
+template <typename T>
+struct ProductType<Sacado::Fad::DFad<T>, double>
+{
+ typedef Sacado::Fad::DFad<T> type;
+};
+
+template <typename T>
+struct ProductType<double, Sacado::Fad::DFad<T> >
+{
+ typedef Sacado::Fad::DFad<T> type;
+};
+
+template <typename T>
+struct ProductType<Sacado::Fad::DFad<T>, int>
+{
+ typedef Sacado::Fad::DFad<T> type;
+};
+
+template <typename T>
+struct ProductType<int, Sacado::Fad::DFad<T> >
+{
+ typedef Sacado::Fad::DFad<T> type;
+};
+
+template <typename T, typename U>
+struct ProductType<Sacado::Fad::DFad<T>, Sacado::Fad::DFad<U> >
+{
+ typedef Sacado::Fad::DFad<typename ProductType<T,U>::type > type;
+};
+
+template <typename T>
+struct EnableIfScalar<Sacado::Fad::DFad<T> >
+{
+ typedef Sacado::Fad::DFad<T> type;
+};
+
+
+/**
+ * Provide an <tt>operator*</tt> for a scalar multiplication of a
+ * sacado type with a different non-sacado type.
+ *
+ * @relates EnableIfScalar
+ * @relates ProductType
+ */
+
+template <typename T, typename U>
+typename ProductType<Sacado::Fad::DFad<T>, typename EnableIfScalar<U>::type>::type
+inline
+operator*(const Sacado::Fad::DFad<T> &left, const U &right)
+{
+ typedef typename ProductType<Sacado::Fad::DFad<T>, U>::type result_type;
+ return static_cast<result_type>(left) * static_cast<result_type>(right);
+}
+
+
+/**
+ * Provide an <tt>operator*</tt> for a scalar multiplication of non-sacado type with a sacado type.
+ *
+ * @relates EnableIfScalar
+ * @relates ProductType
+ */
+
+template <typename T, typename U>
+typename ProductType<typename EnableIfScalar<T>::type, Sacado::Fad::DFad<U> >::type
+inline
+operator*(const T &left, const Sacado::Fad::DFad<U> &right)
+{
+ typedef typename ProductType<T, Sacado::Fad::DFad<U> >::type result_type;
+ return static_cast<result_type>(left) * static_cast<result_type>(right);
+}
+
+/**
+ * Provide an <tt>operator*</tt> for a scalar multiplication of mixed
+ * sacado types.
+ *
+ * @relates EnableIfScalar
+ * @relates ProductType
+ */
+
+template <typename T, typename U>
+typename ProductType<Sacado::Fad::DFad<T>, Sacado::Fad::DFad<U> >::type
+inline
+operator*(const Sacado::Fad::DFad<T> &left, const Sacado::Fad::DFad<U> &right)
+{
+ typedef typename ProductType<Sacado::Fad::DFad<T>, Sacado::Fad::DFad<U> >::type result_type;
+ return static_cast<result_type>(left) * static_cast<result_type>(right);
+}
+
+#endif // DEAL_II_WITH_TRILINOS
+
+DEAL_II_NAMESPACE_CLOSE
+
+#endif
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 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.
+//
+// ---------------------------------------------------------------------
+
+
+// test ProductType with sacado
+
+#include <iomanip>
+#include <iomanip>
+#include <fstream>
+#include <cmath>
+#include <typeinfo>
+
+#include <deal.II/base/tensor.h>
+#include <deal.II/base/sacado_product_type.h>
+
+#include "../tests.h"
+
+template <typename T, typename U, typename CompareType>
+void check()
+{
+ AssertThrow (typeid(typename ProductType<T,U>::type) == typeid(CompareType),
+ ExcInternalError());
+ AssertThrow (typeid(typename ProductType<T,U>::type) == typeid(T() * U()),
+ ExcInternalError());
+}
+
+
+int main()
+{
+ typedef Sacado::Fad::DFad<double> Sdouble;
+ std::ofstream logfile("output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+
+ // check product of scalars
+ check<double,Sdouble,Sdouble>();
+ check<Sdouble,double,Sdouble>();
+
+ check<float,Sdouble,Sdouble>();
+ check<Sdouble,float,Sdouble>();
+
+ check<int,Sdouble,Sdouble>();
+ check<Sdouble,int,Sdouble>();
+
+ // check product with Tensor<1,dim>
+ check<Tensor<1,2,double>,Sdouble,Tensor<1,2,Sdouble> >();
+ check<Tensor<1,2,Sdouble>,double,Tensor<1,2,Sdouble> >();
+
+ check<Sdouble,Tensor<1,2,double>,Tensor<1,2,Sdouble> >();
+ check<double,Tensor<1,2,Sdouble>,Tensor<1,2,Sdouble> >();
+
+ check<Tensor<1,2,float>,Sdouble,Tensor<1,2,Sdouble> >();
+ check<Tensor<1,2,Sdouble>,float,Tensor<1,2,Sdouble> >();
+
+ check<Sdouble,Tensor<1,2,float>,Tensor<1,2,Sdouble> >();
+ check<float,Tensor<1,2,Sdouble>,Tensor<1,2,Sdouble> >();
+
+ check<Tensor<1,2,int>,Sdouble,Tensor<1,2,Sdouble> >();
+ check<Tensor<1,2,Sdouble>,int,Tensor<1,2,Sdouble> >();
+
+ check<Sdouble,Tensor<1,2,int>,Tensor<1,2,Sdouble> >();
+ check<int,Tensor<1,2,Sdouble>,Tensor<1,2,Sdouble> >();
+
+ // check product with Tensor<2,dim> (which is a different class)
+ check<Tensor<2,2,double>,Sdouble,Tensor<2,2,Sdouble> >();
+ check<Tensor<2,2,Sdouble>,double,Tensor<2,2,Sdouble> >();
+
+ check<Sdouble,Tensor<2,2,double>,Tensor<2,2,Sdouble> >();
+ check<double,Tensor<2,2,Sdouble>,Tensor<2,2,Sdouble> >();
+
+ check<Tensor<2,2,float>,Sdouble,Tensor<2,2,Sdouble> >();
+ check<Tensor<2,2,Sdouble>,float,Tensor<2,2,Sdouble> >();
+
+ check<Sdouble,Tensor<2,2,float>,Tensor<2,2,Sdouble> >();
+ check<float,Tensor<2,2,Sdouble>,Tensor<2,2,Sdouble> >();
+
+ check<Tensor<2,2,int>,Sdouble,Tensor<2,2,Sdouble> >();
+ check<Tensor<2,2,Sdouble>,int,Tensor<2,2,Sdouble> >();
+
+ check<Sdouble,Tensor<2,2,int>,Tensor<2,2,Sdouble> >();
+ check<int,Tensor<2,2,Sdouble>,Tensor<2,2,Sdouble> >();
+
+ deallog << "OK" << std::endl;
+}
--- /dev/null
+
+DEAL::OK
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 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.
+//
+// ---------------------------------------------------------------------
+
+
+// test ProductType with sacado
+
+#include <iomanip>
+#include <iomanip>
+#include <fstream>
+#include <cmath>
+#include <typeinfo>
+
+#include <deal.II/base/tensor.h>
+#include <deal.II/base/sacado_product_type.h>
+
+#include "../tests.h"
+
+template <typename T, typename U, typename CompareType>
+void check()
+{
+ AssertThrow (typeid(typename ProductType<T,U>::type) == typeid(CompareType),
+ ExcInternalError());
+ AssertThrow (typeid(typename ProductType<T,U>::type) == typeid(T() * U()),
+ ExcInternalError());
+}
+
+
+int main()
+{
+ typedef Sacado::Fad::DFad<double> Sdouble;
+ typedef Sacado::Fad::DFad<Sdouble> SSdouble;
+ std::ofstream logfile("output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+
+ // check product of scalars
+ check<double,SSdouble,SSdouble>();
+ check<SSdouble,double,SSdouble>();
+
+ check<float,SSdouble,SSdouble>();
+ check<SSdouble,float,SSdouble>();
+
+ check<int,SSdouble,SSdouble>();
+ check<SSdouble,int,SSdouble>();
+
+ // check product with Tensor<1,dim>
+ check<Tensor<1,2,double>,SSdouble,Tensor<1,2,SSdouble> >();
+ check<Tensor<1,2,SSdouble>,double,Tensor<1,2,SSdouble> >();
+
+ check<SSdouble,Tensor<1,2,double>,Tensor<1,2,SSdouble> >();
+ check<double,Tensor<1,2,SSdouble>,Tensor<1,2,SSdouble> >();
+
+ check<Tensor<1,2,float>,SSdouble,Tensor<1,2,SSdouble> >();
+ check<Tensor<1,2,SSdouble>,float,Tensor<1,2,SSdouble> >();
+
+ check<SSdouble,Tensor<1,2,float>,Tensor<1,2,SSdouble> >();
+ check<float,Tensor<1,2,SSdouble>,Tensor<1,2,SSdouble> >();
+
+ check<Tensor<1,2,int>,SSdouble,Tensor<1,2,SSdouble> >();
+ check<Tensor<1,2,SSdouble>,int,Tensor<1,2,SSdouble> >();
+
+ check<SSdouble,Tensor<1,2,int>,Tensor<1,2,SSdouble> >();
+ check<int,Tensor<1,2,SSdouble>,Tensor<1,2,SSdouble> >();
+
+ // check product with Tensor<2,dim> (which is a different class)
+ check<Tensor<2,2,double>,SSdouble,Tensor<2,2,SSdouble> >();
+ check<Tensor<2,2,SSdouble>,double,Tensor<2,2,SSdouble> >();
+
+ check<SSdouble,Tensor<2,2,double>,Tensor<2,2,SSdouble> >();
+ check<double,Tensor<2,2,SSdouble>,Tensor<2,2,SSdouble> >();
+
+ check<Tensor<2,2,float>,SSdouble,Tensor<2,2,SSdouble> >();
+ check<Tensor<2,2,SSdouble>,float,Tensor<2,2,SSdouble> >();
+
+ check<SSdouble,Tensor<2,2,float>,Tensor<2,2,SSdouble> >();
+ check<float,Tensor<2,2,SSdouble>,Tensor<2,2,SSdouble> >();
+
+ check<Tensor<2,2,int>,SSdouble,Tensor<2,2,SSdouble> >();
+ check<Tensor<2,2,SSdouble>,int,Tensor<2,2,SSdouble> >();
+
+ check<SSdouble,Tensor<2,2,int>,Tensor<2,2,SSdouble> >();
+ check<int,Tensor<2,2,SSdouble>,Tensor<2,2,SSdouble> >();
+
+ deallog << "OK" << std::endl;
+}
--- /dev/null
+
+DEAL::OK
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 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.
+//
+// ---------------------------------------------------------------------
+
+
+// test ProductType with sacado
+
+#include <iomanip>
+#include <iomanip>
+#include <fstream>
+#include <cmath>
+#include <typeinfo>
+
+#include <deal.II/base/tensor.h>
+#include <deal.II/base/sacado_product_type.h>
+
+#include "../tests.h"
+
+template <typename T, typename U, typename CompareType>
+void check()
+{
+ AssertThrow (typeid(typename ProductType<T,U>::type) == typeid(CompareType),
+ ExcInternalError());
+ AssertThrow (typeid(typename ProductType<T,U>::type) == typeid(T() * U()),
+ ExcInternalError());
+}
+
+
+int main()
+{
+ typedef Sacado::Fad::DFad<double> Sdouble;
+ typedef Sacado::Fad::DFad<Sdouble> SSdouble;
+ std::ofstream logfile("output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+
+ // check product of scalars
+ check<Sdouble,SSdouble,SSdouble>();
+ check<SSdouble,Sdouble,SSdouble>();
+
+ // check product with Tensor<1,dim>
+ check<Tensor<1,2,Sdouble>,SSdouble,Tensor<1,2,SSdouble> >();
+ check<Tensor<1,2,SSdouble>,Sdouble,Tensor<1,2,SSdouble> >();
+
+ check<SSdouble,Tensor<1,2,Sdouble>,Tensor<1,2,SSdouble> >();
+ check<Sdouble,Tensor<1,2,SSdouble>,Tensor<1,2,SSdouble> >();
+
+ // check product with Tensor<2,dim> (which is a different class)
+ check<Tensor<2,2,Sdouble>,SSdouble,Tensor<2,2,SSdouble> >();
+ check<Tensor<2,2,SSdouble>,Sdouble,Tensor<2,2,SSdouble> >();
+
+ check<SSdouble,Tensor<2,2,Sdouble>,Tensor<2,2,SSdouble> >();
+ check<Sdouble,Tensor<2,2,SSdouble>,Tensor<2,2,SSdouble> >();
+
+ deallog << "OK" << std::endl;
+}
--- /dev/null
+
+DEAL::OK