10 #ifndef ROL_CONSTRAINT_TIMESIMOPT_H
11 #define ROL_CONSTRAINT_TIMESIMOPT_H
118 bool flag =
true,
int iter = -1 ) {
241 bool flag =
true,
int iter = -1 )
override {
251 Real &tol)
override {
263 Real &tol)
override {
275 Real &tol)
override {
287 ROL::Ptr<Vector<Real> > jv_new =
workspace_.clone(jv);
295 jv.
axpy(1.0,*jv_new);
302 Real &tol)
override {
317 Real &tol)
override final {
318 ROL_TEST_FOR_EXCEPTION(
true, std::logic_error,
319 "The method applyInverseJacobian_1 is used but not implemented!\n");
326 Real &tol)
override {
340 Real &tol)
override {
351 Real &tol)
override final {
352 ROL_TEST_FOR_EXCEPTION(
true, std::logic_error,
353 "The method applyInverseAdjointJacobian_1 is used but not implemented!\n");
443 Real &tol)
override {
469 Real &tol)
override {
477 const bool printToStream =
true,
478 std::ostream & outStream = std::cout)
override {
480 Real tol = ROL_EPSILON<Real>();
481 ROL::Ptr<ROL::Vector<Real> > r =
workspace_.clone(c);
482 ROL::Ptr<ROL::Vector<Real> > s =
workspace_.clone(u);
486 ROL::Ptr<ROL::Vector<Real> > cs =
workspace_.clone(c);
490 Real rnorm = r->norm();
491 Real cnorm = cs->norm();
492 if ( printToStream ) {
493 std::stringstream hist;
494 hist << std::scientific << std::setprecision(8);
495 hist <<
"\nTest SimOpt solve at feasible (u,z):\n";
496 hist <<
" Solver Residual = " << rnorm <<
"\n";
497 hist <<
" ||c(u,z)|| = " << cnorm <<
"\n";
498 outStream << hist.str();
509 const bool printToStream =
true,
510 std::ostream & outStream = std::cout) {
511 Real tol = ROL_EPSILON<Real>();
513 update( u_new, u_old, z );
516 update( u_new, u_old, z );
520 diff->axpy(-1.0,*iJJv);
521 Real dnorm = diff->norm();
522 Real vnorm = v_new.
norm();
523 if ( printToStream ) {
524 std::stringstream hist;
525 hist << std::scientific << std::setprecision(8);
526 hist <<
"\nTest TimeSimOpt consistency of inverse Jacobian_1_new: \n ||v-inv(J)Jv|| = "
528 hist <<
" ||v|| = " << vnorm <<
"\n";
529 hist <<
" Relative Error = " << dnorm / (vnorm+ROL_UNDERFLOW<Real>()) <<
"\n";
530 outStream << hist.str();
540 const bool printToStream =
true,
541 std::ostream & outStream = std::cout) {
542 Real tol = ROL_EPSILON<Real>();
544 update( u_new, u_old, z );
547 update( u_new, u_old, z );
551 diff->axpy(-1.0,*iJJv);
552 Real dnorm = diff->norm();
553 Real vnorm = v_new.
norm();
554 if ( printToStream ) {
555 std::stringstream hist;
556 hist << std::scientific << std::setprecision(8);
557 hist <<
"\nTest TimeSimOpt consistency of inverse adjoint Jacobian_1_new: \n ||v-inv(adj(J))adj(J)v|| = "
559 hist <<
" ||v|| = " << vnorm <<
"\n";
560 hist <<
" Relative Error = " << dnorm / (vnorm+ROL_UNDERFLOW<Real>()) <<
"\n";
561 outStream << hist.str();
571 const bool printToStream =
true,
572 std::ostream & outStream = std::cout,
574 const int order = 1) {
575 std::vector<Real> steps(numSteps);
576 for(
int i=0;i<numSteps;++i) {
577 steps[i] = pow(10,-i);
588 const std::vector<Real> &steps,
589 const bool printToStream =
true,
590 std::ostream & outStream = std::cout,
591 const int order = 1) {
593 ROL_TEST_FOR_EXCEPTION( order<1 || order>4, std::invalid_argument,
594 "Error: finite difference order must be 1,2,3, or 4" );
601 Real tol = std::sqrt(ROL_EPSILON<Real>());
603 int numSteps = steps.size();
605 std::vector<Real> tmp(numVals);
606 std::vector<std::vector<Real> > jvCheck(numSteps, tmp);
610 oldFormatState.copyfmt(outStream);
613 ROL::Ptr<Vector<Real> > c =
workspace_.clone(jv);
614 this->
update(u_new, u_old, z);
615 this->
value(*c, u_new, u_old, z, tol);
618 ROL::Ptr<Vector<Real> > Jv =
workspace_.clone(jv);
620 Real normJv = Jv->norm();
623 ROL::Ptr<Vector<Real> > cdif =
workspace_.clone(jv);
624 ROL::Ptr<Vector<Real> > cnew =
workspace_.clone(jv);
625 ROL::Ptr<Vector<Real> > u_2 =
workspace_.clone(u_new);
627 for (
int i=0; i<numSteps; i++) {
634 cdif->scale(
weights[order-1][0]);
636 for(
int j=0; j<order; ++j) {
638 u_2->axpy(eta*
shifts[order-1][j], v);
640 if(
weights[order-1][j+1] != 0 ) {
641 this->
update(*u_2,u_old,z);
642 this->
value(*cnew,*u_2,u_old,z,tol);
643 cdif->axpy(
weights[order-1][j+1],*cnew);
648 cdif->scale(one/eta);
652 jvCheck[i][1] = normJv;
653 jvCheck[i][2] = cdif->norm();
654 cdif->axpy(-one, *Jv);
655 jvCheck[i][3] = cdif->norm();
658 std::stringstream hist;
661 << std::setw(20) <<
"Step size"
662 << std::setw(20) <<
"norm(Jac*vec)"
663 << std::setw(20) <<
"norm(FD approx)"
664 << std::setw(20) <<
"norm(abs error)"
666 << std::setw(20) <<
"---------"
667 << std::setw(20) <<
"-------------"
668 << std::setw(20) <<
"---------------"
669 << std::setw(20) <<
"---------------"
672 hist << std::scientific << std::setprecision(11) << std::right
673 << std::setw(20) << jvCheck[i][0]
674 << std::setw(20) << jvCheck[i][1]
675 << std::setw(20) << jvCheck[i][2]
676 << std::setw(20) << jvCheck[i][3]
678 outStream << hist.str();
684 outStream.copyfmt(oldFormatState);
virtual void applyAdjointHessian_11_old(Vector< Real > &ahwv_old, const Vector< Real > &w, const Vector< Real > &v_new, const Vector< Real > &u_old, const Vector< Real > &u_new, const Vector< Real > &z, Real &tol)=0
virtual void applyJacobian_2(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &u_old, const Vector< Real > &u_new, const Vector< Real > &z, Real &tol)=0
virtual void update(const Vector< Real > &u_old, const Vector< Real > &u_new, const Vector< Real > &z, bool flag=true, int iter=-1)
Update constraint functions. u_old Is the state from the end of the previous time step...
virtual void applyInverseAdjointJacobian_1(Vector< Real > &iajv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol) overridefinal
Apply the inverse of the adjoint of the partial constraint Jacobian at , , to the vector ...
ROL::Ptr< const Vector< Real > > get(size_type i) const
const double weights[4][5]
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Defines the linear algebra of vector space on a generic partitioned vector.
std::vector< std::vector< Real > > checkApplyJacobian_1_new(const Vector< Real > &u_new, const Vector< Real > &u_old, 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_old(Vector< Real > &ajv_old, const Vector< Real > &dualv, const Vector< Real > &u_old, const Vector< Real > &u_new, const Vector< Real > &z, Real &tol)=0
virtual void solve(Vector< Real > &c, const Vector< Real > &u_old, Vector< Real > &u_new, const Vector< Real > &z, Real &tol)=0
virtual void zero()
Set to zero vector.
Defines the linear algebra or vector space interface.
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) override
Apply the optimization-space derivative of the adjoint of the constraint simulation-space Jacobian at...
Defines the time dependent constraint operator interface for simulation-based optimization.
virtual Real checkInverseJacobian_1_new(const ROL::Vector< Real > &c, const ROL::Vector< Real > &u_new, const ROL::Vector< Real > &u_old, const ROL::Vector< Real > &z, const ROL::Vector< Real > &v_new, 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, Real &tol) override
Apply the adjoint of the partial constraint Jacobian at , , to vector . This is the primary interface...
Vector< Real > & getNewVector(Vector< Real > &x) const
virtual void applyJacobian_1_old(Vector< Real > &jv, const Vector< Real > &v_old, const Vector< Real > &u_old, const Vector< Real > &u_new, const Vector< Real > &z, Real &tol)=0
virtual void applyInverseAdjointJacobian_1_new(Vector< Real > &iajv, const Vector< Real > &v_new, const Vector< Real > &u_old, const Vector< Real > &u_new, const Vector< Real > &z, Real &tol)=0
virtual void update_1_old(const Vector< Real > &u_old, bool flag=true, int iter=-1)
Update constraint functions with respect to Sim variable. u_old is the state variable flag = true if ...
virtual void applyJacobian_1(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol) override
Apply the partial constraint Jacobian at , , to the vector .
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) override
Apply the optimization-space derivative of the adjoint of the constraint optimization-space Jacobian ...
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) override
Apply the simulation-space derivative of the adjoint of the constraint simulation-space Jacobian at ...
virtual void solve(Vector< Real > &c, Vector< Real > &u, const Vector< Real > &z, Real &tol) override
Given , solve for .
virtual void value(Vector< Real > &c, const Vector< Real > &u, const Vector< Real > &z, Real &tol) override
Evaluate the constraint operator at .
const Vector< Real > & getNewVector(const Vector< Real > &x) const
virtual void applyAdjointJacobian_1_new(Vector< Real > &ajv_new, const Vector< Real > &dualv, const Vector< Real > &u_old, const Vector< Real > &u_new, const Vector< Real > &z, Real &tol)=0
virtual void applyAdjointJacobian_1(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol) override
Apply the adjoint of the partial constraint Jacobian at , , to the vector . This is the primary inter...
virtual void update(const Vector< Real > &u, const Vector< Real > &z, bool flag=true, int iter=-1) override
Update constraint functions. x is the optimization variable, flag = true if optimization variable is ...
#define ROL_NUM_CHECKDERIV_STEPS
Number of steps for derivative checks.
virtual void applyJacobian_2(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol) override
Apply the partial constraint Jacobian at , , to the vector .
virtual void update_1_new(const Vector< Real > &u_new, bool flag=true, int iter=-1)
Update constraint functions with respect to Sim variable. u_new is the state variable flag = true if ...
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) override
basic_nullstream< char, char_traits< char >> nullstream
virtual void applyInverseJacobian_1(Vector< Real > &ijv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol) overridefinal
Apply the inverse partial constraint Jacobian at , , to the vector .
std::vector< std::vector< Real > > checkApplyJacobian_1_new(const Vector< Real > &u_new, const Vector< Real > &u_old, 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 norm() const =0
Returns where .
virtual void update_2(const Vector< Real > &z, bool flag=true, int iter=-1) override
Update constraint functions with respect to Opt variable. z is the control variable, flag = true if optimization variable is changed, iter is the outer algorithm iterations count.
Defines the constraint operator interface for simulation-based optimization.
VectorWorkspace< Real > workspace_
VectorWorkspace< Real > & getVectorWorkspace() const
virtual void value(Vector< Real > &c, const Vector< Real > &u_old, const Vector< Real > &u_new, const Vector< Real > &z, Real &tol)=0
Evaluate the constraint operator at .
virtual void applyInverseJacobian_1_new(Vector< Real > &ijv, const Vector< Real > &v_new, const Vector< Real > &u_old, const Vector< Real > &u_new, const Vector< Real > &z, Real &tol)=0
virtual void applyJacobian_1_new(Vector< Real > &jv, const Vector< Real > &v_new, const Vector< Real > &u_old, const Vector< Real > &u_new, const Vector< Real > &z, Real &tol)=0
virtual void applyAdjointJacobian_2_time(Vector< Real > &ajv, const Vector< Real > &dualv, const Vector< Real > &u_old, const Vector< Real > &u_new, const Vector< Real > &z, Real &tol)=0
virtual void applyAdjointHessian_11_new(Vector< Real > &ahwv_new, const Vector< Real > &w, const Vector< Real > &v_new, const Vector< Real > &u_old, const Vector< Real > &u_new, const Vector< Real > &z, Real &tol)=0
const Vector< Real > & getOldVector(const Vector< Real > &x) const
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) override
Apply the simulation-space derivative of the adjoint of the constraint optimization-space Jacobian at...
virtual Real checkInverseAdjointJacobian_1_new(const ROL::Vector< Real > &c, const ROL::Vector< Real > &u_new, const ROL::Vector< Real > &u_old, const ROL::Vector< Real > &z, const ROL::Vector< Real > &v_new, const bool printToStream=true, std::ostream &outStream=std::cout)
Vector< Real > & getOldVector(Vector< Real > &x) const