From b8d519875871194b09b8321a02aefb992c5f455b Mon Sep 17 00:00:00 2001 From: Jean-Paul Pelteret Date: Fri, 3 Nov 2017 19:56:53 +0100 Subject: [PATCH] Implement ProductType for Adol-C numbers --- .../differentiation/ad/adolc_product_types.h | 282 ++++++++++++++++++ 1 file changed, 282 insertions(+) create mode 100644 include/deal.II/differentiation/ad/adolc_product_types.h diff --git a/include/deal.II/differentiation/ad/adolc_product_types.h b/include/deal.II/differentiation/ad/adolc_product_types.h new file mode 100644 index 0000000000..eb62f82dba --- /dev/null +++ b/include/deal.II/differentiation/ad/adolc_product_types.h @@ -0,0 +1,282 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2016 - 2017 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_ad_adolc_product_types_h +#define dealii_differentiation_ad_adolc_product_types_h + +#include + +#ifdef DEAL_II_WITH_ADOLC + +#include + +DEAL_II_DISABLE_EXTRA_DIAGNOSTICS +#include // Taped double +#include // Tapeless double +DEAL_II_ENABLE_EXTRA_DIAGNOSTICS + +DEAL_II_NAMESPACE_OPEN + + +/* -------------- Adol-C taped (Differentiation::AD::NumberTypes::adolc_taped) -------------- */ + + +namespace internal +{ + + template <> + struct ProductTypeImpl + { + typedef adouble type; + }; + + // Typedefs for "adub"s are all thats necessary to ensure that no temporary Adol-C types + // "adub" are created when a scalar product is performed. + // If this is not done, then intermediate tensors are filled with unconstructable types. + template <> + struct ProductTypeImpl + { + typedef adouble type; + }; + + template <> + struct ProductTypeImpl + { + typedef adouble type; + }; + + /* --- Double --- */ + + template <> + struct ProductTypeImpl + { + typedef adouble type; + }; + + template <> + struct ProductTypeImpl + { + typedef adouble type; + }; + + template <> + struct ProductTypeImpl + { + typedef adouble type; + }; + + template <> + struct ProductTypeImpl + { + typedef adouble type; + }; + + /* --- Float --- */ + + template <> + struct ProductTypeImpl + { + typedef adouble type; + }; + + template <> + struct ProductTypeImpl + { + typedef adouble type; + }; + + template <> + struct ProductTypeImpl + { + typedef adouble type; + }; + + template <> + struct ProductTypeImpl + { + typedef adouble type; + }; + + /* --- Complex double --- */ + + template <> + struct ProductTypeImpl ,std::complex > + { + typedef std::complex type; + }; + + template <> + struct ProductTypeImpl, std::complex > + { + typedef std::complex type; + }; + + template <> + struct ProductTypeImpl< std::complex, std::complex > + { + typedef std::complex type; + }; + + template <> + struct ProductTypeImpl ,std::complex > + { + typedef std::complex type; + }; + + template <> + struct ProductTypeImpl, std::complex > + { + typedef std::complex type; + }; + + /* --- Complex float --- */ + + template <> + struct ProductTypeImpl ,std::complex > + { + typedef std::complex type; + }; + + template <> + struct ProductTypeImpl, std::complex > + { + typedef std::complex type; + }; + +} + +template <> +struct EnableIfScalar +{ + typedef adouble type; +}; + +template <> +struct EnableIfScalar > +{ + typedef std::complex type; +}; + + +template <> +struct EnableIfScalar +{ + typedef adouble type; +}; + + +template <> +struct EnableIfScalar > +{ + typedef std::complex type; +}; + + +/* -------------- Adol-C tapeless (Differentiation::AD::NumberTypes::adolc_tapeless) -------------- */ + + +namespace internal +{ + + /* --- Double --- */ + + template <> + struct ProductTypeImpl + { + typedef adtl::adouble type; + }; + + template <> + struct ProductTypeImpl + { + typedef adtl::adouble type; + }; + + template <> + struct ProductTypeImpl + { + typedef adtl::adouble type; + }; + + /* --- Float --- */ + + template <> + struct ProductTypeImpl + { + typedef adtl::adouble type; + }; + + template <> + struct ProductTypeImpl + { + typedef adtl::adouble type; + }; + + /* --- Complex double --- */ + + template <> + struct ProductTypeImpl,std::complex > + { + typedef std::complex type; + }; + + template <> + struct ProductTypeImpl,std::complex > + { + typedef std::complex type; + }; + + template <> + struct ProductTypeImpl,std::complex > + { + typedef std::complex type; + }; + + /* --- Complex float --- */ + + template <> + struct ProductTypeImpl,std::complex > + { + typedef std::complex type; + }; + + template <> + struct ProductTypeImpl,std::complex > + { + typedef std::complex type; + }; + +} + + +template <> +struct EnableIfScalar +{ + typedef adtl::adouble type; +}; + + +template <> +struct EnableIfScalar > +{ + typedef std::complex type; +}; + + +DEAL_II_NAMESPACE_CLOSE + +#endif // DEAL_II_WITH_ADOLC + +#endif -- 2.39.5