10 #ifndef ROL_REDUCEDDYNAMICOBJECTIVE_HPP
11 #define ROL_REDUCEDDYNAMICOBJECTIVE_HPP
13 #include "ROL_Ptr.hpp"
45 template<
typename Real>
50 const Ptr<DynamicObjective<Real>>
obj_;
51 const Ptr<DynamicConstraint<Real>>
con_;
52 const Ptr<Vector<Real>>
u0_;
77 std::vector<Ptr<Vector<Real>>>
uhist_;
78 std::vector<Ptr<Vector<Real>>>
lhist_;
79 std::vector<Ptr<Vector<Real>>>
whist_;
80 std::vector<Ptr<Vector<Real>>>
phist_;
109 const std::string &func,
const int line)
const {
111 std::stringstream out;
112 out <<
">>> ROL::ReducedDynamicObjective::" << func <<
" (Line " << line <<
"): ";
114 out <<
"Reconstruction has already been called!";
116 out <<
"Input column index exceeds total number of columns!";
118 out <<
"Reconstruction failed to compute domain-space basis!";
120 out <<
"Reconstruction failed to compute range-space basis!";
122 out <<
"Reconstruction failed to generate core matrix!";
134 ROL::ParameterList &pl,
135 const Ptr<std::ostream> &stream = nullPtr)
140 Nt_ ( timeStamp.size() ),
141 useSketch_ ( pl.get(
"Use Sketching", false) ),
150 maxRank_ ( pl.get(
"Maximum Rank", 100) ),
154 a_ ( pl.get(
"Log Rank Update Slope", 1.0) ),
155 b_ ( pl.get(
"Log Rank Update Shift", 1.0) ),
163 useSymHess_ ( pl.get(
"Use Only Sketched Sensitivity", true) ),
165 print_ ( pl.get(
"Print Optimization Vector", false) ),
166 freq_ ( pl.get(
"Output Frequency", 5) ) {
169 Real orthTol = pl.get(
"Orthogonality Tolerance", 1e2*ROL_EPSILON<Real>());
170 int orthIt = pl.get(
"Reorthogonalization Iterations", 5);
171 bool trunc = pl.get(
"Truncate Approximation",
false);
176 unsigned dseed = pl.get(
"State Domain Seed",0);
177 unsigned rseed = pl.get(
"State Range Seed",0);
182 uhist_.push_back(u0_->clone());
183 uhist_.push_back(u0_->clone());
184 lhist_.push_back(cvec->dual().clone());
185 dseed = pl.get(
"Adjoint Domain Seed",0);
186 rseed = pl.get(
"Adjoint Range Seed",0);
188 orthTol,orthIt,trunc,dseed,rseed);
190 dseed = pl.get(
"State Sensitivity Domain Seed",0);
191 rseed = pl.get(
"State Sensitivity Range Seed",0);
194 whist_.push_back(u0_->clone());
195 whist_.push_back(u0_->clone());
196 phist_.push_back(cvec->dual().clone());
202 lhist_.push_back(cvec->dual().clone());
205 phist_.push_back(cvec->dual().clone());
210 crhs_ = cvec->clone();
213 zdual_ = zvec->dual().clone();
233 val_ =
static_cast<Real
>(0);
239 std::stringstream name;
240 name <<
"optvector." << iter <<
".txt";
242 file.open(name.str());
260 val_ =
static_cast<Real
>(0);
276 val_ =
static_cast<Real
>(0);
310 val_ =
static_cast<Real
>(0);
333 val_ =
static_cast<Real
>(0);
343 std::stringstream name;
344 name <<
"optvector." << iter <<
".txt";
346 file.open(name.str());
405 *
stream_ << std::string(80,
'=') << std::endl;
406 *
stream_ <<
" ROL::ReducedDynamicObjective::gradient" << std::endl;
411 *
stream_ <<
" Residual Norm: " << tol << std::endl;
412 *
stream_ << std::string(80,
'=') << std::endl;
419 throwError(eflag,
"reconstruct",
"gradient",351);
422 throwError(eflag,
"reconstruct",
"gradient",354);
440 *
uhist_[uindex-1], *uhist_[uindex],
447 *uhist_[uindex-1], *uhist_[uindex],
454 uhist_[1]->set(*uhist_[0]);
456 uhist_[0]->set(*
u0_);
459 eflag =
stateSketch_->reconstruct(*uhist_[0],static_cast<int>(k)-2);
460 throwError(eflag,
"reconstruct",
"gradient",392);
464 throwError(eflag,
"reconstruct",
"gradient",396);
473 *uhist_[uindex-1], *uhist_[uindex],
482 *uhist_[uindex-1], *uhist_[uindex],
514 throwError(eflag,
"reconstruct",
"hessVec",446);
516 throwError(eflag,
"reconstruct",
"hessVec",448);
524 *
uhist_[uindex-1], *uhist_[uindex],
529 *uhist_[uindex-1], *uhist_[uindex],
534 *
whist_[uindex-1], *whist_[uindex],
535 *uhist_[uindex-1], *uhist_[uindex],
543 uhist_[0]->set(*uhist_[1]);
554 throwError(eflag,
"reconstruct",
"hessVec",486);
557 throwError(eflag,
"reconstruct",
"hessVec",489);
561 throwError(eflag,
"reconstruct",
"hessVec",493);
569 *
whist_[uindex-1], *whist_[uindex],
570 *
uhist_[uindex-1], *uhist_[uindex],
575 *whist_[uindex-1], *whist_[uindex],
576 *uhist_[uindex-1], *uhist_[uindex],
581 *uhist_[uindex-1], *uhist_[uindex],
587 *whist_[uindex-1], *whist_[uindex],
588 *uhist_[uindex-1], *uhist_[uindex],
593 *uhist_[uindex-1], *uhist_[uindex],
597 *uhist_[uindex-1], *uhist_[uindex],
602 uhist_[1]->set(*uhist_[0]);
603 whist_[1]->set(*whist_[0]);
605 uhist_[0]->set(*
u0_);
609 eflag =
stateSketch_->reconstruct(*uhist_[0],static_cast<int>(k)-2);
610 throwError(eflag,
"reconstruct",
"hessVec",542);
612 throwError(eflag,
"reconstruct",
"hessVec",544);
615 throwError(eflag,
"reconstruct",
"hessVec",547);
624 *whist_[uindex-1], *whist_[uindex],
625 *uhist_[uindex-1], *uhist_[uindex],
630 *uhist_[uindex-1], *uhist_[uindex],
635 *uhist_[uindex-1], *uhist_[uindex],
640 *whist_[uindex-1], *whist_[uindex],
641 *uhist_[uindex-1], *uhist_[uindex],
646 *uhist_[uindex-1], *uhist_[uindex],
681 cnorm = std::max(cnorm,
cprimal_->norm());
697 Real err(0), err2(0), serr(0), cdot(0), dt(0);
698 Real tol0 = std::min(
maxTol_,tol);
701 err =
static_cast<Real
>(0);
706 throwError(eflag,
"reconstruct",
"updateSketch",592);
716 err = std::sqrt(err2);
717 if (err > tol0)
break;
722 *
stream_ <<
" *** Required Tolerance: " << tol0 << std::endl;
723 *
stream_ <<
" *** Residual Norm: " << err << std::endl;
745 *
stream_ <<
" *** Maximum Solver Error: " << serr << std::endl;
761 obj_->gradient_un(*
udual_, uold, unew, z, ts);
762 con_->applyInverseAdjointJacobian_un(l, *
udual_, uold, unew, z, ts);
769 obj_->gradient_uo(rhs, uold, unew, z, ts);
770 con_->applyAdjointJacobian_uo(*
udual_, l, uold, unew, z, ts);
777 obj_->gradient_un(*
udual_, uold, unew, z, ts);
779 con_->applyInverseAdjointJacobian_un(l, rhs, uold, unew, z, ts);
795 throwError(eflag,
"reconstruct",
"solveAdjoint",672);
806 throwError(eflag,
"advance",
"solveAdjoint",683);
822 throwError(eflag,
"reconstruct",
"solveAdjoint",699);
836 throwError(eflag,
"advance",
"solveAdjoint",713);
850 obj_->gradient_z(g, uold, unew, z, ts);
851 con_->applyAdjointJacobian_z(*
zdual_, l, uold, unew, z, ts);
863 con_->applyJacobian_z(*
crhs_, v, uold, unew, z, ts);
864 con_->applyJacobian_uo(*
cprimal_, wold, uold, unew, z, ts);
866 con_->applyInverseJacobian_un(wnew, *
crhs_, uold, unew, z, ts);
879 con_->applyAdjointHessian_z_un(*
rhs_, l, v, uold, unew, z, ts);
880 obj_->hessVec_un_z(*
udual_, v, uold, unew, z, ts);
883 con_->applyAdjointHessian_un_un(*
udual_, l, wnew, uold, unew, z, ts);
885 obj_->hessVec_un_un(*
udual_, wnew, uold, unew, z, ts);
887 con_->applyAdjointHessian_uo_un(*
udual_, l, wold, uold, unew, z, ts);
889 obj_->hessVec_un_uo(*
udual_, wold, uold, unew, z, ts);
892 con_->applyInverseAdjointJacobian_un(p, *
rhs_, uold, unew, z, ts);
899 const bool sumInto =
false) {
903 obj_->hessVec_un_uo(Hv, wold, uold, unew, z, ts);
906 obj_->hessVec_un_uo(*
udual_, wold, uold, unew, z, ts);
909 con_->applyAdjointHessian_uo_un(*
udual_, l, wold, uold, unew, z, ts);
912 obj_->hessVec_un_un(*
udual_, wnew, uold, unew, z, ts);
914 con_->applyAdjointHessian_un_un(*
udual_, l, wnew, uold, unew, z, ts);
922 const bool sumInto =
false) {
926 con_->applyAdjointHessian_z_un(Hv, l, v, uold, unew, z, ts);
929 con_->applyAdjointHessian_z_un(*
udual_, l, v, uold, unew, z, ts);
932 obj_->hessVec_un_z(*
udual_, v, uold, unew, z, ts);
939 const bool sumInto =
false) {
942 con_->applyAdjointJacobian_uo(Hv, p, uold, unew, z, ts);
946 con_->applyAdjointJacobian_uo(*
udual_, p, uold, unew, z, ts);
955 const bool sumInto =
false) {
959 obj_->hessVec_uo_un(Hv, wnew, uold, unew, z, ts);
962 obj_->hessVec_uo_un(*
udual_, wnew, uold, unew, z, ts);
965 con_->applyAdjointHessian_un_uo(*
udual_, l, wnew, uold, unew, z, ts);
968 obj_->hessVec_uo_uo(*
udual_, wold, uold, unew, z, ts);
970 con_->applyAdjointHessian_uo_uo(*
udual_, l, wold, uold, unew, z, ts);
978 const bool sumInto =
false) {
982 con_->applyAdjointHessian_z_uo(Hv, l, v, uold, unew, z, ts);
985 con_->applyAdjointHessian_z_uo(*
udual_, l, v, uold, unew, z, ts);
988 obj_->hessVec_uo_z(*
udual_, v, uold, unew, z, ts);
996 con_->applyInverseAdjointJacobian_un(p, rhs, uold, unew, z, ts);
1008 obj_->hessVec_z_z(Hv, v, uold, unew, z, ts);
1009 con_->applyAdjointHessian_z_z(*
zdual_, l, v, uold, unew, z, ts);
1019 obj_->hessVec_z_uo(*
zdual_, wold, uold, unew, z, ts);
1021 con_->applyAdjointHessian_uo_z(*
zdual_, l, wold, uold, unew, z, ts);
1024 obj_->hessVec_z_un(*
zdual_, wnew, uold, unew, z, ts);
1026 con_->applyAdjointHessian_un_z(*
zdual_, l, wnew, uold, unew, z, ts);
1033 con_->applyAdjointJacobian_z(*
zdual_, p, uold, unew, z, ts);
1040 #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_