11 #ifndef ROL_DYNAMICOBJECTIVECHECK_HPP
12 #define ROL_DYNAMICOBJECTIVECHECK_HPP
15 #include "ROL_ValidateFunction.hpp"
23 template<
typename Real>
27 ValidateFunction<Real>& validator,
31 const std::vector<std::string>& methods ) {
34 check( obj_check, validator, uo, un, z, methods );
38 ValidateFunction<Real>& validator,
43 const std::vector<std::string>& methods ) {
46 check( obj_check, validator, uo, un, z, methods );
49 static void check( DynamicObjective_CheckInterface<Real>& obj_check,
50 ValidateFunction<Real>& validator,
54 const std::vector<std::string>& methods ) {
56 auto gu = uo.
dual().clone();
57 auto gz = z.
dual().clone();
67 if( std::find(methods.begin(),methods.end(),
"gradient_uo") != methods.end() ) {
68 auto value = obj_check.value_uo( un, z );
69 auto grad = obj_check.gradient_uo( un, z );
70 auto update = obj_check.update_uo( un, z );
71 validator.derivative_check(
value, grad,
update, *gu, *vu, uo,
"grad_uo'*dir" );
73 if( std::find(methods.begin(),methods.end(),
"gradient_un") != methods.end() ) {
74 auto value = obj_check.value_un( uo, z );
75 auto grad = obj_check.gradient_un( uo, z );
76 auto update = obj_check.update_un( uo, z );
77 validator.derivative_check(
value, grad,
update, *gu, *vu, un,
"grad_un'*dir" );
79 if( std::find(methods.begin(),methods.end(),
"gradient_z") != methods.end() ) {
80 auto value = obj_check.value_z( uo, un );
81 auto grad = obj_check.gradient_z( uo, un );
82 auto update = obj_check.update_z( uo, un );
83 validator.derivative_check(
value, grad,
update, *gz, *vz, z,
"grad_z'*dir" );
88 if( std::find(methods.begin(),methods.end(),
"hessVec_uo_uo") != methods.end() ) {
89 auto grad = obj_check.gradient_uo_uo( un, z );
90 auto hessVec = obj_check.hessVec_uo_uo( un, z );
91 auto update = obj_check.update_uo( un, z );
92 validator.derivative_check( grad, hessVec,
update, *gu, *vu, uo,
"norm(H_uo_uo*vec)" );
95 if( std::find(methods.begin(),methods.end(),
"hessVec_uo_un") != methods.end() ) {
96 auto grad = obj_check.gradient_uo_un( uo, z );
97 auto hessVec = obj_check.hessVec_uo_un( uo, z );
98 auto update = obj_check.update_un( uo, z );
99 validator.derivative_check( grad, hessVec,
update, *gu, *vu, un,
"norm(H_uo_un*vec)" );
102 if( std::find(methods.begin(),methods.end(),
"hessVec_uo_z") != methods.end() ) {
103 auto grad = obj_check.gradient_uo_z( uo, un );
104 auto hessVec = obj_check.hessVec_uo_z( uo, un );
105 auto update = obj_check.update_z( uo, un );
106 validator.derivative_check( grad, hessVec,
update, *gu, *vz, z,
"norm(H_uo_z*vec)" );
111 if( std::find(methods.begin(),methods.end(),
"hessVec_un_uo") != methods.end() ) {
112 auto grad = obj_check.gradient_un_uo( un, z );
113 auto hessVec = obj_check.hessVec_un_uo( un, z );
114 auto update = obj_check.update_uo( un, z );
115 validator.derivative_check( grad, hessVec,
update, *gu, *vu, uo,
"norm(H_un_uo*vec)" );
118 if( std::find(methods.begin(),methods.end(),
"hessVec_un_un") != methods.end() ) {
119 auto grad = obj_check.gradient_un_un( uo, z );
120 auto hessVec = obj_check.hessVec_un_un( uo, z );
121 auto update = obj_check.update_un( uo, z );
122 validator.derivative_check( grad, hessVec,
update, *gu, *vu, un,
"norm(H_un_un*vec)" );
125 if( std::find(methods.begin(),methods.end(),
"hessVec_un_z") != methods.end() ) {
126 auto grad = obj_check.gradient_un_z( uo, un );
127 auto hessVec = obj_check.hessVec_un_z( uo, un );
128 auto update = obj_check.update_z( uo, un );
129 validator.derivative_check( grad, hessVec,
update, *gu, *vz, z,
"norm(H_un_z*vec)" );
134 if( std::find(methods.begin(),methods.end(),
"hessVec_z_uo") != methods.end() ) {
135 auto grad = obj_check.gradient_z_uo( un, z );
136 auto hessVec = obj_check.hessVec_z_uo( un, z );
137 auto update = obj_check.update_uo( un, z );
138 validator.derivative_check( grad, hessVec,
update, *gz, *vu, uo,
"norm(H_z_uo*vec)" );
141 if( std::find(methods.begin(),methods.end(),
"hessVec_z_un") != methods.end() ) {
142 auto grad = obj_check.gradient_z_un( uo, z );
143 auto hessVec = obj_check.hessVec_z_un( uo, z );
144 auto update = obj_check.update_un( uo, z );
145 validator.derivative_check( grad, hessVec,
update, *gz, *vu, un,
"norm(H_z_un*vec)" );
148 if( std::find(methods.begin(),methods.end(),
"hessVec_z_z") != methods.end() ) {
149 auto grad = obj_check.gradient_z_z( uo, un );
150 auto hessVec = obj_check.hessVec_z_z( uo, un );
151 auto update = obj_check.update_z( uo, un );
152 auto H = obj_check.hessVec_z_z(uo,un);
153 validator.derivative_check( grad, hessVec,
update, *gz, *vz, z,
"norm(H_z_z*vec)" );
158 ValidateFunction<Real>& validator,
162 std::vector<std::string> methods = {
"gradient_uo",
174 check(obj, validator, uo, un, z, methods);
178 ValidateFunction<Real>& validator,
183 std::vector<std::string> methods = {
"gradient_uo",
195 check(obj, validator, uo, un, z, ts, methods);
201 #endif // ROL_DYNAMICOBJECTIVECHECK_HPP
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
static void check(DynamicObjective< Real > &obj, ValidateFunction< Real > &validator, const Vector< Real > &uo, const Vector< Real > &un, const Vector< Real > &z, const std::vector< std::string > &methods)
static void check(DynamicObjective< Real > &obj, ValidateFunction< Real > &validator, const Vector< Real > &uo, const Vector< Real > &un, const Vector< Real > &z, TimeStamp< Real > &ts)
virtual void update(const Vector< Real > &u, const Vector< Real > &z, bool flag=true, int iter=-1) override
static void check(DynamicObjective< Real > &obj, ValidateFunction< Real > &validator, const Vector< Real > &uo, const Vector< Real > &un, const Vector< Real > &z)
ROL::Objective_SimOpt value
static void check(DynamicObjective< Real > &obj, ValidateFunction< Real > &validator, const Vector< Real > &uo, const Vector< Real > &un, const Vector< Real > &z, TimeStamp< Real > &timeStamp, const std::vector< std::string > &methods)
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.
static void check(DynamicObjective_CheckInterface< Real > &obj_check, ValidateFunction< Real > &validator, const Vector< Real > &uo, const Vector< Real > &un, const Vector< Real > &z, const std::vector< std::string > &methods)
DynamicConstraint_CheckInterface< Real > make_check(DynamicConstraint< Real > &con)