16 #ifndef dealii_differentiation_ad_sacado_number_types_h 17 #define dealii_differentiation_ad_sacado_number_types_h 19 #include <deal.II/base/config.h> 20 #include <type_traits> 23 DEAL_II_NAMESPACE_OPEN
38 template <
typename NumberType,
typename =
void>
51 template <
typename NumberType,
typename =
void>
64 template <
typename NumberType,
typename =
void>
73 DEAL_II_NAMESPACE_CLOSE
77 #ifdef DEAL_II_WITH_TRILINOS 79 DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
85 #include <Sacado_Fad_DFad.hpp> 87 #include <Sacado_trad.hpp> 88 DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
90 #include <deal.II/base/numbers.h> 91 #include <deal.II/base/exceptions.h> 93 #include <deal.II/differentiation/ad/ad_number_types.h> 94 #include <deal.II/differentiation/ad/ad_number_traits.h> 97 #include <type_traits> 99 DEAL_II_NAMESPACE_OPEN
119 template <
typename SacadoNumber,
typename =
void>
163 template <
typename SacadoNumber>
164 struct SacadoNumberInfo<SacadoNumber, typename
std::enable_if<
165 std::is_same<SacadoNumber,Sacado::Fad::DFad<typename SacadoNumber::value_type> >::value
168 typedef SacadoNumber ad_type;
169 typedef typename ad_type::scalar_type scalar_type;
170 typedef typename ad_type::value_type value_type;
171 typedef typename ad_type::value_type derivative_type;
173 static const unsigned int n_supported_derivative_levels
174 = 1 + SacadoNumberInfo<derivative_type>::n_supported_derivative_levels;
181 template <
typename SacadoNumber>
182 struct SacadoNumberInfo<SacadoNumber, typename
std::enable_if<
183 std::is_same<SacadoNumber,Sacado::Rad::ADvar<typename SacadoNumber::value_type> >::value
186 typedef SacadoNumber ad_type;
187 typedef typename ad_type::ADVari::scalar_type scalar_type;
188 typedef typename ad_type::ADVari::value_type value_type;
189 typedef typename ad_type::ADVari::value_type derivative_type;
191 static const unsigned int n_supported_derivative_levels
192 = 1 + SacadoNumberInfo<derivative_type>::n_supported_derivative_levels;
202 template <
typename Number>
203 struct SacadoNumberInfo<Number, typename
std::enable_if<
204 std::is_arithmetic<typename std::decay<Number>::type>::value
207 static const unsigned int n_supported_derivative_levels = 0;
215 template<
typename ScalarType>
217 typename std::enable_if<std::is_floating_point<ScalarType>::value>::type
220 static const bool is_taped =
false;
221 typedef Sacado::Fad::DFad<ScalarType> real_type;
222 typedef typename SacadoNumberInfo<real_type>::derivative_type derivative_type;
223 static const unsigned int n_supported_derivative_levels
224 = SacadoNumberInfo<real_type>::n_supported_derivative_levels;
232 template<
typename ScalarType>
234 typename std::enable_if<std::is_floating_point<ScalarType>::value>::type
237 static const bool is_taped =
false;
238 typedef Sacado::Fad::DFad< Sacado::Fad::DFad<ScalarType> > real_type;
239 typedef typename SacadoNumberInfo<real_type>::derivative_type derivative_type;
240 static const unsigned int n_supported_derivative_levels
241 = SacadoNumberInfo<real_type>::n_supported_derivative_levels;
249 template<
typename ScalarType>
251 typename std::enable_if<std::is_floating_point<ScalarType>::value>::type
254 static const bool is_taped =
false;
255 typedef Sacado::Rad::ADvar<ScalarType> real_type;
256 typedef typename SacadoNumberInfo<real_type>::derivative_type derivative_type;
257 static const unsigned int n_supported_derivative_levels
258 = SacadoNumberInfo<real_type>::n_supported_derivative_levels;
266 template<
typename ScalarType>
268 typename std::enable_if<std::is_floating_point<ScalarType>::value>::type
271 static const bool is_taped =
false;
272 typedef Sacado::Rad::ADvar< Sacado::Fad::DFad<ScalarType> > real_type;
273 typedef typename SacadoNumberInfo<real_type>::derivative_type derivative_type;
274 static const unsigned int n_supported_derivative_levels
275 = SacadoNumberInfo<real_type>::n_supported_derivative_levels;
283 template<
typename NumberType>
284 struct Marking< Sacado::Fad::DFad<NumberType> >
286 typedef typename SacadoNumberInfo< Sacado::Fad::DFad<NumberType> >::ad_type ad_type;
287 typedef typename SacadoNumberInfo< Sacado::Fad::DFad<NumberType> >::derivative_type derivative_type;
288 typedef typename SacadoNumberInfo< Sacado::Fad::DFad<NumberType> >::scalar_type scalar_type;
294 independent_variable(
const scalar_type &in,
295 const unsigned int index,
296 const unsigned int n_independent_variables,
301 out = ad_type(n_independent_variables, index, in);
304 Marking<derivative_type>::independent_variable(
305 in, index, n_independent_variables, out.val());
312 dependent_variable(ad_type &out,
324 template<
typename NumberType>
325 struct Marking< Sacado::Rad::ADvar<NumberType> >
327 typedef typename SacadoNumberInfo< Sacado::Rad::ADvar<NumberType> >::ad_type ad_type;
328 typedef typename SacadoNumberInfo< Sacado::Rad::ADvar<NumberType> >::derivative_type derivative_type;
329 typedef typename SacadoNumberInfo< Sacado::Rad::ADvar<NumberType> >::scalar_type scalar_type;
335 independent_variable(
const scalar_type &in,
336 const unsigned int index,
337 const unsigned int n_independent_variables,
346 derivative_type derivative_initializer;
347 Marking<derivative_type>::independent_variable(
348 in, index, n_independent_variables,
349 derivative_initializer);
352 out = derivative_initializer;
359 dependent_variable(ad_type &out,
374 template<
typename NumberType>
375 struct ExtractData< Sacado::Fad::DFad<NumberType> >
377 typedef typename SacadoNumberInfo< Sacado::Fad::DFad<NumberType> >::derivative_type derivative_type;
378 typedef typename SacadoNumberInfo< Sacado::Fad::DFad<NumberType> >::scalar_type scalar_type;
379 typedef typename SacadoNumberInfo< Sacado::Fad::DFad<NumberType> >::value_type value_type;
385 value (
const Sacado::Fad::DFad<NumberType> &x)
387 return ExtractData<value_type>::value(x.val());
395 n_directional_derivatives (
const Sacado::Fad::DFad<NumberType> &x)
404 static derivative_type
405 directional_derivative (
const Sacado::Fad::DFad<NumberType> &x,
406 const unsigned int direction)
408 if (x.hasFastAccess())
409 return x.fastAccessDx(direction);
411 return x.dx(direction);
423 template<
typename NumberType>
424 struct ExtractData< Sacado::Rad::ADvar<NumberType> >
426 typedef typename SacadoNumberInfo< Sacado::Rad::ADvar<NumberType> >::derivative_type derivative_type;
427 typedef typename SacadoNumberInfo< Sacado::Rad::ADvar<NumberType> >::scalar_type scalar_type;
428 typedef typename SacadoNumberInfo< Sacado::Rad::ADvar<NumberType> >::value_type value_type;
434 value (
const Sacado::Rad::ADvar<NumberType> &x)
436 return ExtractData<value_type>::value(x.val());
444 n_directional_derivatives (
const Sacado::Rad::ADvar<NumberType> &)
460 static derivative_type
461 directional_derivative (
const Sacado::Rad::ADvar<NumberType> &x,
480 template<
typename ADNumberType>
481 struct ADNumberTraits<ADNumberType, typename
std::enable_if<
482 std::is_same<ADNumberType, Sacado::Fad::DFad<typename ADNumberType::scalar_type> >::value
484 : NumberTraits<typename ADNumberType::scalar_type, NumberTypes::sacado_dfad>
494 template<
typename ADNumberType>
495 struct ADNumberTraits<ADNumberType, typename
std::enable_if<
496 std::is_same<ADNumberType, std::complex<Sacado::Fad::DFad<typename ADNumberType::value_type::scalar_type> > >::value
498 : NumberTraits<std::complex<typename ADNumberType::value_type::scalar_type>, NumberTypes::sacado_dfad>
508 : NumberTraits<typename ADNumberTraits<Sacado::Fad::DFad<float> >::scalar_type,NumberTypes::sacado_dfad>
518 : NumberTraits<typename ADNumberTraits<std::complex< Sacado::Fad::DFad<float> > >::scalar_type,NumberTypes::sacado_dfad>
528 : NumberTraits<typename ADNumberTraits<Sacado::Fad::DFad<double> >::scalar_type,NumberTypes::sacado_dfad>
538 : NumberTraits<typename ADNumberTraits<std::complex< Sacado::Fad::DFad<double> > >::scalar_type,NumberTypes::sacado_dfad>
551 template<
typename ADNumberType>
552 struct ADNumberTraits<ADNumberType, typename
std::enable_if<
553 std::is_same<ADNumberType, Sacado::Rad::ADvar<typename ADNumberType::ADVari::scalar_type> >::value
555 : NumberTraits<typename ADNumberType::ADVari::scalar_type, NumberTypes::sacado_rad>
565 : NumberTraits<typename ADNumberTraits<Sacado::Rad::ADvar<float> >::scalar_type,NumberTypes::sacado_rad>
575 : NumberTraits<typename ADNumberTraits<Sacado::Rad::ADvar<double> >::scalar_type,NumberTypes::sacado_rad>
579 #ifdef DEAL_II_TRILINOS_CXX_SUPPORTS_SACADO_COMPLEX_RAD 588 template<
typename ADNumberType>
589 struct ADNumberTraits<ADNumberType, typename
std::enable_if<
590 std::is_same<ADNumberType, std::complex<Sacado::Rad::ADvar<typename ADNumberType::value_type::ADVari::scalar_type> > >::value
592 : NumberTraits<std::complex<typename ADNumberType::value_type::ADVari::scalar_type>, NumberTypes::sacado_rad>
602 : NumberTraits<typename ADNumberTraits<std::complex< Sacado::Rad::ADvar<float> > >::scalar_type,NumberTypes::sacado_rad>
612 : NumberTraits<typename ADNumberTraits<std::complex< Sacado::Rad::ADvar<double> > >::scalar_type,NumberTypes::sacado_rad>
628 template<
typename ADNumberType>
629 struct ADNumberTraits<ADNumberType, typename
std::enable_if<
630 std::is_same<ADNumberType, Sacado::Fad::DFad<Sacado::Fad::DFad<typename ADNumberType::scalar_type> > >::value
632 : NumberTraits<typename ADNumberType::scalar_type, NumberTypes::sacado_dfad_dfad>
643 template<
typename ADNumberType>
644 struct ADNumberTraits<ADNumberType, typename
std::enable_if<
645 std::is_same<ADNumberType, std::complex<Sacado::Fad::DFad<Sacado::Fad::DFad<typename ADNumberType::value_type::scalar_type> > > >::value
647 : NumberTraits<std::complex<typename ADNumberType::value_type::scalar_type>, NumberTypes::sacado_dfad_dfad>
657 : NumberTraits<typename ADNumberTraits<Sacado::Fad::DFad<Sacado::Fad::DFad<float> > >::scalar_type,NumberTypes::sacado_dfad_dfad>
667 : NumberTraits<typename ADNumberTraits<std::complex< Sacado::Fad::DFad<Sacado::Fad::DFad<float> > > >::scalar_type,NumberTypes::sacado_dfad_dfad>
677 : NumberTraits<typename ADNumberTraits<Sacado::Fad::DFad<Sacado::Fad::DFad<double> > >::scalar_type,NumberTypes::sacado_dfad_dfad>
687 : NumberTraits<typename ADNumberTraits<std::complex< Sacado::Fad::DFad<Sacado::Fad::DFad<double> > > >::scalar_type,NumberTypes::sacado_dfad_dfad>
700 template<
typename ADNumberType>
701 struct ADNumberTraits<ADNumberType, typename
std::enable_if<
702 std::is_same<ADNumberType, Sacado::Rad::ADvar<Sacado::Fad::DFad<typename ADNumberType::ADVari::scalar_type> > >::value
704 : NumberTraits<typename ADNumberType::ADVari::scalar_type, NumberTypes::sacado_rad_dfad>
714 : NumberTraits<typename ADNumberTraits<Sacado::Rad::ADvar<Sacado::Fad::DFad<float> > >::scalar_type,NumberTypes::sacado_rad_dfad>
724 : NumberTraits<typename ADNumberTraits<Sacado::Rad::ADvar<Sacado::Fad::DFad<double> > >::scalar_type,NumberTypes::sacado_rad_dfad>
728 #ifdef DEAL_II_TRILINOS_CXX_SUPPORTS_SACADO_COMPLEX_RAD 738 template<
typename ADNumberType>
739 struct ADNumberTraits<ADNumberType, typename
std::enable_if<
740 std::is_same<ADNumberType, std::complex<Sacado::Rad::ADvar<Sacado::Fad::DFad<typename ADNumberType::value_type::ADVari::scalar_type> > > >::value
742 : NumberTraits<std::complex<typename ADNumberType::value_type::ADVari::scalar_type>, NumberTypes::sacado_rad_dfad>
752 : NumberTraits<typename ADNumberTraits<std::complex< Sacado::Rad::ADvar<Sacado::Fad::DFad<float> > > >::scalar_type,NumberTypes::sacado_rad_dfad>
762 : NumberTraits<typename ADNumberTraits<std::complex< Sacado::Rad::ADvar<Sacado::Fad::DFad<double> > > >::scalar_type,NumberTypes::sacado_rad_dfad>
772 template <
typename NumberType>
773 struct is_sacado_dfad_number<NumberType, typename
std::enable_if<
774 ADNumberTraits<typename std::decay<NumberType>::type>::type_code == NumberTypes::sacado_dfad ||
775 ADNumberTraits<typename std::decay<NumberType>::type>::type_code == NumberTypes::sacado_dfad_dfad
781 template <
typename NumberType>
782 struct is_sacado_rad_number<NumberType, typename
std::enable_if<
783 ADNumberTraits<typename std::decay<NumberType>::type>::type_code == NumberTypes::sacado_rad ||
784 ADNumberTraits<typename std::decay<NumberType>::type>::type_code == NumberTypes::sacado_rad_dfad
790 template <
typename NumberType>
791 struct is_sacado_number<NumberType, typename
std::enable_if<
792 is_sacado_dfad_number<NumberType>::value ||
793 is_sacado_rad_number<NumberType>::value
805 DEAL_II_NAMESPACE_CLOSE
808 #endif // DEAL_II_WITH_TRILINOS