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
80# include <Sacado_Fad_DFad.hpp>
81# include <Sacado_trad.hpp>
100 template <
typename SacadoNumber,
typename =
void>
143 template <
typename SacadoNumber>
144 struct SacadoNumberInfo<
146 std::enable_if_t<std::is_same<
148 Sacado::Fad::DFad<typename SacadoNumber::value_type>>::value>>
150 using ad_type = SacadoNumber;
151 using scalar_type =
typename ad_type::scalar_type;
152 using value_type =
typename ad_type::value_type;
153 using derivative_type =
typename ad_type::value_type;
155 static const unsigned int n_supported_derivative_levels =
156 1 + SacadoNumberInfo<derivative_type>::n_supported_derivative_levels;
163 template <
typename SacadoNumber>
164 struct SacadoNumberInfo<
166 std::enable_if_t<std::is_same<
168 Sacado::Rad::ADvar<typename SacadoNumber::value_type>>::value>>
170 using ad_type = SacadoNumber;
171 using scalar_type =
typename ad_type::ADVari::scalar_type;
172 using value_type =
typename ad_type::ADVari::value_type;
173 using derivative_type =
typename ad_type::ADVari::value_type;
175 static const unsigned int n_supported_derivative_levels =
176 1 + SacadoNumberInfo<derivative_type>::n_supported_derivative_levels;
186 template <
typename Number>
187 struct SacadoNumberInfo<Number,
188 std::enable_if_t<std::is_arithmetic<
189 typename std::decay<Number>::type>::value>>
191 static const unsigned int n_supported_derivative_levels = 0;
199 template <
typename ScalarType>
200 struct ADNumberInfoFromEnum<
203 std::enable_if_t<std::is_floating_point<ScalarType>::value>>
205 static const bool is_taped =
false;
206 using real_type = Sacado::Fad::DFad<ScalarType>;
207 using derivative_type =
208 typename SacadoNumberInfo<real_type>::derivative_type;
209 static const unsigned int n_supported_derivative_levels =
210 SacadoNumberInfo<real_type>::n_supported_derivative_levels;
218 template <
typename ScalarType>
219 struct ADNumberInfoFromEnum<
222 std::enable_if_t<std::is_floating_point<ScalarType>::value>>
224 static const bool is_taped =
false;
225 using real_type = Sacado::Fad::DFad<Sacado::Fad::DFad<ScalarType>>;
226 using derivative_type =
227 typename SacadoNumberInfo<real_type>::derivative_type;
228 static const unsigned int n_supported_derivative_levels =
229 SacadoNumberInfo<real_type>::n_supported_derivative_levels;
237 template <
typename ScalarType>
238 struct ADNumberInfoFromEnum<
241 std::enable_if_t<std::is_floating_point<ScalarType>::value>>
243 static const bool is_taped =
false;
244 using real_type = Sacado::Rad::ADvar<ScalarType>;
245 using derivative_type =
246 typename SacadoNumberInfo<real_type>::derivative_type;
247 static const unsigned int n_supported_derivative_levels =
248 SacadoNumberInfo<real_type>::n_supported_derivative_levels;
256 template <
typename ScalarType>
257 struct ADNumberInfoFromEnum<
260 std::enable_if_t<std::is_floating_point<ScalarType>::value>>
262 static const bool is_taped =
false;
263 using real_type = Sacado::Rad::ADvar<Sacado::Fad::DFad<ScalarType>>;
264 using derivative_type =
265 typename SacadoNumberInfo<real_type>::derivative_type;
266 static const unsigned int n_supported_derivative_levels =
267 SacadoNumberInfo<real_type>::n_supported_derivative_levels;
275 template <
typename NumberType>
276 struct Marking<Sacado::Fad::DFad<NumberType>>
279 typename SacadoNumberInfo<Sacado::Fad::DFad<NumberType>>::ad_type;
280 using derivative_type =
typename SacadoNumberInfo<
281 Sacado::Fad::DFad<NumberType>>::derivative_type;
283 typename SacadoNumberInfo<Sacado::Fad::DFad<NumberType>>::scalar_type;
289 independent_variable(
const scalar_type &in,
290 const unsigned int index,
291 const unsigned int n_independent_variables,
296 out = ad_type(n_independent_variables, index, in);
299 Marking<derivative_type>::independent_variable(
300 in, index, n_independent_variables, out.val());
307 dependent_variable(ad_type &out,
const ad_type &func)
318 template <
typename NumberType>
319 struct Marking<Sacado::Rad::ADvar<NumberType>>
322 typename SacadoNumberInfo<Sacado::Rad::ADvar<NumberType>>::ad_type;
323 using derivative_type =
typename SacadoNumberInfo<
324 Sacado::Rad::ADvar<NumberType>>::derivative_type;
325 using scalar_type =
typename SacadoNumberInfo<
326 Sacado::Rad::ADvar<NumberType>>::scalar_type;
332 independent_variable(
const scalar_type &in,
333 const unsigned int index,
334 const unsigned int n_independent_variables,
343 derivative_type derivative_initializer;
344 Marking<derivative_type>::independent_variable(
345 in, index, n_independent_variables, derivative_initializer);
348 out = derivative_initializer;
355 dependent_variable(ad_type &out,
const ad_type &func)
367 template <
typename NumberType>
368 struct ExtractData<Sacado::Fad::DFad<NumberType>>
370 using derivative_type =
typename SacadoNumberInfo<
371 Sacado::Fad::DFad<NumberType>>::derivative_type;
373 typename SacadoNumberInfo<Sacado::Fad::DFad<NumberType>>::scalar_type;
375 typename SacadoNumberInfo<Sacado::Fad::DFad<NumberType>>::value_type;
381 value(
const Sacado::Fad::DFad<NumberType> &x)
383 return ExtractData<value_type>::value(x.val());
391 n_directional_derivatives(
const Sacado::Fad::DFad<NumberType> &x)
400 static derivative_type
401 directional_derivative(
const Sacado::Fad::DFad<NumberType> &x,
402 const unsigned int direction)
404 if (x.hasFastAccess())
405 return x.fastAccessDx(direction);
407 return x.dx(direction);
417 template <
typename NumberType>
418 struct ExtractData<Sacado::Rad::ADvar<NumberType>>
420 using derivative_type =
typename SacadoNumberInfo<
421 Sacado::Rad::ADvar<NumberType>>::derivative_type;
422 using scalar_type =
typename SacadoNumberInfo<
423 Sacado::Rad::ADvar<NumberType>>::scalar_type;
425 typename SacadoNumberInfo<Sacado::Rad::ADvar<NumberType>>::value_type;
431 value(
const Sacado::Rad::ADvar<NumberType> &x)
433 return ExtractData<value_type>::value(x.val());
441 n_directional_derivatives(
const Sacado::Rad::ADvar<NumberType> &)
457 static derivative_type
458 directional_derivative(
const Sacado::Rad::ADvar<NumberType> &x,
477 template <
typename ADNumberType>
478 struct ADNumberTraits<
480 std::enable_if_t<std::is_same<
482 Sacado::Fad::DFad<typename ADNumberType::scalar_type>>::value>>
483 : NumberTraits<typename ADNumberType::scalar_type,
484 NumberTypes::sacado_dfad>
494 template <
typename ADNumberType>
495 struct ADNumberTraits<
497 std::enable_if_t<std::is_same<
499 std::complex<Sacado::Fad::DFad<
500 typename ADNumberType::value_type::scalar_type>>>::value>>
502 std::complex<typename ADNumberType::value_type::scalar_type>,
503 NumberTypes::sacado_dfad>
514 typename ADNumberTraits<Sacado::Fad::DFad<float>>::scalar_type,
515 NumberTypes::sacado_dfad>
524 struct NumberTraits<
std::complex<Sacado::Fad::DFad<float>>,
526 : NumberTraits<typename ADNumberTraits<
527 std::complex<Sacado::Fad::DFad<float>>>::scalar_type,
528 NumberTypes::sacado_dfad>
539 typename ADNumberTraits<Sacado::Fad::DFad<double>>::scalar_type,
540 NumberTypes::sacado_dfad>
549 struct NumberTraits<
std::complex<Sacado::Fad::DFad<double>>,
551 : NumberTraits<typename ADNumberTraits<
552 std::complex<Sacado::Fad::DFad<double>>>::scalar_type,
553 NumberTypes::sacado_dfad>
566 template <
typename ADNumberType>
567 struct ADNumberTraits<
569 std::enable_if_t<std::is_same<
571 Sacado::Rad::ADvar<typename ADNumberType::ADVari::scalar_type>>::value>>
572 : NumberTraits<typename ADNumberType::ADVari::scalar_type,
573 NumberTypes::sacado_rad>
584 typename ADNumberTraits<Sacado::Rad::ADvar<float>>::scalar_type,
585 NumberTypes::sacado_rad>
596 typename ADNumberTraits<Sacado::Rad::ADvar<double>>::scalar_type,
597 NumberTypes::sacado_rad>
601# ifdef DEAL_II_TRILINOS_CXX_SUPPORTS_SACADO_COMPLEX_RAD
610 template <
typename ADNumberType>
611 struct ADNumberTraits<
613 std::enable_if_t<std::is_same<
615 std::complex<Sacado::Rad::ADvar<
616 typename ADNumberType::value_type::ADVari::scalar_type>>>::value>>
618 std::complex<typename ADNumberType::value_type::ADVari::scalar_type>,
619 NumberTypes::sacado_rad>
628 struct NumberTraits<
std::complex<Sacado::Rad::ADvar<float>>,
630 : NumberTraits<typename ADNumberTraits<
631 std::complex<Sacado::Rad::ADvar<float>>>::scalar_type,
632 NumberTypes::sacado_rad>
641 struct NumberTraits<
std::complex<Sacado::Rad::ADvar<double>>,
643 : NumberTraits<typename ADNumberTraits<
644 std::complex<Sacado::Rad::ADvar<double>>>::scalar_type,
645 NumberTypes::sacado_rad>
661 template <
typename ADNumberType>
662 struct ADNumberTraits<ADNumberType,
663 std::enable_if_t<std::is_same<
665 Sacado::Fad::DFad<Sacado::Fad::DFad<
666 typename ADNumberType::scalar_type>>>::value>>
667 : NumberTraits<typename ADNumberType::scalar_type,
668 NumberTypes::sacado_dfad_dfad>
679 template <
typename ADNumberType>
680 struct ADNumberTraits<
682 std::enable_if_t<std::is_same<
684 std::complex<Sacado::Fad::DFad<Sacado::Fad::DFad<
685 typename ADNumberType::value_type::scalar_type>>>>::value>>
687 std::complex<typename ADNumberType::value_type::scalar_type>,
688 NumberTypes::sacado_dfad_dfad>
697 struct NumberTraits<Sacado::Fad::DFad<Sacado::Fad::DFad<float>>,
699 : NumberTraits<typename ADNumberTraits<Sacado::Fad::DFad<
700 Sacado::Fad::DFad<float>>>::scalar_type,
701 NumberTypes::sacado_dfad_dfad>
711 std::complex<Sacado::Fad::DFad<Sacado::Fad::DFad<float>>>,
713 : NumberTraits<typename ADNumberTraits<std::complex<Sacado::Fad::DFad<
714 Sacado::Fad::DFad<float>>>>::scalar_type,
715 NumberTypes::sacado_dfad_dfad>
724 struct NumberTraits<Sacado::Fad::DFad<Sacado::Fad::DFad<double>>,
726 : NumberTraits<typename ADNumberTraits<Sacado::Fad::DFad<
727 Sacado::Fad::DFad<double>>>::scalar_type,
728 NumberTypes::sacado_dfad_dfad>
738 std::complex<Sacado::Fad::DFad<Sacado::Fad::DFad<double>>>,
740 : NumberTraits<typename ADNumberTraits<std::complex<Sacado::Fad::DFad<
741 Sacado::Fad::DFad<double>>>>::scalar_type,
742 NumberTypes::sacado_dfad_dfad>
755 template <
typename ADNumberType>
756 struct ADNumberTraits<
759 std::is_same<ADNumberType,
760 Sacado::Rad::ADvar<Sacado::Fad::DFad<
761 typename ADNumberType::ADVari::scalar_type>>>::value>>
762 : NumberTraits<typename ADNumberType::ADVari::scalar_type,
763 NumberTypes::sacado_rad_dfad>
772 struct NumberTraits<Sacado::Rad::ADvar<Sacado::Fad::DFad<float>>,
774 : NumberTraits<typename ADNumberTraits<Sacado::Rad::ADvar<
775 Sacado::Fad::DFad<float>>>::scalar_type,
776 NumberTypes::sacado_rad_dfad>
785 struct NumberTraits<Sacado::Rad::ADvar<Sacado::Fad::DFad<double>>,
787 : NumberTraits<typename ADNumberTraits<Sacado::Rad::ADvar<
788 Sacado::Fad::DFad<double>>>::scalar_type,
789 NumberTypes::sacado_rad_dfad>
793# ifdef DEAL_II_TRILINOS_CXX_SUPPORTS_SACADO_COMPLEX_RAD
803 template <
typename ADNumberType>
804 struct ADNumberTraits<
806 std::enable_if_t<std::is_same<
808 std::complex<Sacado::Rad::ADvar<Sacado::Fad::DFad<
809 typename ADNumberType::value_type::ADVari::scalar_type>>>>::value>>
811 std::complex<typename ADNumberType::value_type::ADVari::scalar_type>,
812 NumberTypes::sacado_rad_dfad>
822 std::complex<Sacado::Rad::ADvar<Sacado::Fad::DFad<float>>>,
824 : NumberTraits<typename ADNumberTraits<std::complex<Sacado::Rad::ADvar<
825 Sacado::Fad::DFad<float>>>>::scalar_type,
826 NumberTypes::sacado_rad_dfad>
836 std::complex<Sacado::Rad::ADvar<Sacado::Fad::DFad<double>>>,
838 : NumberTraits<typename ADNumberTraits<std::complex<Sacado::Rad::ADvar<
839 Sacado::Fad::DFad<double>>>>::scalar_type,
840 NumberTypes::sacado_rad_dfad>
850 template <
typename NumberType>
851 struct is_sacado_dfad_number<
854 ADNumberTraits<typename std::decay<NumberType>::type>::type_code ==
855 NumberTypes::sacado_dfad ||
856 ADNumberTraits<typename std::decay<NumberType>::type>::type_code ==
857 NumberTypes::sacado_dfad_dfad>> : std::true_type
861 template <
typename NumberType>
862 struct is_sacado_dfad_number<
864 std::enable_if_t<std::is_same<
866 Sacado::Fad::Expr<typename NumberType::value_type>>::value>>
871 template <
typename NumberType>
872 struct is_sacado_rad_number<
875 ADNumberTraits<typename std::decay<NumberType>::type>::type_code ==
876 NumberTypes::sacado_rad ||
877 ADNumberTraits<typename std::decay<NumberType>::type>::type_code ==
878 NumberTypes::sacado_rad_dfad>> : std::true_type
882 template <
typename NumberType>
883 struct is_sacado_rad_number<
886 std::is_same<NumberType,
887 Sacado::Rad::ADvari<Sacado::Fad::DFad<
888 typename NumberType::ADVari::scalar_type>>>::value>>
893 template <
typename NumberType>
894 struct is_sacado_number<
896 std::enable_if_t<is_sacado_dfad_number<NumberType>::value ||
897 is_sacado_rad_number<NumberType>::value>>
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE