ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
sol
function
ROL_MeanValueConstraint_Def.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_MEANVALUECONSTRAINT_DEF_HPP
11
#define ROL_MEANVALUECONSTRAINT_DEF_HPP
12
13
namespace
ROL
{
14
15
template
<
typename
Real>
16
MeanValueConstraint<Real>::MeanValueConstraint
(
const
Ptr<
Constraint<Real>
> &con,
17
const
Ptr<
SampleGenerator<Real>
> &sampler)
18
:
con_
(con) {
19
std::vector<Real> param =
computeSampleMean
(sampler);
20
con_
->setParameter(param);
21
}
22
23
template
<
typename
Real>
24
void
MeanValueConstraint<Real>::update
(
const
Vector<Real>
&x,
bool
flag,
int
iter ) {
25
con_
->update(x,flag,iter);
26
}
27
28
template
<
typename
Real>
29
void
MeanValueConstraint<Real>::update
(
const
Vector<Real>
&x,
UpdateType
type,
int
iter ) {
30
con_
->update(x,type,iter);
31
}
32
33
template
<
typename
Real>
34
void
MeanValueConstraint<Real>::value
(
Vector<Real>
&c,
const
Vector<Real>
&x, Real &tol ) {
35
con_
->value(c,x,tol);
36
}
37
38
template
<
typename
Real>
39
void
MeanValueConstraint<Real>::applyJacobian
(
Vector<Real>
&jv,
const
Vector<Real>
&v,
const
Vector<Real>
&x, Real &tol) {
40
con_
->applyJacobian(jv,v,x,tol);
41
}
42
43
template
<
typename
Real>
44
void
MeanValueConstraint<Real>::applyAdjointJacobian
(
Vector<Real>
&ajv,
const
Vector<Real>
&v,
const
Vector<Real>
&x, Real &tol) {
45
con_
->applyAdjointJacobian(ajv,v,x,tol);
46
}
47
48
template
<
typename
Real>
49
void
MeanValueConstraint<Real>::applyAdjointHessian
(
Vector<Real>
&ahuv,
const
Vector<Real>
&u,
const
Vector<Real>
&v,
const
Vector<Real>
&x, Real &tol) {
50
con_
->applyAdjointHessian(ahuv,u,v,x,tol);
51
}
52
53
template
<
typename
Real>
54
std::vector<Real>
MeanValueConstraint<Real>::computeSampleMean
(
const
Ptr<
SampleGenerator<Real>
> &sampler)
const
{
55
// Compute mean value of inputs and set parameter in constraint
56
int
dim
= sampler->getMyPoint(0).size(), nsamp = sampler->numMySamples();
57
std::vector<Real> loc(
dim
), mean(
dim
), pt(
dim
);
58
Real wt(0);
59
for
(
int
i = 0; i < nsamp; i++) {
60
pt = sampler->getMyPoint(i);
61
wt = sampler->getMyWeight(i);
62
for
(
int
j = 0; j <
dim
; j++) {
63
loc[j] += wt*pt[j];
64
}
65
}
66
sampler->sumAll(&loc[0],&mean[0],
dim
);
67
return
mean;
68
}
69
70
}
71
72
#endif
ROL::MeanValueConstraint::applyAdjointHessian
void applyAdjointHessian(Vector< Real > &ahuv, const Vector< Real > &u, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Definition
ROL_MeanValueConstraint_Def.hpp:49
ROL::MeanValueConstraint::computeSampleMean
std::vector< Real > computeSampleMean(const Ptr< SampleGenerator< Real > > &sampler) const
Definition
ROL_MeanValueConstraint_Def.hpp:54
ROL::MeanValueConstraint::applyAdjointJacobian
void applyAdjointJacobian(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Definition
ROL_MeanValueConstraint_Def.hpp:44
ROL::MeanValueConstraint::applyJacobian
void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Definition
ROL_MeanValueConstraint_Def.hpp:39
ROL::MeanValueConstraint::update
void update(const Vector< Real > &x, bool flag=true, int iter=-1) override
Definition
ROL_MeanValueConstraint_Def.hpp:24
ROL::MeanValueConstraint::MeanValueConstraint
MeanValueConstraint(const Ptr< Constraint< Real > > &con, const Ptr< SampleGenerator< Real > > &sampler)
Definition
ROL_MeanValueConstraint_Def.hpp:16
ROL::MeanValueConstraint::value
void value(Vector< Real > &c, const Vector< Real > &x, Real &tol) override
Definition
ROL_MeanValueConstraint_Def.hpp:34
ROL::MeanValueConstraint::con_
const Ptr< Constraint< Real > > con_
Definition
ROL_MeanValueConstraint.hpp:21
ROL::ROL::Constraint::Constraint
Constraint(void)
Definition
ROL_Constraint_SerialSimOpt.hpp:59
ROL::SampleGenerator
Definition
ROL_SampleGenerator.hpp:20
ROL::Vector
Defines the linear algebra or vector space interface.
Definition
ROL_Vector.hpp:51
ROL
Definition
ROL_ElementwiseVector.hpp:27
ROL::UpdateType
UpdateType
Definition
ROL_UpdateType.hpp:18
dim
constexpr auto dim
Definition
vector/test_11.cpp:23
Generated by
1.17.0