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>>>>
149 using ad_type = SacadoNumber;
150 using scalar_type =
typename ad_type::scalar_type;
151 using value_type =
typename ad_type::value_type;
152 using derivative_type =
typename ad_type::value_type;
154 static const unsigned int n_supported_derivative_levels =
155 1 + SacadoNumberInfo<derivative_type>::n_supported_derivative_levels;
162 template <
typename SacadoNumber>
163 struct SacadoNumberInfo<
165 std::enable_if_t<std::is_same_v<
167 Sacado::Rad::ADvar<typename SacadoNumber::value_type>>>>
169 using ad_type = SacadoNumber;
170 using scalar_type =
typename ad_type::ADVari::scalar_type;
171 using value_type =
typename ad_type::ADVari::value_type;
172 using derivative_type =
typename ad_type::ADVari::value_type;
174 static const unsigned int n_supported_derivative_levels =
175 1 + SacadoNumberInfo<derivative_type>::n_supported_derivative_levels;
185 template <
typename Number>
186 struct SacadoNumberInfo<
188 std::enable_if_t<std::is_arithmetic<std::decay_t<Number>>::value>>
190 static const unsigned int n_supported_derivative_levels = 0;
198 template <
typename ScalarType>
199 struct ADNumberInfoFromEnum<
202 std::enable_if_t<std::is_floating_point_v<ScalarType>>>
204 static const bool is_taped =
false;
205 using real_type = Sacado::Fad::DFad<ScalarType>;
206 using derivative_type =
207 typename SacadoNumberInfo<real_type>::derivative_type;
208 static const unsigned int n_supported_derivative_levels =
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>>>
223 static const bool is_taped =
false;
224 using real_type = Sacado::Fad::DFad<Sacado::Fad::DFad<ScalarType>>;
225 using derivative_type =
226 typename SacadoNumberInfo<real_type>::derivative_type;
227 static const unsigned int n_supported_derivative_levels =
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>>>
242 static const bool is_taped =
false;
243 using real_type = Sacado::Rad::ADvar<ScalarType>;
244 using derivative_type =
245 typename SacadoNumberInfo<real_type>::derivative_type;
246 static const unsigned int n_supported_derivative_levels =
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>>>
261 static const bool is_taped =
false;
262 using real_type = Sacado::Rad::ADvar<Sacado::Fad::DFad<ScalarType>>;
263 using derivative_type =
264 typename SacadoNumberInfo<real_type>::derivative_type;
265 static const unsigned int n_supported_derivative_levels =
266 SacadoNumberInfo<real_type>::n_supported_derivative_levels;
274 template <
typename NumberType>
275 struct Marking<Sacado::Fad::DFad<NumberType>>
278 typename SacadoNumberInfo<Sacado::Fad::DFad<NumberType>>::ad_type;
279 using derivative_type =
typename SacadoNumberInfo<
280 Sacado::Fad::DFad<NumberType>>::derivative_type;
282 typename SacadoNumberInfo<Sacado::Fad::DFad<NumberType>>::scalar_type;
288 independent_variable(
const scalar_type &in,
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());
306 dependent_variable(ad_type &out,
const ad_type &func)
317 template <
typename NumberType>
318 struct Marking<Sacado::Rad::ADvar<NumberType>>
321 typename SacadoNumberInfo<Sacado::Rad::ADvar<NumberType>>::ad_type;
322 using derivative_type =
typename SacadoNumberInfo<
323 Sacado::Rad::ADvar<NumberType>>::derivative_type;
324 using scalar_type =
typename SacadoNumberInfo<
325 Sacado::Rad::ADvar<NumberType>>::scalar_type;
331 independent_variable(
const scalar_type &in,
332 const unsigned int index,
333 const unsigned int n_independent_variables,
342 derivative_type derivative_initializer;
343 Marking<derivative_type>::independent_variable(
344 in, index, n_independent_variables, derivative_initializer);
347 out = derivative_initializer;
354 dependent_variable(ad_type &out,
const ad_type &func)
366 template <
typename NumberType>
367 struct ExtractData<Sacado::Fad::DFad<NumberType>>
369 using derivative_type =
typename SacadoNumberInfo<
370 Sacado::Fad::DFad<NumberType>>::derivative_type;
372 typename SacadoNumberInfo<Sacado::Fad::DFad<NumberType>>::scalar_type;
374 typename SacadoNumberInfo<Sacado::Fad::DFad<NumberType>>::value_type;
380 value(
const Sacado::Fad::DFad<NumberType> &x)
382 return ExtractData<value_type>::value(x.val());
390 n_directional_derivatives(
const Sacado::Fad::DFad<NumberType> &x)
399 static derivative_type
400 directional_derivative(
const Sacado::Fad::DFad<NumberType> &x,
401 const unsigned int direction)
403 if (x.hasFastAccess())
404 return x.fastAccessDx(direction);
406 return x.dx(direction);
416 template <
typename NumberType>
417 struct ExtractData<Sacado::Rad::ADvar<NumberType>>
419 using derivative_type =
typename SacadoNumberInfo<
420 Sacado::Rad::ADvar<NumberType>>::derivative_type;
421 using scalar_type =
typename SacadoNumberInfo<
422 Sacado::Rad::ADvar<NumberType>>::scalar_type;
424 typename SacadoNumberInfo<Sacado::Rad::ADvar<NumberType>>::value_type;
430 value(
const Sacado::Rad::ADvar<NumberType> &x)
432 return ExtractData<value_type>::value(x.val());
440 n_directional_derivatives(
const Sacado::Rad::ADvar<NumberType> &)
456 static derivative_type
457 directional_derivative(
const Sacado::Rad::ADvar<NumberType> &x,
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<
568 std::enable_if_t<std::is_same_v<
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<
612 std::enable_if_t<std::is_same_v<
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<
663 std::enable_if_t<std::is_same_v<ADNumberType,
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>
696 struct NumberTraits<Sacado::Fad::DFad<Sacado::Fad::DFad<float>>,
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>
723 struct NumberTraits<Sacado::Fad::DFad<Sacado::Fad::DFad<double>>,
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>
755 struct ADNumberTraits<ADNumberType,
756 std::enable_if_t<std::is_same_v<
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>
770 struct NumberTraits<Sacado::Rad::ADvar<Sacado::Fad::DFad<float>>,
772 : NumberTraits<typename ADNumberTraits<Sacado::Rad::ADvar<
773 Sacado::Fad::DFad<float>>>::scalar_type,
774 NumberTypes::sacado_rad_dfad>
783 struct NumberTraits<Sacado::Rad::ADvar<Sacado::Fad::DFad<double>>,
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<
804 std::enable_if_t<std::is_same_v<
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<
892 std::enable_if_t<is_sacado_dfad_number<NumberType>::value ||
893 is_sacado_rad_number<NumberType>::value>>
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE