Reference documentation for deal.II version 9.3.3
\(\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\}}\)
adolc_number_types.cc
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2017 - 2019 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16
17#include <deal.II/base/config.h>
18
19#ifdef DEAL_II_WITH_ADOLC
20
23
24# include <functional>
25# include <utility>
26
28
29
30# ifdef DEAL_II_ADOLC_WITH_ADVANCED_BRANCHING
31
32namespace numbers
33{
34 namespace internal
35 {
36 namespace
37 {
38 // Apply some comparator and extract the boolean result of the operation,
39 // instead of the "adub" return type tpyically returned by ADOL-C for
40 // such a comparison. This is implemented as a general function so that
41 // the list of implemented comparative operations can be easily extended.
42 bool
43 adouble_boolean_comparator(
44 const adouble &value_1,
45 const adouble &value_2,
46 const std::function<adouble(const adouble &, const adouble &)>
47 &comparator)
48 {
49 using ad_type = typename Differentiation::AD::NumberTraits<
50 double,
52 static_assert(
53 std::is_same<adouble, ad_type>::value,
54 "The type of the AD number is not that which was expected.");
55 const ad_type result = comparator(value_1, value_2);
57 result) == 0.0);
58 }
59 } // namespace
60 } // namespace internal
61
62 bool
63 values_are_equal(const adouble &value_1, const adouble &value_2)
64 {
65 return internal::adouble_boolean_comparator(
66 value_1, value_2, [](const adouble &a, const adouble &b) -> adouble {
67 return ::internal::NumberType<adouble>::value(a == b);
68 });
69 }
70
71 bool
72 value_is_less_than(const adouble &value_1, const adouble &value_2)
73 {
74 return internal::adouble_boolean_comparator(
75 value_1, value_2, [](const adouble &a, const adouble &b) -> adouble {
76 return ::internal::NumberType<adouble>::value(a < b);
77 });
78 }
79} // namespace numbers
80
81# endif
82
83
84/*---------------------- Explicit Instantiations ----------------------*/
85
86# include "adolc_number_types.inst"
87
89
90#endif
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:402
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:403
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
constexpr bool values_are_equal(const Number1 &value_1, const Number2 &value_2)
Definition: numbers.h:915
bool value_is_less_than(const Number1 &value_1, const Number2 &value_2)
Definition: numbers.h:939