50 #include "Teuchos_oblackholestream.hpp" 51 #include "Teuchos_GlobalMPISession.hpp" 61 Teuchos::RCP<std::vector<Real> > cp
63 Teuchos::RCP<const std::vector<Real> > up
65 Teuchos::RCP<const std::vector<Real> > zp
68 Real half(0.5), two(2);
70 (*cp)[0] = (*up)[0]-(*zp)[0];
72 (*cp)[1] = half*std::pow((*up)[0]+(*up)[1]-(*zp)[0],two);
77 Teuchos::RCP<std::vector<Real> > jvp
79 Teuchos::RCP<const std::vector<Real> > vp
81 Teuchos::RCP<const std::vector<Real> > up
83 Teuchos::RCP<const std::vector<Real> > zp
86 (*jvp)[1] = ((*up)[0] + (*up)[1] - (*zp)[0]) * ((*vp)[0] + (*vp)[1]);
91 Teuchos::RCP<std::vector<Real> > jvp
93 Teuchos::RCP<const std::vector<Real> > vp
95 Teuchos::RCP<const std::vector<Real> > up
97 Teuchos::RCP<const std::vector<Real> > zp
99 (*jvp)[0] = -(*vp)[0];
100 (*jvp)[1] = ((*zp)[0] - (*up)[0] - (*up)[1]) * (*vp)[0];
105 Teuchos::RCP<std::vector<Real> > ajvp
107 Teuchos::RCP<const std::vector<Real> > vp
109 Teuchos::RCP<const std::vector<Real> > up
111 Teuchos::RCP<const std::vector<Real> > zp
113 (*ajvp)[0] = (*vp)[0] + ((*up)[0] + (*up)[1] - (*zp)[0]) * (*vp)[1];
114 (*ajvp)[1] = ((*up)[0] + (*up)[1] - (*zp)[0]) * (*vp)[1];
119 Teuchos::RCP<std::vector<Real> > ajvp
121 Teuchos::RCP<const std::vector<Real> > vp
123 Teuchos::RCP<const std::vector<Real> > up
125 Teuchos::RCP<const std::vector<Real> > zp
127 (*ajvp)[0] = ((*zp)[0] - (*up)[0] - (*up)[1]) * (*vp)[1] - (*vp)[0];
132 Teuchos::RCP<std::vector<Real> > ahwvp
134 Teuchos::RCP<const std::vector<Real> > wp
136 Teuchos::RCP<const std::vector<Real> > vp
138 Teuchos::RCP<const std::vector<Real> > up
140 Teuchos::RCP<const std::vector<Real> > zp
142 (*ahwvp)[0] = (*wp)[1] * ((*vp)[0] + (*vp)[1]);
143 (*ahwvp)[1] = (*wp)[1] * ((*vp)[0] + (*vp)[1]);
148 Teuchos::RCP<std::vector<Real> > ahwvp
150 Teuchos::RCP<const std::vector<Real> > wp
152 Teuchos::RCP<const std::vector<Real> > vp
154 Teuchos::RCP<const std::vector<Real> > up
156 Teuchos::RCP<const std::vector<Real> > zp
158 (*ahwvp)[0] = -(*wp)[1] * ((*vp)[0] + (*vp)[1]);
163 Teuchos::RCP<std::vector<Real> > ahwvp
165 Teuchos::RCP<const std::vector<Real> > wp
167 Teuchos::RCP<const std::vector<Real> > vp
169 Teuchos::RCP<const std::vector<Real> > up
171 Teuchos::RCP<const std::vector<Real> > zp
173 (*ahwvp)[0] = -(*wp)[1] * (*vp)[0];
174 (*ahwvp)[1] = -(*wp)[1] * (*vp)[0];
179 Teuchos::RCP<std::vector<Real> > ahwvp
181 Teuchos::RCP<const std::vector<Real> > wp
183 Teuchos::RCP<const std::vector<Real> > vp
185 Teuchos::RCP<const std::vector<Real> > up
187 Teuchos::RCP<const std::vector<Real> > zp
189 (*ahwvp)[0] = (*wp)[1] * (*vp)[0];
199 Teuchos::RCP<std::vector<Real> > cp
201 Teuchos::RCP<const std::vector<Real> > up
203 Teuchos::RCP<const std::vector<Real> > zp
206 const Real one(1), two(2);
208 (*cp)[0] = std::exp((*up)[0])-(std::pow((*zp)[0],two) + one);
213 Teuchos::RCP<std::vector<Real> > jvp
215 Teuchos::RCP<const std::vector<Real> > vp
217 Teuchos::RCP<const std::vector<Real> > up
219 Teuchos::RCP<const std::vector<Real> > zp
221 (*jvp)[0] = std::exp((*up)[0]) * (*vp)[0];
226 Teuchos::RCP<std::vector<Real> > jvp
228 Teuchos::RCP<const std::vector<Real> > vp
230 Teuchos::RCP<const std::vector<Real> > up
232 Teuchos::RCP<const std::vector<Real> > zp
236 (*jvp)[0] = -two * (*zp)[0] * (*vp)[0];
241 Teuchos::RCP<std::vector<Real> > ajvp
243 Teuchos::RCP<const std::vector<Real> > vp
245 Teuchos::RCP<const std::vector<Real> > up
247 Teuchos::RCP<const std::vector<Real> > zp
249 (*ajvp)[0] = std::exp((*up)[0]) * (*vp)[0];
254 Teuchos::RCP<std::vector<Real> > ajvp
256 Teuchos::RCP<const std::vector<Real> > vp
258 Teuchos::RCP<const std::vector<Real> > up
260 Teuchos::RCP<const std::vector<Real> > zp
264 (*ajvp)[0] = -two * (*zp)[0] * (*vp)[0];
269 Teuchos::RCP<std::vector<Real> > ijvp
271 Teuchos::RCP<const std::vector<Real> > vp
273 Teuchos::RCP<const std::vector<Real> > up
275 Teuchos::RCP<const std::vector<Real> > zp
277 (*ijvp)[0] = (*vp)[0] / std::exp((*up)[0]);
282 Teuchos::RCP<std::vector<Real> > ijvp
284 Teuchos::RCP<const std::vector<Real> > vp
286 Teuchos::RCP<const std::vector<Real> > up
288 Teuchos::RCP<const std::vector<Real> > zp
290 (*ijvp)[0] = (*vp)[0] / std::exp((*up)[0]);
295 Teuchos::RCP<std::vector<Real> > ahwvp
297 Teuchos::RCP<const std::vector<Real> > wp
299 Teuchos::RCP<const std::vector<Real> > vp
301 Teuchos::RCP<const std::vector<Real> > up
303 Teuchos::RCP<const std::vector<Real> > zp
305 (*ahwvp)[0] = std::exp((*up)[0]) * (*wp)[0] * (*vp)[0];
310 Teuchos::RCP<std::vector<Real> > ahwvp
312 Teuchos::RCP<const std::vector<Real> > wp
314 Teuchos::RCP<const std::vector<Real> > vp
316 Teuchos::RCP<const std::vector<Real> > up
318 Teuchos::RCP<const std::vector<Real> > zp
320 (*ahwvp)[0] =
static_cast<Real
>(0);
325 Teuchos::RCP<std::vector<Real> > ahwvp
327 Teuchos::RCP<const std::vector<Real> > wp
329 Teuchos::RCP<const std::vector<Real> > vp
331 Teuchos::RCP<const std::vector<Real> > up
333 Teuchos::RCP<const std::vector<Real> > zp
335 (*ahwvp)[0] =
static_cast<Real
>(0);
340 Teuchos::RCP<std::vector<Real> > ahwvp
342 Teuchos::RCP<const std::vector<Real> > wp
344 Teuchos::RCP<const std::vector<Real> > vp
346 Teuchos::RCP<const std::vector<Real> > up
348 Teuchos::RCP<const std::vector<Real> > zp
350 (*ahwvp)[0] =
static_cast<Real
>(-2) * (*wp)[0] * (*vp)[0];
356 int main(
int argc,
char *argv[]) {
358 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
361 int iprint = argc - 1;
362 Teuchos::RCP<std::ostream> outStream;
363 Teuchos::oblackholestream bhs;
365 outStream = Teuchos::rcp(&std::cout,
false);
367 outStream = Teuchos::rcp(&bhs,
false);
377 Teuchos::RCP<std::vector<RealT> > ustd = Teuchos::rcp(
new std::vector<RealT>(dim));
378 Teuchos::RCP<std::vector<RealT> > dustd = Teuchos::rcp(
new std::vector<RealT>(dim));
379 Teuchos::RCP<std::vector<RealT> > zstd = Teuchos::rcp(
new std::vector<RealT>(dimz));
380 Teuchos::RCP<std::vector<RealT> > dzstd = Teuchos::rcp(
new std::vector<RealT>(dimz));
381 Teuchos::RCP<std::vector<RealT> > cstd = Teuchos::rcp(
new std::vector<RealT>(dim));
382 Teuchos::RCP<std::vector<RealT> > czstd = Teuchos::rcp(
new std::vector<RealT>(dimz));
383 Teuchos::RCP<std::vector<RealT> > sstd = Teuchos::rcp(
new std::vector<RealT>(dimz));
384 Teuchos::RCP<std::vector<RealT> > dsstd = Teuchos::rcp(
new std::vector<RealT>(dimz));
386 (*ustd)[0] =
static_cast<RealT>(rand())/static_cast<RealT>(RAND_MAX);
387 (*ustd)[1] =
static_cast<RealT>(rand())/static_cast<RealT>(RAND_MAX);
388 (*dustd)[0] =
static_cast<RealT>(rand())/static_cast<RealT>(RAND_MAX);
389 (*dustd)[1] =
static_cast<RealT>(rand())/static_cast<RealT>(RAND_MAX);
390 (*zstd)[0] =
static_cast<RealT>(rand())/static_cast<RealT>(RAND_MAX);
391 (*dzstd)[0] =
static_cast<RealT>(rand())/static_cast<RealT>(RAND_MAX);
392 (*cstd)[0] =
static_cast<RealT>(rand())/static_cast<RealT>(RAND_MAX);
393 (*cstd)[1] =
static_cast<RealT>(rand())/static_cast<RealT>(RAND_MAX);
394 (*czstd)[0] =
static_cast<RealT>(rand())/static_cast<RealT>(RAND_MAX);
395 (*sstd)[0] =
static_cast<RealT>(rand())/static_cast<RealT>(RAND_MAX);
396 (*dsstd)[0] =
static_cast<RealT>(rand())/static_cast<RealT>(RAND_MAX);
414 Teuchos::RCP<ROL::EqualityConstraint_SimOpt<RealT> > valCon = Teuchos::rcp(
new valConstraint<RealT>());
415 valCon->checkAdjointConsistencyJacobian_1(*c,*du,*u,*s,
true,*outStream);
416 valCon->checkAdjointConsistencyJacobian_2(*c,*dz,*u,*s,
true,*outStream);
417 valCon->checkApplyJacobian_1(*u,*s,*du,*c,
true,*outStream);
418 valCon->checkApplyJacobian_2(*u,*s,*ds,*c,
true,*outStream);
419 valCon->checkApplyJacobian(x,dx,*c,
true,*outStream);
420 valCon->checkApplyAdjointHessian_11(*u,*s,*c,*du,*u,
true,*outStream);
421 valCon->checkApplyAdjointHessian_12(*u,*s,*c,*du,*s,
true,*outStream);
422 valCon->checkApplyAdjointHessian_21(*u,*s,*c,*ds,*u,
true,*outStream);
423 valCon->checkApplyAdjointHessian_22(*u,*s,*c,*ds,*s,
true,*outStream);
424 valCon->checkApplyAdjointHessian(x,*c,dx,x,
true,*outStream);
426 Teuchos::RCP<ROL::EqualityConstraint_SimOpt<RealT> > redCon = Teuchos::rcp(
new redConstraint<RealT>());
427 redCon->checkAdjointConsistencyJacobian_1(*cz,*ds,*s,*z,
true,*outStream);
428 redCon->checkAdjointConsistencyJacobian_2(*cz,*dz,*s,*z,
true,*outStream);
429 redCon->checkInverseJacobian_1(*cz,*ds,*s,*z,
true,*outStream);
430 redCon->checkInverseAdjointJacobian_1(*ds,*cz,*s,*z,
true,*outStream);
431 redCon->checkApplyJacobian_1(*s,*z,*ds,*cz,
true,*outStream);
432 redCon->checkApplyJacobian_2(*s,*z,*dz,*cz,
true,*outStream);
433 redCon->checkApplyJacobian(y,dy,*cz,
true,*outStream);
434 redCon->checkApplyAdjointHessian_11(*s,*z,*cz,*ds,*s,
true,*outStream);
435 redCon->checkApplyAdjointHessian_12(*s,*z,*cz,*ds,*z,
true,*outStream);
436 redCon->checkApplyAdjointHessian_21(*s,*z,*cz,*dz,*s,
true,*outStream);
437 redCon->checkApplyAdjointHessian_22(*s,*z,*cz,*dz,*z,
true,*outStream);
438 redCon->checkApplyAdjointHessian(y,*cz,dy,y,
true,*outStream);
452 catch (std::logic_error err) {
453 *outStream << err.what() <<
"\n";
458 std::cout <<
"End Result: TEST FAILED\n";
460 std::cout <<
"End Result: TEST PASSED\n";
void applyAdjointHessian_12(ROL::Vector< Real > &ahwv, const ROL::Vector< Real > &w, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the optimization-space derivative of the adjoint of the constraint simulation-space Jacobian at...
std::vector< std::vector< Real > > checkApplyAdjointHessian_12(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &p, const Vector< Real > &v, const Vector< Real > &hv, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
void applyAdjointHessian_21(ROL::Vector< Real > &ahwv, const ROL::Vector< Real > &w, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the simulation-space derivative of the adjoint of the constraint optimization-space Jacobian at...
void applyAdjointHessian_11(ROL::Vector< Real > &ahwv, const ROL::Vector< Real > &w, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the simulation-space derivative of the adjoint of the constraint simulation-space Jacobian at ...
void applyAdjointHessian_21(ROL::Vector< Real > &ahwv, const ROL::Vector< Real > &w, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the simulation-space derivative of the adjoint of the constraint optimization-space Jacobian at...
int main(int argc, char *argv[])
void value(ROL::Vector< Real > &c, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Evaluate the constraint operator at .
std::vector< std::vector< Real > > checkApplyAdjointHessian_11(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &p, const Vector< Real > &v, const Vector< Real > &hv, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Defines the linear algebra or vector space interface for simulation-based optimization.
void applyAdjointHessian_22(ROL::Vector< Real > &ahwv, const ROL::Vector< Real > &w, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the optimization-space derivative of the adjoint of the constraint optimization-space Jacobian ...
std::vector< std::vector< Real > > checkApplyAdjointHessian_22(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &p, const Vector< Real > &v, const Vector< Real > &hv, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
void applyJacobian_2(ROL::Vector< Real > &jv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the partial constraint Jacobian at , , to the vector .
void applyAdjointJacobian_1(ROL::Vector< Real > &ajv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the adjoint of the partial constraint Jacobian at , , to the vector . This is the primary inter...
void applyAdjointHessian_11(ROL::Vector< Real > &ahwv, const ROL::Vector< Real > &w, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the simulation-space derivative of the adjoint of the constraint simulation-space Jacobian at ...
Defines the linear algebra or vector space interface.
Defines the equality constraint operator interface for simulation-based optimization.
virtual std::vector< std::vector< Real > > checkApplyJacobian(const Vector< Real > &x, const Vector< Real > &v, const Vector< Real > &jv, const std::vector< Real > &steps, const bool printToStream=true, std::ostream &outStream=std::cout, const int order=1)
Finite-difference check for the constraint Jacobian application.
void applyJacobian_1(ROL::Vector< Real > &jv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the partial constraint Jacobian at , , to the vector .
void applyJacobian_1(ROL::Vector< Real > &jv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the partial constraint Jacobian at , , to the vector .
void applyAdjointJacobian_2(ROL::Vector< Real > &ajv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the adjoint of the partial constraint Jacobian at , , to vector . This is the primary interface...
void applyAdjointJacobian_1(ROL::Vector< Real > &ajv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the adjoint of the partial constraint Jacobian at , , to the vector . This is the primary inter...
EqualityConstraint_SimOpt()
void applyInverseAdjointJacobian_1(ROL::Vector< Real > &ijv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the inverse of the adjoint of the partial constraint Jacobian at , , to the vector ...
void applyAdjointHessian_22(ROL::Vector< Real > &ahwv, const ROL::Vector< Real > &w, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the optimization-space derivative of the adjoint of the constraint optimization-space Jacobian ...
void applyAdjointJacobian_2(ROL::Vector< Real > &ajv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the adjoint of the partial constraint Jacobian at , , to vector . This is the primary interface...
std::vector< std::vector< Real > > checkApplyJacobian_2(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &v, const Vector< Real > &jv, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
void applyAdjointHessian_12(ROL::Vector< Real > &ahwv, const ROL::Vector< Real > &w, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the optimization-space derivative of the adjoint of the constraint simulation-space Jacobian at...
void applyInverseJacobian_1(ROL::Vector< Real > &ijv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the inverse partial constraint Jacobian at , , to the vector .
virtual Real checkAdjointConsistencyJacobian_1(const Vector< Real > &w, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, const bool printToStream=true, std::ostream &outStream=std::cout)
Check the consistency of the Jacobian and its adjoint. This is the primary interface.
virtual std::vector< std::vector< Real > > checkApplyAdjointHessian(const Vector< Real > &x, const Vector< Real > &u, const Vector< Real > &v, const Vector< Real > &hv, const std::vector< Real > &step, const bool printToScreen=true, std::ostream &outStream=std::cout, const int order=1)
Finite-difference check for the application of the adjoint of constraint Hessian. ...
void applyJacobian_2(ROL::Vector< Real > &jv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the partial constraint Jacobian at , , to the vector .
Defines a composite equality constraint operator interface for simulation-based optimization.
std::vector< std::vector< Real > > checkApplyJacobian_1(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &v, const Vector< Real > &jv, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
virtual Real checkAdjointConsistencyJacobian_2(const Vector< Real > &w, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, const bool printToStream=true, std::ostream &outStream=std::cout)
Check the consistency of the Jacobian and its adjoint. This is the primary interface.
std::vector< std::vector< Real > > checkApplyAdjointHessian_21(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &p, const Vector< Real > &v, const Vector< Real > &hv, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
void value(ROL::Vector< Real > &c, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Evaluate the constraint operator at .