44 #ifndef ROL_EQUALITY_CONSTRAINT_SIMOPT_H
45 #define ROL_EQUALITY_CONSTRAINT_SIMOPT_H
104 Teuchos::RCP<Vector<Real> >
jv_;
134 unew_(Teuchos::null),
jv_(Teuchos::null),
211 Real cnorm = c.
norm();
212 const Real ctol = std::min(
atol_,
rtol_*cnorm);
219 Real alpha(1), tmp(0);
222 std::cout <<
"\n Default EqualityConstraint_SimOpt::solve\n";
224 std::cout << std::setw(6) << std::left <<
"iter";
225 std::cout << std::setw(15) << std::left <<
"rnorm";
226 std::cout << std::setw(15) << std::left <<
"alpha";
229 for (cnt = 0; cnt <
maxit_; ++cnt) {
239 while ( tmp > (1.0-
decr_*alpha)*cnorm &&
251 std::cout << std::setw(6) << std::left << cnt;
252 std::cout << std::scientific << std::setprecision(6);
253 std::cout << std::setw(15) << std::left << tmp;
254 std::cout << std::scientific << std::setprecision(6);
255 std::cout << std::setw(15) << std::left << alpha;
269 Teuchos::RCP<EqualityConstraint_SimOpt<Real> > con = Teuchos::rcp(
this,
false);
271 Teuchos::ParameterList parlist;
272 parlist.sublist(
"Status Test").set(
"Gradient Tolerance",ctol);
273 parlist.sublist(
"Status Test").set(
"Step Tolerance",
stol_);
274 parlist.sublist(
"Status Test").set(
"Iteration Limit",
maxit_);
275 parlist.sublist(
"Step").sublist(
"Trust Region").set(
"Subproblem Solver",
"Truncated CG");
276 parlist.sublist(
"General").sublist(
"Krylov").set(
"Iteration Limit",100);
277 Teuchos::RCP<Algorithm<Real> > algo = Teuchos::rcp(
new Algorithm<Real>(
"Trust Region",parlist,
false));
282 Teuchos::RCP<EqualityConstraint_SimOpt<Real> > con = Teuchos::rcp(
this,
false);
283 Teuchos::RCP<const Vector<Real> > zVec = Teuchos::rcpFromRef(z);
284 Teuchos::RCP<EqualityConstraint<Real> > conU
286 Teuchos::RCP<Objective<Real> > objU
288 Teuchos::ParameterList parlist;
289 parlist.sublist(
"Status Test").set(
"Constraint Tolerance",ctol);
290 parlist.sublist(
"Status Test").set(
"Step Tolerance",
stol_);
291 parlist.sublist(
"Status Test").set(
"Iteration Limit",
maxit_);
292 Teuchos::RCP<Algorithm<Real> > algo = Teuchos::rcp(
new Algorithm<Real>(
"Composite Step",parlist,
false));
293 Teuchos::RCP<Vector<Real> > l = c.
dual().clone();
294 algo->run(u,*l,*objU,*conU,
print_);
298 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
299 ">>> ERROR (ROL:EqualityConstraint_SimOpt:solve): Invalid solver type!");
324 Teuchos::ParameterList & list = parlist.sublist(
"SimOpt").sublist(
"Solve");
356 Real ctol = std::sqrt(ROL_EPSILON<Real>());
359 if (v.
norm() > std::sqrt(ROL_EPSILON<Real>())) {
360 h = std::max(1.0,u.
norm()/v.
norm())*tol;
363 Teuchos::RCP<Vector<Real> > unew = u.
clone();
368 value(jv,*unew,z,ctol);
370 Teuchos::RCP<Vector<Real> > cold = jv.
clone();
372 value(*cold,u,z,ctol);
399 Real ctol = std::sqrt(ROL_EPSILON<Real>());
402 if (v.
norm() > std::sqrt(ROL_EPSILON<Real>())) {
403 h = std::max(1.0,u.
norm()/v.
norm())*tol;
406 Teuchos::RCP<Vector<Real> > znew = z.
clone();
411 value(jv,u,*znew,ctol);
413 Teuchos::RCP<Vector<Real> > cold = jv.
clone();
415 value(*cold,u,z,ctol);
441 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
442 "The method applyInverseJacobian_1 is used but not implemented!\n");
492 Real ctol = std::sqrt(ROL_EPSILON<Real>());
494 if (v.
norm() > std::sqrt(ROL_EPSILON<Real>())) {
495 h = std::max(1.0,u.
norm()/v.
norm())*tol;
497 Teuchos::RCP<Vector<Real> > cold = dualv.
clone();
498 Teuchos::RCP<Vector<Real> > cnew = dualv.
clone();
500 value(*cold,u,z,ctol);
501 Teuchos::RCP<Vector<Real> > unew = u.
clone();
503 for (
int i = 0; i < u.
dimension(); i++) {
505 unew->axpy(h,*(u.
basis(i)));
507 value(*cnew,*unew,z,ctol);
508 cnew->axpy(-1.0,*cold);
510 ajv.
axpy(cnew->dot(v),*((u.
dual()).basis(i)));
563 Real ctol = std::sqrt(ROL_EPSILON<Real>());
565 if (v.
norm() > std::sqrt(ROL_EPSILON<Real>())) {
566 h = std::max(1.0,u.
norm()/v.
norm())*tol;
568 Teuchos::RCP<Vector<Real> > cold = dualv.
clone();
569 Teuchos::RCP<Vector<Real> > cnew = dualv.
clone();
571 value(*cold,u,z,ctol);
572 Teuchos::RCP<Vector<Real> > znew = z.
clone();
574 for (
int i = 0; i < z.
dimension(); i++) {
576 znew->axpy(h,*(z.
basis(i)));
578 value(*cnew,u,*znew,ctol);
579 cnew->axpy(-1.0,*cold);
581 ajv.
axpy(cnew->dot(v),*((z.
dual()).basis(i)));
606 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
607 "The method applyInverseAdjointJacobian_1 is used but not implemented!\n");
633 Real jtol = std::sqrt(ROL_EPSILON<Real>());
636 if (v.
norm() > std::sqrt(ROL_EPSILON<Real>())) {
637 h = std::max(1.0,u.
norm()/v.
norm())*tol;
640 Teuchos::RCP<Vector<Real> > unew = u.
clone();
646 Teuchos::RCP<Vector<Real> > jv = ahwv.
clone();
678 Real jtol = std::sqrt(ROL_EPSILON<Real>());
681 if (v.
norm() > std::sqrt(ROL_EPSILON<Real>())) {
682 h = std::max(1.0,u.
norm()/v.
norm())*tol;
685 Teuchos::RCP<Vector<Real> > unew = u.
clone();
691 Teuchos::RCP<Vector<Real> > jv = ahwv.
clone();
723 Real jtol = std::sqrt(ROL_EPSILON<Real>());
726 if (v.
norm() > std::sqrt(ROL_EPSILON<Real>())) {
727 h = std::max(1.0,u.
norm()/v.
norm())*tol;
730 Teuchos::RCP<Vector<Real> > znew = z.
clone();
736 Teuchos::RCP<Vector<Real> > jv = ahwv.
clone();
767 Real jtol = std::sqrt(ROL_EPSILON<Real>());
770 if (v.
norm() > std::sqrt(ROL_EPSILON<Real>())) {
771 h = std::max(1.0,u.
norm()/v.
norm())*tol;
774 Teuchos::RCP<Vector<Real> > znew = z.
clone();
780 Teuchos::RCP<Vector<Real> > jv = ahwv.
clone();
860 Teuchos::RCP<ROL::Vector<Real> > ijv = (xs.
get_1())->clone();
865 catch (
const std::logic_error &e) {
871 Teuchos::RCP<ROL::Vector<Real> > ijv_dual = (gs.
get_1())->clone();
872 ijv_dual->
set(ijv->dual());
877 catch (
const std::logic_error &e) {
917 const Vector_SimOpt<Real> &vs = Teuchos::dyn_cast<
const Vector_SimOpt<Real> >(
920 Teuchos::RCP<Vector<Real> > jv2 = jv.
clone();
932 const Vector_SimOpt<Real> &xs = Teuchos::dyn_cast<
const Vector_SimOpt<Real> >(
934 Teuchos::RCP<Vector<Real> > ajv1 = (ajvs.
get_1())->clone();
937 Teuchos::RCP<Vector<Real> > ajv2 = (ajvs.
get_2())->clone();
950 const Vector_SimOpt<Real> &xs = Teuchos::dyn_cast<
const Vector_SimOpt<Real> >(
952 const Vector_SimOpt<Real> &vs = Teuchos::dyn_cast<
const Vector_SimOpt<Real> >(
955 Teuchos::RCP<Vector<Real> > C11 = (ahwvs.
get_1())->clone();
956 Teuchos::RCP<Vector<Real> > C21 = (ahwvs.
get_1())->clone();
962 Teuchos::RCP<Vector<Real> > C12 = (ahwvs.
get_2())->clone();
963 Teuchos::RCP<Vector<Real> > C22 = (ahwvs.
get_2())->clone();
975 const bool printToStream =
true,
976 std::ostream & outStream = std::cout) {
978 Real tol = ROL_EPSILON<Real>();
979 Teuchos::RCP<ROL::Vector<Real> > r = c.
clone();
980 Teuchos::RCP<ROL::Vector<Real> > s = u.
clone();
983 Teuchos::RCP<ROL::Vector<Real> > cs = c.
clone();
987 Real rnorm = r->norm();
988 Real cnorm = cs->norm();
989 if ( printToStream ) {
990 std::stringstream hist;
991 hist << std::scientific << std::setprecision(8);
992 hist <<
"\nTest SimOpt solve at feasible (u,z):\n";
993 hist <<
" Solver Residual = " << rnorm <<
"\n";
994 hist <<
" ||c(u,z)|| = " << cnorm <<
"\n";
995 outStream << hist.str();
1017 const bool printToStream =
true,
1018 std::ostream & outStream = std::cout) {
1044 const bool printToStream =
true,
1045 std::ostream & outStream = std::cout) {
1046 Real tol = ROL_EPSILON<Real>();
1047 Teuchos::RCP<Vector<Real> > Jv = dualw.
clone();
1050 Real wJv = w.
dot(Jv->dual());
1051 Teuchos::RCP<Vector<Real> > Jw = dualv.
clone();
1054 Real vJw = v.
dot(Jw->dual());
1055 Real diff = std::abs(wJv-vJw);
1056 if ( printToStream ) {
1057 std::stringstream hist;
1058 hist << std::scientific << std::setprecision(8);
1059 hist <<
"\nTest SimOpt consistency of Jacobian_1 and its adjoint: \n |<w,Jv> - <adj(J)w,v>| = "
1061 hist <<
" |<w,Jv>| = " << std::abs(wJv) <<
"\n";
1062 hist <<
" Relative Error = " << diff / (std::abs(wJv)+ROL_UNDERFLOW<Real>()) <<
"\n";
1063 outStream << hist.str();
1085 const bool printToStream =
true,
1086 std::ostream & outStream = std::cout) {
1111 const bool printToStream =
true,
1112 std::ostream & outStream = std::cout) {
1113 Real tol = ROL_EPSILON<Real>();
1114 Teuchos::RCP<Vector<Real> > Jv = dualw.
clone();
1117 Real wJv = w.
dot(Jv->dual());
1118 Teuchos::RCP<Vector<Real> > Jw = dualv.
clone();
1121 Real vJw = v.
dot(Jw->dual());
1122 Real diff = std::abs(wJv-vJw);
1123 if ( printToStream ) {
1124 std::stringstream hist;
1125 hist << std::scientific << std::setprecision(8);
1126 hist <<
"\nTest SimOpt consistency of Jacobian_2 and its adjoint: \n |<w,Jv> - <adj(J)w,v>| = "
1128 hist <<
" |<w,Jv>| = " << std::abs(wJv) <<
"\n";
1129 hist <<
" Relative Error = " << diff / (std::abs(wJv)+ROL_UNDERFLOW<Real>()) <<
"\n";
1130 outStream << hist.str();
1139 const bool printToStream =
true,
1140 std::ostream & outStream = std::cout) {
1141 Real tol = ROL_EPSILON<Real>();
1142 Teuchos::RCP<Vector<Real> > Jv = jv.
clone();
1145 Teuchos::RCP<Vector<Real> > iJJv = u.
clone();
1148 Teuchos::RCP<Vector<Real> > diff = v.
clone();
1150 diff->axpy(-1.0,*iJJv);
1151 Real dnorm = diff->norm();
1152 Real vnorm = v.
norm();
1153 if ( printToStream ) {
1154 std::stringstream hist;
1155 hist << std::scientific << std::setprecision(8);
1156 hist <<
"\nTest SimOpt consistency of inverse Jacobian_1: \n ||v-inv(J)Jv|| = "
1158 hist <<
" ||v|| = " << vnorm <<
"\n";
1159 hist <<
" Relative Error = " << dnorm / (vnorm+ROL_UNDERFLOW<Real>()) <<
"\n";
1160 outStream << hist.str();
1169 const bool printToStream =
true,
1170 std::ostream & outStream = std::cout) {
1171 Real tol = ROL_EPSILON<Real>();
1172 Teuchos::RCP<Vector<Real> > Jv = jv.
clone();
1175 Teuchos::RCP<Vector<Real> > iJJv = v.
clone();
1178 Teuchos::RCP<Vector<Real> > diff = v.
clone();
1180 diff->axpy(-1.0,*iJJv);
1181 Real dnorm = diff->norm();
1182 Real vnorm = v.
norm();
1183 if ( printToStream ) {
1184 std::stringstream hist;
1185 hist << std::scientific << std::setprecision(8);
1186 hist <<
"\nTest SimOpt consistency of inverse adjoint Jacobian_1: \n ||v-inv(adj(J))adj(J)v|| = "
1188 hist <<
" ||v|| = " << vnorm <<
"\n";
1189 hist <<
" Relative Error = " << dnorm / (vnorm+ROL_UNDERFLOW<Real>()) <<
"\n";
1190 outStream << hist.str();
1201 const bool printToStream =
true,
1202 std::ostream & outStream = std::cout,
1204 const int order = 1) {
1205 std::vector<Real> steps(numSteps);
1206 for(
int i=0;i<numSteps;++i) {
1207 steps[i] = pow(10,-i);
1220 const std::vector<Real> &steps,
1221 const bool printToStream =
true,
1222 std::ostream & outStream = std::cout,
1223 const int order = 1) {
1225 TEUCHOS_TEST_FOR_EXCEPTION( order<1 || order>4, std::invalid_argument,
1226 "Error: finite difference order must be 1,2,3, or 4" );
1233 Real tol = std::sqrt(ROL_EPSILON<Real>());
1235 int numSteps = steps.size();
1237 std::vector<Real> tmp(numVals);
1238 std::vector<std::vector<Real> > jvCheck(numSteps, tmp);
1241 Teuchos::oblackholestream oldFormatState;
1242 oldFormatState.copyfmt(outStream);
1245 Teuchos::RCP<Vector<Real> > c = jv.
clone();
1247 this->
value(*c, u, z, tol);
1250 Teuchos::RCP<Vector<Real> > Jv = jv.
clone();
1252 Real normJv = Jv->norm();
1255 Teuchos::RCP<Vector<Real> > cdif = jv.
clone();
1256 Teuchos::RCP<Vector<Real> > cnew = jv.
clone();
1257 Teuchos::RCP<Vector<Real> > unew = u.
clone();
1259 for (
int i=0; i<numSteps; i++) {
1261 Real eta = steps[i];
1266 cdif->scale(
weights[order-1][0]);
1268 for(
int j=0; j<order; ++j) {
1270 unew->axpy(eta*
shifts[order-1][j], v);
1272 if(
weights[order-1][j+1] != 0 ) {
1274 this->
value(*cnew,*unew,z,tol);
1275 cdif->axpy(
weights[order-1][j+1],*cnew);
1280 cdif->scale(one/eta);
1283 jvCheck[i][0] = eta;
1284 jvCheck[i][1] = normJv;
1285 jvCheck[i][2] = cdif->norm();
1286 cdif->axpy(-one, *Jv);
1287 jvCheck[i][3] = cdif->norm();
1289 if (printToStream) {
1290 std::stringstream hist;
1293 << std::setw(20) <<
"Step size"
1294 << std::setw(20) <<
"norm(Jac*vec)"
1295 << std::setw(20) <<
"norm(FD approx)"
1296 << std::setw(20) <<
"norm(abs error)"
1298 << std::setw(20) <<
"---------"
1299 << std::setw(20) <<
"-------------"
1300 << std::setw(20) <<
"---------------"
1301 << std::setw(20) <<
"---------------"
1304 hist << std::scientific << std::setprecision(11) << std::right
1305 << std::setw(20) << jvCheck[i][0]
1306 << std::setw(20) << jvCheck[i][1]
1307 << std::setw(20) << jvCheck[i][2]
1308 << std::setw(20) << jvCheck[i][3]
1310 outStream << hist.str();
1316 outStream.copyfmt(oldFormatState);
1326 const bool printToStream =
true,
1327 std::ostream & outStream = std::cout,
1329 const int order = 1) {
1330 std::vector<Real> steps(numSteps);
1331 for(
int i=0;i<numSteps;++i) {
1332 steps[i] = pow(10,-i);
1345 const std::vector<Real> &steps,
1346 const bool printToStream =
true,
1347 std::ostream & outStream = std::cout,
1348 const int order = 1) {
1350 TEUCHOS_TEST_FOR_EXCEPTION( order<1 || order>4, std::invalid_argument,
1351 "Error: finite difference order must be 1,2,3, or 4" );
1358 Real tol = std::sqrt(ROL_EPSILON<Real>());
1360 int numSteps = steps.size();
1362 std::vector<Real> tmp(numVals);
1363 std::vector<std::vector<Real> > jvCheck(numSteps, tmp);
1366 Teuchos::oblackholestream oldFormatState;
1367 oldFormatState.copyfmt(outStream);
1370 Teuchos::RCP<Vector<Real> > c = jv.
clone();
1372 this->
value(*c, u, z, tol);
1375 Teuchos::RCP<Vector<Real> > Jv = jv.
clone();
1377 Real normJv = Jv->norm();
1380 Teuchos::RCP<Vector<Real> > cdif = jv.
clone();
1381 Teuchos::RCP<Vector<Real> > cnew = jv.
clone();
1382 Teuchos::RCP<Vector<Real> > znew = z.
clone();
1384 for (
int i=0; i<numSteps; i++) {
1386 Real eta = steps[i];
1391 cdif->scale(
weights[order-1][0]);
1393 for(
int j=0; j<order; ++j) {
1395 znew->axpy(eta*
shifts[order-1][j], v);
1397 if(
weights[order-1][j+1] != 0 ) {
1399 this->
value(*cnew,u,*znew,tol);
1400 cdif->axpy(
weights[order-1][j+1],*cnew);
1405 cdif->scale(one/eta);
1408 jvCheck[i][0] = eta;
1409 jvCheck[i][1] = normJv;
1410 jvCheck[i][2] = cdif->norm();
1411 cdif->axpy(-one, *Jv);
1412 jvCheck[i][3] = cdif->norm();
1414 if (printToStream) {
1415 std::stringstream hist;
1418 << std::setw(20) <<
"Step size"
1419 << std::setw(20) <<
"norm(Jac*vec)"
1420 << std::setw(20) <<
"norm(FD approx)"
1421 << std::setw(20) <<
"norm(abs error)"
1423 << std::setw(20) <<
"---------"
1424 << std::setw(20) <<
"-------------"
1425 << std::setw(20) <<
"---------------"
1426 << std::setw(20) <<
"---------------"
1429 hist << std::scientific << std::setprecision(11) << std::right
1430 << std::setw(20) << jvCheck[i][0]
1431 << std::setw(20) << jvCheck[i][1]
1432 << std::setw(20) << jvCheck[i][2]
1433 << std::setw(20) << jvCheck[i][3]
1435 outStream << hist.str();
1441 outStream.copyfmt(oldFormatState);
1453 const bool printToStream =
true,
1454 std::ostream & outStream = std::cout,
1456 const int order = 1 ) {
1457 std::vector<Real> steps(numSteps);
1458 for(
int i=0;i<numSteps;++i) {
1459 steps[i] = pow(10,-i);
1471 const std::vector<Real> &steps,
1472 const bool printToStream =
true,
1473 std::ostream & outStream = std::cout,
1474 const int order = 1 ) {
1480 Real tol = std::sqrt(ROL_EPSILON<Real>());
1482 int numSteps = steps.size();
1484 std::vector<Real> tmp(numVals);
1485 std::vector<std::vector<Real> > ahpvCheck(numSteps, tmp);
1488 Teuchos::RCP<Vector<Real> > AJdif = hv.
clone();
1489 Teuchos::RCP<Vector<Real> > AJp = hv.
clone();
1490 Teuchos::RCP<Vector<Real> > AHpv = hv.
clone();
1491 Teuchos::RCP<Vector<Real> > AJnew = hv.
clone();
1492 Teuchos::RCP<Vector<Real> > unew = u.
clone();
1495 Teuchos::oblackholestream oldFormatState;
1496 oldFormatState.copyfmt(outStream);
1504 Real normAHpv = AHpv->norm();
1506 for (
int i=0; i<numSteps; i++) {
1508 Real eta = steps[i];
1514 AJdif->scale(
weights[order-1][0]);
1516 for(
int j=0; j<order; ++j) {
1518 unew->axpy(eta*
shifts[order-1][j],v);
1520 if(
weights[order-1][j+1] != 0 ) {
1523 AJdif->axpy(
weights[order-1][j+1],*AJnew);
1527 AJdif->scale(one/eta);
1530 ahpvCheck[i][0] = eta;
1531 ahpvCheck[i][1] = normAHpv;
1532 ahpvCheck[i][2] = AJdif->norm();
1533 AJdif->axpy(-one, *AHpv);
1534 ahpvCheck[i][3] = AJdif->norm();
1536 if (printToStream) {
1537 std::stringstream hist;
1540 << std::setw(20) <<
"Step size"
1541 << std::setw(20) <<
"norm(adj(H)(u,v))"
1542 << std::setw(20) <<
"norm(FD approx)"
1543 << std::setw(20) <<
"norm(abs error)"
1545 << std::setw(20) <<
"---------"
1546 << std::setw(20) <<
"-----------------"
1547 << std::setw(20) <<
"---------------"
1548 << std::setw(20) <<
"---------------"
1551 hist << std::scientific << std::setprecision(11) << std::right
1552 << std::setw(20) << ahpvCheck[i][0]
1553 << std::setw(20) << ahpvCheck[i][1]
1554 << std::setw(20) << ahpvCheck[i][2]
1555 << std::setw(20) << ahpvCheck[i][3]
1557 outStream << hist.str();
1563 outStream.copyfmt(oldFormatState);
1573 const bool printToStream =
true,
1574 std::ostream & outStream = std::cout,
1576 const int order = 1 ) {
1577 std::vector<Real> steps(numSteps);
1578 for(
int i=0;i<numSteps;++i) {
1579 steps[i] = pow(10,-i);
1591 const std::vector<Real> &steps,
1592 const bool printToStream =
true,
1593 std::ostream & outStream = std::cout,
1594 const int order = 1 ) {
1600 Real tol = std::sqrt(ROL_EPSILON<Real>());
1602 int numSteps = steps.size();
1604 std::vector<Real> tmp(numVals);
1605 std::vector<std::vector<Real> > ahpvCheck(numSteps, tmp);
1608 Teuchos::RCP<Vector<Real> > AJdif = hv.
clone();
1609 Teuchos::RCP<Vector<Real> > AJp = hv.
clone();
1610 Teuchos::RCP<Vector<Real> > AHpv = hv.
clone();
1611 Teuchos::RCP<Vector<Real> > AJnew = hv.
clone();
1612 Teuchos::RCP<Vector<Real> > znew = z.
clone();
1615 Teuchos::oblackholestream oldFormatState;
1616 oldFormatState.copyfmt(outStream);
1624 Real normAHpv = AHpv->norm();
1626 for (
int i=0; i<numSteps; i++) {
1628 Real eta = steps[i];
1634 AJdif->scale(
weights[order-1][0]);
1636 for(
int j=0; j<order; ++j) {
1638 znew->axpy(eta*
shifts[order-1][j],v);
1640 if(
weights[order-1][j+1] != 0 ) {
1643 AJdif->axpy(
weights[order-1][j+1],*AJnew);
1647 AJdif->scale(one/eta);
1650 ahpvCheck[i][0] = eta;
1651 ahpvCheck[i][1] = normAHpv;
1652 ahpvCheck[i][2] = AJdif->norm();
1653 AJdif->axpy(-one, *AHpv);
1654 ahpvCheck[i][3] = AJdif->norm();
1656 if (printToStream) {
1657 std::stringstream hist;
1660 << std::setw(20) <<
"Step size"
1661 << std::setw(20) <<
"norm(adj(H)(u,v))"
1662 << std::setw(20) <<
"norm(FD approx)"
1663 << std::setw(20) <<
"norm(abs error)"
1665 << std::setw(20) <<
"---------"
1666 << std::setw(20) <<
"-----------------"
1667 << std::setw(20) <<
"---------------"
1668 << std::setw(20) <<
"---------------"
1671 hist << std::scientific << std::setprecision(11) << std::right
1672 << std::setw(20) << ahpvCheck[i][0]
1673 << std::setw(20) << ahpvCheck[i][1]
1674 << std::setw(20) << ahpvCheck[i][2]
1675 << std::setw(20) << ahpvCheck[i][3]
1677 outStream << hist.str();
1683 outStream.copyfmt(oldFormatState);
1693 const bool printToStream =
true,
1694 std::ostream & outStream = std::cout,
1696 const int order = 1 ) {
1697 std::vector<Real> steps(numSteps);
1698 for(
int i=0;i<numSteps;++i) {
1699 steps[i] = pow(10,-i);
1711 const std::vector<Real> &steps,
1712 const bool printToStream =
true,
1713 std::ostream & outStream = std::cout,
1714 const int order = 1 ) {
1720 Real tol = std::sqrt(ROL_EPSILON<Real>());
1722 int numSteps = steps.size();
1724 std::vector<Real> tmp(numVals);
1725 std::vector<std::vector<Real> > ahpvCheck(numSteps, tmp);
1728 Teuchos::RCP<Vector<Real> > AJdif = hv.
clone();
1729 Teuchos::RCP<Vector<Real> > AJp = hv.
clone();
1730 Teuchos::RCP<Vector<Real> > AHpv = hv.
clone();
1731 Teuchos::RCP<Vector<Real> > AJnew = hv.
clone();
1732 Teuchos::RCP<Vector<Real> > unew = u.
clone();
1735 Teuchos::oblackholestream oldFormatState;
1736 oldFormatState.copyfmt(outStream);
1744 Real normAHpv = AHpv->norm();
1746 for (
int i=0; i<numSteps; i++) {
1748 Real eta = steps[i];
1754 AJdif->scale(
weights[order-1][0]);
1756 for(
int j=0; j<order; ++j) {
1758 unew->axpy(eta*
shifts[order-1][j],v);
1760 if(
weights[order-1][j+1] != 0 ) {
1763 AJdif->axpy(
weights[order-1][j+1],*AJnew);
1767 AJdif->scale(one/eta);
1770 ahpvCheck[i][0] = eta;
1771 ahpvCheck[i][1] = normAHpv;
1772 ahpvCheck[i][2] = AJdif->norm();
1773 AJdif->axpy(-one, *AHpv);
1774 ahpvCheck[i][3] = AJdif->norm();
1776 if (printToStream) {
1777 std::stringstream hist;
1780 << std::setw(20) <<
"Step size"
1781 << std::setw(20) <<
"norm(adj(H)(u,v))"
1782 << std::setw(20) <<
"norm(FD approx)"
1783 << std::setw(20) <<
"norm(abs error)"
1785 << std::setw(20) <<
"---------"
1786 << std::setw(20) <<
"-----------------"
1787 << std::setw(20) <<
"---------------"
1788 << std::setw(20) <<
"---------------"
1791 hist << std::scientific << std::setprecision(11) << std::right
1792 << std::setw(20) << ahpvCheck[i][0]
1793 << std::setw(20) << ahpvCheck[i][1]
1794 << std::setw(20) << ahpvCheck[i][2]
1795 << std::setw(20) << ahpvCheck[i][3]
1797 outStream << hist.str();
1803 outStream.copyfmt(oldFormatState);
1813 const bool printToStream =
true,
1814 std::ostream & outStream = std::cout,
1816 const int order = 1 ) {
1817 std::vector<Real> steps(numSteps);
1818 for(
int i=0;i<numSteps;++i) {
1819 steps[i] = pow(10,-i);
1831 const std::vector<Real> &steps,
1832 const bool printToStream =
true,
1833 std::ostream & outStream = std::cout,
1834 const int order = 1 ) {
1840 Real tol = std::sqrt(ROL_EPSILON<Real>());
1842 int numSteps = steps.size();
1844 std::vector<Real> tmp(numVals);
1845 std::vector<std::vector<Real> > ahpvCheck(numSteps, tmp);
1848 Teuchos::RCP<Vector<Real> > AJdif = hv.
clone();
1849 Teuchos::RCP<Vector<Real> > AJp = hv.
clone();
1850 Teuchos::RCP<Vector<Real> > AHpv = hv.
clone();
1851 Teuchos::RCP<Vector<Real> > AJnew = hv.
clone();
1852 Teuchos::RCP<Vector<Real> > znew = z.
clone();
1855 Teuchos::oblackholestream oldFormatState;
1856 oldFormatState.copyfmt(outStream);
1864 Real normAHpv = AHpv->norm();
1866 for (
int i=0; i<numSteps; i++) {
1868 Real eta = steps[i];
1874 AJdif->scale(
weights[order-1][0]);
1876 for(
int j=0; j<order; ++j) {
1878 znew->axpy(eta*
shifts[order-1][j],v);
1880 if(
weights[order-1][j+1] != 0 ) {
1883 AJdif->axpy(
weights[order-1][j+1],*AJnew);
1887 AJdif->scale(one/eta);
1890 ahpvCheck[i][0] = eta;
1891 ahpvCheck[i][1] = normAHpv;
1892 ahpvCheck[i][2] = AJdif->norm();
1893 AJdif->axpy(-one, *AHpv);
1894 ahpvCheck[i][3] = AJdif->norm();
1896 if (printToStream) {
1897 std::stringstream hist;
1900 << std::setw(20) <<
"Step size"
1901 << std::setw(20) <<
"norm(adj(H)(u,v))"
1902 << std::setw(20) <<
"norm(FD approx)"
1903 << std::setw(20) <<
"norm(abs error)"
1905 << std::setw(20) <<
"---------"
1906 << std::setw(20) <<
"-----------------"
1907 << std::setw(20) <<
"---------------"
1908 << std::setw(20) <<
"---------------"
1911 hist << std::scientific << std::setprecision(11) << std::right
1912 << std::setw(20) << ahpvCheck[i][0]
1913 << std::setw(20) << ahpvCheck[i][1]
1914 << std::setw(20) << ahpvCheck[i][2]
1915 << std::setw(20) << ahpvCheck[i][3]
1917 outStream << hist.str();
1923 outStream.copyfmt(oldFormatState);
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)
virtual Real checkInverseJacobian_1(const Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, const bool printToStream=true, std::ostream &outStream=std::cout)
virtual void applyAdjointJacobian_2(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &dualv, Real &tol)
Apply the adjoint of the partial constraint Jacobian at , , to vector . This is the secondary interfa...
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
virtual void applyAdjointJacobian_1(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Apply the adjoint of the partial constraint Jacobian at , , to the vector . This is the primary inter...
virtual void applyAdjointJacobian_2(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Apply the adjoint of the partial constraint Jacobian at , , to vector . This is the primary interface...
virtual void scale(const Real alpha)=0
Compute where .
Teuchos::RCP< const Vector< Real > > get_1() const
virtual int dimension() const
Return dimension of the vector space.
virtual void applyJacobian_2(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Apply the partial constraint Jacobian at , , to the vector .
virtual void setSolveParameters(Teuchos::ParameterList &parlist)
Set solve parameters.
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)
virtual void plus(const Vector &x)=0
Compute , where .
const double weights[4][5]
virtual void solve(Vector< Real > &c, Vector< Real > &u, const Vector< Real > &z, Real &tol)
Given , solve for .
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Defines the linear algebra or vector space interface for simulation-based optimization.
virtual void value(Vector< Real > &c, const Vector< Real > &u, const Vector< Real > &z, Real &tol)=0
Evaluate the constraint operator at .
std::vector< std::vector< Real > > checkApplyJacobian_2(const Vector< Real > &u, const Vector< Real > &z, 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)
virtual void applyInverseAdjointJacobian_1(Vector< Real > &iajv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Apply the inverse of the adjoint of the partial constraint Jacobian at , , to the vector ...
virtual void applyAdjointHessian_11(Vector< Real > &ahwv, const Vector< Real > &w, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Apply the simulation-space derivative of the adjoint of the constraint simulation-space Jacobian at ...
virtual void applyAdjointHessian_22(Vector< Real > &ahwv, const Vector< Real > &w, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Apply the optimization-space derivative of the adjoint of the constraint optimization-space Jacobian ...
Contains definitions of custom data types in ROL.
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)
const Real DEFAULT_factor_
void set_1(const Vector< Real > &vec)
virtual void applyAdjointHessian_21(Vector< Real > &ahwv, const Vector< Real > &w, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Apply the simulation-space derivative of the adjoint of the constraint optimization-space Jacobian at...
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
Provides the interface to evaluate nonlinear least squares objective functions.
virtual void applyAdjointHessian(Vector< Real > &ahwv, const Vector< Real > &w, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the derivative of the adjoint of the constraint Jacobian at to vector in direction ...
virtual void zero()
Set to zero vector.
Defines the linear algebra or vector space interface.
Teuchos::RCP< Vector< Real > > jv_
const bool DEFAULT_print_
Defines the equality constraint operator interface for simulation-based optimization.
virtual Real dot(const Vector &x) const =0
Compute where .
Teuchos::RCP< Vector< Real > > unew_
virtual void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Evaluate the constraint operator at .
virtual void applyPreconditioner(Vector< Real > &pv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g, Real &tol)
Apply a constraint preconditioner at , , to vector . In general, this preconditioner satisfies the fo...
virtual void update(const Vector< Real > &u, const Vector< Real > &z, bool flag=true, int iter=-1)
Update constraint functions. x is the optimization variable, flag = true if optimization variable is ...
virtual std::vector< Real > solveAugmentedSystem(Vector< Real > &v1, Vector< Real > &v2, const Vector< Real > &b1, const Vector< Real > &b2, const Vector< Real > &x, Real &tol)
Approximately solves the augmented system where , , , , is an identity or Riesz operator...
Defines the equality constraint operator interface.
virtual Real checkSolve(const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, const ROL::Vector< Real > &c, const bool printToStream=true, std::ostream &outStream=std::cout)
virtual void applyInverseJacobian_1(Vector< Real > &ijv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Apply the inverse partial constraint Jacobian at , , to the vector .
virtual void applyAdjointHessian_12(Vector< Real > &ahwv, const Vector< Real > &w, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Apply the optimization-space derivative of the adjoint of the constraint simulation-space Jacobian at...
EqualityConstraint_SimOpt()
virtual bool isFeasible(const Vector< Real > &v)
Check if the vector, v, is feasible.
Provides an interface to run optimization algorithms.
virtual void applyJacobian_1(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Apply the partial constraint Jacobian at , , to the vector .
virtual void applyAdjointJacobian(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the adjoint of the the constraint Jacobian at , , to vector .
virtual Real checkAdjointConsistencyJacobian_2(const Vector< Real > &w, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &dualw, const Vector< Real > &dualv, const bool printToStream=true, std::ostream &outStream=std::cout)
Check the consistency of the Jacobian and its adjoint. This is the secondary interface, for use with dual spaces where the user does not define the dual() operation.
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)
virtual void applyPreconditioner(Vector< Real > &pv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g, Real &tol)
Apply a constraint preconditioner at , , to vector . Ideally, this preconditioner satisfies the follo...
virtual void update_1(const Vector< Real > &u, bool flag=true, int iter=-1)
Update constraint functions with respect to Sim variable. x is the optimization variable, flag = true if optimization variable is changed, iter is the outer algorithm iterations count.
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 std::vector< Real > &steps, const bool printToStream=true, std::ostream &outStream=std::cout, const int order=1)
#define ROL_NUM_CHECKDERIV_STEPS
Number of steps for derivative checks.
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 std::vector< Real > &steps, const bool printToStream=true, std::ostream &outStream=std::cout, const int order=1)
virtual void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the constraint Jacobian at , , to vector .
virtual void update_2(const Vector< Real > &z, bool flag=true, int iter=-1)
Update constraint functions with respect to Opt variable. x is the optimization variable, flag = true if optimization variable is changed, iter is the outer algorithm iterations count.
virtual Real checkAdjointConsistencyJacobian_1(const Vector< Real > &w, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &dualw, const Vector< Real > &dualv, const bool printToStream=true, std::ostream &outStream=std::cout)
Check the consistency of the Jacobian and its adjoint. This is the secondary interface, for use with dual spaces where the user does not define the dual() operation.
virtual void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update constraint functions. x is the optimization variable, flag = true if optimization variable is ...
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 void set(const Vector &x)
Set where .
virtual void applyAdjointJacobian_1(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &dualv, Real &tol)
Apply the adjoint of the partial constraint Jacobian at , , to the vector . This is the secondary int...
virtual Real checkInverseAdjointJacobian_1(const Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, const bool printToStream=true, std::ostream &outStream=std::cout)
virtual Teuchos::RCP< Vector > basis(const int i) const
Return i-th basis vector.
virtual Real norm() const =0
Returns where .
virtual std::vector< Real > solveAugmentedSystem(Vector< Real > &v1, Vector< Real > &v2, const Vector< Real > &b1, const Vector< Real > &b2, const Vector< Real > &x, Real &tol)
Approximately solves the augmented system where , , , , is an identity operator, and is a zero operator.
const int DEFAULT_solverType_
Real ROL_EPSILON(void)
Platform-dependent machine epsilon.
std::vector< std::vector< Real > > checkApplyJacobian_1(const Vector< Real > &u, const Vector< Real > &z, 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)
Teuchos::RCP< const Vector< Real > > get_2() const
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 std::vector< Real > &steps, const bool printToStream=true, std::ostream &outStream=std::cout, const int order=1)
void set_2(const Vector< Real > &vec)
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 std::vector< Real > &steps, const bool printToStream=true, std::ostream &outStream=std::cout, const int order=1)
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)