53 #include "Teuchos_GlobalMPISession.hpp"
56 template<
typename Real>
70 (*(cs.getVector()))[0] = std::exp(z1*u1)-z2*z2;
80 (*(us.getVector()))[0] =
static_cast<Real
>(2)*std::log(std::abs(z2)) / z1;
95 (*(jvs.getVector()))[0] = z1*std::exp(z1*u1)*v1;
111 (*(jvs.getVector()))[0] = u1*std::exp(z1*u1)*v1 -
static_cast<Real
>(2)*z2*v2;
125 (*(ijvs.getVector()))[0] = v1 / (z1*std::exp(z1*u1));
143 (*(ajvs.getVector()))[0] = u1*std::exp(z1*u1)*v1;
144 (*(ajvs.getVector()))[1] = -
static_cast<Real
>(2)*z2*v1;
164 (*(ahwvs.getVector()))[0] = z1*z1*std::exp(z1*u1)*v1*w1;
181 (*(ahwvs.getVector()))[0] = std::exp(z1*u1)*(
static_cast<Real
>(1)+u1*z1)*v1*w1;
182 (*(ahwvs.getVector()))[1] =
static_cast<Real
>(0);
199 (*(ahwvs.getVector()))[0] = std::exp(z1*u1)*(
static_cast<Real
>(1)+u1*z1)*v1*w1;
217 (*(ahwvs.getVector()))[0] = u1*u1*std::exp(z1*u1)*v1*w1;
218 (*(ahwvs.getVector()))[1] = -
static_cast<Real
>(2)*v2*w1;
223 template<
typename Real>
237 (*(cs.getVector()))[0] = z1*z2*u1;
238 (*(cs.getVector()))[1] = (z1-z2)*u1;
239 (*(cs.getVector()))[2] = u1*u1;
255 (*(jvs.getVector()))[0] = z1*z2*v1;
256 (*(jvs.getVector()))[1] = (z1-z2)*v1;
257 (*(jvs.getVector()))[2] = two*u1*v1;
273 (*(jvs.getVector()))[0] = z2*u1*v1 + z1*u1*v2;
274 (*(jvs.getVector()))[1] = (v1-v2)*u1;
275 (*(jvs.getVector()))[2] =
static_cast<Real
>(0);
293 (*(ajvs.getVector()))[0] = z1*z2*v1 + (z1-z2)*v2 + two*u1*v3;
309 (*(ajvs.getVector()))[0] = (z2*u1*v1 + u1*v2);
310 (*(ajvs.getVector()))[1] = (z1*u1*v1 - u1*v2);
326 (*(ahwvs.getVector()))[0] = two*v1*w3;
344 (*(ahwvs.getVector()))[0] = (z2*v1*w1 + v1*w2);
345 (*(ahwvs.getVector()))[1] = (z1*v1*w1 - v1*w2);
364 (*(ahwvs.getVector()))[0] = (v1*z2+z1*v2)*w1 + (v1-v2)*w2;
381 (*(ahwvs.getVector()))[0] = v2*u1*w1;
382 (*(ahwvs.getVector()))[1] = v1*u1*w1;
386 int main(
int argc,
char *argv[]) {
387 using RealT = double;
389 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
392 int iprint = argc - 1;
393 ROL::Ptr<std::ostream> outStream;
396 outStream = ROL::makePtrFromRef(std::cout);
398 outStream = ROL::makePtrFromRef(bhs);
402 oldFormatState.copyfmt(std::cout);
417 auto c1 = ROL::makePtr<ROL::StdVector<RealT>>(c1_dim);
418 auto c2 = ROL::makePtr<ROL::StdVector<RealT>>(c2_dim);
419 auto u = ROL::makePtr<ROL::StdVector<RealT>>(u_dim);
420 auto z = ROL::makePtr<ROL::StdVector<RealT>>(z_dim);
421 auto vc1 = ROL::makePtr<ROL::StdVector<RealT>>(c1_dim);
422 auto vc2 = ROL::makePtr<ROL::StdVector<RealT>>(c2_dim);
423 auto vu = ROL::makePtr<ROL::StdVector<RealT>>(u_dim);
424 auto vz = ROL::makePtr<ROL::StdVector<RealT>>(z_dim);
425 auto du = ROL::makePtr<ROL::StdVector<RealT>>(u_dim);
426 auto dz = ROL::makePtr<ROL::StdVector<RealT>>(z_dim);
427 c1->randomize(static_cast<RealT>(-1),static_cast<RealT>(1));
428 c2->randomize(static_cast<RealT>(-1),static_cast<RealT>(1));
429 u->randomize(static_cast<RealT>(-1),static_cast<RealT>(1));
430 z->randomize(static_cast<RealT>(-1),static_cast<RealT>(1));
431 vc1->randomize(static_cast<RealT>(-1),static_cast<RealT>(1));
432 vc2->randomize(static_cast<RealT>(-1),static_cast<RealT>(1));
433 vu->randomize(static_cast<RealT>(-1),static_cast<RealT>(1));
434 vz->randomize(static_cast<RealT>(-1),static_cast<RealT>(1));
435 du->randomize(static_cast<RealT>(-1),static_cast<RealT>(1));
436 dz->randomize(static_cast<RealT>(-1),static_cast<RealT>(1));
438 auto con1 = ROL::makePtr<constraint1<RealT>>();
439 auto con2 = ROL::makePtr<constraint2<RealT>>();
440 auto stateStore = ROL::makePtr<ROL::VectorController<RealT>>();
441 auto rcon = ROL::makePtr<ROL::Reduced_Constraint_SimOpt<RealT>>(con2,con1,stateStore,u,z,vc1,c2,
true,
false);
443 con1->checkSolve(*u,*z,*c1,
true,*outStream);
444 con1->checkAdjointConsistencyJacobian_1(*vc1,*vu,*u,*z,
true,*outStream);
445 con1->checkAdjointConsistencyJacobian_2(*vc1,*vz,*u,*z,
true,*outStream);
446 con1->checkInverseJacobian_1(*c1,*vu,*u,*z,
true,*outStream);
447 con1->checkInverseAdjointJacobian_1(*c1,*vu,*u,*z,
true,*outStream);
448 con1->checkApplyJacobian_1(*u,*z,*vu,*vc1,
true,*outStream);
449 con1->checkApplyJacobian_2(*u,*z,*vz,*vc1,
true,*outStream);
450 con1->checkApplyAdjointHessian_11(*u,*z,*vc1,*vu,*du,
true,*outStream);
451 con1->checkApplyAdjointHessian_12(*u,*z,*vc1,*vu,*dz,
true,*outStream);
452 con1->checkApplyAdjointHessian_21(*u,*z,*vc1,*vz,*du,
true,*outStream);
453 con1->checkApplyAdjointHessian_22(*u,*z,*vc1,*vz,*dz,
true,*outStream);
455 con2->checkAdjointConsistencyJacobian_1(*vc2,*vu,*u,*z,
true,*outStream);
456 con2->checkAdjointConsistencyJacobian_2(*vc2,*vz,*u,*z,
true,*outStream);
457 con2->checkApplyJacobian_1(*u,*z,*vu,*vc2,
true,*outStream);
458 con2->checkApplyJacobian_2(*u,*z,*vz,*vc2,
true,*outStream);
459 con2->checkApplyAdjointHessian_11(*u,*z,*vc2,*vu,*du,
true,*outStream);
460 con2->checkApplyAdjointHessian_12(*u,*z,*vc2,*vu,*dz,
true,*outStream);
461 con2->checkApplyAdjointHessian_21(*u,*z,*vc2,*vz,*du,
true,*outStream);
462 con2->checkApplyAdjointHessian_22(*u,*z,*vc2,*vz,*dz,
true,*outStream);
464 rcon->checkAdjointConsistencyJacobian(*vc2,*vz,*z,
true,*outStream);
465 rcon->checkApplyJacobian(*z,*vz,*vc2,
true,*outStream);
466 rcon->checkApplyAdjointHessian(*z,*vc2,*vz,*dz,
true,*outStream);
468 catch (std::logic_error& err) {
469 *outStream << err.what() <<
"\n";
474 std::cout <<
"End Result: TEST FAILED\n";
476 std::cout <<
"End Result: TEST PASSED\n";
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...
virtual int dimension() const
Return dimension of the vector space.
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 solve(ROL::Vector< Real > &c, ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Given , solve for .
Ptr< const std::vector< Element > > getVector() const
void applyInverseAdjointJacobian_1(ROL::Vector< Real > &iajv, 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 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...
Defines the linear algebra or vector space interface.
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 no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
basic_nullstream< char, std::char_traits< char >> nullstream
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_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 value(ROL::Vector< Real > &c, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Evaluate the constraint operator at .
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 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 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 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 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 .
int main(int argc, char *argv[])
Defines the constraint operator interface for simulation-based optimization.
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 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 value(ROL::Vector< Real > &c, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Evaluate the constraint operator 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 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...