16#ifndef dealii_differentiation_ad_sacado_number_types_h
17#define dealii_differentiation_ad_sacado_number_types_h
36 template <
typename NumberType,
typename =
void>
46 template <
typename NumberType,
typename =
void>
56 template <
typename NumberType,
typename =
void>
68#ifdef DEAL_II_TRILINOS_WITH_SACADO
76# include <Sacado_Fad_DFad.hpp>
78# include <Sacado_trad.hpp>
104 template <
typename SacadoNumber,
typename =
void>
147 template <
typename SacadoNumber>
148 struct SacadoNumberInfo<
150 typename
std::enable_if<std::is_same<
152 Sacado::Fad::DFad<typename SacadoNumber::value_type>>::value>::type>
154 using ad_type = SacadoNumber;
155 using scalar_type =
typename ad_type::scalar_type;
156 using value_type =
typename ad_type::value_type;
157 using derivative_type =
typename ad_type::value_type;
159 static const unsigned int n_supported_derivative_levels =
160 1 + SacadoNumberInfo<derivative_type>::n_supported_derivative_levels;
167 template <
typename SacadoNumber>
168 struct SacadoNumberInfo<
170 typename
std::enable_if<std::is_same<
172 Sacado::Rad::ADvar<typename SacadoNumber::value_type>>::value>::type>
174 using ad_type = SacadoNumber;
175 using scalar_type =
typename ad_type::ADVari::scalar_type;
176 using value_type =
typename ad_type::ADVari::value_type;
177 using derivative_type =
typename ad_type::ADVari::value_type;
179 static const unsigned int n_supported_derivative_levels =
180 1 + SacadoNumberInfo<derivative_type>::n_supported_derivative_levels;
190 template <
typename Number>
191 struct SacadoNumberInfo<
193 typename
std::enable_if<
194 std::is_arithmetic<typename std::decay<Number>::type>::value>::type>
196 static const unsigned int n_supported_derivative_levels = 0;
204 template <
typename ScalarType>
205 struct ADNumberInfoFromEnum<
208 typename std::enable_if<
209 std::is_floating_point<ScalarType>::value>::type>
211 static const bool is_taped =
false;
212 using real_type = Sacado::Fad::DFad<ScalarType>;
213 using derivative_type =
214 typename SacadoNumberInfo<real_type>::derivative_type;
215 static const unsigned int n_supported_derivative_levels =
216 SacadoNumberInfo<real_type>::n_supported_derivative_levels;
224 template <
typename ScalarType>
225 struct ADNumberInfoFromEnum<
228 typename std::enable_if<
229 std::is_floating_point<ScalarType>::value>::type>
231 static const bool is_taped =
false;
232 using real_type = Sacado::Fad::DFad<Sacado::Fad::DFad<ScalarType>>;
233 using derivative_type =
234 typename SacadoNumberInfo<real_type>::derivative_type;
235 static const unsigned int n_supported_derivative_levels =
236 SacadoNumberInfo<real_type>::n_supported_derivative_levels;
244 template <
typename ScalarType>
245 struct ADNumberInfoFromEnum<
248 typename std::enable_if<
249 std::is_floating_point<ScalarType>::value>::type>
251 static const bool is_taped =
false;
252 using real_type = Sacado::Rad::ADvar<ScalarType>;
253 using derivative_type =
254 typename SacadoNumberInfo<real_type>::derivative_type;
255 static const unsigned int n_supported_derivative_levels =
256 SacadoNumberInfo<real_type>::n_supported_derivative_levels;
264 template <
typename ScalarType>
265 struct ADNumberInfoFromEnum<
268 typename std::enable_if<
269 std::is_floating_point<ScalarType>::value>::type>
271 static const bool is_taped =
false;
272 using real_type = Sacado::Rad::ADvar<Sacado::Fad::DFad<ScalarType>>;
273 using derivative_type =
274 typename SacadoNumberInfo<real_type>::derivative_type;
275 static const unsigned int n_supported_derivative_levels =
276 SacadoNumberInfo<real_type>::n_supported_derivative_levels;
284 template <
typename NumberType>
285 struct Marking<Sacado::Fad::DFad<NumberType>>
288 typename SacadoNumberInfo<Sacado::Fad::DFad<NumberType>>::ad_type;
289 using derivative_type =
typename SacadoNumberInfo<
290 Sacado::Fad::DFad<NumberType>>::derivative_type;
292 typename SacadoNumberInfo<Sacado::Fad::DFad<NumberType>>::scalar_type;
298 independent_variable(
const scalar_type &in,
299 const unsigned int index,
300 const unsigned int n_independent_variables,
305 out = ad_type(n_independent_variables, index, in);
308 Marking<derivative_type>::independent_variable(
309 in, index, n_independent_variables, out.val());
316 dependent_variable(ad_type &out,
const ad_type &func)
327 template <
typename NumberType>
328 struct Marking<Sacado::Rad::ADvar<NumberType>>
331 typename SacadoNumberInfo<Sacado::Rad::ADvar<NumberType>>::ad_type;
332 using derivative_type =
typename SacadoNumberInfo<
333 Sacado::Rad::ADvar<NumberType>>::derivative_type;
334 using scalar_type =
typename SacadoNumberInfo<
335 Sacado::Rad::ADvar<NumberType>>::scalar_type;
341 independent_variable(
const scalar_type &in,
342 const unsigned int index,
343 const unsigned int n_independent_variables,
352 derivative_type derivative_initializer;
353 Marking<derivative_type>::independent_variable(
354 in, index, n_independent_variables, derivative_initializer);
357 out = derivative_initializer;
364 dependent_variable(ad_type &out,
const ad_type &func)
376 template <
typename NumberType>
377 struct ExtractData<Sacado::Fad::DFad<NumberType>>
379 using derivative_type =
typename SacadoNumberInfo<
380 Sacado::Fad::DFad<NumberType>>::derivative_type;
382 typename SacadoNumberInfo<Sacado::Fad::DFad<NumberType>>::scalar_type;
384 typename SacadoNumberInfo<Sacado::Fad::DFad<NumberType>>::value_type;
390 value(
const Sacado::Fad::DFad<NumberType> &x)
392 return ExtractData<value_type>::value(x.val());
400 n_directional_derivatives(
const Sacado::Fad::DFad<NumberType> &x)
409 static derivative_type
410 directional_derivative(
const Sacado::Fad::DFad<NumberType> &x,
411 const unsigned int direction)
413 if (x.hasFastAccess())
414 return x.fastAccessDx(direction);
416 return x.dx(direction);
426 template <
typename NumberType>
427 struct ExtractData<Sacado::Rad::ADvar<NumberType>>
429 using derivative_type =
typename SacadoNumberInfo<
430 Sacado::Rad::ADvar<NumberType>>::derivative_type;
431 using scalar_type =
typename SacadoNumberInfo<
432 Sacado::Rad::ADvar<NumberType>>::scalar_type;
434 typename SacadoNumberInfo<Sacado::Rad::ADvar<NumberType>>::value_type;
440 value(
const Sacado::Rad::ADvar<NumberType> &x)
442 return ExtractData<value_type>::value(x.val());
450 n_directional_derivatives(
const Sacado::Rad::ADvar<NumberType> &)
466 static derivative_type
467 directional_derivative(
const Sacado::Rad::ADvar<NumberType> &x,
486 template <
typename ADNumberType>
487 struct ADNumberTraits<
489 typename
std::enable_if<std::is_same<
491 Sacado::Fad::DFad<typename ADNumberType::scalar_type>>::value>::type>
492 : NumberTraits<typename ADNumberType::scalar_type,
493 NumberTypes::sacado_dfad>
503 template <
typename ADNumberType>
504 struct ADNumberTraits<
506 typename
std::enable_if<std::is_same<
508 std::complex<Sacado::Fad::DFad<
509 typename ADNumberType::value_type::scalar_type>>>::value>::type>
511 std::complex<typename ADNumberType::value_type::scalar_type>,
512 NumberTypes::sacado_dfad>
523 typename ADNumberTraits<Sacado::Fad::DFad<float>>::scalar_type,
524 NumberTypes::sacado_dfad>
533 struct NumberTraits<
std::complex<Sacado::Fad::DFad<float>>,
535 : NumberTraits<typename ADNumberTraits<
536 std::complex<Sacado::Fad::DFad<float>>>::scalar_type,
537 NumberTypes::sacado_dfad>
548 typename ADNumberTraits<Sacado::Fad::DFad<double>>::scalar_type,
549 NumberTypes::sacado_dfad>
558 struct NumberTraits<
std::complex<Sacado::Fad::DFad<double>>,
560 : NumberTraits<typename ADNumberTraits<
561 std::complex<Sacado::Fad::DFad<double>>>::scalar_type,
562 NumberTypes::sacado_dfad>
575 template <
typename ADNumberType>
576 struct ADNumberTraits<
578 typename
std::enable_if<std::is_same<
580 Sacado::Rad::ADvar<typename ADNumberType::ADVari::scalar_type>>::
582 : NumberTraits<typename ADNumberType::ADVari::scalar_type,
583 NumberTypes::sacado_rad>
594 typename ADNumberTraits<Sacado::Rad::ADvar<float>>::scalar_type,
595 NumberTypes::sacado_rad>
606 typename ADNumberTraits<Sacado::Rad::ADvar<double>>::scalar_type,
607 NumberTypes::sacado_rad>
611# ifdef DEAL_II_TRILINOS_CXX_SUPPORTS_SACADO_COMPLEX_RAD
620 template <
typename ADNumberType>
621 struct ADNumberTraits<
623 typename
std::enable_if<std::is_same<
625 std::complex<Sacado::Rad::ADvar<typename ADNumberType::value_type::
626 ADVari::scalar_type>>>::value>::type>
628 std::complex<typename ADNumberType::value_type::ADVari::scalar_type>,
629 NumberTypes::sacado_rad>
638 struct NumberTraits<
std::complex<Sacado::Rad::ADvar<float>>,
640 : NumberTraits<typename ADNumberTraits<
641 std::complex<Sacado::Rad::ADvar<float>>>::scalar_type,
642 NumberTypes::sacado_rad>
651 struct NumberTraits<
std::complex<Sacado::Rad::ADvar<double>>,
653 : NumberTraits<typename ADNumberTraits<
654 std::complex<Sacado::Rad::ADvar<double>>>::scalar_type,
655 NumberTypes::sacado_rad>
671 template <
typename ADNumberType>
672 struct ADNumberTraits<
674 typename
std::enable_if<
675 std::is_same<ADNumberType,
676 Sacado::Fad::DFad<Sacado::Fad::DFad<
677 typename ADNumberType::scalar_type>>>::value>::type>
678 : NumberTraits<typename ADNumberType::scalar_type,
679 NumberTypes::sacado_dfad_dfad>
690 template <
typename ADNumberType>
691 struct ADNumberTraits<
693 typename
std::enable_if<std::is_same<
695 std::complex<Sacado::Fad::DFad<Sacado::Fad::DFad<
696 typename ADNumberType::value_type::scalar_type>>>>::value>::type>
698 std::complex<typename ADNumberType::value_type::scalar_type>,
699 NumberTypes::sacado_dfad_dfad>
708 struct NumberTraits<Sacado::Fad::DFad<Sacado::Fad::DFad<float>>,
710 : NumberTraits<typename ADNumberTraits<Sacado::Fad::DFad<
711 Sacado::Fad::DFad<float>>>::scalar_type,
712 NumberTypes::sacado_dfad_dfad>
722 std::complex<Sacado::Fad::DFad<Sacado::Fad::DFad<float>>>,
724 : NumberTraits<typename ADNumberTraits<std::complex<Sacado::Fad::DFad<
725 Sacado::Fad::DFad<float>>>>::scalar_type,
726 NumberTypes::sacado_dfad_dfad>
735 struct NumberTraits<Sacado::Fad::DFad<Sacado::Fad::DFad<double>>,
737 : NumberTraits<typename ADNumberTraits<Sacado::Fad::DFad<
738 Sacado::Fad::DFad<double>>>::scalar_type,
739 NumberTypes::sacado_dfad_dfad>
749 std::complex<Sacado::Fad::DFad<Sacado::Fad::DFad<double>>>,
751 : NumberTraits<typename ADNumberTraits<std::complex<Sacado::Fad::DFad<
752 Sacado::Fad::DFad<double>>>>::scalar_type,
753 NumberTypes::sacado_dfad_dfad>
766 template <
typename ADNumberType>
767 struct ADNumberTraits<
769 typename
std::enable_if<std::is_same<
771 Sacado::Rad::ADvar<Sacado::Fad::DFad<
772 typename ADNumberType::ADVari::scalar_type>>>::value>::type>
773 : NumberTraits<typename ADNumberType::ADVari::scalar_type,
774 NumberTypes::sacado_rad_dfad>
783 struct NumberTraits<Sacado::Rad::ADvar<Sacado::Fad::DFad<float>>,
785 : NumberTraits<typename ADNumberTraits<Sacado::Rad::ADvar<
786 Sacado::Fad::DFad<float>>>::scalar_type,
787 NumberTypes::sacado_rad_dfad>
796 struct NumberTraits<Sacado::Rad::ADvar<Sacado::Fad::DFad<double>>,
798 : NumberTraits<typename ADNumberTraits<Sacado::Rad::ADvar<
799 Sacado::Fad::DFad<double>>>::scalar_type,
800 NumberTypes::sacado_rad_dfad>
804# ifdef DEAL_II_TRILINOS_CXX_SUPPORTS_SACADO_COMPLEX_RAD
814 template <
typename ADNumberType>
815 struct ADNumberTraits<
817 typename
std::enable_if<std::is_same<
819 std::complex<Sacado::Rad::ADvar<Sacado::Fad::DFad<
820 typename ADNumberType::value_type::ADVari::scalar_type>>>>::value>::
823 std::complex<typename ADNumberType::value_type::ADVari::scalar_type>,
824 NumberTypes::sacado_rad_dfad>
834 std::complex<Sacado::Rad::ADvar<Sacado::Fad::DFad<float>>>,
836 : NumberTraits<typename ADNumberTraits<std::complex<Sacado::Rad::ADvar<
837 Sacado::Fad::DFad<float>>>>::scalar_type,
838 NumberTypes::sacado_rad_dfad>
848 std::complex<Sacado::Rad::ADvar<Sacado::Fad::DFad<double>>>,
850 : NumberTraits<typename ADNumberTraits<std::complex<Sacado::Rad::ADvar<
851 Sacado::Fad::DFad<double>>>>::scalar_type,
852 NumberTypes::sacado_rad_dfad>
862 template <
typename NumberType>
863 struct is_sacado_dfad_number<
865 typename
std::enable_if<
866 ADNumberTraits<typename std::decay<NumberType>::type>::type_code ==
867 NumberTypes::sacado_dfad ||
868 ADNumberTraits<typename std::decay<NumberType>::type>::type_code ==
869 NumberTypes::sacado_dfad_dfad>::type> : std::true_type
873 template <
typename NumberType>
874 struct is_sacado_dfad_number<
876 typename
std::enable_if<std::is_same<
878 Sacado::Fad::Expr<typename NumberType::value_type>>::value>::type>
883 template <
typename NumberType>
884 struct is_sacado_rad_number<
886 typename
std::enable_if<
887 ADNumberTraits<typename std::decay<NumberType>::type>::type_code ==
888 NumberTypes::sacado_rad ||
889 ADNumberTraits<typename std::decay<NumberType>::type>::type_code ==
890 NumberTypes::sacado_rad_dfad>::type> : std::true_type
894 template <
typename NumberType>
895 struct is_sacado_rad_number<
897 typename
std::enable_if<std::is_same<
899 Sacado::Rad::ADvari<Sacado::Fad::DFad<
900 typename NumberType::ADVari::scalar_type>>>::value>::type>
905 template <
typename NumberType>
906 struct is_sacado_number<
908 typename
std::enable_if<is_sacado_dfad_number<NumberType>::value ||
909 is_sacado_rad_number<NumberType>::value>::type>
919 template <
typename NumberType>
920 struct is_cuda_compatible<
922 typename
std::enable_if<::Differentiation::AD::is_sacado_rad_number<
923 NumberType>::value>::type> : std::false_type
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
#define DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_ENABLE_EXTRA_DIAGNOSTICS