ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
sol
function
randvarfunctional
ROL_SampledVector.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_SAMPLEDVECTOR_H
11
#define ROL_SAMPLEDVECTOR_H
12
13
namespace
ROL
{
14
15
template
<
class
Real,
class
Key=std::vector<Real>>
16
class
SampledVector
{
17
private
:
18
// Storage
19
std::map<Key, int>
indices_
;
20
std::vector<bool>
flags_
;
21
std::vector<ROL::Ptr<Vector<Real>>>
vectors_
;
22
int
maxIndex_
;
23
24
// Update flags
25
bool
updated_
;
26
27
void
reset
(
const
bool
flag =
true
) {
28
if
( flag ) {
29
flags_
.assign(
flags_
.size(),
false
);
30
// typename std::map<Key, int>::iterator it;
31
// for (it = indices_.begin(); it != indices_.end(); ++it) {
32
// flags_[it->second] = false;
33
// }
34
}
35
}
36
37
public
:
40
SampledVector
(
void
)
41
:
maxIndex_
(0),
updated_
(false) {
42
indices_
.clear();
43
flags_
.clear();
44
vectors_
.clear();
45
}
46
49
void
update
(
const
bool
flag =
true
) {
50
updated_
= flag;
51
reset
(flag);
52
}
53
56
bool
get
(
Vector<Real>
&x,
const
Key ¶m) {
57
int
count =
indices_
.count(param);
58
bool
flag =
false
;
59
int
index =
maxIndex_
;
60
if
(count) {
61
typename
std::map<Key, int>::iterator it =
indices_
.find(param);
62
index = it->second;
63
flag =
flags_
[index];
64
if
(flag) {
65
x.
set
(*
vectors_
[index]);
66
}
67
}
68
else
{
69
indices_
.insert(std::pair<Key, int>(param, index));
70
flags_
.push_back(
false
);
71
vectors_
.push_back(x.
clone
());
72
maxIndex_
++;
73
}
74
return
flag;
75
}
76
79
void
set
(
const
Vector<Real>
&x,
const
Key ¶m) {
80
int
count =
indices_
.count(param);
81
int
index =
maxIndex_
;
82
if
(count) {
83
typename
std::map<Key, int>::iterator it =
indices_
.find(param);
84
index = it->second;
85
flags_
[index] =
true
;
86
vectors_
[index]->set(x);
87
}
88
else
{
89
indices_
.insert(std::pair<Key, int>(param, index));
90
flags_
.push_back(
true
);
91
vectors_
.push_back(x.
clone
());
92
vectors_
[index]->set(x);
93
maxIndex_
++;
94
}
95
}
96
};
// class SampledVector
97
98
}
// namespace ROL
99
100
#endif
ROL::SampledVector::updated_
bool updated_
Definition
ROL_SampledVector.hpp:25
ROL::SampledVector::update
void update(const bool flag=true)
Update for SampledVector storage.
Definition
ROL_SampledVector.hpp:49
ROL::SampledVector::SampledVector
SampledVector(void)
Constructor.
Definition
ROL_SampledVector.hpp:40
ROL::SampledVector::indices_
std::map< Key, int > indices_
Definition
ROL_SampledVector.hpp:19
ROL::SampledVector::maxIndex_
int maxIndex_
Definition
ROL_SampledVector.hpp:22
ROL::SampledVector::set
void set(const Vector< Real > &x, const Key ¶m)
Set vector corresponding to input parameter.
Definition
ROL_SampledVector.hpp:79
ROL::SampledVector::vectors_
std::vector< ROL::Ptr< Vector< Real > > > vectors_
Definition
ROL_SampledVector.hpp:21
ROL::SampledVector::get
bool get(Vector< Real > &x, const Key ¶m)
Return vector corresponding to input parameter.
Definition
ROL_SampledVector.hpp:56
ROL::SampledVector::flags_
std::vector< bool > flags_
Definition
ROL_SampledVector.hpp:20
ROL::SampledVector::reset
void reset(const bool flag=true)
Definition
ROL_SampledVector.hpp:27
ROL::Vector
Defines the linear algebra or vector space interface.
Definition
ROL_Vector.hpp:51
ROL::Vector::set
virtual void set(const Vector &x)
Set where .
Definition
ROL_Vector.hpp:176
ROL::Vector::clone
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
ROL
Definition
ROL_ElementwiseVector.hpp:27
Generated by
1.17.0