44 #ifndef ROL_CONSTRAINT_TIMESIMOPT_H
45 #define ROL_CONSTRAINT_TIMESIMOPT_H
152 bool flag =
true,
int iter = -1 ) {
275 bool flag =
true,
int iter = -1 )
override {
285 Real &tol)
override {
297 Real &tol)
override {
309 Real &tol)
override {
321 ROL::Ptr<Vector<Real> > jv_new =
workspace_.clone(jv);
329 jv.
axpy(1.0,*jv_new);
336 Real &tol)
override {
351 Real &tol)
override final {
352 ROL_TEST_FOR_EXCEPTION(
true, std::logic_error,
353 "The method applyInverseJacobian_1 is used but not implemented!\n");
360 Real &tol)
override {
374 Real &tol)
override {
385 Real &tol)
override final {
386 ROL_TEST_FOR_EXCEPTION(
true, std::logic_error,
387 "The method applyInverseAdjointJacobian_1 is used but not implemented!\n");
477 Real &tol)
override {
503 Real &tol)
override {
511 const bool printToStream =
true,
512 std::ostream & outStream = std::cout)
override {
514 Real tol = ROL_EPSILON<Real>();
515 ROL::Ptr<ROL::Vector<Real> > r =
workspace_.clone(c);
516 ROL::Ptr<ROL::Vector<Real> > s =
workspace_.clone(u);
520 ROL::Ptr<ROL::Vector<Real> > cs =
workspace_.clone(c);
524 Real rnorm = r->norm();
525 Real cnorm = cs->norm();
526 if ( printToStream ) {
527 std::stringstream hist;
528 hist << std::scientific << std::setprecision(8);
529 hist <<
"\nTest SimOpt solve at feasible (u,z):\n";
530 hist <<
" Solver Residual = " << rnorm <<
"\n";
531 hist <<
" ||c(u,z)|| = " << cnorm <<
"\n";
532 outStream << hist.str();
543 const bool printToStream =
true,
544 std::ostream & outStream = std::cout) {
545 Real tol = ROL_EPSILON<Real>();
547 update( u_new, u_old, z );
550 update( u_new, u_old, z );
554 diff->axpy(-1.0,*iJJv);
555 Real dnorm = diff->norm();
556 Real vnorm = v_new.
norm();
557 if ( printToStream ) {
558 std::stringstream hist;
559 hist << std::scientific << std::setprecision(8);
560 hist <<
"\nTest TimeSimOpt consistency of inverse Jacobian_1_new: \n ||v-inv(J)Jv|| = "
562 hist <<
" ||v|| = " << vnorm <<
"\n";
563 hist <<
" Relative Error = " << dnorm / (vnorm+ROL_UNDERFLOW<Real>()) <<
"\n";
564 outStream << hist.str();
574 const bool printToStream =
true,
575 std::ostream & outStream = std::cout) {
576 Real tol = ROL_EPSILON<Real>();
578 update( u_new, u_old, z );
581 update( u_new, u_old, z );
585 diff->axpy(-1.0,*iJJv);
586 Real dnorm = diff->norm();
587 Real vnorm = v_new.
norm();
588 if ( printToStream ) {
589 std::stringstream hist;
590 hist << std::scientific << std::setprecision(8);
591 hist <<
"\nTest TimeSimOpt consistency of inverse adjoint Jacobian_1_new: \n ||v-inv(adj(J))adj(J)v|| = "
593 hist <<
" ||v|| = " << vnorm <<
"\n";
594 hist <<
" Relative Error = " << dnorm / (vnorm+ROL_UNDERFLOW<Real>()) <<
"\n";
595 outStream << hist.str();
605 const bool printToStream =
true,
606 std::ostream & outStream = std::cout,
608 const int order = 1) {
609 std::vector<Real> steps(numSteps);
610 for(
int i=0;i<numSteps;++i) {
611 steps[i] = pow(10,-i);
622 const std::vector<Real> &steps,
623 const bool printToStream =
true,
624 std::ostream & outStream = std::cout,
625 const int order = 1) {
627 ROL_TEST_FOR_EXCEPTION( order<1 || order>4, std::invalid_argument,
628 "Error: finite difference order must be 1,2,3, or 4" );
635 Real tol = std::sqrt(ROL_EPSILON<Real>());
637 int numSteps = steps.size();
639 std::vector<Real> tmp(numVals);
640 std::vector<std::vector<Real> > jvCheck(numSteps, tmp);
644 oldFormatState.copyfmt(outStream);
647 ROL::Ptr<Vector<Real> > c =
workspace_.clone(jv);
648 this->
update(u_new, u_old, z);
649 this->
value(*c, u_new, u_old, z, tol);
652 ROL::Ptr<Vector<Real> > Jv =
workspace_.clone(jv);
654 Real normJv = Jv->norm();
657 ROL::Ptr<Vector<Real> > cdif =
workspace_.clone(jv);
658 ROL::Ptr<Vector<Real> > cnew =
workspace_.clone(jv);
659 ROL::Ptr<Vector<Real> > u_2 =
workspace_.clone(u_new);
661 for (
int i=0; i<numSteps; i++) {
668 cdif->scale(
weights[order-1][0]);
670 for(
int j=0; j<order; ++j) {
672 u_2->axpy(eta*
shifts[order-1][j], v);
674 if(
weights[order-1][j+1] != 0 ) {
675 this->
update(*u_2,u_old,z);
676 this->
value(*cnew,*u_2,u_old,z,tol);
677 cdif->axpy(
weights[order-1][j+1],*cnew);
682 cdif->scale(one/eta);
686 jvCheck[i][1] = normJv;
687 jvCheck[i][2] = cdif->norm();
688 cdif->axpy(-one, *Jv);
689 jvCheck[i][3] = cdif->norm();
692 std::stringstream hist;
695 << std::setw(20) <<
"Step size"
696 << std::setw(20) <<
"norm(Jac*vec)"
697 << std::setw(20) <<
"norm(FD approx)"
698 << std::setw(20) <<
"norm(abs error)"
700 << std::setw(20) <<
"---------"
701 << std::setw(20) <<
"-------------"
702 << std::setw(20) <<
"---------------"
703 << std::setw(20) <<
"---------------"
706 hist << std::scientific << std::setprecision(11) << std::right
707 << std::setw(20) << jvCheck[i][0]
708 << std::setw(20) << jvCheck[i][1]
709 << std::setw(20) << jvCheck[i][2]
710 << std::setw(20) << jvCheck[i][3]
712 outStream << hist.str();
718 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