10 #ifndef ROL_COMPOSITECONSTRAINT_SIMOPT_DEF_H
11 #define ROL_COMPOSITECONSTRAINT_SIMOPT_DEF_H
15 template<
typename Real>
25 bool isConRedParametrized)
27 updateFlag_(true), newUpdate_(false), updateIter_(0), updateType_(
UpdateType::
Initial),
28 storage_(storage), isConRedParametrized_(isConRedParametrized) {
36 stateStore_ = ROL::makePtr<VectorController<Real>>();
39 template<
typename Real>
42 bool flag,
int iter) {
43 update_1(u,flag,iter);
47 template<
typename Real>
49 bool flag,
int iter) {
51 conVal_->update_1(u, flag, iter);
54 template<
typename Real>
56 bool flag,
int iter) {
57 conRed_->update_2(z,flag,iter);
60 stateStore_->constraintUpdate(
true);
63 template<
typename Real>
67 update_1(u,type,iter);
71 template<
typename Real>
75 conVal_->update_1(u,type,iter);
78 template<
typename Real>
81 conRed_->update_2(z,type,iter);
84 stateStore_->constraintUpdate(type);
87 template<
typename Real>
91 Real ctol(std::sqrt(ROL_EPSILON<Real>()));
92 solveConRed(*Sz_, z, ctol);
93 conVal_->solve_update(u,*Sz_,type,iter);
96 template<
typename Real>
101 solveConRed(*Sz_, z, tol);
102 conVal_->value(c, u, *Sz_, tol);
105 template<
typename Real>
110 solveConRed(*Sz_, z, tol);
111 conVal_->solve(c, u, *Sz_, tol);
114 template<
typename Real>
120 solveConRed(*Sz_, z, tol);
121 conVal_->applyJacobian_1(jv, v, u, *Sz_, tol);
124 template<
typename Real>
130 solveConRed(*Sz_, z, tol);
131 applySens(*primZ_, v, *Sz_, z, tol);
132 conVal_->applyJacobian_2(jv, *primZ_, u, *Sz_, tol);
135 template<
typename Real>
141 solveConRed(*Sz_, z, tol);
142 conVal_->applyInverseJacobian_1(ijv, v, u, *Sz_, tol);
145 template<
typename Real>
151 solveConRed(*Sz_, z, tol);
152 conVal_->applyAdjointJacobian_1(ajv, v, u, *Sz_, tol);
155 template<
typename Real>
161 solveConRed(*Sz_, z, tol);
162 conVal_->applyAdjointJacobian_2(*dualZ_, v, u, *Sz_, tol);
163 applyAdjointSens(ajv, *dualZ_, *Sz_, z, tol);
166 template<
typename Real>
172 solveConRed(*Sz_, z, tol);
173 conVal_->applyInverseAdjointJacobian_1(ijv, v, u, *Sz_, tol);
176 template<
typename Real>
183 solveConRed(*Sz_, z, tol);
184 conVal_->applyAdjointHessian_11(ahwv, w, v, u, *Sz_, tol);
187 template<
typename Real>
194 solveConRed(*Sz_, z, tol);
195 conVal_->applyAdjointHessian_12(*dualZ_, w, v, u, *Sz_, tol);
196 applyAdjointSens(ahwv, *dualZ_, *Sz_, z, tol);
199 template<
typename Real>
206 solveConRed(*Sz_, z, tol);
207 applySens(*primZ_, v, *Sz_, z, tol);
208 conVal_->applyAdjointHessian_21(ahwv, w, *primZ_, u, *Sz_, tol);
211 template<
typename Real>
219 solveConRed(*Sz_, z, tol);
220 applySens(*primZ_, v, *Sz_, z, tol);
222 conVal_->applyAdjointJacobian_2(*dualZ_, w, u, *Sz_, tol);
223 conRed_->applyInverseAdjointJacobian_1(*dualRed_, *dualZ_, *Sz_, z, tol);
224 conRed_->applyAdjointHessian_22(*dualZ_, *dualRed_, v, *Sz_, z, tol);
225 ahwv.
axpy(static_cast<Real>(-1), *dualZ_);
226 conRed_->applyAdjointHessian_12(*dualZ_, *dualRed_, *primZ_, *Sz_, z, tol);
227 ahwv.
axpy(static_cast<Real>(-1), *dualZ_);
229 conRed_->applyAdjointHessian_11(*dualZ1_, *dualRed_, *primZ_, *Sz_, z, tol);
230 conRed_->applyAdjointHessian_21(*dualZ_, *dualRed_, v, *Sz_, z, tol);
231 dualZ1_->plus(*dualZ_);
232 dualZ1_->scale(static_cast<Real>(-1));
234 conVal_->applyAdjointHessian_22(*dualZ_, w, *primZ_, u, *Sz_, tol);
235 dualZ1_->plus(*dualZ_);
237 applyAdjointSens(*dualZ_, *dualZ1_, *Sz_, z, tol);
241 template<
typename Real>
243 conVal_->setParameter(param);
244 if (isConRedParametrized_) {
245 conRed_->setParameter(param);
250 template<
typename Real>
256 bool isComputed =
false;
257 if (storage_) isComputed = stateStore_->get(Sz,param);
259 if (!isComputed || !storage_) {
261 conRed_->solve(*primRed_,Sz,z,tol);
263 if (newUpdate_) conRed_->update_1(Sz,updateType_,updateIter_);
264 else conRed_->update_1(Sz,updateFlag_,updateIter_);
266 if (newUpdate_) conRed_->update(Sz,z,updateType_,updateIter_);
267 else conRed_->update(Sz,z,updateFlag_,updateIter_);
268 if (newUpdate_) conVal_->update(*primU_,Sz,updateType_,updateIter_);
269 else conVal_->update(*primU_,Sz,updateFlag_,updateIter_);
271 if (storage_) stateStore_->set(Sz,param);
275 template<
typename Real>
282 conRed_->applyJacobian_2(*primRed_, v, Sz, z, tol);
283 conRed_->applyInverseJacobian_1(jv, *primRed_, Sz, z, tol);
284 jv.
scale(static_cast<Real>(-1));
287 template<
typename Real>
294 conRed_->applyInverseAdjointJacobian_1(*dualRed_, v, Sz, z, tol);
295 conRed_->applyAdjointJacobian_2(ajv, *dualRed_, Sz, z, tol);
296 ajv.
scale(static_cast<Real>(-1));
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...
void solve_update(const Vector< Real > &u, const Vector< Real > &z, UpdateType type, int iter=-1) override
Update SimOpt constraint during solve (disconnected from optimization updates).
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
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...
virtual void scale(const Real alpha)=0
Compute where .
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual void plus(const Vector &x)=0
Compute , where .
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
void solveConRed(Vector< Real > &Sz, const Vector< Real > &z, Real &tol)
void update_2(const Vector< Real > &z, bool flag=true, int iter=-1) override
Update constraint functions with respect to Opt variable. x is the optimization variable, flag = true if optimization variable is changed, iter is the outer algorithm iterations count.
const std::vector< Real > getParameter(void) const
ROL::Ptr< Vector< Real > > primRed_
void value(Vector< Real > &c, const Vector< Real > &u, const Vector< Real > &z, Real &tol) override
Evaluate the constraint operator at .
ROL::Ptr< Vector< Real > > Sz_
CompositeConstraint_SimOpt(const ROL::Ptr< Constraint_SimOpt< Real >> &conVal, const ROL::Ptr< Constraint_SimOpt< Real >> &conRed, const Vector< Real > &cVal, const Vector< Real > &cRed, const Vector< Real > &u, const Vector< Real > &Sz, const Vector< Real > &z, bool storage=true, bool isConRedParametrized=false)
virtual void zero()
Set to zero vector.
Defines the linear algebra or vector space interface.
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...
void applyInverseAdjointJacobian_1(Vector< Real > &ijv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol) override
Apply the inverse of the adjoint of the partial constraint Jacobian at , , to the vector ...
void setParameter(const std::vector< Real > ¶m) override
void applyInverseJacobian_1(Vector< Real > &ijv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol) override
Apply the inverse partial constraint Jacobian at , , to the vector .
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...
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 ...
void applyAdjointSens(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &Sz, const Vector< Real > &z, Real &tol)
ROL::Ptr< Vector< Real > > dualRed_
ROL::Ptr< Vector< Real > > primZ_
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 setParameter(const std::vector< Real > ¶m)
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 .
ROL::Ptr< Vector< Real > > dualZ_
void applySens(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &Sz, const Vector< Real > &z, Real &tol)
ROL::Ptr< Vector< Real > > dualZ1_
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.
void solve(Vector< Real > &c, Vector< Real > &u, const Vector< Real > &z, Real &tol) override
Given , solve for .
void update_1(const Vector< Real > &u, bool flag=true, int iter=-1) override
Update constraint functions with respect to Sim variable. x is the optimization variable, flag = true if optimization variable is changed, iter is the outer algorithm iterations count.
ROL::Ptr< Vector< Real > > primU_
Defines the constraint operator interface for simulation-based optimization.
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 .
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 ...
ROL::Ptr< VectorController< Real > > stateStore_