53 #include "Teuchos_oblackholestream.hpp" 54 #include "Teuchos_GlobalMPISession.hpp" 55 #include "Teuchos_XMLParameterListHelpers.hpp" 70 int main(
int argc,
char *argv[]) {
72 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
74 int iprint = argc - 1;
75 Teuchos::RCP<std::ostream> outStream;
76 Teuchos::oblackholestream bhs;
78 outStream = Teuchos::rcp(&std::cout,
false);
80 outStream = Teuchos::rcp(&bhs,
false);
98 Teuchos::RCP<BurgersFEM<RealT> > fem
100 fem->test_inverse_mass(*outStream);
101 fem->test_inverse_H1(*outStream);
105 Teuchos::RCP<std::vector<RealT> > ud_rcp
106 = Teuchos::rcp(
new std::vector<RealT> (nx, 1.) );
107 Teuchos::RCP<ROL::Vector<RealT> > ud
113 bool useEChessian =
true;
119 std::vector<RealT> Ulo(nx, 0.), Uhi(nx, 1.);
121 Teuchos::RCP<ROL::BoundConstraint<RealT> > Ubnd
126 std::vector<RealT> Zlo(nx+2,0.), Zhi(nx+2,2.);
127 Teuchos::RCP<ROL::BoundConstraint<RealT> > Zbnd
137 Teuchos::RCP<std::vector<RealT> > z_rcp
138 = Teuchos::rcp(
new std::vector<RealT> (nx+2, 0.) );
139 Teuchos::RCP<std::vector<RealT> > zrand_rcp
140 = Teuchos::rcp(
new std::vector<RealT> (nx+2, 1.) );
141 Teuchos::RCP<std::vector<RealT> > gz_rcp
142 = Teuchos::rcp(
new std::vector<RealT> (nx+2, 1.) );
143 Teuchos::RCP<std::vector<RealT> > yz_rcp
144 = Teuchos::rcp(
new std::vector<RealT> (nx+2, 1.) );
145 for (
int i=0; i<nx+2; i++) {
146 (*zrand_rcp)[i] = 10.*(
RealT)rand()/(
RealT)RAND_MAX-5.;
147 (*yz_rcp)[i] = 10.*(
RealT)rand()/(
RealT)RAND_MAX-5.;
149 Teuchos::RCP<ROL::Vector<RealT> > zp
151 Teuchos::RCP<ROL::Vector<RealT> > zrandp
153 Teuchos::RCP<ROL::Vector<RealT> > gzp
155 Teuchos::RCP<ROL::Vector<RealT> > yzp
158 Teuchos::RCP<std::vector<RealT> > u_rcp
159 = Teuchos::rcp(
new std::vector<RealT> (nx, 1.) );
160 Teuchos::RCP<std::vector<RealT> > gu_rcp
161 = Teuchos::rcp(
new std::vector<RealT> (nx, 1.) );
162 Teuchos::RCP<std::vector<RealT> > yu_rcp
163 = Teuchos::rcp(
new std::vector<RealT> (nx, 1.) );
164 for (
int i=0; i<nx; i++) {
165 (*yu_rcp)[i] = 10.*(
RealT)rand()/(
RealT)RAND_MAX-5.;
167 Teuchos::RCP<ROL::Vector<RealT> > up
169 Teuchos::RCP<ROL::Vector<RealT> > gup
171 Teuchos::RCP<ROL::Vector<RealT> > yup
174 Teuchos::RCP<std::vector<RealT> > c_rcp
175 = Teuchos::rcp(
new std::vector<RealT> (nx, 1.) );
176 Teuchos::RCP<std::vector<RealT> > l_rcp
177 = Teuchos::rcp(
new std::vector<RealT> (nx, 1.) );
178 for (
int i=0; i<nx; i++) {
188 std::string filename =
"input.xml";
189 Teuchos::RCP<Teuchos::ParameterList> parlist
190 = Teuchos::rcp(
new Teuchos::ParameterList() );
191 Teuchos::updateParametersFromXmlFile( filename, parlist.ptr() );
223 con.
solve(c,*up,*zp,zerotol);
227 gup->zero(); c.
zero();
228 algoMY.
run(x, g, l, c, obj, con, bnd,
true, *outStream);
229 Teuchos::RCP<ROL::Vector<RealT> > xMY = x.
clone();
234 con.
solve(c,*up,*zp,zerotol);
238 gup->zero(); c.
zero();
239 algoAL.
run(x, g, l, c, obj, con, bnd,
true, *outStream);
241 Teuchos::RCP<ROL::Vector<RealT> > err = x.
clone();
242 err->set(x); err->axpy(-1.,*xMY);
243 errorFlag += ((err->norm() > 1.e-7*x.
norm()) ? 1 : 0);
245 catch (std::logic_error err) {
246 *outStream << err.what() <<
"\n";
251 std::cout <<
"End Result: TEST FAILED\n";
253 std::cout <<
"End Result: TEST PASSED\n";
virtual Real checkInverseJacobian_1(const Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, const bool printToStream=true, std::ostream &outStream=std::cout)
Provides the interface to evaluate the augmented Lagrangian.
H1VectorDual< RealT > PrimalConstraintVector
Defines the linear algebra or vector space interface for simulation-based optimization.
void solve(ROL::Vector< Real > &c, ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Given , solve for .
Real norm() const
Returns where .
virtual void zero()
Set to zero vector.
int main(int argc, char *argv[])
H1VectorPrimal< RealT > DualConstraintVector
virtual std::vector< std::vector< Real > > checkGradient(const Vector< Real > &x, const Vector< Real > &d, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Finite-difference gradient check.
L2VectorDual< RealT > DualControlVector
virtual std::vector< std::vector< Real > > checkApplyJacobian(const Vector< Real > &x, const Vector< Real > &v, const Vector< Real > &jv, const std::vector< Real > &steps, const bool printToStream=true, std::ostream &outStream=std::cout, const int order=1)
Finite-difference check for the constraint Jacobian application.
void gradient_1(ROL::Vector< Real > &g, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Compute gradient with respect to first component.
void applyInverseAdjointJacobian_1(ROL::Vector< Real > &iajv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Apply the inverse of the adjoint of the partial constraint Jacobian at , , to the vector ...
virtual Real checkSolve(const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, const ROL::Vector< Real > &c, const bool printToStream=true, std::ostream &outStream=std::cout)
Provides an interface to run optimization algorithms.
Provides the interface to evaluate the Moreau-Yosida penalty function.
H1VectorDual< RealT > DualStateVector
L2VectorPrimal< RealT > PrimalControlVector
Teuchos::RCP< Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
H1VectorPrimal< RealT > PrimalStateVector
Provides definitions of equality constraint and objective for example_04.
virtual std::vector< std::vector< Real > > checkHessVec(const Vector< Real > &x, const Vector< Real > &v, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Finite-difference Hessian-applied-to-vector check.
virtual std::vector< std::string > run(Vector< Real > &x, Objective< Real > &obj, bool print=false, std::ostream &outStream=std::cout)
Run algorithm on unconstrained problems (Type-U). This is the primary Type-U interface.
virtual Real checkAdjointConsistencyJacobian_1(const Vector< Real > &w, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, const bool printToStream=true, std::ostream &outStream=std::cout)
Check the consistency of the Jacobian and its adjoint. This is the primary interface.
virtual Real checkInverseAdjointJacobian_1(const Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, const bool printToStream=true, std::ostream &outStream=std::cout)
virtual std::vector< std::vector< Real > > checkApplyAdjointHessian(const Vector< Real > &x, const Vector< Real > &u, const Vector< Real > &v, const Vector< Real > &hv, const std::vector< Real > &step, const bool printToScreen=true, std::ostream &outStream=std::cout, const int order=1)
Finite-difference check for the application of the adjoint of constraint Hessian. ...
void deactivate(void)
Turn off bounds.
virtual Real checkAdjointConsistencyJacobian_2(const Vector< Real > &w, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, const bool printToStream=true, std::ostream &outStream=std::cout)
Check the consistency of the Jacobian and its adjoint. This is the primary interface.
static const double ROL_EPSILON
Platform-dependent machine epsilon.