52 #include "ROL_ParameterList.hpp"
55 #include "Teuchos_GlobalMPISession.hpp"
56 #include "Teuchos_Comm.hpp"
57 #include "Teuchos_DefaultComm.hpp"
58 #include "Teuchos_CommHelpers.hpp"
74 int main(
int argc,
char *argv[]) {
76 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
77 ROL::Ptr<const Teuchos::Comm<int>> comm
78 = ROL::toPtr(Teuchos::DefaultComm<int>::getComm());
81 int iprint = argc - 1;
82 bool print = (iprint>0);
83 ROL::Ptr<std::ostream> outStream;
86 outStream = ROL::makePtrFromRef(std::cout);
88 outStream = ROL::makePtrFromRef(bhs);
90 bool print0 = print && !(comm->getRank());
91 ROL::Ptr<std::ostream> outStream0;
93 outStream0 = ROL::makePtrFromRef(std::cout);
95 outStream0 = ROL::makePtrFromRef(bhs);
110 ROL::Ptr<BurgersFEM<RealT>> fem
111 = ROL::makePtr<BurgersFEM<RealT>>(nx,nl,cH1,cL2);
112 fem->test_inverse_mass(*outStream0);
113 fem->test_inverse_H1(*outStream0);
117 ROL::Ptr<ROL::Objective_SimOpt<RealT>> pobj
118 = ROL::makePtr<Objective_BurgersControl<RealT>>(fem,x);
123 ROL::Ptr<ROL::Constraint_SimOpt<RealT>> pcon
124 = ROL::makePtr<Constraint_BurgersControl<RealT>>(fem,hess);
128 ROL::Ptr<std::vector<RealT>> z_ptr, u_ptr, c_ptr, l_ptr;
129 z_ptr = ROL::makePtr<std::vector<RealT>>(nx+2, 0.0);
130 u_ptr = ROL::makePtr<std::vector<RealT>>(nx, 1.0);
131 c_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
132 l_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
133 ROL::Ptr<ROL::Vector<RealT>> zp, up, cp, lp;
134 zp = ROL::makePtr<PrimalControlVector>(z_ptr,fem);
135 up = ROL::makePtr<PrimalStateVector>(u_ptr,fem);
136 cp = ROL::makePtr<PrimalConstraintVector>(c_ptr,fem);
137 lp = ROL::makePtr<DualConstraintVector>(l_ptr,fem);
141 int dim = 4, nSamp = 1000;
142 std::vector<RealT> tmp(2,0.0); tmp[0] = -1.0; tmp[1] = 1.0;
143 std::vector<std::vector<RealT>> bounds(dim,tmp);
144 ROL::Ptr<ROL::BatchManager<RealT>> bman
145 = ROL::makePtr<L2VectorBatchManager<RealT,int>>(comm);
146 ROL::Ptr<ROL::SampleGenerator<RealT>> sampler
147 = ROL::makePtr<ROL::MonteCarloGenerator<RealT>>(
148 nSamp,bounds,bman,
false,
false,100);
152 bool storage =
true, fdhess =
false;
153 ROL::Ptr<ROL::Objective<RealT>> robj
154 = ROL::makePtr<ROL::Reduced_Objective_SimOpt<RealT>>(
155 pobj,pcon,up,zp,lp,storage,fdhess);
159 std::vector<RealT> Zlo(nx+2,0.0), Zhi(nx+2,10.0);
160 for (
int i = 0; i < nx+2; i++) {
161 if ( i < (
int)((nx+2)/3) ) {
165 if ( i >= (
int)((nx+2)/3) && i < (
int)(2*(nx+2)/3) ) {
169 if ( i >= (
int)(2*(nx+2)/3) ) {
174 ROL::Ptr<ROL::BoundConstraint<RealT>> bnd
175 = ROL::makePtr<L2BoundConstraint<RealT>>(Zlo,Zhi,fem);
179 RealT order = 2.0, threshold = -0.85*(1.0-x);
180 ROL::Ptr<ROL::ParameterList> bpoelist = ROL::makePtr<ROL::ParameterList>();
181 bpoelist->sublist(
"SOL").set(
"Store Sampled Value and Gradient",
true);
182 bpoelist->sublist(
"SOL").set(
"Stochastic Component Type",
"Probability");
183 bpoelist->sublist(
"SOL").sublist(
"Probability").set(
"Name",
"bPOE");
184 bpoelist->sublist(
"SOL").sublist(
"Probability").sublist(
"bPOE").set(
"Threshold",threshold);
185 bpoelist->sublist(
"SOL").sublist(
"Probability").sublist(
"bPOE").set(
"Moment Order",order);
189 bool derivcheck =
false;
191 problem.
check(*outStream0);
197 std::string filename =
"input.xml";
198 auto parlist = ROL::getParametersFromXmlFile( filename );
201 solver.
solve(*outStream);
207 ofs.open(
"output_example_09.txt",std::ofstream::out);
208 for (
int i = 0; i < nx+2; i++ ) {
209 ofs << std::scientific << std::setprecision(10);
210 ofs << std::setw(20) << std::left << (
RealT)i/((
RealT)nx+1.0);
211 ofs << std::setw(20) << std::left << (*z_ptr)[i];
218 catch (std::logic_error err) {
219 *outStream << err.what() <<
"\n";
225 std::cout <<
"End Result: TEST FAILED\n";
227 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