Reference documentation for deal.II version 9.0.0
adolc_number_types.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2017 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 at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 
17 #include <deal.II/base/config.h>
18 
19 #ifdef DEAL_II_WITH_ADOLC
20 
21 #include <deal.II/differentiation/ad/adolc_number_types.h>
22 #include <deal.II/differentiation/ad/ad_number_traits.h>
23 
24 #include <utility>
25 
26 DEAL_II_NAMESPACE_OPEN
27 
28 
29 #ifdef DEAL_II_ADOLC_WITH_ADVANCED_BRANCHING
30 
31 namespace numbers
32 {
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 (const adouble &value_1,
44  const adouble &value_2,
45  const std::function<adouble(const adouble &, const adouble &)> &comparator)
46  {
48  static_assert(std::is_same<adouble,ad_type>::value, "The type of the AD number is not that which was expected.");
49  const ad_type result = comparator(value_1,value_2);
51  }
52  }
53  }
54 
55  bool
56  values_are_equal (const adouble &value_1,
57  const adouble &value_2)
58  {
59  return internal::adouble_boolean_comparator(
60  value_1, value_2,
61  [](const adouble &a,const adouble &b) -> adouble
62  {
63  return ::internal::NumberType<adouble>::value(a == b);
64  });
65  }
66 
67  bool
68  value_is_less_than (const adouble &value_1,
69  const adouble &value_2)
70  {
71  return internal::adouble_boolean_comparator(
72  value_1, value_2,
73  [](const adouble &a,const adouble &b) -> adouble
74  {
75  return ::internal::NumberType<adouble>::value(a < b);
76  });
77  }
78 }
79 
80 #endif
81 
82 
83 /*---------------------- Explicit Instantiations ----------------------*/
84 
85 #include "adolc_number_types.inst"
86 
87 DEAL_II_NAMESPACE_CLOSE
88 
89 #endif
bool values_are_equal(const Number1 &value_1, const Number2 &value_2)
Definition: numbers.h:768
bool value_is_less_than(const Number1 &value_1, const Number2 &value_2)
Definition: numbers.h:792