18 #include "ROL_ParameterList.hpp"
21 #include "Teuchos_GlobalMPISession.hpp"
22 #include "Teuchos_Comm.hpp"
23 #include "Teuchos_DefaultComm.hpp"
24 #include "Teuchos_CommHelpers.hpp"
40 int main(
int argc,
char *argv[]) {
42 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
43 ROL::Ptr<const Teuchos::Comm<int>> comm
44 = ROL::toPtr(Teuchos::DefaultComm<int>::getComm());
47 int iprint = argc - 1;
48 bool print = (iprint>0);
49 ROL::Ptr<std::ostream> outStream;
52 outStream = ROL::makePtrFromRef(std::cout);
54 outStream = ROL::makePtrFromRef(bhs);
56 bool print0 = print && !(comm->getRank());
57 ROL::Ptr<std::ostream> outStream0;
59 outStream0 = ROL::makePtrFromRef(std::cout);
61 outStream0 = ROL::makePtrFromRef(bhs);
76 ROL::Ptr<BurgersFEM<RealT>> fem
77 = ROL::makePtr<BurgersFEM<RealT>>(nx,nl,cH1,cL2);
78 fem->test_inverse_mass(*outStream0);
79 fem->test_inverse_H1(*outStream0);
83 ROL::Ptr<ROL::Objective_SimOpt<RealT>> pobj
84 = ROL::makePtr<Objective_BurgersControl<RealT>>(fem,x);
89 ROL::Ptr<ROL::Constraint_SimOpt<RealT>> pcon
90 = ROL::makePtr<Constraint_BurgersControl<RealT>>(fem,hess);
94 ROL::Ptr<std::vector<RealT>> z_ptr, u_ptr, c_ptr, l_ptr;
95 z_ptr = ROL::makePtr<std::vector<RealT>>(nx+2, 0.0);
96 u_ptr = ROL::makePtr<std::vector<RealT>>(nx, 1.0);
97 c_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
98 l_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
99 ROL::Ptr<ROL::Vector<RealT>> zp, up, cp, lp;
100 zp = ROL::makePtr<PrimalControlVector>(z_ptr,fem);
101 up = ROL::makePtr<PrimalStateVector>(u_ptr,fem);
102 cp = ROL::makePtr<PrimalConstraintVector>(c_ptr,fem);
103 lp = ROL::makePtr<DualConstraintVector>(l_ptr,fem);
107 int dim = 4, nSamp = 1000;
108 std::vector<RealT> tmp(2,0.0); tmp[0] = -1.0; tmp[1] = 1.0;
109 std::vector<std::vector<RealT>> bounds(dim,tmp);
110 ROL::Ptr<ROL::BatchManager<RealT>> bman
111 = ROL::makePtr<L2VectorBatchManager<RealT,int>>(comm);
112 ROL::Ptr<ROL::SampleGenerator<RealT>> sampler
113 = ROL::makePtr<ROL::MonteCarloGenerator<RealT>>(
114 nSamp,bounds,bman,
false,
false,100);
118 bool storage =
true, fdhess =
false;
119 ROL::Ptr<ROL::Objective<RealT>> robj
120 = ROL::makePtr<ROL::Reduced_Objective_SimOpt<RealT>>(
121 pobj,pcon,up,zp,lp,storage,fdhess);
125 std::vector<RealT> Zlo(nx+2,0.0), Zhi(nx+2,10.0);
126 for (
int i = 0; i < nx+2; i++) {
127 if ( i < (
int)((nx+2)/3) ) {
131 if ( i >= (
int)((nx+2)/3) && i < (
int)(2*(nx+2)/3) ) {
135 if ( i >= (
int)(2*(nx+2)/3) ) {
140 ROL::Ptr<ROL::BoundConstraint<RealT>> bnd
141 = ROL::makePtr<L2BoundConstraint<RealT>>(Zlo,Zhi,fem);
145 RealT order = 2.0, threshold = -0.85*(1.0-x);
146 ROL::Ptr<ROL::ParameterList> bpoelist = ROL::makePtr<ROL::ParameterList>();
147 bpoelist->sublist(
"SOL").set(
"Store Sampled Value and Gradient",
true);
148 bpoelist->sublist(
"SOL").set(
"Type",
"Probability");
149 bpoelist->sublist(
"SOL").sublist(
"Probability").set(
"Name",
"bPOE");
150 bpoelist->sublist(
"SOL").sublist(
"Probability").sublist(
"bPOE").set(
"Threshold",threshold);
151 bpoelist->sublist(
"SOL").sublist(
"Probability").sublist(
"bPOE").set(
"Moment Order",order);
155 bool derivcheck =
false;
157 problem.
check(*outStream0);
163 std::string filename =
"input.xml";
164 auto parlist = ROL::getParametersFromXmlFile( filename );
167 solver.
solve(*outStream);
173 ofs.open(
"output_example_09.txt",std::ofstream::out);
174 for (
int i = 0; i < nx+2; i++ ) {
175 ofs << std::scientific << std::setprecision(10);
176 ofs << std::setw(20) << std::left << (
RealT)i/((
RealT)nx+1.0);
177 ofs << std::setw(20) << std::left << (*z_ptr)[i];
184 catch (std::logic_error& err) {
185 *outStream << err.what() <<
"\n";
191 std::cout <<
"End Result: TEST FAILED\n";
193 std::cout <<
"End Result: TEST PASSED\n";
L2VectorPrimal< RealT > PrimalControlVector
void setStochasticObjective(ParameterList &parlist, const Ptr< SampleGenerator< Real >> &vsampler, const Ptr< SampleGenerator< Real >> &gsampler=nullPtr, const Ptr< SampleGenerator< Real >> &hsampler=nullPtr)
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
H1VectorDual< RealT > DualStateVector
Real getSolutionStatistic(int comp=0, int index=0)
Returns the statistic from the soluton vector.
L2VectorDual< RealT > DualControlVector
H1VectorDual< RealT > PrimalConstraintVector
Provides a simplified interface for solving a wide range of optimization problems.
basic_nullstream< char, char_traits< char >> nullstream
int main(int argc, char *argv[])
void check(std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
int solve(const ROL::Ptr< StatusTest< Real > > &status=ROL::nullPtr, const bool combineStatus=true)
Solve optimization problem with no iteration output.
H1VectorPrimal< RealT > PrimalStateVector
H1VectorPrimal< RealT > DualConstraintVector