ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
sol
function
randvarfunctional
ROL_SampledScalar.hpp
Go to the documentation of this file.
1
// @HEADER
2
// *****************************************************************************
3
// Rapid Optimization Library (ROL) Package
4
//
5
// Copyright 2014 NTESS and the ROL contributors.
6
// SPDX-License-Identifier: BSD-3-Clause
7
// *****************************************************************************
8
// @HEADER
9
10
#ifndef ROL_SAMPLEDSCALAR_H
11
#define ROL_SAMPLEDSCALAR_H
12
13
namespace
ROL
{
14
15
template
<
class
Real,
class
Key=std::vector<Real>>
16
class
SampledScalar
{
17
private
:
18
// Storage
19
std::map<Key, int>
indices_
;
20
std::vector<bool>
flags_
;
21
std::vector<Real>
scalars_
;
22
int
maxIndex_
;
23
24
// Update flags
25
bool
updated_
;
26
27
void
reset
(
const
bool
flag =
true
) {
28
if
( flag ) {
29
typename
std::map<Key, int>::iterator it;
30
for
(it =
indices_
.begin(); it !=
indices_
.end(); ++it) {
31
flags_
[it->second] =
false
;
32
}
33
}
34
}
35
36
public
:
39
SampledScalar
(
void
)
40
:
maxIndex_
(0),
updated_
(false) {
41
indices_
.clear();
42
flags_
.clear();
43
scalars_
.clear();
44
}
45
48
void
update
(
const
bool
flag =
true
) {
49
updated_
= flag;
50
reset
(flag);
51
}
52
55
bool
get
(Real &x,
const
Key ¶m) {
56
int
count =
indices_
.count(param);
57
bool
flag =
false
;
58
int
index =
maxIndex_
;
59
if
(count) {
60
typename
std::map<Key, int>::iterator it =
indices_
.find(param);
61
index = it->second;
62
flag =
flags_
[index];
63
if
(flag) {
64
x =
scalars_
[index];
65
}
66
}
67
else
{
68
indices_
.insert(std::pair<Key, int>(param, index));
69
flags_
.push_back(
false
);
70
scalars_
.push_back(
static_cast<
Real
>
(0));
71
maxIndex_
++;
72
}
73
return
flag;
74
}
75
78
void
set
(
const
Real &x,
const
Key ¶m) {
79
int
count =
indices_
.count(param);
80
int
index =
maxIndex_
;
81
if
(count) {
82
typename
std::map<Key, int>::iterator it =
indices_
.find(param);
83
index = it->second;
84
flags_
[index] =
true
;
85
scalars_
[index] = x;
86
}
87
else
{
88
indices_
.insert(std::pair<Key, int>(param, index));
89
flags_
.push_back(
true
);
90
scalars_
.push_back(x);
91
maxIndex_
++;
92
}
93
}
94
};
// class SampledScalar
95
96
}
// namespace ROL
97
98
#endif
ROL::SampledScalar::flags_
std::vector< bool > flags_
Definition
ROL_SampledScalar.hpp:20
ROL::SampledScalar::reset
void reset(const bool flag=true)
Definition
ROL_SampledScalar.hpp:27
ROL::SampledScalar::updated_
bool updated_
Definition
ROL_SampledScalar.hpp:25
ROL::SampledScalar::scalars_
std::vector< Real > scalars_
Definition
ROL_SampledScalar.hpp:21
ROL::SampledScalar::SampledScalar
SampledScalar(void)
Constructor.
Definition
ROL_SampledScalar.hpp:39
ROL::SampledScalar::maxIndex_
int maxIndex_
Definition
ROL_SampledScalar.hpp:22
ROL::SampledScalar::indices_
std::map< Key, int > indices_
Definition
ROL_SampledScalar.hpp:19
ROL::SampledScalar::get
bool get(Real &x, const Key ¶m)
Return vector corresponding to input parameter.
Definition
ROL_SampledScalar.hpp:55
ROL::SampledScalar::set
void set(const Real &x, const Key ¶m)
Set vector corresponding to input parameter.
Definition
ROL_SampledScalar.hpp:78
ROL::SampledScalar::update
void update(const bool flag=true)
Update for SampledScalar storage.
Definition
ROL_SampledScalar.hpp:48
ROL
Definition
ROL_ElementwiseVector.hpp:27
Generated by
1.17.0