44 #ifndef ROL_REDUCEDDYNAMICOBJECTIVE_HPP
45 #define ROL_REDUCEDDYNAMICOBJECTIVE_HPP
47 #include "ROL_Ptr.hpp"
79 template<
typename Real>
84 const Ptr<DynamicObjective<Real>>
obj_;
85 const Ptr<DynamicConstraint<Real>>
con_;
86 const Ptr<Vector<Real>>
u0_;
143 const std::string &func,
const int line)
const {
145 std::stringstream out;
146 out <<
">>> ROL::ReducedDynamicObjective::" << func <<
" (Line " << line <<
"): ";
148 out <<
"Reconstruction has already been called!";
150 out <<
"Input column index exceeds total number of columns!";
152 out <<
"Reconstruction failed to compute domain-space basis!";
154 out <<
"Reconstruction failed to compute range-space basis!";
156 out <<
"Reconstruction failed to generate core matrix!";
168 ROL::ParameterList &pl,
169 const Ptr<std::ostream> &stream = nullPtr)
174 Nt_ ( timeStamp.size() ),
175 useSketch_ ( pl.get(
"Use Sketching", false) ),
184 maxRank_ ( pl.get(
"Maximum Rank", 100) ),
188 a_ ( pl.get(
"Log Rank Update Slope", 1.0) ),
189 b_ ( pl.get(
"Log Rank Update Shift", 1.0) ),
197 useSymHess_ ( pl.get(
"Use Only Sketched Sensitivity", true) ),
199 print_ ( pl.get(
"Print Optimization Vector", false) ),
200 freq_ ( pl.get(
"Output Frequency", 5) ) {
203 Real orthTol = pl.get(
"Orthogonality Tolerance", 1e2*ROL_EPSILON<Real>());
204 int orthIt = pl.get(
"Reorthogonalization Iterations", 5);
205 bool trunc = pl.get(
"Truncate Approximation",
false);
210 unsigned dseed = pl.get(
"State Domain Seed",0);
211 unsigned rseed = pl.get(
"State Range Seed",0);
216 uhist_.push_back(u0_->clone());
217 uhist_.push_back(u0_->clone());
218 lhist_.push_back(cvec->dual().clone());
219 dseed = pl.get(
"Adjoint Domain Seed",0);
220 rseed = pl.get(
"Adjoint Range Seed",0);
222 orthTol,orthIt,trunc,dseed,rseed);
224 dseed = pl.get(
"State Sensitivity Domain Seed",0);
225 rseed = pl.get(
"State Sensitivity Range Seed",0);
228 whist_.push_back(u0_->clone());
229 whist_.push_back(u0_->clone());
230 phist_.push_back(cvec->dual().clone());
236 lhist_.push_back(cvec->dual().clone());
239 phist_.push_back(cvec->dual().clone());
244 crhs_ = cvec->clone();
247 zdual_ = zvec->dual().clone();
267 val_ =
static_cast<Real
>(0);
273 std::stringstream name;
274 name <<
"optvector." << iter <<
".txt";
276 file.open(name.str());
294 val_ =
static_cast<Real
>(0);
310 val_ =
static_cast<Real
>(0);
344 val_ =
static_cast<Real
>(0);
367 val_ =
static_cast<Real
>(0);
377 std::stringstream name;
378 name <<
"optvector." << iter <<
".txt";
380 file.open(name.str());
439 *
stream_ << std::string(80,
'=') << std::endl;
440 *
stream_ <<
" ROL::ReducedDynamicObjective::gradient" << std::endl;
445 *
stream_ <<
" Residual Norm: " << tol << std::endl;
446 *
stream_ << std::string(80,
'=') << std::endl;
453 throwError(eflag,
"reconstruct",
"gradient",351);
456 throwError(eflag,
"reconstruct",
"gradient",354);
474 *
uhist_[uindex-1], *uhist_[uindex],
481 *uhist_[uindex-1], *uhist_[uindex],
488 uhist_[1]->set(*uhist_[0]);
490 uhist_[0]->set(*
u0_);
493 eflag =
stateSketch_->reconstruct(*uhist_[0],static_cast<int>(k)-2);
494 throwError(eflag,
"reconstruct",
"gradient",392);
498 throwError(eflag,
"reconstruct",
"gradient",396);
507 *uhist_[uindex-1], *uhist_[uindex],
516 *uhist_[uindex-1], *uhist_[uindex],
548 throwError(eflag,
"reconstruct",
"hessVec",446);
550 throwError(eflag,
"reconstruct",
"hessVec",448);
558 *
uhist_[uindex-1], *uhist_[uindex],
563 *uhist_[uindex-1], *uhist_[uindex],
568 *
whist_[uindex-1], *whist_[uindex],
569 *uhist_[uindex-1], *uhist_[uindex],
577 uhist_[0]->set(*uhist_[1]);
588 throwError(eflag,
"reconstruct",
"hessVec",486);
591 throwError(eflag,
"reconstruct",
"hessVec",489);
595 throwError(eflag,
"reconstruct",
"hessVec",493);
603 *
whist_[uindex-1], *whist_[uindex],
604 *
uhist_[uindex-1], *uhist_[uindex],
609 *whist_[uindex-1], *whist_[uindex],
610 *uhist_[uindex-1], *uhist_[uindex],
615 *uhist_[uindex-1], *uhist_[uindex],
621 *whist_[uindex-1], *whist_[uindex],
622 *uhist_[uindex-1], *uhist_[uindex],
627 *uhist_[uindex-1], *uhist_[uindex],
631 *uhist_[uindex-1], *uhist_[uindex],
636 uhist_[1]->set(*uhist_[0]);
637 whist_[1]->set(*whist_[0]);
639 uhist_[0]->set(*
u0_);
643 eflag =
stateSketch_->reconstruct(*uhist_[0],static_cast<int>(k)-2);
644 throwError(eflag,
"reconstruct",
"hessVec",542);
646 throwError(eflag,
"reconstruct",
"hessVec",544);
649 throwError(eflag,
"reconstruct",
"hessVec",547);
658 *whist_[uindex-1], *whist_[uindex],
659 *uhist_[uindex-1], *uhist_[uindex],
664 *uhist_[uindex-1], *uhist_[uindex],
669 *uhist_[uindex-1], *uhist_[uindex],
674 *whist_[uindex-1], *whist_[uindex],
675 *uhist_[uindex-1], *uhist_[uindex],
680 *uhist_[uindex-1], *uhist_[uindex],
715 cnorm = std::max(cnorm,
cprimal_->norm());
731 Real err(0), err2(0), serr(0), cdot(0), dt(0);
732 Real tol0 = std::min(
maxTol_,tol);
735 err =
static_cast<Real
>(0);
740 throwError(eflag,
"reconstruct",
"updateSketch",592);
750 err = std::sqrt(err2);
751 if (err > tol0)
break;
756 *
stream_ <<
" *** Required Tolerance: " << tol0 << std::endl;
757 *
stream_ <<
" *** Residual Norm: " << err << std::endl;
779 *
stream_ <<
" *** Maximum Solver Error: " << serr << std::endl;
795 obj_->gradient_un(*
udual_, uold, unew, z, ts);
796 con_->applyInverseAdjointJacobian_un(l, *
udual_, uold, unew, z, ts);
803 obj_->gradient_uo(rhs, uold, unew, z, ts);
804 con_->applyAdjointJacobian_uo(*
udual_, l, uold, unew, z, ts);
811 obj_->gradient_un(*
udual_, uold, unew, z, ts);
813 con_->applyInverseAdjointJacobian_un(l, rhs, uold, unew, z, ts);
829 throwError(eflag,
"reconstruct",
"solveAdjoint",672);
840 throwError(eflag,
"advance",
"solveAdjoint",683);
856 throwError(eflag,
"reconstruct",
"solveAdjoint",699);
870 throwError(eflag,
"advance",
"solveAdjoint",713);
884 obj_->gradient_z(g, uold, unew, z, ts);
885 con_->applyAdjointJacobian_z(*
zdual_, l, uold, unew, z, ts);
897 con_->applyJacobian_z(*
crhs_, v, uold, unew, z, ts);
898 con_->applyJacobian_uo(*
cprimal_, wold, uold, unew, z, ts);
900 con_->applyInverseJacobian_un(wnew, *
crhs_, uold, unew, z, ts);
913 con_->applyAdjointHessian_z_un(*
rhs_, l, v, uold, unew, z, ts);
914 obj_->hessVec_un_z(*
udual_, v, uold, unew, z, ts);
917 con_->applyAdjointHessian_un_un(*
udual_, l, wnew, uold, unew, z, ts);
919 obj_->hessVec_un_un(*
udual_, wnew, uold, unew, z, ts);
921 con_->applyAdjointHessian_uo_un(*
udual_, l, wold, uold, unew, z, ts);
923 obj_->hessVec_un_uo(*
udual_, wold, uold, unew, z, ts);
926 con_->applyInverseAdjointJacobian_un(p, *
rhs_, uold, unew, z, ts);
933 const bool sumInto =
false) {
937 obj_->hessVec_un_uo(Hv, wold, uold, unew, z, ts);
940 obj_->hessVec_un_uo(*
udual_, wold, uold, unew, z, ts);
943 con_->applyAdjointHessian_uo_un(*
udual_, l, wold, uold, unew, z, ts);
946 obj_->hessVec_un_un(*
udual_, wnew, uold, unew, z, ts);
948 con_->applyAdjointHessian_un_un(*
udual_, l, wnew, uold, unew, z, ts);
956 const bool sumInto =
false) {
960 con_->applyAdjointHessian_z_un(Hv, l, v, uold, unew, z, ts);
963 con_->applyAdjointHessian_z_un(*
udual_, l, v, uold, unew, z, ts);
966 obj_->hessVec_un_z(*
udual_, v, uold, unew, z, ts);
973 const bool sumInto =
false) {
976 con_->applyAdjointJacobian_uo(Hv, p, uold, unew, z, ts);
980 con_->applyAdjointJacobian_uo(*
udual_, p, uold, unew, z, ts);
989 const bool sumInto =
false) {
993 obj_->hessVec_uo_un(Hv, wnew, uold, unew, z, ts);
996 obj_->hessVec_uo_un(*
udual_, wnew, uold, unew, z, ts);
999 con_->applyAdjointHessian_un_uo(*
udual_, l, wnew, uold, unew, z, ts);
1002 obj_->hessVec_uo_uo(*
udual_, wold, uold, unew, z, ts);
1004 con_->applyAdjointHessian_uo_uo(*
udual_, l, wold, uold, unew, z, ts);
1012 const bool sumInto =
false) {
1016 con_->applyAdjointHessian_z_uo(Hv, l, v, uold, unew, z, ts);
1019 con_->applyAdjointHessian_z_uo(*
udual_, l, v, uold, unew, z, ts);
1022 obj_->hessVec_uo_z(*
udual_, v, uold, unew, z, ts);
1030 con_->applyInverseAdjointJacobian_un(p, rhs, uold, unew, z, ts);
1042 obj_->hessVec_z_z(Hv, v, uold, unew, z, ts);
1043 con_->applyAdjointHessian_z_z(*
zdual_, l, v, uold, unew, z, ts);
1053 obj_->hessVec_z_uo(*
zdual_, wold, uold, unew, z, ts);
1055 con_->applyAdjointHessian_uo_z(*
zdual_, l, wold, uold, unew, z, ts);
1058 obj_->hessVec_z_un(*
zdual_, wnew, uold, unew, z, ts);
1060 con_->applyAdjointHessian_un_z(*
zdual_, l, wnew, uold, unew, z, ts);
1067 con_->applyAdjointJacobian_z(*
zdual_, p, uold, unew, z, ts);
1074 #endif // ROL_REDUCEDDYNAMICOBJECTIVE_HPP
void advanceAdjointSens(Vector< Real > &p, Vector< Real > &rhs, const Vector< Real > &uold, const Vector< Real > &unew, const Vector< Real > &z, const TimeStamp< Real > &ts)
Provides the interface to evaluate objective functions.
Ptr< Sketch< Real > > stateSensSketch_
static Ptr< PartitionedVector > create(std::initializer_list< Vp > vs)
void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
typename PV< Real >::size_type size_type
virtual void scale(const Real alpha)=0
Compute where .
void computeOldStateHessLag(Vector< Real > &Hv, const Vector< Real > &l, const Vector< Real > &wold, const Vector< Real > &wnew, const Vector< Real > &uold, const Vector< Real > &unew, const Vector< Real > &z, const TimeStamp< Real > &ts, const bool sumInto=false)
const PartitionedVector< Real > & partition(const Vector< Real > &x) const
void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update objective function.
ROL::Ptr< const Vector< Real > > get(size_type i) const
Defines the reduced time-dependent objective function interface for simulation-based optimization...
virtual void plus(const Vector &x)=0
Compute , where .
Ptr< Vector< Real > > makeDynamicVector(const Vector< Real > &x) const
virtual void print(std::ostream &outStream) const
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Ptr< Vector< Real > > udual_
Defines the time-dependent constraint operator interface for simulation-based optimization.
void computeNewStateJacobian(Vector< Real > &Hv, const Vector< Real > &p, const Vector< Real > &uold, const Vector< Real > &unew, const Vector< Real > &z, const TimeStamp< Real > &ts, const bool sumInto=false)
const size_type updateFactor_
Defines the linear algebra of vector space on a generic partitioned vector.
const bool useDefaultRankUpdate_
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
void addAdjointSens(Vector< Real > &Hv, const Vector< Real > &p, const Vector< Real > &uold, const Vector< Real > &unew, const Vector< Real > &z, const TimeStamp< Real > &ts)
Ptr< Vector< Real > > crhs_
Ptr< std::ostream > stream_
Real solveState(const Vector< Real > &x)
const std::vector< TimeStamp< Real > > timeStamp_
Ptr< Vector< Real > > zdual_
Defines the linear algebra or vector space interface.
Defines the time-dependent objective function interface for simulation-based optimization. Computes time-local contributions of value, gradient, Hessian-vector product etc to a larger composite objective defined over the simulation time. In contrast to other objective classes Objective_TimeSimOpt has a default implementation of value which returns zero, as time-dependent simulation based optimization problems may have an objective value which depends only on the final state of the system.
void advanceAdjoint(Vector< Real > &l, Vector< Real > &rhs, const Vector< Real > &uold, const Vector< Real > &unew, const Vector< Real > &z, const TimeStamp< Real > &ts)
size_type getStateRank() const
void computeNewStateHessLag(Vector< Real > &Hv, const Vector< Real > &l, const Vector< Real > &wold, const Vector< Real > &wnew, const Vector< Real > &uold, const Vector< Real > &unew, const Vector< Real > &z, const TimeStamp< Real > &ts, const bool sumInto=false)
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
Ptr< Sketch< Real > > adjointSketch_
Real value(const Vector< Real > &x, Real &tol)
Compute value.
PartitionedVector< Real > & partition(Vector< Real > &x) const
Real updateSketch(const Vector< Real > &x, const Real tol)
typename std::vector< Real >::size_type size_type
size_type getAdjointRank() const
void computeNewMixedHessLag(Vector< Real > &Hv, const Vector< Real > &v, const Vector< Real > &l, const Vector< Real > &uold, const Vector< Real > &unew, const Vector< Real > &z, const TimeStamp< Real > &ts, const bool sumInto=false)
const Ptr< DynamicObjective< Real > > obj_
Ptr< Vector< Real > > cprimal_
void throwError(const int err, const std::string &sfunc, const std::string &func, const int line) const
Ptr< Sketch< Real > > stateSketchCache_
const Ptr< DynamicConstraint< Real > > con_
void advanceStateSens(Vector< Real > &wnew, const Vector< Real > &v, const Vector< Real > &wold, const Vector< Real > &uold, const Vector< Real > &unew, const Vector< Real > &z, const TimeStamp< Real > &ts)
const bool sumRankUpdate_
void computeControlHessLag(Vector< Real > &Hv, const Vector< Real > &v, const Vector< Real > &l, const Vector< Real > &uold, const Vector< Real > &unew, const Vector< Real > &z, const TimeStamp< Real > &ts)
std::vector< Ptr< Vector< Real > > > whist_
void solveAdjoint(const Vector< Real > &x)
void setTerminalCondition(Vector< Real > &l, const Vector< Real > &uold, const Vector< Real > &unew, const Vector< Real > &z, const TimeStamp< Real > &ts)
size_type getStateSensitivityRank() const
std::vector< Ptr< Vector< Real > > > uhist_
std::vector< Ptr< Vector< Real > > > lhist_
Ptr< Vector< Real > > rhs_
const Ptr< Vector< Real > > u0_
void setTerminalConditionHess(Vector< Real > &p, const Vector< Real > &v, const Vector< Real > &l, const Vector< Real > &wold, const Vector< Real > &wnew, const Vector< Real > &uold, const Vector< Real > &unew, const Vector< Real > &z, const TimeStamp< Real > &ts)
std::vector< Ptr< Vector< Real > > > phist_
ReducedDynamicObjective(const Ptr< DynamicObjective< Real >> &obj, const Ptr< DynamicConstraint< Real >> &con, const Ptr< Vector< Real >> &u0, const Ptr< Vector< Real >> &zvec, const Ptr< Vector< Real >> &cvec, const std::vector< TimeStamp< Real >> &timeStamp, ROL::ParameterList &pl, const Ptr< std::ostream > &stream=nullPtr)
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
void computeAdjointRHS(Vector< Real > &rhs, const Vector< Real > &l, const Vector< Real > &uold, const Vector< Real > &unew, const Vector< Real > &z, const TimeStamp< Real > &ts)
void computeOldMixedHessLag(Vector< Real > &Hv, const Vector< Real > &v, const Vector< Real > &l, const Vector< Real > &uold, const Vector< Real > &unew, const Vector< Real > &z, const TimeStamp< Real > &ts, const bool sumInto=false)
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
void addMixedHessLag(Vector< Real > &Hv, const Vector< Real > &l, const Vector< Real > &wold, const Vector< Real > &wnew, const Vector< Real > &uold, const Vector< Real > &unew, const Vector< Real > &z, const TimeStamp< Real > &ts)
void updateGradient(Vector< Real > &g, const Vector< Real > &l, const Vector< Real > &uold, const Vector< Real > &unew, const Vector< Real > &z, const TimeStamp< Real > &ts)
Ptr< Sketch< Real > > stateSketch_