From ab67ed22932f45e353b2c71ad4080e83e85f10d8 Mon Sep 17 00:00:00 2001 From: Jean-Paul Pelteret Date: Wed, 17 Apr 2019 22:27:00 +0200 Subject: [PATCH] Add ProductType for SD::Expression class. This is the first step towards support of SD::Expression within the Tensor and SymmetricTensor classes. --- include/deal.II/differentiation/sd.h | 1 + .../sd/symengine_product_types.h | 121 ++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 include/deal.II/differentiation/sd/symengine_product_types.h diff --git a/include/deal.II/differentiation/sd.h b/include/deal.II/differentiation/sd.h index 2050e6a509..5039e8a4a2 100644 --- a/include/deal.II/differentiation/sd.h +++ b/include/deal.II/differentiation/sd.h @@ -23,6 +23,7 @@ # include # include # include +# include # include # include # include diff --git a/include/deal.II/differentiation/sd/symengine_product_types.h b/include/deal.II/differentiation/sd/symengine_product_types.h new file mode 100644 index 0000000000..06d78aa6c5 --- /dev/null +++ b/include/deal.II/differentiation/sd/symengine_product_types.h @@ -0,0 +1,121 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2019 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_differentiation_sd_symengine_product_types_h +#define dealii_differentiation_sd_symengine_product_types_h + +#include + +#ifdef DEAL_II_WITH_SYMENGINE + + +# include + +# include + +# include + +# include + + +DEAL_II_NAMESPACE_OPEN + + +template <> +struct EnableIfScalar +{ + typedef Differentiation::SD::Expression type; +}; + + +namespace internal +{ + namespace SD + { + /** + * A more general implementation of product types. + * There are so many permutation of admissible operations + * that getting the compiler to determine the valid + * combinations using template metaprogramming makes + * more sense than manually maintaining the list by + * hand. + * + * This class is a workaround for issue of non-deduction + * of types in template partial specializations that + * would otherwise occur if trying to directly implement + * these as specializations of the ProductTypeImpl class + * itself. + * + * @author Jean-Paul Pelteret, 2019 + */ + template + struct GeneralProductTypeImpl; + + template + struct GeneralProductTypeImpl< + T, + Differentiation::SD::Expression, + typename std::enable_if::value>::type> + { + typedef Differentiation::SD::Expression type; + }; + + template + struct GeneralProductTypeImpl< + T, + Differentiation::SD::Expression, + typename std::enable_if< + boost::is_complex::value && + std::is_arithmetic::value>::type> + { + typedef Differentiation::SD::Expression type; + }; + + } // namespace SD + + + template <> + struct ProductTypeImpl + { + typedef Differentiation::SD::Expression type; + }; + + + template + struct ProductTypeImpl + { + typedef + typename SD::GeneralProductTypeImpl::type + type; + }; + + template + struct ProductTypeImpl + { + typedef + typename SD::GeneralProductTypeImpl::type + type; + }; + +} // namespace internal + +DEAL_II_NAMESPACE_CLOSE + +#endif // DEAL_II_WITH_SYMENGINE + +#endif -- 2.39.5