52 #include "ROL_ParameterList.hpp"
55 #include "Teuchos_GlobalMPISession.hpp"
70 int main(
int argc,
char *argv[]) {
72 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
74 int iprint = argc - 1;
75 ROL::Ptr<std::ostream> outStream;
78 outStream = ROL::makePtrFromRef(std::cout);
80 outStream = ROL::makePtrFromRef(bhs);
98 ROL::Ptr<BurgersFEM<RealT> > fem
99 = ROL::makePtr<BurgersFEM<RealT>>(nx,nu,nl,u0,u1,f,cH1,cL2);
100 fem->test_inverse_mass(*outStream);
101 fem->test_inverse_H1(*outStream);
105 ROL::Ptr<std::vector<RealT> > ud_ptr
106 = ROL::makePtr<std::vector<RealT>>(nx, 1.);
107 ROL::Ptr<ROL::Vector<RealT> > ud
108 = ROL::makePtr<L2VectorPrimal<RealT>>(ud_ptr,fem);
113 bool useEChessian =
true;
119 std::vector<RealT> Ulo(nx, 0.), Uhi(nx, 1.);
121 ROL::Ptr<ROL::BoundConstraint<RealT> > Ubnd
122 = ROL::makePtr<H1BoundConstraint<RealT>>(Ulo,Uhi,fem);
126 std::vector<RealT> Zlo(nx+2,0.), Zhi(nx+2,2.);
127 ROL::Ptr<ROL::BoundConstraint<RealT> > Zbnd
128 = ROL::makePtr<L2BoundConstraint<RealT>>(Zlo,Zhi,fem);
137 ROL::Ptr<std::vector<RealT> > z_ptr
138 = ROL::makePtr<std::vector<RealT>>(nx+2, 0.);
139 ROL::Ptr<std::vector<RealT> > zrand_ptr
140 = ROL::makePtr<std::vector<RealT>>(nx+2, 1.);
141 ROL::Ptr<std::vector<RealT> > gz_ptr
142 = ROL::makePtr<std::vector<RealT>>(nx+2, 1.);
143 ROL::Ptr<std::vector<RealT> > yz_ptr
144 = ROL::makePtr<std::vector<RealT>>(nx+2, 1.);
145 for (
int i=0; i<nx+2; i++) {
146 (*zrand_ptr)[i] = 10.*(
RealT)rand()/(
RealT)RAND_MAX-5.;
147 (*yz_ptr)[i] = 10.*(
RealT)rand()/(
RealT)RAND_MAX-5.;
149 ROL::Ptr<ROL::Vector<RealT> > zp
150 = ROL::makePtr<PrimalControlVector>(z_ptr,fem);
151 ROL::Ptr<ROL::Vector<RealT> > zrandp
152 = ROL::makePtr<PrimalControlVector>(zrand_ptr,fem);
153 ROL::Ptr<ROL::Vector<RealT> > gzp
154 = ROL::makePtr<DualControlVector>(gz_ptr,fem);
155 ROL::Ptr<ROL::Vector<RealT> > yzp
156 = ROL::makePtr<PrimalControlVector>(yz_ptr,fem);
158 ROL::Ptr<std::vector<RealT> > u_ptr
159 = ROL::makePtr<std::vector<RealT>>(nx, 1.);
160 ROL::Ptr<std::vector<RealT> > gu_ptr
161 = ROL::makePtr<std::vector<RealT>>(nx, 1.);
162 ROL::Ptr<std::vector<RealT> > yu_ptr
163 = ROL::makePtr<std::vector<RealT>>(nx, 1.);
164 for (
int i=0; i<nx; i++) {
165 (*yu_ptr)[i] = 10.*(
RealT)rand()/(
RealT)RAND_MAX-5.;
167 ROL::Ptr<ROL::Vector<RealT> > up
168 = ROL::makePtr<PrimalStateVector>(u_ptr,fem);
169 ROL::Ptr<ROL::Vector<RealT> > gup
170 = ROL::makePtr<DualStateVector>(gu_ptr,fem);
171 ROL::Ptr<ROL::Vector<RealT> > yup
172 = ROL::makePtr<PrimalStateVector>(yu_ptr,fem);
174 ROL::Ptr<std::vector<RealT> > c_ptr
175 = ROL::makePtr<std::vector<RealT>>(nx, 1.);
176 ROL::Ptr<std::vector<RealT> > l_ptr
177 = ROL::makePtr<std::vector<RealT>>(nx, 1.);
178 for (
int i=0; i<nx; i++) {
188 std::string filename =
"input.xml";
189 auto parlist = ROL::getParametersFromXmlFile( filename );
196 obj.checkGradient(x,g,y,
true,*outStream);
197 obj.checkHessVec(x,g,y,
true,*outStream);
209 ROL::Ptr<ROL::Objective<RealT> > obj_ptr = ROL::makePtrFromRef(obj);
210 ROL::Ptr<ROL::Constraint<RealT> > con_ptr = ROL::makePtrFromRef(con);
211 ROL::Ptr<ROL::BoundConstraint<RealT> > bnd_ptr = ROL::makePtrFromRef(bnd);
224 RealT zerotol = std::sqrt(ROL::ROL_EPSILON<RealT>());
225 con.
solve(c,*up,*zp,zerotol);
226 obj.gradient_1(*gup,*up,*zp,zerotol);
229 gup->zero(); c.
zero();
230 algoMY.
run(x, g, l, c, myPen, con, bnd,
true, *outStream);
231 ROL::Ptr<ROL::Vector<RealT> > xMY = x.
clone();
236 con.
solve(c,*up,*zp,zerotol);
237 obj.gradient_1(*gup,*up,*zp,zerotol);
240 gup->zero(); c.
zero();
241 algoAL.
run(x, g, l, c, myAugLag, con, bnd,
true, *outStream);
243 ROL::Ptr<ROL::Vector<RealT> > err = x.
clone();
244 err->set(x); err->axpy(-1.,*xMY);
245 errorFlag += ((err->norm() > 1.e-7*x.
norm()) ? 1 : 0);
247 catch (std::logic_error err) {
248 *outStream << err.what() <<
"\n";
253 std::cout <<
"End Result: TEST FAILED\n";
255 std::cout <<
"End Result: TEST PASSED\n";