15#ifndef dealii_differentiation_ad_sacado_number_types_h
16#define dealii_differentiation_ad_sacado_number_types_h
35 template <
typename NumberType,
typename =
void>
45 template <
typename NumberType,
typename =
void>
55 template <
typename NumberType,
typename =
void>
67#ifdef DEAL_II_TRILINOS_WITH_SACADO
79# include <Sacado_Fad_DFad.hpp>
80# include <Sacado_trad.hpp>
99 template <
typename SacadoNumber,
typename =
void>
142 template <
typename SacadoNumber>
143 struct SacadoNumberInfo<
146 std::is_same_v<SacadoNumber,
147 Sacado::Fad::DFad<typename SacadoNumber::value_type>>>>
150 using scalar_type =
typename ad_type::scalar_type;
151 using value_type =
typename ad_type::value_type;
155 1 + SacadoNumberInfo<derivative_type>::n_supported_derivative_levels;
162 template <
typename SacadoNumber>
163 struct SacadoNumberInfo<
167 Sacado::Rad::ADvar<typename SacadoNumber::value_type>>>>
170 using scalar_type =
typename ad_type::ADVari::scalar_type;
171 using value_type =
typename ad_type::ADVari::value_type;
175 1 + SacadoNumberInfo<derivative_type>::n_supported_derivative_levels;
185 template <
typename Number>
186 struct SacadoNumberInfo<
198 template <
typename ScalarType>
199 struct ADNumberInfoFromEnum<
202 std::enable_if_t<std::is_floating_point_v<ScalarType>>>
205 using real_type = Sacado::Fad::DFad<ScalarType>;
207 typename SacadoNumberInfo<real_type>::derivative_type;
209 SacadoNumberInfo<real_type>::n_supported_derivative_levels;
217 template <
typename ScalarType>
218 struct ADNumberInfoFromEnum<
221 std::enable_if_t<std::is_floating_point_v<ScalarType>>>
224 using real_type = Sacado::Fad::DFad<Sacado::Fad::DFad<ScalarType>>;
226 typename SacadoNumberInfo<real_type>::derivative_type;
228 SacadoNumberInfo<real_type>::n_supported_derivative_levels;
236 template <
typename ScalarType>
237 struct ADNumberInfoFromEnum<
240 std::enable_if_t<std::is_floating_point_v<ScalarType>>>
243 using real_type = Sacado::Rad::ADvar<ScalarType>;
245 typename SacadoNumberInfo<real_type>::derivative_type;
247 SacadoNumberInfo<real_type>::n_supported_derivative_levels;
255 template <
typename ScalarType>
256 struct ADNumberInfoFromEnum<
259 std::enable_if_t<std::is_floating_point_v<ScalarType>>>
262 using real_type = Sacado::Rad::ADvar<Sacado::Fad::DFad<ScalarType>>;
264 typename SacadoNumberInfo<real_type>::derivative_type;
266 SacadoNumberInfo<real_type>::n_supported_derivative_levels;
274 template <
typename NumberType>
289 const unsigned int index,
290 const unsigned int n_independent_variables,
295 out = ad_type(n_independent_variables, index, in);
298 Marking<derivative_type>::independent_variable(
299 in, index, n_independent_variables, out.val());
317 template <
typename NumberType>
324 using scalar_type =
typename SacadoNumberInfo<
325 Sacado::Rad::ADvar<NumberType>>::scalar_type;
332 const unsigned int index,
333 const unsigned int n_independent_variables,
343 Marking<derivative_type>::independent_variable(
366 template <
typename NumberType>
380 value(
const Sacado::Fad::DFad<NumberType> &
x)
382 return ExtractData<value_type>::value(
x.val());
401 const unsigned int direction)
403 if (
x.hasFastAccess())
404 return x.fastAccessDx(direction);
406 return x.dx(direction);
416 template <
typename NumberType>
421 using scalar_type =
typename SacadoNumberInfo<
422 Sacado::Rad::ADvar<NumberType>>::scalar_type;
430 value(
const Sacado::Rad::ADvar<NumberType> &
x)
432 return ExtractData<value_type>::value(
x.val());
476 template <
typename ADNumberType>
477 struct ADNumberTraits<
480 std::is_same_v<ADNumberType,
481 Sacado::Fad::DFad<typename ADNumberType::scalar_type>>>>
482 : NumberTraits<typename ADNumberType::scalar_type,
483 NumberTypes::sacado_dfad>
493 template <
typename ADNumberType>
494 struct ADNumberTraits<
497 std::is_same_v<ADNumberType,
498 std::complex<Sacado::Fad::DFad<
499 typename ADNumberType::value_type::scalar_type>>>>>
501 std::complex<typename ADNumberType::value_type::scalar_type>,
502 NumberTypes::sacado_dfad>
513 typename ADNumberTraits<Sacado::Fad::DFad<float>>::scalar_type,
514 NumberTypes::sacado_dfad>
523 struct NumberTraits<
std::complex<Sacado::Fad::DFad<float>>,
525 : NumberTraits<typename ADNumberTraits<
526 std::complex<Sacado::Fad::DFad<float>>>::scalar_type,
527 NumberTypes::sacado_dfad>
538 typename ADNumberTraits<Sacado::Fad::DFad<double>>::scalar_type,
539 NumberTypes::sacado_dfad>
548 struct NumberTraits<
std::complex<Sacado::Fad::DFad<double>>,
550 : NumberTraits<typename ADNumberTraits<
551 std::complex<Sacado::Fad::DFad<double>>>::scalar_type,
552 NumberTypes::sacado_dfad>
565 template <
typename ADNumberType>
566 struct ADNumberTraits<
570 Sacado::Rad::ADvar<typename ADNumberType::ADVari::scalar_type>>>>
571 : NumberTraits<typename ADNumberType::ADVari::scalar_type,
572 NumberTypes::sacado_rad>
583 typename ADNumberTraits<Sacado::Rad::ADvar<float>>::scalar_type,
584 NumberTypes::sacado_rad>
595 typename ADNumberTraits<Sacado::Rad::ADvar<double>>::scalar_type,
596 NumberTypes::sacado_rad>
600# ifdef DEAL_II_TRILINOS_CXX_SUPPORTS_SACADO_COMPLEX_RAD
609 template <
typename ADNumberType>
610 struct ADNumberTraits<
614 std::complex<Sacado::Rad::ADvar<
615 typename ADNumberType::value_type::ADVari::scalar_type>>>>>
617 std::complex<typename ADNumberType::value_type::ADVari::scalar_type>,
618 NumberTypes::sacado_rad>
627 struct NumberTraits<
std::complex<Sacado::Rad::ADvar<float>>,
629 : NumberTraits<typename ADNumberTraits<
630 std::complex<Sacado::Rad::ADvar<float>>>::scalar_type,
631 NumberTypes::sacado_rad>
640 struct NumberTraits<
std::complex<Sacado::Rad::ADvar<double>>,
642 : NumberTraits<typename ADNumberTraits<
643 std::complex<Sacado::Rad::ADvar<double>>>::scalar_type,
644 NumberTypes::sacado_rad>
660 template <
typename ADNumberType>
661 struct ADNumberTraits<
664 Sacado::Fad::DFad<Sacado::Fad::DFad<
665 typename ADNumberType::scalar_type>>>>>
666 : NumberTraits<typename ADNumberType::scalar_type,
667 NumberTypes::sacado_dfad_dfad>
678 template <
typename ADNumberType>
679 struct ADNumberTraits<
682 std::is_same_v<ADNumberType,
683 std::complex<Sacado::Fad::DFad<Sacado::Fad::DFad<
684 typename ADNumberType::value_type::scalar_type>>>>>>
686 std::complex<typename ADNumberType::value_type::scalar_type>,
687 NumberTypes::sacado_dfad_dfad>
698 : NumberTraits<typename ADNumberTraits<Sacado::Fad::DFad<
699 Sacado::Fad::DFad<float>>>::scalar_type,
700 NumberTypes::sacado_dfad_dfad>
710 std::complex<Sacado::Fad::DFad<Sacado::Fad::DFad<float>>>,
712 : NumberTraits<typename ADNumberTraits<std::complex<Sacado::Fad::DFad<
713 Sacado::Fad::DFad<float>>>>::scalar_type,
714 NumberTypes::sacado_dfad_dfad>
725 : NumberTraits<typename ADNumberTraits<Sacado::Fad::DFad<
726 Sacado::Fad::DFad<double>>>::scalar_type,
727 NumberTypes::sacado_dfad_dfad>
737 std::complex<Sacado::Fad::DFad<Sacado::Fad::DFad<double>>>,
739 : NumberTraits<typename ADNumberTraits<std::complex<Sacado::Fad::DFad<
740 Sacado::Fad::DFad<double>>>>::scalar_type,
741 NumberTypes::sacado_dfad_dfad>
754 template <
typename ADNumberType>
758 Sacado::Rad::ADvar<Sacado::Fad::DFad<
759 typename ADNumberType::ADVari::scalar_type>>>>>
760 : NumberTraits<typename ADNumberType::ADVari::scalar_type,
761 NumberTypes::sacado_rad_dfad>
772 : NumberTraits<typename ADNumberTraits<Sacado::Rad::ADvar<
773 Sacado::Fad::DFad<float>>>::scalar_type,
774 NumberTypes::sacado_rad_dfad>
785 : NumberTraits<typename ADNumberTraits<Sacado::Rad::ADvar<
786 Sacado::Fad::DFad<double>>>::scalar_type,
787 NumberTypes::sacado_rad_dfad>
791# ifdef DEAL_II_TRILINOS_CXX_SUPPORTS_SACADO_COMPLEX_RAD
801 template <
typename ADNumberType>
802 struct ADNumberTraits<
806 std::complex<Sacado::Rad::ADvar<Sacado::Fad::DFad<
807 typename ADNumberType::value_type::ADVari::scalar_type>>>>>>
809 std::complex<typename ADNumberType::value_type::ADVari::scalar_type>,
810 NumberTypes::sacado_rad_dfad>
820 std::complex<Sacado::Rad::ADvar<Sacado::Fad::DFad<float>>>,
822 : NumberTraits<typename ADNumberTraits<std::complex<Sacado::Rad::ADvar<
823 Sacado::Fad::DFad<float>>>>::scalar_type,
824 NumberTypes::sacado_rad_dfad>
834 std::complex<Sacado::Rad::ADvar<Sacado::Fad::DFad<double>>>,
836 : NumberTraits<typename ADNumberTraits<std::complex<Sacado::Rad::ADvar<
837 Sacado::Fad::DFad<double>>>>::scalar_type,
838 NumberTypes::sacado_rad_dfad>
848 template <
typename NumberType>
849 struct is_sacado_dfad_number<
851 std::
enable_if_t<ADNumberTraits<std::decay_t<NumberType>>::type_code ==
852 NumberTypes::sacado_dfad ||
853 ADNumberTraits<std::decay_t<NumberType>>::type_code ==
854 NumberTypes::sacado_dfad_dfad>> : std::true_type
858 template <
typename NumberType>
859 struct is_sacado_dfad_number<
862 std::is_same_v<NumberType,
863 Sacado::Fad::Expr<typename NumberType::value_type>>>>
868 template <
typename NumberType>
869 struct is_sacado_rad_number<
871 std::
enable_if_t<ADNumberTraits<std::decay_t<NumberType>>::type_code ==
872 NumberTypes::sacado_rad ||
873 ADNumberTraits<std::decay_t<NumberType>>::type_code ==
874 NumberTypes::sacado_rad_dfad>> : std::true_type
878 template <
typename NumberType>
879 struct is_sacado_rad_number<
882 std::is_same_v<NumberType,
883 Sacado::Rad::ADvari<Sacado::Fad::DFad<
884 typename NumberType::ADVari::scalar_type>>>>>
889 template <
typename NumberType>
890 struct is_sacado_number<
893 is_sacado_rad_number<NumberType>::value>>
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE