ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
zoo
testproblems
ROL_CantileverBeam.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
16
17
#ifndef ROL_CANTILEVERBEAM_HPP
18
#define ROL_CANTILEVERBEAM_HPP
19
20
#include "
ROL_StdVector.hpp
"
21
#include "
ROL_TestProblem.hpp
"
22
#include "
ROL_Bounds.hpp
"
23
#include "
ROL_StdObjective.hpp
"
24
#include "
ROL_StdConstraint.hpp
"
25
26
namespace
ROL
{
27
namespace
ZOO
{
28
29
template
<
class
Real>
30
class
Objective_CantileverBeam
:
public
StdObjective
<Real> {
31
private
:
32
int
nseg_
;
33
Real
len_
;
34
std::vector<Real>
l_
;
35
36
public
:
37
Objective_CantileverBeam
(
const
int
nseg = 5)
38
:
nseg_
(nseg),
len_
(500) {
39
l_
.clear();
l_
.resize(nseg,
len_
/
static_cast<
Real
>
(
nseg_
));
40
}
41
42
Real
value
(
const
std::vector<Real> &x, Real &tol ) {
43
Real val(0);
44
for
(
int
i = 0; i <
nseg_
; ++i) {
45
val +=
l_
[i]*x[i]*x[i+
nseg_
];
46
}
47
return
val;
48
}
49
50
void
gradient
( std::vector<Real> &g,
const
std::vector<Real> &x, Real &tol ) {
51
for
(
int
i = 0; i <
nseg_
; ++i) {
52
g[i] =
l_
[i]*x[i+
nseg_
];
53
g[i+
nseg_
] =
l_
[i]*x[i];
54
}
55
}
56
57
void
hessVec
( std::vector<Real> &hv,
const
std::vector<Real> &v,
const
std::vector<Real> &x, Real &tol ) {
58
for
(
int
i = 0; i <
nseg_
; ++i) {
59
hv[i] =
l_
[i]*v[i+
nseg_
];
60
hv[i+
nseg_
] =
l_
[i]*v[i];
61
}
62
}
63
};
// class Objective_CantileverBeam
64
65
66
template
<
class
Real>
67
class
Constraint_CantileverBeam
:
public
StdConstraint
<Real> {
68
private
:
69
int
nseg_
;
70
Real
len_
,
P_
,
E_
,
Sigma_max_
,
tip_max_
;
71
std::vector<Real>
l_
,
suml_
,
M_
,
dyp_
;
72
73
public
:
74
Constraint_CantileverBeam
(
const
int
nseg = 5)
75
:
nseg_
(nseg),
len_
(500),
P_
(50e3),
E_
(200e5),
Sigma_max_
(14e3),
tip_max_
(2.5),
suml_
(0) {
76
const
Real half(0.5);
77
l_
.clear();
78
l_
.resize(
nseg_
,
len_
/
static_cast<
Real
>
(
nseg_
));
79
suml_
.resize(
nseg_
);
80
M_
.resize(
nseg_
);
81
dyp_
.resize(
nseg_
);
82
for
(
int
i = 0; i <
nseg_
; ++i) {
83
suml_
[i] =
static_cast<
Real
>
(i+1)*
l_
[i];
84
M_
[i] =
P_
*(
len_
-
suml_
[i] +
l_
[i]);
85
dyp_
[i] = (
len_
-
suml_
[i] + half*
l_
[i])*
static_cast<
Real
>
(
nseg_
-i-1);
86
}
87
}
88
89
void
value
( std::vector<Real> &c,
const
std::vector<Real> &x, Real &tol ) {
90
const
Real one(1), two(2), three(3), twelve(12), twenty(20);
91
std::vector<Real> y1(
nseg_
), yp(
nseg_
);
92
Real Inertia(0), sigma(0), sumy1(0), sumypl(0);
93
for
(
int
i = 0; i <
nseg_
; ++i) {
94
// stress constraint
95
Inertia = x[i]*std::pow(x[i+
nseg_
],3)/twelve;
96
sigma =
M_
[i]*(x[i+
nseg_
]/two)/Inertia;
97
c[i] = sigma /
Sigma_max_
- one;
98
// lateral slope constraint
99
c[i+
nseg_
] = x[i+
nseg_
] - twenty*x[i];
100
// tip deflection constraint
101
y1[i] =
P_
*std::pow(
l_
[i],2)/(two*
E_
*Inertia) * (
len_
-
suml_
[i] + two/three*
l_
[i]);
102
yp[i] =
P_
*
l_
[i]/(
E_
*Inertia) * (
len_
-
suml_
[i] +
l_
[i]/two);
103
sumy1 += y1[i];
104
}
105
// tip deflection constraint
106
for
(
int
i = 1; i <
nseg_
; ++i) {
107
yp[i] += yp[i-1];
108
sumypl += yp[i-1]*
l_
[i];
109
}
110
Real yN = sumy1 + sumypl;
111
c[2*
nseg_
] = yN /
tip_max_
- one;
112
}
113
114
void
applyJacobian
( std::vector<Real> &jv,
const
std::vector<Real> &v,
115
const
std::vector<Real> &x, Real &tol ) {
116
const
Real two(2), three(3), six(6), twelve(12), twenty(20);
117
// const Real one(1); // Unused
118
Real Inertia(0), dyN(0), sumW(0), sumH(0);
119
for
(
int
i = 0; i <
nseg_
; ++i) {
120
// stress constraint
121
jv[i] = -six/
Sigma_max_
*
M_
[i]*v[i]/std::pow(x[i]*x[i+
nseg_
],2)
122
-twelve/
Sigma_max_
*
M_
[i]*v[i+
nseg_
]/(x[i]*std::pow(x[i+
nseg_
],3));
123
// lateral slope constraint
124
jv[i+
nseg_
] = v[i+
nseg_
] - twenty*v[i];
125
// tip deflection constraint
126
Inertia = x[i]*std::pow(x[i+
nseg_
],3)/twelve;
127
dyN = -
P_
/
E_
* std::pow(
l_
[i],2)/Inertia*((
len_
-
suml_
[i] + two/three*
l_
[i])/two +
dyp_
[i]);
128
sumW += v[i]*(dyN/x[i])/
tip_max_
;
129
sumH += three*v[i+
nseg_
]*(dyN/x[i+
nseg_
])/
tip_max_
;
130
}
131
// tip deflection constraint
132
jv[2*
nseg_
] = sumW+sumH;
133
}
134
135
void
applyAdjointJacobian
( std::vector<Real> &ajv,
const
std::vector<Real> &v,
136
const
std::vector<Real> &x, Real &tol ) {
137
const
Real two(2), three(3), six(6), twelve(12), twenty(20);
138
// const Real one(1); // Unused
139
Real Inertia(0), dyN(0);
140
for
(
int
i = 0; i <
nseg_
; ++i) {
141
// stress constraint
142
ajv[i] = -six/
Sigma_max_
*
M_
[i]*v[i]/std::pow(x[i]*x[i+
nseg_
],2);
143
ajv[i+
nseg_
] = -twelve/
Sigma_max_
*
M_
[i]*v[i]/(x[i]*std::pow(x[i+
nseg_
],3));
144
// lateral slope constraint
145
ajv[i] += -twenty*v[i+
nseg_
];
146
ajv[i+
nseg_
] += v[i+
nseg_
];
147
// tip deflection constraint
148
Inertia = x[i]*std::pow(x[i+
nseg_
],3)/twelve;
149
dyN = -
P_
/
E_
* std::pow(
l_
[i],2)/Inertia*((
len_
-
suml_
[i] + two/three*
l_
[i])/two +
dyp_
[i]);
150
ajv[i] += v[2*
nseg_
]*(dyN/x[i])/
tip_max_
;
151
ajv[i+
nseg_
] += three*v[2*
nseg_
]*(dyN/x[i+
nseg_
])/
tip_max_
;
152
}
153
}
154
155
// void applyAdjointHessian( std::vector<Real> &ahuv, const std::vector<Real> &u,
156
// const std::vector<Real> &v, const std::vector<Real> &x,
157
// Real &tol ) {
158
// }
159
160
};
// class Constraint_CantileverBeam
161
162
163
164
template
<
class
Real>
165
class
getCantileverBeam
:
public
TestProblem
<Real> {
166
private
:
167
int
nseg_
;
168
169
public
:
170
getCantileverBeam
(
int
nseg = 5) :
nseg_
(nseg) {}
171
172
Ptr<Objective<Real> >
getObjective
(
void
)
const
{
173
return
makePtr<Objective_CantileverBeam<Real>>(
nseg_
);
174
}
175
176
Ptr<Constraint<Real> >
getInequalityConstraint
(
void
)
const
{
177
return
makePtr<Constraint_CantileverBeam<Real>>(
nseg_
);
178
}
179
180
Ptr<BoundConstraint<Real>>
getBoundConstraint
(
void
)
const
{
181
// Lower bound is zero
182
Ptr<std::vector<Real>> lp = makePtr<std::vector<Real>>(2*
nseg_
);
183
for
(
int
i = 0; i <
nseg_
; ++i) {
184
(*lp)[i] =
static_cast<
Real
>
(1);
185
(*lp)[i+
nseg_
] =
static_cast<
Real
>
(5);
186
}
187
188
// No upper bound
189
Ptr<std::vector<Real>> up = makePtr<std::vector<Real>>(2*
nseg_
,
ROL_INF<Real>
());
190
191
Ptr<Vector<Real>> l = makePtr<StdVector<Real>>(lp);
192
Ptr<Vector<Real>> u = makePtr<StdVector<Real>>(up);
193
194
return
makePtr<Bounds<Real>>(l,u);
195
}
196
197
Ptr<Vector<Real>>
getInitialGuess
(
void
)
const
{
198
Ptr<std::vector<Real> > x0p = makePtr<std::vector<Real>>(2*
nseg_
,0);
199
for
(
int
i = 0; i <
nseg_
; ++i) {
200
(*x0p)[i] =
static_cast<
Real
>
(5);
201
(*x0p)[i+
nseg_
] =
static_cast<
Real
>
(40);
202
}
203
204
return
makePtr<StdVector<Real>>(x0p);
205
}
206
207
Ptr<Vector<Real>>
getSolution
(
const
int
i = 0 )
const
{
208
//Ptr<std::vector<Real> > xp = makePtr<std::vector<Real>>(2);
209
//(*xp)[0] = 3.0;
210
//(*xp)[1] = std::sqrt(3.0);
211
212
Ptr<std::vector<Real>> xp = makePtr<std::vector<Real>>(2*
nseg_
);
213
for
(
int
li = 0; li <
nseg_
; ++li) {
214
(*xp)[li] = 3.0;
215
(*xp)[li+
nseg_
] = std::sqrt(3.0);
216
}
217
218
return
makePtr<StdVector<Real>>(xp);
219
}
220
221
Ptr<Vector<Real>>
getInequalityMultiplier
(
void
)
const
{
222
Ptr<std::vector<Real> > lp = makePtr<std::vector<Real>>(2*
nseg_
+1,0.0);
223
return
makePtr<StdVector<Real>>(lp);
224
}
225
226
Ptr<BoundConstraint<Real>>
getSlackBoundConstraint
(
void
)
const
{
227
// No lower bound
228
Ptr<std::vector<Real> > lp = makePtr<std::vector<Real>>(2*
nseg_
+1,
ROL_NINF<Real>
());
229
230
// Upper bound is zero
231
Ptr<std::vector<Real> > up = makePtr<std::vector<Real>>(2*
nseg_
+1,0);
232
233
Ptr<Vector<Real> > l = makePtr<StdVector<Real>>(lp);
234
Ptr<Vector<Real> > u = makePtr<StdVector<Real>>(up);
235
236
return
makePtr<Bounds<Real>>(l,u);
237
}
238
};
239
240
241
}
// namespace ZOO
242
}
// namespace ROL
243
244
#endif
// ROL_CANTILEVERBEAM_HPP
245
ROL_Bounds.hpp
ROL_StdConstraint.hpp
ROL_StdObjective.hpp
ROL_StdVector.hpp
ROL_TestProblem.hpp
Contains definitions of test objective functions.
ROL::StdConstraint
Defines the equality constraint operator interface for StdVectors.
Definition
ROL_StdConstraint.hpp:25
ROL::StdObjective
Specializes the ROL::Objective interface for objective functions that operate on ROL::StdVector's.
Definition
ROL_StdObjective.hpp:26
ROL::TestProblem::TestProblem
TestProblem(void)
Definition
ROL_TestProblem.hpp:28
ROL::ZOO::Constraint_CantileverBeam::P_
Real P_
Definition
ROL_CantileverBeam.hpp:70
ROL::ZOO::Constraint_CantileverBeam::applyAdjointJacobian
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition
ROL_CantileverBeam.hpp:135
ROL::ZOO::Constraint_CantileverBeam::dyp_
std::vector< Real > dyp_
Definition
ROL_CantileverBeam.hpp:71
ROL::ZOO::Constraint_CantileverBeam::Sigma_max_
Real Sigma_max_
Definition
ROL_CantileverBeam.hpp:70
ROL::ZOO::Constraint_CantileverBeam::len_
Real len_
Definition
ROL_CantileverBeam.hpp:70
ROL::ZOO::Constraint_CantileverBeam::M_
std::vector< Real > M_
Definition
ROL_CantileverBeam.hpp:71
ROL::ZOO::Constraint_CantileverBeam::value
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition
ROL_CantileverBeam.hpp:89
ROL::ZOO::Constraint_CantileverBeam::nseg_
int nseg_
Definition
ROL_CantileverBeam.hpp:69
ROL::ZOO::Constraint_CantileverBeam::Constraint_CantileverBeam
Constraint_CantileverBeam(const int nseg=5)
Definition
ROL_CantileverBeam.hpp:74
ROL::ZOO::Constraint_CantileverBeam::tip_max_
Real tip_max_
Definition
ROL_CantileverBeam.hpp:70
ROL::ZOO::Constraint_CantileverBeam::suml_
std::vector< Real > suml_
Definition
ROL_CantileverBeam.hpp:71
ROL::ZOO::Constraint_CantileverBeam::l_
std::vector< Real > l_
Definition
ROL_CantileverBeam.hpp:71
ROL::ZOO::Constraint_CantileverBeam::applyJacobian
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition
ROL_CantileverBeam.hpp:114
ROL::ZOO::Constraint_CantileverBeam::E_
Real E_
Definition
ROL_CantileverBeam.hpp:70
ROL::ZOO::Objective_CantileverBeam::Objective_CantileverBeam
Objective_CantileverBeam(const int nseg=5)
Definition
ROL_CantileverBeam.hpp:37
ROL::ZOO::Objective_CantileverBeam::len_
Real len_
Definition
ROL_CantileverBeam.hpp:33
ROL::ZOO::Objective_CantileverBeam::gradient
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Definition
ROL_CantileverBeam.hpp:50
ROL::ZOO::Objective_CantileverBeam::l_
std::vector< Real > l_
Definition
ROL_CantileverBeam.hpp:34
ROL::ZOO::Objective_CantileverBeam::nseg_
int nseg_
Definition
ROL_CantileverBeam.hpp:32
ROL::ZOO::Objective_CantileverBeam::value
Real value(const std::vector< Real > &x, Real &tol)
Definition
ROL_CantileverBeam.hpp:42
ROL::ZOO::Objective_CantileverBeam::hessVec
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition
ROL_CantileverBeam.hpp:57
ROL::ZOO::getCantileverBeam::getSolution
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition
ROL_CantileverBeam.hpp:207
ROL::ZOO::getCantileverBeam::getObjective
Ptr< Objective< Real > > getObjective(void) const
Definition
ROL_CantileverBeam.hpp:172
ROL::ZOO::getCantileverBeam::getInequalityConstraint
Ptr< Constraint< Real > > getInequalityConstraint(void) const
Definition
ROL_CantileverBeam.hpp:176
ROL::ZOO::getCantileverBeam::getInitialGuess
Ptr< Vector< Real > > getInitialGuess(void) const
Definition
ROL_CantileverBeam.hpp:197
ROL::ZOO::getCantileverBeam::nseg_
int nseg_
Definition
ROL_CantileverBeam.hpp:167
ROL::ZOO::getCantileverBeam::getBoundConstraint
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition
ROL_CantileverBeam.hpp:180
ROL::ZOO::getCantileverBeam::getInequalityMultiplier
Ptr< Vector< Real > > getInequalityMultiplier(void) const
Definition
ROL_CantileverBeam.hpp:221
ROL::ZOO::getCantileverBeam::getCantileverBeam
getCantileverBeam(int nseg=5)
Definition
ROL_CantileverBeam.hpp:170
ROL::ZOO::getCantileverBeam::getSlackBoundConstraint
Ptr< BoundConstraint< Real > > getSlackBoundConstraint(void) const
Definition
ROL_CantileverBeam.hpp:226
ROL::ZOO
Definition
ROL_Beale.hpp:26
ROL
Definition
ROL_ElementwiseVector.hpp:27
ROL::ROL_NINF
Real ROL_NINF(void)
Definition
ROL_Types.hpp:74
ROL::ROL_INF
Real ROL_INF(void)
Definition
ROL_Types.hpp:71
Generated by
1.17.0