44#ifndef ROL_REDUCEDDYNAMICOBJECTIVE_HPP
45#define ROL_REDUCEDDYNAMICOBJECTIVE_HPP
79template<
typename Real>
81 using size_type =
typename std::vector<Real>::size_type;
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() ),
173 useSketch_ ( pl.get(
"Use Sketching", false) ),
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) ) {
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);
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);
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());
279 val_ =
static_cast<Real
>(0);
285 std::stringstream name;
286 name <<
"optvector." << iter <<
".txt";
288 file.open(name.str());
349 *
stream_ << std::string(80,
'=') << std::endl;
350 *
stream_ <<
" ROL::ReducedDynamicObjective::gradient" << std::endl;
355 *
stream_ <<
" Residual Norm: " << tol << std::endl;
356 *
stream_ << std::string(80,
'=') << std::endl;
363 throwError(eflag,
"reconstruct",
"gradient",309);
366 throwError(eflag,
"reconstruct",
"gradient",312);
404 throwError(eflag,
"reconstruct",
"gradient",350);
408 throwError(eflag,
"reconstruct",
"gradient",354);
458 throwError(eflag,
"reconstruct",
"hessVec",404);
460 throwError(eflag,
"reconstruct",
"hessVec",406);
498 throwError(eflag,
"reconstruct",
"hessVec",444);
501 throwError(eflag,
"reconstruct",
"hessVec",447);
505 throwError(eflag,
"reconstruct",
"hessVec",451);
554 throwError(eflag,
"reconstruct",
"hessVec",500);
556 throwError(eflag,
"reconstruct",
"hessVec",502);
559 throwError(eflag,
"reconstruct",
"hessVec",505);
626 cnorm = std::max(cnorm,
cprimal_->norm());
642 Real err(0), serr(0), cnorm(0);
645 err =
static_cast<Real
>(0);
649 throwError(eflag,
"reconstruct",
"updateSketch",592);
654 err = (cnorm > err ? cnorm : err);
668 *
stream_ <<
" *** Required Tolerance: " << tol << std::endl;
669 *
stream_ <<
" *** Residual Norm: " << err << std::endl;
688 *
stream_ <<
" *** Maximum Solver Error: " << serr << std::endl;
705 obj_->gradient_un(*
udual_, uold, unew, z, ts);
706 con_->applyInverseAdjointJacobian_un(l, *
udual_, uold, unew, z, ts);
713 obj_->gradient_uo(rhs, uold, unew, z, ts);
714 con_->applyAdjointJacobian_uo(*
udual_, l, uold, unew, z, ts);
721 obj_->gradient_un(*
udual_, uold, unew, z, ts);
723 con_->applyInverseAdjointJacobian_un(l, rhs, uold, unew, z, ts);
739 throwError(eflag,
"reconstruct",
"solveAdjoint",672);
750 throwError(eflag,
"advance",
"solveAdjoint",683);
766 throwError(eflag,
"reconstruct",
"solveAdjoint",699);
780 throwError(eflag,
"advance",
"solveAdjoint",713);
794 obj_->gradient_z(g, uold, unew, z, ts);
795 con_->applyAdjointJacobian_z(*
zdual_, l, uold, unew, z, ts);
807 con_->applyJacobian_z(*
crhs_, v, uold, unew, z, ts);
808 con_->applyJacobian_uo(*
cprimal_, wold, uold, unew, z, ts);
810 con_->applyInverseJacobian_un(wnew, *
crhs_, uold, unew, z, ts);
823 con_->applyAdjointHessian_z_un(*
rhs_, l, v, uold, unew, z, ts);
824 obj_->hessVec_un_z(*
udual_, v, uold, unew, z, ts);
827 con_->applyAdjointHessian_un_un(*
udual_, l, wnew, uold, unew, z, ts);
829 obj_->hessVec_un_un(*
udual_, wnew, uold, unew, z, ts);
831 con_->applyAdjointHessian_uo_un(*
udual_, l, wold, uold, unew, z, ts);
833 obj_->hessVec_un_uo(*
udual_, wold, uold, unew, z, ts);
836 con_->applyInverseAdjointJacobian_un(p, *
rhs_, uold, unew, z, ts);
843 const bool sumInto =
false) {
847 obj_->hessVec_un_uo(Hv, wold, uold, unew, z, ts);
850 obj_->hessVec_un_uo(*
udual_, wold, uold, unew, z, ts);
853 con_->applyAdjointHessian_uo_un(*
udual_, l, wold, uold, unew, z, ts);
856 obj_->hessVec_un_un(*
udual_, wnew, uold, unew, z, ts);
858 con_->applyAdjointHessian_un_un(*
udual_, l, wnew, uold, unew, z, ts);
866 const bool sumInto =
false) {
870 con_->applyAdjointHessian_z_un(Hv, l, v, uold, unew, z, ts);
873 con_->applyAdjointHessian_z_un(*
udual_, l, v, uold, unew, z, ts);
876 obj_->hessVec_un_z(*
udual_, v, uold, unew, z, ts);
883 const bool sumInto =
false) {
886 con_->applyAdjointJacobian_uo(Hv, p, uold, unew, z, ts);
890 con_->applyAdjointJacobian_uo(*
udual_, p, uold, unew, z, ts);
899 const bool sumInto =
false) {
903 obj_->hessVec_uo_un(Hv, wnew, uold, unew, z, ts);
906 obj_->hessVec_uo_un(*
udual_, wnew, uold, unew, z, ts);
909 con_->applyAdjointHessian_un_uo(*
udual_, l, wnew, uold, unew, z, ts);
912 obj_->hessVec_uo_uo(*
udual_, wold, uold, unew, z, ts);
914 con_->applyAdjointHessian_uo_uo(*
udual_, l, wold, uold, unew, z, ts);
922 const bool sumInto =
false) {
926 con_->applyAdjointHessian_z_uo(Hv, l, v, uold, unew, z, ts);
929 con_->applyAdjointHessian_z_uo(*
udual_, l, v, uold, unew, z, ts);
932 obj_->hessVec_uo_z(*
udual_, v, uold, unew, z, ts);
940 con_->applyInverseAdjointJacobian_un(p, rhs, uold, unew, z, ts);
952 obj_->hessVec_z_z(Hv, v, uold, unew, z, ts);
953 con_->applyAdjointHessian_z_z(*
zdual_, l, v, uold, unew, z, ts);
963 obj_->hessVec_z_uo(*
zdual_, wold, uold, unew, z, ts);
965 con_->applyAdjointHessian_uo_z(*
zdual_, l, wold, uold, unew, z, ts);
968 obj_->hessVec_z_un(*
zdual_, wnew, uold, unew, z, ts);
970 con_->applyAdjointHessian_un_z(*
zdual_, l, wnew, uold, unew, z, ts);
977 con_->applyAdjointJacobian_z(*
zdual_, p, uold, unew, z, ts);
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0 zero)()
Defines the time-dependent constraint operator interface for simulation-based optimization.
Defines the time-dependent objective function interface for simulation-based optimization....
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Defines the linear algebra of vector space on a generic partitioned vector.
ROL::Ptr< const Vector< Real > > get(size_type i) const
static Ptr< PartitionedVector > create(std::initializer_list< Vp > vs)
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Real updateSketch(const Vector< Real > &x, const Real tol)
Ptr< std::ostream > stream_
Ptr< Vector< Real > > zdual_
const PartitionedVector< Real > & partition(const Vector< Real > &x) const
Ptr< Vector< Real > > makeDynamicVector(const Vector< Real > &x) const
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 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 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)
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)
Ptr< Vector< Real > > cprimal_
const Ptr< Vector< Real > > u0_
typename std::vector< Real >::size_type size_type
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)
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)
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)
std::vector< Ptr< Vector< Real > > > uhist_
Ptr< Sketch< Real > > adjointSketch_
std::vector< Ptr< Vector< Real > > > phist_
Real solveState(const Vector< Real > &x)
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 > > stateSketch_
void setTerminalCondition(Vector< Real > &l, const Vector< Real > &uold, const Vector< Real > &unew, const Vector< Real > &z, const TimeStamp< Real > &ts)
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
std::vector< Ptr< Vector< Real > > > whist_
void update(const Vector< Real > &x, UpdateType type, int iter=-1)
const std::vector< TimeStamp< Real > > timeStamp_
void solveAdjoint(const Vector< Real > &x)
void update(const Vector< Real > &x, bool flag=true, int iter=-1)
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)
const size_type updateFactor_
Real value(const Vector< Real > &x, Real &tol)
void advanceAdjointSens(Vector< Real > &p, Vector< Real > &rhs, const Vector< Real > &uold, const Vector< Real > &unew, const Vector< Real > &z, const TimeStamp< Real > &ts)
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 Ptr< DynamicConstraint< Real > > con_
Ptr< Vector< Real > > udual_
std::vector< Ptr< Vector< Real > > > lhist_
void advanceAdjoint(Vector< Real > &l, Vector< Real > &rhs, const Vector< Real > &uold, const Vector< Real > &unew, const Vector< Real > &z, const TimeStamp< Real > &ts)
PartitionedVector< Real > & partition(Vector< Real > &x) const
const Ptr< DynamicObjective< Real > > obj_
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)
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 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 throwError(const int err, const std::string &sfunc, const std::string &func, const int line) const
Ptr< Sketch< Real > > stateSensSketch_
Ptr< Vector< Real > > crhs_
Ptr< Vector< Real > > rhs_
Defines the linear algebra or vector space interface.
virtual void scale(const Real alpha)=0
Compute where .
virtual void print(std::ostream &outStream) const
virtual void plus(const Vector &x)=0
Compute , where .
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Real ROL_EPSILON(void)
Platform-dependent machine epsilon.
Contains local time step information.