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_;
136 const std::string &func,
const int line)
const {
138 std::stringstream out;
139 out <<
">>> ROL::ReducedDynamicObjective::" << func <<
" (Line " << line <<
"): ";
141 out <<
"Reconstruction has already been called!";
144 out <<
"Input column index exceeds total number of columns!";
147 out <<
"Reconstruction failed to compute domain-space basis!";
150 out <<
"Reconstruction failed to compute range-space basis!";
153 out <<
"Reconstruction failed to generate core matrix!";
166 ROL::ParameterList &pl,
167 const Ptr<std::ostream> &stream = nullPtr)
172 Nt_ ( timeStamp.size() ),
182 maxRank_ ( pl.get(
"Maximum Rank", 100) ),
188 useSymHess_ ( pl.get(
"Use Only Sketched Sensitivity", true) ),
190 print_ ( pl.get(
"Print Optimization Vector", false) ),
191 freq_ ( pl.get(
"Output Frequency", 5) ) {
194 Real orthTol = pl.get(
"Orthogonality Tolerance", 1e2*ROL_EPSILON<Real>());
195 int orthIt = pl.get(
"Reorthogonalization Iterations", 5);
196 bool trunc = pl.get(
"Truncate Approximation",
false);
201 unsigned dseed = pl.get(
"State Domain Seed",0);
202 unsigned rseed = pl.get(
"State Range Seed",0);
204 orthTol,orthIt,trunc,dseed,rseed);
205 uhist_.push_back(u0_->clone());
206 uhist_.push_back(u0_->clone());
207 lhist_.push_back(cvec->dual().clone());
208 dseed = pl.get(
"Adjoint Domain Seed",0);
209 rseed = pl.get(
"Adjoint Range Seed",0);
211 orthTol,orthIt,trunc,dseed,rseed);
213 dseed = pl.get(
"State Sensitivity Domain Seed",0);
214 rseed = pl.get(
"State Sensitivity Range Seed",0);
217 whist_.push_back(u0_->clone());
218 whist_.push_back(u0_->clone());
219 phist_.push_back(cvec->dual().clone());
225 lhist_.push_back(cvec->dual().clone());
228 phist_.push_back(cvec->dual().clone());
233 crhs_ = cvec->clone();
236 zdual_ = zvec->dual().clone();
256 val_ =
static_cast<Real
>(0);
263 std::stringstream name;
264 name <<
"optvector." << iter <<
".txt";
266 file.open(name.str());
327 *
stream_ << std::string(80,
'=') << std::endl;
328 *
stream_ <<
" ROL::ReducedDynamicObjective::gradient" << std::endl;
333 *
stream_ <<
" Residual Norm: " << tol << std::endl;
334 *
stream_ << std::string(80,
'=') << std::endl;
341 throwError(eflag,
"reconstruct",
"gradient",309);
344 throwError(eflag,
"reconstruct",
"gradient",312);
362 *
uhist_[uindex-1], *uhist_[uindex],
369 *uhist_[uindex-1], *uhist_[uindex],
376 uhist_[1]->set(*uhist_[0]);
378 uhist_[0]->set(*
u0_);
381 eflag =
stateSketch_->reconstruct(*uhist_[0],static_cast<int>(k)-2);
382 throwError(eflag,
"reconstruct",
"gradient",350);
386 throwError(eflag,
"reconstruct",
"gradient",354);
395 *uhist_[uindex-1], *uhist_[uindex],
404 *uhist_[uindex-1], *uhist_[uindex],
436 throwError(eflag,
"reconstruct",
"hessVec",404);
438 throwError(eflag,
"reconstruct",
"hessVec",406);
446 *
uhist_[uindex-1], *uhist_[uindex],
451 *uhist_[uindex-1], *uhist_[uindex],
456 *
whist_[uindex-1], *whist_[uindex],
457 *uhist_[uindex-1], *uhist_[uindex],
465 uhist_[0]->set(*uhist_[1]);
476 throwError(eflag,
"reconstruct",
"hessVec",444);
479 throwError(eflag,
"reconstruct",
"hessVec",447);
483 throwError(eflag,
"reconstruct",
"hessVec",451);
491 *
whist_[uindex-1], *whist_[uindex],
492 *
uhist_[uindex-1], *uhist_[uindex],
497 *whist_[uindex-1], *whist_[uindex],
498 *uhist_[uindex-1], *uhist_[uindex],
503 *uhist_[uindex-1], *uhist_[uindex],
509 *whist_[uindex-1], *whist_[uindex],
510 *uhist_[uindex-1], *uhist_[uindex],
515 *uhist_[uindex-1], *uhist_[uindex],
519 *uhist_[uindex-1], *uhist_[uindex],
524 uhist_[1]->set(*uhist_[0]);
525 whist_[1]->set(*whist_[0]);
527 uhist_[0]->set(*
u0_);
531 eflag =
stateSketch_->reconstruct(*uhist_[0],static_cast<int>(k)-2);
532 throwError(eflag,
"reconstruct",
"hessVec",500);
534 throwError(eflag,
"reconstruct",
"hessVec",502);
537 throwError(eflag,
"reconstruct",
"hessVec",505);
546 *whist_[uindex-1], *whist_[uindex],
547 *uhist_[uindex-1], *uhist_[uindex],
552 *uhist_[uindex-1], *uhist_[uindex],
557 *uhist_[uindex-1], *uhist_[uindex],
562 *whist_[uindex-1], *whist_[uindex],
563 *uhist_[uindex-1], *uhist_[uindex],
568 *uhist_[uindex-1], *uhist_[uindex],
604 cnorm = std::max(cnorm,
cprimal_->norm());
620 Real err(0), serr(0), cnorm(0);
623 err =
static_cast<Real
>(0);
627 throwError(eflag,
"reconstruct",
"updateSketch",592);
632 err = (cnorm > err ? cnorm : err);
646 *
stream_ <<
" *** Required Tolerance: " << tol << std::endl;
647 *
stream_ <<
" *** Residual Norm: " << err << std::endl;
666 *
stream_ <<
" *** Maximum Solver Error: " << serr << std::endl;
683 obj_->gradient_un(*
udual_, uold, unew, z, ts);
684 con_->applyInverseAdjointJacobian_un(l, *
udual_, uold, unew, z, ts);
691 obj_->gradient_uo(rhs, uold, unew, z, ts);
692 con_->applyAdjointJacobian_uo(*
udual_, l, uold, unew, z, ts);
699 obj_->gradient_un(*
udual_, uold, unew, z, ts);
701 con_->applyInverseAdjointJacobian_un(l, rhs, uold, unew, z, ts);
717 throwError(eflag,
"reconstruct",
"solveAdjoint",672);
728 throwError(eflag,
"advance",
"solveAdjoint",683);
744 throwError(eflag,
"reconstruct",
"solveAdjoint",699);
758 throwError(eflag,
"advance",
"solveAdjoint",713);
772 obj_->gradient_z(g, uold, unew, z, ts);
773 con_->applyAdjointJacobian_z(*
zdual_, l, uold, unew, z, ts);
785 con_->applyJacobian_z(*
crhs_, v, uold, unew, z, ts);
786 con_->applyJacobian_uo(*
cprimal_, wold, uold, unew, z, ts);
788 con_->applyInverseJacobian_un(wnew, *
crhs_, uold, unew, z, ts);
801 con_->applyAdjointHessian_z_un(*
rhs_, l, v, uold, unew, z, ts);
802 obj_->hessVec_un_z(*
udual_, v, uold, unew, z, ts);
805 con_->applyAdjointHessian_un_un(*
udual_, l, wnew, uold, unew, z, ts);
807 obj_->hessVec_un_un(*
udual_, wnew, uold, unew, z, ts);
809 con_->applyAdjointHessian_uo_un(*
udual_, l, wold, uold, unew, z, ts);
811 obj_->hessVec_un_uo(*
udual_, wold, uold, unew, z, ts);
814 con_->applyInverseAdjointJacobian_un(p, *
rhs_, uold, unew, z, ts);
821 const bool sumInto =
false) {
825 obj_->hessVec_un_uo(Hv, wold, uold, unew, z, ts);
828 obj_->hessVec_un_uo(*
udual_, wold, uold, unew, z, ts);
831 con_->applyAdjointHessian_uo_un(*
udual_, l, wold, uold, unew, z, ts);
834 obj_->hessVec_un_un(*
udual_, wnew, uold, unew, z, ts);
836 con_->applyAdjointHessian_un_un(*
udual_, l, wnew, uold, unew, z, ts);
844 const bool sumInto =
false) {
848 con_->applyAdjointHessian_z_un(Hv, l, v, uold, unew, z, ts);
851 con_->applyAdjointHessian_z_un(*
udual_, l, v, uold, unew, z, ts);
854 obj_->hessVec_un_z(*
udual_, v, uold, unew, z, ts);
861 const bool sumInto =
false) {
864 con_->applyAdjointJacobian_uo(Hv, p, uold, unew, z, ts);
868 con_->applyAdjointJacobian_uo(*
udual_, p, uold, unew, z, ts);
877 const bool sumInto =
false) {
881 obj_->hessVec_uo_un(Hv, wnew, uold, unew, z, ts);
884 obj_->hessVec_uo_un(*
udual_, wnew, uold, unew, z, ts);
887 con_->applyAdjointHessian_un_uo(*
udual_, l, wnew, uold, unew, z, ts);
890 obj_->hessVec_uo_uo(*
udual_, wold, uold, unew, z, ts);
892 con_->applyAdjointHessian_uo_uo(*
udual_, l, wold, uold, unew, z, ts);
900 const bool sumInto =
false) {
904 con_->applyAdjointHessian_z_uo(Hv, l, v, uold, unew, z, ts);
907 con_->applyAdjointHessian_z_uo(*
udual_, l, v, uold, unew, z, ts);
910 obj_->hessVec_uo_z(*
udual_, v, uold, unew, z, ts);
918 con_->applyInverseAdjointJacobian_un(p, rhs, uold, unew, z, ts);
930 obj_->hessVec_z_z(Hv, v, uold, unew, z, ts);
931 con_->applyAdjointHessian_z_z(*
zdual_, l, v, uold, unew, z, ts);
941 obj_->hessVec_z_uo(*
zdual_, wold, uold, unew, z, ts);
943 con_->applyAdjointHessian_uo_z(*
zdual_, l, wold, uold, unew, z, ts);
946 obj_->hessVec_z_un(*
zdual_, wnew, uold, unew, z, ts);
948 con_->applyAdjointHessian_un_z(*
zdual_, l, wnew, uold, unew, z, ts);
955 con_->applyAdjointJacobian_z(*
zdual_, p, uold, unew, z, ts);
962 #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
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.
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)
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)
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
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
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)
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)
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_