ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
example
sacado
ROL_Sacado_Traits.hpp
Go to the documentation of this file.
1
#ifndef ROL_SACADO_TRAITS_HPP
2
#define ROL_SACADO_TRAITS_HPP
3
4
#include <type_traits>
5
#include <utility>
6
7
#include "Sacado.hpp"
8
#include "
ROL_Objective.hpp
"
9
10
constexpr
bool
is_Objective
( ... ) {
return
false
; }
11
constexpr
bool
is_Constraint
( ... ) {
return
false
; }
12
13
template
<
class
Real>
14
constexpr
bool
is_Objective
(
const
ROL::Objective<Real>
& ) {
return
true
; }
15
16
template
<
class
Real>
17
constexpr
bool
is_Constraint
(
const
ROL::Constraint<Real>
& ) {
return
true
; }
18
19
constexpr
bool
is_DFad
( ... ) {
return
false
; }
20
constexpr
bool
is_SFad
( ... ) {
return
false
; }
21
22
template
<
typename
T>
23
constexpr
bool
is_DFad
(
const
Sacado::Fad::DFad<T>& ) {
return
true
; }
24
25
template
<
typename
T,
int
Num>
26
constexpr
bool
is_SFad
(
const
Sacado::Fad::SFad<T,Num>& ) {
return
true
; }
27
28
struct
InvalidType
{};
29
30
constexpr
bool
InvalidType
Fad_value
( ... );
31
32
template
<
typename
T>
33
constexpr
T
Fad_value
(
const
Sacado::Fad::DFad<T>& );
34
35
template
<
typename
T,
int
Num>
36
constexpr
T
Fad_value
(
const
Sacado::Fad::SFad<T,Num>& );
37
38
template
<
typename
T>
39
using
Fad_value_t
=
decltype
(
Fad_value
( std::declval<T>() ) );
40
41
template
<
typename
VectorType>
42
struct
Accessor
{};
43
44
template
<
typename
Real>
45
struct
Accessor
<std::vector<Real>> {
46
using
container_type
= std::vector<Real>;
47
using
value_type
=
typename
std::vector<Real>::value_type;
48
using
size_type
=
typename
std::vector<Real>::size_type;
49
inline
value_type
get_value
(
const
container_type
& x,
size_type
i )
const
{
50
return
x[i];
51
}
52
inline
void
set_value
(
container_type
& x,
size_type
i,
value_type
xi )
const
{
53
x[i] = xi;
54
}
55
};
56
57
// 1. Define the trait structure
58
template
<
typename
T,
typename
=
void
>
// SFINAE helper for more complex traits, not strictly needed here but good practice
59
struct
is_accessor_specialization
: std::false_type {};
60
61
// 2. Define the partial specialization for Accessor<VectorType>
62
template
<
typename
VectorType>
63
struct
is_accessor_specialization
<
Accessor
<VectorType>> : std::true_type {};
64
65
// 3. Define the C++17 style _v variable template
66
template
<
typename
T>
67
inline
constexpr
bool
has_accessor_v
=
is_accessor_specialization<T>::value
;
68
69
// --- Example Usage (C++17) ---
70
71
// SFINAE example for a function
72
template
<
typename
T,
73
typename
std::enable_if_t<has_accessor_v<T>,
int
> = 0>
74
void
process_if_accessor
(
const
T& acc_specialization) {
75
// This function will only be available in overload resolution if has_accessor_v<T> is true.
76
// You can use acc_specialization here.
77
// For demonstration:
78
if
constexpr
(
has_accessor_v<T>
) {
// if constexpr is C++17
79
// Additional compile-time checks or type usage
80
}
81
}
82
83
84
template
<
typename
Real>
85
struct
ObjectiveValue
{
86
template
<
typename
ScalarT>
87
ScalarT
value
88
};
89
90
#endif
// ROL_SACADO_TRAITS_HPP
ROL_Objective.hpp
value
virtual Real value(const Vector< Real > &u_old, const Vector< Real > &u_new, const Vector< Real > &z, Real &tol)
Compute contribution to objective value from this time step.
Definition
ROL_Objective_TimeSimOpt.hpp:112
is_DFad
constexpr bool is_DFad(...)
Definition
ROL_Sacado_Traits.hpp:19
Fad_value
constexpr bool InvalidType Fad_value(...)
process_if_accessor
void process_if_accessor(const T &acc_specialization)
Definition
ROL_Sacado_Traits.hpp:74
is_Constraint
constexpr bool is_Constraint(...)
Definition
ROL_Sacado_Traits.hpp:11
is_SFad
constexpr bool is_SFad(...)
Definition
ROL_Sacado_Traits.hpp:20
has_accessor_v
constexpr bool has_accessor_v
Definition
ROL_Sacado_Traits.hpp:67
is_Objective
constexpr bool is_Objective(...)
Definition
ROL_Sacado_Traits.hpp:10
Fad_value_t
decltype(Fad_value(std::declval< T >())) Fad_value_t
Definition
ROL_Sacado_Traits.hpp:39
ROL::Constraint
Defines the general constraint operator interface.
Definition
ROL_Constraint.hpp:52
ROL::Objective
Provides the interface to evaluate objective functions.
Definition
ROL_Objective.hpp:44
Accessor< std::vector< Real > >::size_type
typename std::vector< Real >::size_type size_type
Definition
ROL_Sacado_Traits.hpp:48
Accessor< std::vector< Real > >::value_type
typename std::vector< Real >::value_type value_type
Definition
ROL_Sacado_Traits.hpp:47
Accessor< std::vector< Real > >::container_type
std::vector< Real > container_type
Definition
ROL_Sacado_Traits.hpp:46
Accessor< std::vector< Real > >::get_value
value_type get_value(const container_type &x, size_type i) const
Definition
ROL_Sacado_Traits.hpp:49
Accessor< std::vector< Real > >::set_value
void set_value(container_type &x, size_type i, value_type xi) const
Definition
ROL_Sacado_Traits.hpp:52
Accessor
Definition
ROL_Sacado_Traits.hpp:42
InvalidType
Definition
ROL_Sacado_Traits.hpp:28
ObjectiveValue
Definition
ROL_Sacado_Traits.hpp:85
is_accessor_specialization
Definition
ROL_Sacado_Traits.hpp:59
Generated by
1.17.0