44 #ifndef ROL_CONSTRAINT_SIMOPT_H
45 #define ROL_CONSTRAINT_SIMOPT_H
104 ROL::Ptr<Vector<Real> >
jv_;
134 unew_(ROL::nullPtr),
jv_(ROL::nullPtr),
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 Constraint_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 ROL::Ptr<Constraint_SimOpt<Real> > con = ROL::makePtrFromRef(*
this);
270 ROL::Ptr<Objective<Real> > obj = ROL::makePtr<NonlinearLeastSquaresObjective_SimOpt<Real>>(con,u,z,c,
true);
271 ROL::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 ROL::Ptr<Algorithm<Real> > algo = ROL::makePtr<Algorithm<Real>>(
"Trust Region",parlist,
false);
282 ROL::Ptr<Constraint_SimOpt<Real> > con = ROL::makePtrFromRef(*
this);
283 ROL::Ptr<const Vector<Real> > zVec = ROL::makePtrFromRef(z);
284 ROL::Ptr<Constraint<Real> > conU
285 = ROL::makePtr<Constraint_State<Real>>(con,zVec);
286 ROL::Ptr<Objective<Real> > objU
287 = ROL::makePtr<Objective_FSsolver<Real>>();
288 ROL::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 ROL::Ptr<Algorithm<Real> > algo = ROL::makePtr<Algorithm<Real>>(
"Composite Step",parlist,
false);
293 ROL::Ptr<Vector<Real> > l = c.
dual().clone();
294 algo->run(u,*l,*objU,*conU,
print_);
298 ROL_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
299 ">>> ERROR (ROL:Constraint_SimOpt:solve): Invalid solver type!");
324 ROL::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 ROL::Ptr<Vector<Real> > unew = u.
clone();
368 value(jv,*unew,z,ctol);
370 ROL::Ptr<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 ROL::Ptr<Vector<Real> > znew = z.
clone();
411 value(jv,u,*znew,ctol);
413 ROL::Ptr<Vector<Real> > cold = jv.
clone();
415 value(*cold,u,z,ctol);
441 ROL_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 ROL::Ptr<Vector<Real> > cold = dualv.
clone();
498 ROL::Ptr<Vector<Real> > cnew = dualv.
clone();
500 value(*cold,u,z,ctol);
501 ROL::Ptr<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 ROL::Ptr<Vector<Real> > cold = dualv.
clone();
569 ROL::Ptr<Vector<Real> > cnew = dualv.
clone();
571 value(*cold,u,z,ctol);
572 ROL::Ptr<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 ROL_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 ROL::Ptr<Vector<Real> > unew = u.
clone();
646 ROL::Ptr<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 ROL::Ptr<Vector<Real> > unew = u.
clone();
691 ROL::Ptr<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 ROL::Ptr<Vector<Real> > znew = z.
clone();
736 ROL::Ptr<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 ROL::Ptr<Vector<Real> > znew = z.
clone();
780 ROL::Ptr<Vector<Real> > jv = ahwv.
clone();
860 ROL::Ptr<ROL::Vector<Real> > ijv = (xs.
get_1())->clone();
865 catch (
const std::logic_error &e) {
871 ROL::Ptr<ROL::Vector<Real> > ijv_dual = (gs.
get_1())->clone();
877 catch (
const std::logic_error &e) {
913 ROL::Ptr<Vector<Real> > jv2 = jv.
clone();
927 ROL::Ptr<Vector<Real> > ajv1 = (ajvs.
get_1())->clone();
930 ROL::Ptr<Vector<Real> > ajv2 = (ajvs.
get_2())->clone();
948 ROL::Ptr<Vector<Real> > C11 = (ahwvs.
get_1())->clone();
949 ROL::Ptr<Vector<Real> > C21 = (ahwvs.
get_1())->clone();
955 ROL::Ptr<Vector<Real> > C12 = (ahwvs.
get_2())->clone();
956 ROL::Ptr<Vector<Real> > C22 = (ahwvs.
get_2())->clone();
968 const bool printToStream =
true,
969 std::ostream & outStream = std::cout) {
971 Real tol = ROL_EPSILON<Real>();
972 ROL::Ptr<ROL::Vector<Real> > r = c.
clone();
973 ROL::Ptr<ROL::Vector<Real> > s = u.
clone();
976 ROL::Ptr<ROL::Vector<Real> > cs = c.
clone();
980 Real rnorm = r->norm();
981 Real cnorm = cs->norm();
982 if ( printToStream ) {
983 std::stringstream hist;
984 hist << std::scientific << std::setprecision(8);
985 hist <<
"\nTest SimOpt solve at feasible (u,z):\n";
986 hist <<
" Solver Residual = " << rnorm <<
"\n";
987 hist <<
" ||c(u,z)|| = " << cnorm <<
"\n";
988 outStream << hist.str();
1010 const bool printToStream =
true,
1011 std::ostream & outStream = std::cout) {
1039 const bool printToStream =
true,
1040 std::ostream & outStream = std::cout) {
1041 Real tol = ROL_EPSILON<Real>();
1042 ROL::Ptr<Vector<Real> > Jv = dualw.
clone();
1045 Real wJv = w.
dot(Jv->dual());
1046 ROL::Ptr<Vector<Real> > Jw = dualv.
clone();
1049 Real vJw = v.
dot(Jw->dual());
1050 Real diff = std::abs(wJv-vJw);
1051 if ( printToStream ) {
1052 std::stringstream hist;
1053 hist << std::scientific << std::setprecision(8);
1054 hist <<
"\nTest SimOpt consistency of Jacobian_1 and its adjoint: \n |<w,Jv> - <adj(J)w,v>| = "
1056 hist <<
" |<w,Jv>| = " << std::abs(wJv) <<
"\n";
1057 hist <<
" Relative Error = " << diff / (std::abs(wJv)+ROL_UNDERFLOW<Real>()) <<
"\n";
1058 outStream << hist.str();
1080 const bool printToStream =
true,
1081 std::ostream & outStream = std::cout) {
1106 const bool printToStream =
true,
1107 std::ostream & outStream = std::cout) {
1108 Real tol = ROL_EPSILON<Real>();
1109 ROL::Ptr<Vector<Real> > Jv = dualw.
clone();
1112 Real wJv = w.
dot(Jv->dual());
1113 ROL::Ptr<Vector<Real> > Jw = dualv.
clone();
1116 Real vJw = v.
dot(Jw->dual());
1117 Real diff = std::abs(wJv-vJw);
1118 if ( printToStream ) {
1119 std::stringstream hist;
1120 hist << std::scientific << std::setprecision(8);
1121 hist <<
"\nTest SimOpt consistency of Jacobian_2 and its adjoint: \n |<w,Jv> - <adj(J)w,v>| = "
1123 hist <<
" |<w,Jv>| = " << std::abs(wJv) <<
"\n";
1124 hist <<
" Relative Error = " << diff / (std::abs(wJv)+ROL_UNDERFLOW<Real>()) <<
"\n";
1125 outStream << hist.str();
1134 const bool printToStream =
true,
1135 std::ostream & outStream = std::cout) {
1136 Real tol = ROL_EPSILON<Real>();
1137 ROL::Ptr<Vector<Real> > Jv = jv.
clone();
1140 ROL::Ptr<Vector<Real> > iJJv = u.
clone();
1143 ROL::Ptr<Vector<Real> > diff = v.
clone();
1145 diff->axpy(-1.0,*iJJv);
1146 Real dnorm = diff->norm();
1147 Real vnorm = v.
norm();
1148 if ( printToStream ) {
1149 std::stringstream hist;
1150 hist << std::scientific << std::setprecision(8);
1151 hist <<
"\nTest SimOpt consistency of inverse Jacobian_1: \n ||v-inv(J)Jv|| = "
1153 hist <<
" ||v|| = " << vnorm <<
"\n";
1154 hist <<
" Relative Error = " << dnorm / (vnorm+ROL_UNDERFLOW<Real>()) <<
"\n";
1155 outStream << hist.str();
1164 const bool printToStream =
true,
1165 std::ostream & outStream = std::cout) {
1166 Real tol = ROL_EPSILON<Real>();
1167 ROL::Ptr<Vector<Real> > Jv = jv.
clone();
1170 ROL::Ptr<Vector<Real> > iJJv = v.
clone();
1173 ROL::Ptr<Vector<Real> > diff = v.
clone();
1175 diff->axpy(-1.0,*iJJv);
1176 Real dnorm = diff->norm();
1177 Real vnorm = v.
norm();
1178 if ( printToStream ) {
1179 std::stringstream hist;
1180 hist << std::scientific << std::setprecision(8);
1181 hist <<
"\nTest SimOpt consistency of inverse adjoint Jacobian_1: \n ||v-inv(adj(J))adj(J)v|| = "
1183 hist <<
" ||v|| = " << vnorm <<
"\n";
1184 hist <<
" Relative Error = " << dnorm / (vnorm+ROL_UNDERFLOW<Real>()) <<
"\n";
1185 outStream << hist.str();
1196 const bool printToStream =
true,
1197 std::ostream & outStream = std::cout,
1199 const int order = 1) {
1200 std::vector<Real> steps(numSteps);
1201 for(
int i=0;i<numSteps;++i) {
1202 steps[i] = pow(10,-i);
1215 const std::vector<Real> &steps,
1216 const bool printToStream =
true,
1217 std::ostream & outStream = std::cout,
1218 const int order = 1) {
1220 ROL_TEST_FOR_EXCEPTION( order<1 || order>4, std::invalid_argument,
1221 "Error: finite difference order must be 1,2,3, or 4" );
1228 Real tol = std::sqrt(ROL_EPSILON<Real>());
1230 int numSteps = steps.size();
1232 std::vector<Real> tmp(numVals);
1233 std::vector<std::vector<Real> > jvCheck(numSteps, tmp);
1237 oldFormatState.copyfmt(outStream);
1240 ROL::Ptr<Vector<Real> > c = jv.
clone();
1242 this->
value(*c, u, z, tol);
1245 ROL::Ptr<Vector<Real> > Jv = jv.
clone();
1247 Real normJv = Jv->norm();
1250 ROL::Ptr<Vector<Real> > cdif = jv.
clone();
1251 ROL::Ptr<Vector<Real> > cnew = jv.
clone();
1252 ROL::Ptr<Vector<Real> > unew = u.
clone();
1254 for (
int i=0; i<numSteps; i++) {
1256 Real eta = steps[i];
1261 cdif->scale(
weights[order-1][0]);
1263 for(
int j=0; j<order; ++j) {
1265 unew->axpy(eta*
shifts[order-1][j], v);
1267 if(
weights[order-1][j+1] != 0 ) {
1269 this->
value(*cnew,*unew,z,tol);
1270 cdif->axpy(
weights[order-1][j+1],*cnew);
1275 cdif->scale(one/eta);
1278 jvCheck[i][0] = eta;
1279 jvCheck[i][1] = normJv;
1280 jvCheck[i][2] = cdif->norm();
1281 cdif->axpy(-one, *Jv);
1282 jvCheck[i][3] = cdif->norm();
1284 if (printToStream) {
1285 std::stringstream hist;
1288 << std::setw(20) <<
"Step size"
1289 << std::setw(20) <<
"norm(Jac*vec)"
1290 << std::setw(20) <<
"norm(FD approx)"
1291 << std::setw(20) <<
"norm(abs error)"
1293 << std::setw(20) <<
"---------"
1294 << std::setw(20) <<
"-------------"
1295 << std::setw(20) <<
"---------------"
1296 << std::setw(20) <<
"---------------"
1299 hist << std::scientific << std::setprecision(11) << std::right
1300 << std::setw(20) << jvCheck[i][0]
1301 << std::setw(20) << jvCheck[i][1]
1302 << std::setw(20) << jvCheck[i][2]
1303 << std::setw(20) << jvCheck[i][3]
1305 outStream << hist.str();
1311 outStream.copyfmt(oldFormatState);
1321 const bool printToStream =
true,
1322 std::ostream & outStream = std::cout,
1324 const int order = 1) {
1325 std::vector<Real> steps(numSteps);
1326 for(
int i=0;i<numSteps;++i) {
1327 steps[i] = pow(10,-i);
1340 const std::vector<Real> &steps,
1341 const bool printToStream =
true,
1342 std::ostream & outStream = std::cout,
1343 const int order = 1) {
1345 ROL_TEST_FOR_EXCEPTION( order<1 || order>4, std::invalid_argument,
1346 "Error: finite difference order must be 1,2,3, or 4" );
1353 Real tol = std::sqrt(ROL_EPSILON<Real>());
1355 int numSteps = steps.size();
1357 std::vector<Real> tmp(numVals);
1358 std::vector<std::vector<Real> > jvCheck(numSteps, tmp);
1362 oldFormatState.copyfmt(outStream);
1365 ROL::Ptr<Vector<Real> > c = jv.
clone();
1367 this->
value(*c, u, z, tol);
1370 ROL::Ptr<Vector<Real> > Jv = jv.
clone();
1372 Real normJv = Jv->norm();
1375 ROL::Ptr<Vector<Real> > cdif = jv.
clone();
1376 ROL::Ptr<Vector<Real> > cnew = jv.
clone();
1377 ROL::Ptr<Vector<Real> > znew = z.
clone();
1379 for (
int i=0; i<numSteps; i++) {
1381 Real eta = steps[i];
1386 cdif->scale(
weights[order-1][0]);
1388 for(
int j=0; j<order; ++j) {
1390 znew->axpy(eta*
shifts[order-1][j], v);
1392 if(
weights[order-1][j+1] != 0 ) {
1394 this->
value(*cnew,u,*znew,tol);
1395 cdif->axpy(
weights[order-1][j+1],*cnew);
1400 cdif->scale(one/eta);
1403 jvCheck[i][0] = eta;
1404 jvCheck[i][1] = normJv;
1405 jvCheck[i][2] = cdif->norm();
1406 cdif->axpy(-one, *Jv);
1407 jvCheck[i][3] = cdif->norm();
1409 if (printToStream) {
1410 std::stringstream hist;
1413 << std::setw(20) <<
"Step size"
1414 << std::setw(20) <<
"norm(Jac*vec)"
1415 << std::setw(20) <<
"norm(FD approx)"
1416 << std::setw(20) <<
"norm(abs error)"
1418 << std::setw(20) <<
"---------"
1419 << std::setw(20) <<
"-------------"
1420 << std::setw(20) <<
"---------------"
1421 << std::setw(20) <<
"---------------"
1424 hist << std::scientific << std::setprecision(11) << std::right
1425 << std::setw(20) << jvCheck[i][0]
1426 << std::setw(20) << jvCheck[i][1]
1427 << std::setw(20) << jvCheck[i][2]
1428 << std::setw(20) << jvCheck[i][3]
1430 outStream << hist.str();
1436 outStream.copyfmt(oldFormatState);
1448 const bool printToStream =
true,
1449 std::ostream & outStream = std::cout,
1451 const int order = 1 ) {
1452 std::vector<Real> steps(numSteps);
1453 for(
int i=0;i<numSteps;++i) {
1454 steps[i] = pow(10,-i);
1466 const std::vector<Real> &steps,
1467 const bool printToStream =
true,
1468 std::ostream & outStream = std::cout,
1469 const int order = 1 ) {
1475 Real tol = std::sqrt(ROL_EPSILON<Real>());
1477 int numSteps = steps.size();
1479 std::vector<Real> tmp(numVals);
1480 std::vector<std::vector<Real> > ahpvCheck(numSteps, tmp);
1483 ROL::Ptr<Vector<Real> > AJdif = hv.
clone();
1484 ROL::Ptr<Vector<Real> > AJp = hv.
clone();
1485 ROL::Ptr<Vector<Real> > AHpv = hv.
clone();
1486 ROL::Ptr<Vector<Real> > AJnew = hv.
clone();
1487 ROL::Ptr<Vector<Real> > unew = u.
clone();
1491 oldFormatState.copyfmt(outStream);
1499 Real normAHpv = AHpv->norm();
1501 for (
int i=0; i<numSteps; i++) {
1503 Real eta = steps[i];
1509 AJdif->scale(
weights[order-1][0]);
1511 for(
int j=0; j<order; ++j) {
1513 unew->axpy(eta*
shifts[order-1][j],v);
1515 if(
weights[order-1][j+1] != 0 ) {
1518 AJdif->axpy(
weights[order-1][j+1],*AJnew);
1522 AJdif->scale(one/eta);
1525 ahpvCheck[i][0] = eta;
1526 ahpvCheck[i][1] = normAHpv;
1527 ahpvCheck[i][2] = AJdif->norm();
1528 AJdif->axpy(-one, *AHpv);
1529 ahpvCheck[i][3] = AJdif->norm();
1531 if (printToStream) {
1532 std::stringstream hist;
1535 << std::setw(20) <<
"Step size"
1536 << std::setw(20) <<
"norm(adj(H)(u,v))"
1537 << std::setw(20) <<
"norm(FD approx)"
1538 << std::setw(20) <<
"norm(abs error)"
1540 << std::setw(20) <<
"---------"
1541 << std::setw(20) <<
"-----------------"
1542 << std::setw(20) <<
"---------------"
1543 << std::setw(20) <<
"---------------"
1546 hist << std::scientific << std::setprecision(11) << std::right
1547 << std::setw(20) << ahpvCheck[i][0]
1548 << std::setw(20) << ahpvCheck[i][1]
1549 << std::setw(20) << ahpvCheck[i][2]
1550 << std::setw(20) << ahpvCheck[i][3]
1552 outStream << hist.str();
1558 outStream.copyfmt(oldFormatState);
1571 const bool printToStream =
true,
1572 std::ostream & outStream = std::cout,
1574 const int order = 1 ) {
1575 std::vector<Real> steps(numSteps);
1576 for(
int i=0;i<numSteps;++i) {
1577 steps[i] = pow(10,-i);
1592 const std::vector<Real> &steps,
1593 const bool printToStream =
true,
1594 std::ostream & outStream = std::cout,
1595 const int order = 1 ) {
1601 Real tol = std::sqrt(ROL_EPSILON<Real>());
1603 int numSteps = steps.size();
1605 std::vector<Real> tmp(numVals);
1606 std::vector<std::vector<Real> > ahpvCheck(numSteps, tmp);
1609 ROL::Ptr<Vector<Real> > AJdif = hv.
clone();
1610 ROL::Ptr<Vector<Real> > AJp = hv.
clone();
1611 ROL::Ptr<Vector<Real> > AHpv = hv.
clone();
1612 ROL::Ptr<Vector<Real> > AJnew = hv.
clone();
1613 ROL::Ptr<Vector<Real> > znew = z.
clone();
1617 oldFormatState.copyfmt(outStream);
1625 Real normAHpv = AHpv->norm();
1627 for (
int i=0; i<numSteps; i++) {
1629 Real eta = steps[i];
1635 AJdif->scale(
weights[order-1][0]);
1637 for(
int j=0; j<order; ++j) {
1639 znew->axpy(eta*
shifts[order-1][j],v);
1641 if(
weights[order-1][j+1] != 0 ) {
1644 AJdif->axpy(
weights[order-1][j+1],*AJnew);
1648 AJdif->scale(one/eta);
1651 ahpvCheck[i][0] = eta;
1652 ahpvCheck[i][1] = normAHpv;
1653 ahpvCheck[i][2] = AJdif->norm();
1654 AJdif->axpy(-one, *AHpv);
1655 ahpvCheck[i][3] = AJdif->norm();
1657 if (printToStream) {
1658 std::stringstream hist;
1661 << std::setw(20) <<
"Step size"
1662 << std::setw(20) <<
"norm(adj(H)(u,v))"
1663 << std::setw(20) <<
"norm(FD approx)"
1664 << std::setw(20) <<
"norm(abs error)"
1666 << std::setw(20) <<
"---------"
1667 << std::setw(20) <<
"-----------------"
1668 << std::setw(20) <<
"---------------"
1669 << std::setw(20) <<
"---------------"
1672 hist << std::scientific << std::setprecision(11) << std::right
1673 << std::setw(20) << ahpvCheck[i][0]
1674 << std::setw(20) << ahpvCheck[i][1]
1675 << std::setw(20) << ahpvCheck[i][2]
1676 << std::setw(20) << ahpvCheck[i][3]
1678 outStream << hist.str();
1684 outStream.copyfmt(oldFormatState);
1697 const bool printToStream =
true,
1698 std::ostream & outStream = std::cout,
1700 const int order = 1 ) {
1701 std::vector<Real> steps(numSteps);
1702 for(
int i=0;i<numSteps;++i) {
1703 steps[i] = pow(10,-i);
1716 const std::vector<Real> &steps,
1717 const bool printToStream =
true,
1718 std::ostream & outStream = std::cout,
1719 const int order = 1 ) {
1725 Real tol = std::sqrt(ROL_EPSILON<Real>());
1727 int numSteps = steps.size();
1729 std::vector<Real> tmp(numVals);
1730 std::vector<std::vector<Real> > ahpvCheck(numSteps, tmp);
1733 ROL::Ptr<Vector<Real> > AJdif = hv.
clone();
1734 ROL::Ptr<Vector<Real> > AJp = hv.
clone();
1735 ROL::Ptr<Vector<Real> > AHpv = hv.
clone();
1736 ROL::Ptr<Vector<Real> > AJnew = hv.
clone();
1737 ROL::Ptr<Vector<Real> > unew = u.
clone();
1741 oldFormatState.copyfmt(outStream);
1749 Real normAHpv = AHpv->norm();
1751 for (
int i=0; i<numSteps; i++) {
1753 Real eta = steps[i];
1759 AJdif->scale(
weights[order-1][0]);
1761 for(
int j=0; j<order; ++j) {
1763 unew->axpy(eta*
shifts[order-1][j],v);
1765 if(
weights[order-1][j+1] != 0 ) {
1768 AJdif->axpy(
weights[order-1][j+1],*AJnew);
1772 AJdif->scale(one/eta);
1775 ahpvCheck[i][0] = eta;
1776 ahpvCheck[i][1] = normAHpv;
1777 ahpvCheck[i][2] = AJdif->norm();
1778 AJdif->axpy(-one, *AHpv);
1779 ahpvCheck[i][3] = AJdif->norm();
1781 if (printToStream) {
1782 std::stringstream hist;
1785 << std::setw(20) <<
"Step size"
1786 << std::setw(20) <<
"norm(adj(H)(u,v))"
1787 << std::setw(20) <<
"norm(FD approx)"
1788 << std::setw(20) <<
"norm(abs error)"
1790 << std::setw(20) <<
"---------"
1791 << std::setw(20) <<
"-----------------"
1792 << std::setw(20) <<
"---------------"
1793 << std::setw(20) <<
"---------------"
1796 hist << std::scientific << std::setprecision(11) << std::right
1797 << std::setw(20) << ahpvCheck[i][0]
1798 << std::setw(20) << ahpvCheck[i][1]
1799 << std::setw(20) << ahpvCheck[i][2]
1800 << std::setw(20) << ahpvCheck[i][3]
1802 outStream << hist.str();
1808 outStream.copyfmt(oldFormatState);
1818 const bool printToStream =
true,
1819 std::ostream & outStream = std::cout,
1821 const int order = 1 ) {
1822 std::vector<Real> steps(numSteps);
1823 for(
int i=0;i<numSteps;++i) {
1824 steps[i] = pow(10,-i);
1836 const std::vector<Real> &steps,
1837 const bool printToStream =
true,
1838 std::ostream & outStream = std::cout,
1839 const int order = 1 ) {
1845 Real tol = std::sqrt(ROL_EPSILON<Real>());
1847 int numSteps = steps.size();
1849 std::vector<Real> tmp(numVals);
1850 std::vector<std::vector<Real> > ahpvCheck(numSteps, tmp);
1853 ROL::Ptr<Vector<Real> > AJdif = hv.
clone();
1854 ROL::Ptr<Vector<Real> > AJp = hv.
clone();
1855 ROL::Ptr<Vector<Real> > AHpv = hv.
clone();
1856 ROL::Ptr<Vector<Real> > AJnew = hv.
clone();
1857 ROL::Ptr<Vector<Real> > znew = z.
clone();
1861 oldFormatState.copyfmt(outStream);
1869 Real normAHpv = AHpv->norm();
1871 for (
int i=0; i<numSteps; i++) {
1873 Real eta = steps[i];
1879 AJdif->scale(
weights[order-1][0]);
1881 for(
int j=0; j<order; ++j) {
1883 znew->axpy(eta*
shifts[order-1][j],v);
1885 if(
weights[order-1][j+1] != 0 ) {
1888 AJdif->axpy(
weights[order-1][j+1],*AJnew);
1892 AJdif->scale(one/eta);
1895 ahpvCheck[i][0] = eta;
1896 ahpvCheck[i][1] = normAHpv;
1897 ahpvCheck[i][2] = AJdif->norm();
1898 AJdif->axpy(-one, *AHpv);
1899 ahpvCheck[i][3] = AJdif->norm();
1901 if (printToStream) {
1902 std::stringstream hist;
1905 << std::setw(20) <<
"Step size"
1906 << std::setw(20) <<
"norm(adj(H)(u,v))"
1907 << std::setw(20) <<
"norm(FD approx)"
1908 << std::setw(20) <<
"norm(abs error)"
1910 << std::setw(20) <<
"---------"
1911 << std::setw(20) <<
"-----------------"
1912 << std::setw(20) <<
"---------------"
1913 << std::setw(20) <<
"---------------"
1916 hist << std::scientific << std::setprecision(11) << std::right
1917 << std::setw(20) << ahpvCheck[i][0]
1918 << std::setw(20) << ahpvCheck[i][1]
1919 << std::setw(20) << ahpvCheck[i][2]
1920 << std::setw(20) << ahpvCheck[i][3]
1922 outStream << hist.str();
1928 outStream.copyfmt(oldFormatState);
virtual void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Evaluate the constraint operator at .
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
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 scale(const Real alpha)=0
Compute where .
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 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 ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
ROL::Ptr< const Vector< Real > > get_2() const
virtual int dimension() const
Return dimension of the vector space.
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 ROL::Ptr< Vector > basis(const int i) const
Return i-th basis vector.
virtual void plus(const Vector &x)=0
Compute , where .
const double weights[4][5]
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
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 .
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)
Defines the linear algebra or vector space interface for simulation-based optimization.
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 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.
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 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.
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.
void set_1(const Vector< Real > &vec)
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 void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply 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 bool printToStream=true, std::ostream &outStream=std::cout)
Check the consistency of the Jacobian and its adjoint. This is the primary interface.
virtual void setSolveParameters(ROL::ParameterList &parlist)
Set solve parameters.
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 zero()
Set to zero vector.
Defines the linear algebra or vector space interface.
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 Real dot(const Vector &x) const =0
Compute where .
ROL::Ptr< Vector< Real > > jv_
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)
ROL::Ptr< Vector< Real > > unew_
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 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 .
const int DEFAULT_solverType_
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...
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.
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 value(Vector< Real > &c, const Vector< Real > &u, const Vector< Real > &z, Real &tol)=0
Evaluate the constraint operator at .
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...
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)
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 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 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...
const Real DEFAULT_factor_
#define ROL_NUM_CHECKDERIV_STEPS
Number of steps for derivative checks.
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...
basic_nullstream< char, char_traits< char >> nullstream
virtual void solve(Vector< Real > &c, Vector< Real > &u, const Vector< Real > &z, Real &tol)
Given , solve for .
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...
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)
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 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 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 Real norm() const =0
Returns where .
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.
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)
Real ROL_EPSILON(void)
Platform-dependent machine epsilon.
Defines the constraint operator interface for simulation-based optimization.
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 .
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)
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)
, , , ,
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 ...
void set_2(const Vector< Real > &vec)
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)
, , , ,
Defines the general constraint operator interface.
const bool DEFAULT_print_
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 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)
const Vector< Real > & dual(void) const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
ROL::Ptr< const Vector< Real > > get_1() const