16 #include "Teuchos_GlobalMPISession.hpp"
17 #include "Teuchos_Comm.hpp"
18 #include "Teuchos_DefaultComm.hpp"
19 #include "Teuchos_CommHelpers.hpp"
35 int main(
int argc,
char *argv[]) {
37 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
40 int iprint = argc - 1;
41 bool print = (iprint>0);
42 ROL::Ptr<std::ostream> outStream;
45 outStream = ROL::makePtrFromRef(std::cout);
47 outStream = ROL::makePtrFromRef(bhs);
61 ROL::Ptr<BurgersFEM<RealT> > fem
62 = ROL::makePtr<BurgersFEM<RealT>>(nx,nl,cH1,cL2);
63 fem->test_inverse_mass(*outStream);
64 fem->test_inverse_H1(*outStream);
69 ROL::Ptr<ROL::Constraint_SimOpt<RealT> > con
70 = ROL::makePtr<Constraint_BurgersControl<RealT>>(fem,hess);
75 ROL::Ptr<std::vector<RealT> > z_ptr
76 = ROL::makePtr<std::vector<RealT>>(nx+2, 0.0);
77 ROL::Ptr<ROL::Vector<RealT> > zp
78 = ROL::makePtr<PrimalControlVector>(z_ptr,fem);
80 ROL::Ptr<std::vector<RealT> > u_ptr
81 = ROL::makePtr<std::vector<RealT>>(nx, 1.0);
82 ROL::Ptr<ROL::Vector<RealT> > up
83 = ROL::makePtr<PrimalStateVector>(u_ptr,fem);
85 ROL::Ptr<std::vector<RealT> > c_ptr
86 = ROL::makePtr<std::vector<RealT>>(nx, 1.0);
87 ROL::Ptr<ROL::Vector<RealT> > cp
88 = ROL::makePtr<PrimalConstraintVector>(c_ptr,fem);
92 RealT rnorm(0), cnorm(0);
93 ROL::ParameterList list;
94 RealT tol = std::sqrt(ROL::ROL_EPSILON<RealT>());
95 list.sublist(
"SimOpt").sublist(
"Solve").set(
"Output Iteration History",print);
96 list.sublist(
"SimOpt").sublist(
"Solve").set(
"Step Tolerance",ROL::ROL_EPSILON<RealT>());
98 list.sublist(
"SimOpt").sublist(
"Solve").set(
"Absolute Residual Tolerance",tol);
99 list.sublist(
"SimOpt").sublist(
"Solve").set(
"Solver Type",0);
100 con->setSolveParameters(list);
101 u_ptr->assign(nx, 1.0);
102 con->solve(*cp,*up,*zp,tol);
104 con->value(*cp,*up,*zp,tol);
106 errorFlag += ((cnorm > tol) ? 1 : 0) + ((rnorm > tol) ? 1 : 0);
107 *outStream << std::scientific << std::setprecision(8);
108 *outStream << std::endl;
109 *outStream <<
"Test SimOpt solve at feasible (u,z):" << std::endl;
110 *outStream <<
" Solver Residual = " << rnorm << std::endl;
111 *outStream <<
" ||c(u,z)|| = " << cnorm;
112 *outStream << std::endl << std::endl;
114 list.sublist(
"SimOpt").sublist(
"Solve").set(
"Absolute Residual Tolerance",1e-4*tol);
115 list.sublist(
"SimOpt").sublist(
"Solve").set(
"Solver Type",1);
116 con->setSolveParameters(list);
117 u_ptr->assign(nx, 1.0);
118 con->solve(*cp,*up,*zp,tol);
120 con->value(*cp,*up,*zp,tol);
122 errorFlag += ((cnorm > tol) ? 1 : 0) + ((rnorm > tol) ? 1 : 0);
123 *outStream << std::scientific << std::setprecision(8);
124 *outStream << std::endl;
125 *outStream <<
"Test SimOpt solve at feasible (u,z):" << std::endl;
126 *outStream <<
" Solver Residual = " << rnorm << std::endl;
127 *outStream <<
" ||c(u,z)|| = " << cnorm;
128 *outStream << std::endl << std::endl;
130 list.sublist(
"SimOpt").sublist(
"Solve").set(
"Absolute Residual Tolerance",tol);
131 list.sublist(
"SimOpt").sublist(
"Solve").set(
"Solver Type",2);
132 con->setSolveParameters(list);
133 u_ptr->assign(nx, 1.0);
134 con->solve(*cp,*up,*zp,tol);
136 con->value(*cp,*up,*zp,tol);
139 errorFlag += ((cnorm > tol) ? 1 : 0) + ((rnorm > tol) ? 1 : 0);
140 *outStream << std::scientific << std::setprecision(8);
141 *outStream << std::endl;
142 *outStream <<
"Test SimOpt solve at feasible (u,z):" << std::endl;
143 *outStream <<
" Solver Residual = " << rnorm << std::endl;
144 *outStream <<
" ||c(u,z)|| = " << cnorm;
145 *outStream << std::endl << std::endl;
147 catch (std::logic_error& err) {
148 *outStream << err.what() <<
"\n";
153 std::cout <<
"End Result: TEST FAILED\n";
155 std::cout <<
"End Result: TEST PASSED\n";
L2VectorPrimal< RealT > PrimalControlVector
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
H1VectorDual< RealT > DualStateVector
L2VectorDual< RealT > DualControlVector
H1VectorDual< RealT > PrimalConstraintVector
basic_nullstream< char, char_traits< char >> nullstream
int main(int argc, char *argv[])
H1VectorPrimal< RealT > PrimalStateVector
H1VectorPrimal< RealT > DualConstraintVector