Loading [MathJax]/extensions/TeX/AMSsymbols.js
 deal.II version GIT relicensing-2836-g362046b457 2025-03-13 15:40:00+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\}}\)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
adolc_number_types.cc
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2017 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15
16#include <deal.II/base/config.h>
17
18#ifdef DEAL_II_WITH_ADOLC
19
22
23# include <functional>
24# include <utility>
25
26# ifdef DEAL_II_WITH_ADOLC
27# include <adolc/adouble.h> // Taped double
28# include <adolc/adtl.h> // Tapeless double
29# endif
30
32
33
34# ifdef DEAL_II_ADOLC_WITH_ADVANCED_BRANCHING
35
36namespace numbers
37{
38 namespace internal
39 {
40 namespace
41 {
42 // Apply some comparator and extract the boolean result of the operation,
43 // instead of the "adub" return type typically returned by ADOL-C for
44 // such a comparison. This is implemented as a general function so that
45 // the list of implemented comparative operations can be easily extended.
46 bool
47 adouble_boolean_comparator(
48 const adouble &value_1,
49 const adouble &value_2,
50 const std::function<adouble(const adouble &, const adouble &)>
51 &comparator)
52 {
53 using ad_type = typename Differentiation::AD::NumberTraits<
54 double,
56 static_assert(
57 std::is_same_v<adouble, ad_type>,
58 "The type of the AD number is not that which was expected.");
59 const ad_type result = comparator(value_1, value_2);
61 result) == 0.0);
62 }
63 } // namespace
64 } // namespace internal
65
66 bool
67 values_are_equal(const adouble &value_1, const adouble &value_2)
68 {
69 return internal::adouble_boolean_comparator(
70 value_1, value_2, [](const adouble &a, const adouble &b) -> adouble {
71 return ::internal::NumberType<adouble>::value(a == b);
72 });
73 }
74
75 bool
76 value_is_less_than(const adouble &value_1, const adouble &value_2)
77 {
78 return internal::adouble_boolean_comparator(
79 value_1, value_2, [](const adouble &a, const adouble &b) -> adouble {
80 return ::internal::NumberType<adouble>::value(a < b);
81 });
82 }
83} // namespace numbers
84
85# endif
86
87
88/*---------------------- Explicit Instantiations ----------------------*/
89
90# include "differentiation/ad/adolc_number_types.inst"
91
93
94#endif
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:40
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:41
constexpr bool values_are_equal(const Number1 &value_1, const Number2 &value_2)
Definition numbers.h:879
bool value_is_less_than(const Number1 &value_1, const Number2 &value_2)
Definition numbers.h:903