Reference documentation for deal.II version 9.5.1
\(\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
source
differentiation
ad
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
21
# include <
deal.II/differentiation/ad/ad_number_traits.h
>
22
# include <
deal.II/differentiation/ad/adolc_number_types.h
>
23
24
# include <functional>
25
# include <utility>
26
27
DEAL_II_NAMESPACE_OPEN
28
29
30
# ifdef DEAL_II_ADOLC_WITH_ADVANCED_BRANCHING
31
32
namespace
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,
51
Differentiation::AD::NumberTypes::adolc_taped
>::ad_type;
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
);
56
return
!(
Differentiation::AD::ADNumberTraits<ad_type>::get_scalar_value
(
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
88
DEAL_II_NAMESPACE_CLOSE
89
90
#endif
ad_number_traits.h
adolc_number_types.h
ArrayView
Definition
array_view.h:86
config.h
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition
config.h:472
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition
config.h:473
Differentiation::AD::NumberTypes::adolc_taped
@ adolc_taped
internal
Definition
aligned_vector.h:698
numbers
Definition
numbers.h:230
numbers::values_are_equal
constexpr bool values_are_equal(const Number1 &value_1, const Number2 &value_2)
Definition
numbers.h:923
numbers::value_is_less_than
bool value_is_less_than(const Number1 &value_1, const Number2 &value_2)
Definition
numbers.h:947
Differentiation::AD::ADNumberTraits
Definition
ad_number_traits.h:68
Differentiation::AD::NumberTraits
Definition
ad_number_traits.h:51
Generated by
1.9.8