deal.II version GIT relicensing-2289-g1e5549a87a 2024-12-21 21:30: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\}}\)
Loading...
Searching...
No Matches
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
27
28
29# ifdef DEAL_II_ADOLC_WITH_ADVANCED_BRANCHING
30
31namespace numbers
32{
33 namespace internal
34 {
35 namespace
36 {
37 // Apply some comparator and extract the boolean result of the operation,
38 // instead of the "adub" return type typically returned by ADOL-C for
39 // such a comparison. This is implemented as a general function so that
40 // the list of implemented comparative operations can be easily extended.
41 bool
42 adouble_boolean_comparator(
43 const adouble &value_1,
44 const adouble &value_2,
45 const std::function<adouble(const adouble &, const adouble &)>
46 &comparator)
47 {
48 using ad_type = typename Differentiation::AD::NumberTraits<
49 double,
51 static_assert(
52 std::is_same_v<adouble, ad_type>,
53 "The type of the AD number is not that which was expected.");
54 const ad_type result = comparator(value_1, value_2);
56 result) == 0.0);
57 }
58 } // namespace
59 } // namespace internal
60
61 bool
62 values_are_equal(const adouble &value_1, const adouble &value_2)
63 {
64 return internal::adouble_boolean_comparator(
65 value_1, value_2, [](const adouble &a, const adouble &b) -> adouble {
66 return ::internal::NumberType<adouble>::value(a == b);
67 });
68 }
69
70 bool
71 value_is_less_than(const adouble &value_1, const adouble &value_2)
72 {
73 return internal::adouble_boolean_comparator(
74 value_1, value_2, [](const adouble &a, const adouble &b) -> adouble {
75 return ::internal::NumberType<adouble>::value(a < b);
76 });
77 }
78} // namespace numbers
79
80# endif
81
82
83/*---------------------- Explicit Instantiations ----------------------*/
84
85# include "adolc_number_types.inst"
86
88
89#endif
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:498
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:499
constexpr bool values_are_equal(const Number1 &value_1, const Number2 &value_2)
Definition numbers.h:894
bool value_is_less_than(const Number1 &value_1, const Number2 &value_2)
Definition numbers.h:918