ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
sol
function
ROL_AlmostSureConstraint.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_ALMOST_SURE_CONSTRAINT_H
11
#define ROL_ALMOST_SURE_CONSTRAINT_H
12
13
#include "
ROL_RiskVector.hpp
"
14
#include "
ROL_Constraint.hpp
"
15
#include "
ROL_SampleGenerator.hpp
"
16
#include "
ROL_SimulatedVector.hpp
"
17
18
namespace
ROL
{
19
20
template
<
class
Real>
21
class
AlmostSureConstraint
:
public
Constraint
<Real> {
22
private
:
23
const
Ptr<SampleGenerator<Real>>
sampler_
;
24
const
Ptr<Constraint<Real>>
con_
;
25
26
Ptr<Vector<Real>>
scratch1_
;
27
Ptr<Vector<Real>>
scratch2_
;
28
bool
isInitialized_
;
29
30
public
:
31
virtual
~AlmostSureConstraint
() {}
32
33
AlmostSureConstraint
(
const
Ptr<
SampleGenerator<Real>
> &sampler,
34
const
Ptr<
Constraint<Real>
> &con)
35
:
sampler_
(sampler),
con_
(con),
isInitialized_
(false) {}
36
37
void
update
(
const
Vector<Real>
&x,
bool
flag =
true
,
int
iter = -1 ) {
38
con_
->update(x,flag,iter);
39
}
40
void
update
(
const
Vector<Real>
&x,
UpdateType
type,
int
iter = -1 ) {
41
con_
->update(x,type,iter);
42
}
43
44
void
value
(
Vector<Real>
&c,
45
const
Vector<Real>
&x,
46
Real &tol) {
47
c.
zero
();
48
SimulatedVector<Real>
&pc =
dynamic_cast<
SimulatedVector<Real>
&
>
(c);
49
50
std::vector<Real> param;
51
for
(
int
i = 0; i <
sampler_
->numMySamples(); ++i) {
52
param =
sampler_
->getMyPoint(i);
53
con_
->setParameter(param);
54
con_
->update(x);
55
con_
->value(*(pc.
get
(i)), x, tol);
56
}
57
}
58
59
void
applyJacobian
(
Vector<Real>
&jv,
60
const
Vector<Real>
&v,
61
const
Vector<Real>
&x,
62
Real &tol) {
63
jv.
zero
();
64
SimulatedVector<Real>
&pjv =
dynamic_cast<
SimulatedVector<Real>
&
>
(jv);
65
66
std::vector<Real> param;
67
for
(
int
i = 0; i <
sampler_
->numMySamples(); ++i) {
68
param =
sampler_
->getMyPoint(i);
69
con_
->setParameter(param);
70
con_
->update(x);
71
con_
->applyJacobian(*(pjv.
get
(i)), v, x, tol);
72
}
73
}
74
75
void
applyAdjointJacobian
(
Vector<Real>
&ajv,
76
const
Vector<Real>
&v,
77
const
Vector<Real>
&x,
78
Real &tol) {
79
ajv.
zero
();
80
if
(!
isInitialized_
) {
81
scratch1_
= ajv.
clone
();
82
scratch2_
= ajv.
clone
();
83
isInitialized_
=
true
;
84
}
85
const
SimulatedVector<Real>
&pv =
dynamic_cast<
const
SimulatedVector<Real>
&
>
(v);
86
87
std::vector<Real> param;
88
scratch1_
->zero();
scratch2_
->zero();
89
for
(
int
i = 0; i <
sampler_
->numMySamples(); ++i) {
90
param =
sampler_
->getMyPoint(i);
91
con_
->setParameter(param);
92
con_
->update(x);
93
con_
->applyAdjointJacobian(*
scratch1_
, *(pv.
get
(i)), x, tol);
94
scratch2_
->plus(*
scratch1_
);
95
}
96
sampler_
->sumAll(*
scratch2_
, ajv);
97
}
98
99
void
applyAdjointHessian
(
Vector<Real>
&ahuv,
100
const
Vector<Real>
&u,
101
const
Vector<Real>
&v,
102
const
Vector<Real>
&x,
103
Real &tol) {
104
ahuv.
zero
();
105
if
(!
isInitialized_
) {
106
scratch1_
= ahuv.
clone
();
107
scratch2_
= ahuv.
clone
();
108
isInitialized_
=
true
;
109
}
110
const
SimulatedVector<Real>
&pu =
dynamic_cast<
const
SimulatedVector<Real>
&
>
(u);
111
112
std::vector<Real> param;
113
scratch1_
->zero();
scratch2_
->zero();
114
for
(
int
i = 0; i <
sampler_
->numMySamples(); ++i) {
115
param =
sampler_
->getMyPoint(i);
116
con_
->setParameter(param);
117
con_
->update(x);
118
con_
->applyAdjointHessian(*
scratch1_
, *(pu.
get
(i)), v, x, tol);
119
scratch2_
->plus(*
scratch1_
);
120
}
121
sampler_
->sumAll(*
scratch2_
, ahuv);
122
}
123
124
void
applyPreconditioner
(
Vector<Real>
&Pv,
125
const
Vector<Real>
&v,
126
const
Vector<Real>
&x,
127
const
Vector<Real>
&g,
128
Real &tol) {
129
Pv.
zero
();
130
SimulatedVector<Real>
&ppv =
dynamic_cast<
SimulatedVector<Real>
&
>
(Pv);
131
const
SimulatedVector<Real>
&pv =
dynamic_cast<
const
SimulatedVector<Real>
&
>
(v);
132
133
std::vector<Real> param;
134
scratch1_
->zero();
scratch2_
->zero();
135
for
(
int
i = 0; i <
sampler_
->numMySamples(); ++i) {
136
param =
sampler_
->getMyPoint(i);
137
con_
->setParameter(param);
138
con_
->update(x);
139
con_
->applyPreconditioner(*(ppv.
get
(i)), *(pv.
get
(i)), x, g, tol);
140
}
141
}
142
143
};
// class AlmostSureConstraint
144
145
}
// namespace ROL
146
147
#endif
ROL_Constraint.hpp
ROL_RiskVector.hpp
ROL_SampleGenerator.hpp
ROL_SimulatedVector.hpp
ROL::AlmostSureConstraint::update
void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Definition
ROL_AlmostSureConstraint.hpp:37
ROL::AlmostSureConstraint::applyAdjointHessian
void applyAdjointHessian(Vector< Real > &ahuv, const Vector< Real > &u, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Definition
ROL_AlmostSureConstraint.hpp:99
ROL::AlmostSureConstraint::AlmostSureConstraint
AlmostSureConstraint(const Ptr< SampleGenerator< Real > > &sampler, const Ptr< Constraint< Real > > &con)
Definition
ROL_AlmostSureConstraint.hpp:33
ROL::AlmostSureConstraint::update
void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Definition
ROL_AlmostSureConstraint.hpp:40
ROL::AlmostSureConstraint::scratch1_
Ptr< Vector< Real > > scratch1_
Definition
ROL_AlmostSureConstraint.hpp:26
ROL::AlmostSureConstraint::value
void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Definition
ROL_AlmostSureConstraint.hpp:44
ROL::AlmostSureConstraint::applyPreconditioner
void applyPreconditioner(Vector< Real > &Pv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g, Real &tol)
Definition
ROL_AlmostSureConstraint.hpp:124
ROL::AlmostSureConstraint::~AlmostSureConstraint
virtual ~AlmostSureConstraint()
Definition
ROL_AlmostSureConstraint.hpp:31
ROL::AlmostSureConstraint::applyJacobian
void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Definition
ROL_AlmostSureConstraint.hpp:59
ROL::AlmostSureConstraint::applyAdjointJacobian
void applyAdjointJacobian(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Definition
ROL_AlmostSureConstraint.hpp:75
ROL::AlmostSureConstraint::sampler_
const Ptr< SampleGenerator< Real > > sampler_
Definition
ROL_AlmostSureConstraint.hpp:23
ROL::AlmostSureConstraint::isInitialized_
bool isInitialized_
Definition
ROL_AlmostSureConstraint.hpp:28
ROL::AlmostSureConstraint::con_
const Ptr< Constraint< Real > > con_
Definition
ROL_AlmostSureConstraint.hpp:24
ROL::AlmostSureConstraint::scratch2_
Ptr< Vector< Real > > scratch2_
Definition
ROL_AlmostSureConstraint.hpp:27
ROL::ROL::Constraint::Constraint
Constraint(void)
Definition
ROL_Constraint_SerialSimOpt.hpp:59
ROL::SampleGenerator
Definition
ROL_SampleGenerator.hpp:20
ROL::SimulatedVector
Defines the linear algebra of a vector space on a generic partitioned vector where the individual vec...
Definition
ROL_SimulatedVector.hpp:34
ROL::SimulatedVector::get
ROL::Ptr< const Vector< Real > > get(size_type i) const
Definition
ROL_SimulatedVector.hpp:231
ROL::Vector
Defines the linear algebra or vector space interface.
Definition
ROL_Vector.hpp:51
ROL::Vector::zero
virtual void zero()
Set to zero vector.
Definition
ROL_Vector.hpp:134
ROL::Vector::clone
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
ROL
Definition
ROL_ElementwiseVector.hpp:27
ROL::UpdateType
UpdateType
Definition
ROL_UpdateType.hpp:18
Generated by
1.17.0