deal.II version GIT relicensing-6839-g338455934c 2026-10-02 12:10:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
adolc_number_types.cc
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2017 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13
14#include <deal.II/base/config.h>
15
16#ifdef DEAL_II_WITH_ADOLC
17
20
21# include <functional>
22# include <utility>
23
24# ifdef DEAL_II_WITH_ADOLC
25# include <adolc/adouble.h> // Taped double
26# include <adolc/adtl.h> // Tapeless double
27# endif
28
29
30#endif
31
33
34#ifdef DEAL_II_WITH_ADOLC
35
36
37# ifdef DEAL_II_ADOLC_WITH_ADVANCED_BRANCHING
38
39namespace numbers
40{
41 namespace internal
42 {
43 namespace
44 {
45 // Apply some comparator and extract the boolean result of the operation,
46 // instead of the "adub" return type typically returned by ADOL-C for
47 // such a comparison. This is implemented as a general function so that
48 // the list of implemented comparative operations can be easily extended.
49 bool
50 adouble_boolean_comparator(
51 const adouble &value_1,
52 const adouble &value_2,
53 const std::function<adouble(const adouble &, const adouble &)>
54 &comparator)
55 {
56 using ad_type = typename Differentiation::AD::NumberTraits<
57 double,
59 static_assert(
60 std::is_same_v<adouble, ad_type>,
61 "The type of the AD number is not that which was expected.");
62 const ad_type result = comparator(value_1, value_2);
64 result) == 0.0);
65 }
66 } // namespace
67 } // namespace internal
68
69 bool
70 values_are_equal(const adouble &value_1, const adouble &value_2)
71 {
72 return internal::adouble_boolean_comparator(
73 value_1, value_2, [](const adouble &a, const adouble &b) -> adouble {
74 return ::internal::NumberType<adouble>::value(a == b);
75 });
76 }
77
78 bool
79 value_is_less_than(const adouble &value_1, const adouble &value_2)
80 {
81 return internal::adouble_boolean_comparator(
82 value_1, value_2, [](const adouble &a, const adouble &b) -> adouble {
83 return ::internal::NumberType<adouble>::value(a < b);
84 });
85 }
86} // namespace numbers
87
88# endif
89
90
91/*---------------------- Explicit Instantiations ----------------------*/
92
93# include "differentiation/ad/adolc_number_types.inst"
94
95
96#endif
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
constexpr bool values_are_equal(const Number1 &value_1, const Number2 &value_2)
Definition numbers.h:858
bool value_is_less_than(const Number1 &value_1, const Number2 &value_2)
Definition numbers.h:882