58 #include "Teuchos_oblackholestream.hpp" 59 #include "Teuchos_XMLParameterListHelpers.hpp" 60 #include "Teuchos_GlobalMPISession.hpp" 61 #include "Teuchos_Comm.hpp" 62 #include "Teuchos_DefaultComm.hpp" 63 #include "Teuchos_CommHelpers.hpp" 79 int main(
int argc,
char *argv[]) {
81 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
82 Teuchos::RCP<const Teuchos::Comm<int> > comm
83 = Teuchos::DefaultComm<int>::getComm();
86 int iprint = argc - 1;
87 bool print = (iprint>0);
88 Teuchos::RCP<std::ostream> outStream;
89 Teuchos::oblackholestream bhs;
91 outStream = Teuchos::rcp(&std::cout,
false);
93 outStream = Teuchos::rcp(&bhs,
false);
95 bool print0 = print && !(comm->getRank());
96 Teuchos::RCP<std::ostream> outStream0;
98 outStream0 = Teuchos::rcp(&std::cout,
false);
100 outStream0 = Teuchos::rcp(&bhs,
false);
115 Teuchos::RCP<BurgersFEM<RealT> > fem
117 fem->test_inverse_mass(*outStream0);
118 fem->test_inverse_H1(*outStream0);
122 Teuchos::RCP<ROL::Objective_SimOpt<RealT> > pobj
128 Teuchos::RCP<ROL::EqualityConstraint_SimOpt<RealT> > pcon
134 Teuchos::RCP<std::vector<RealT> > z_rcp
135 = Teuchos::rcp(
new std::vector<RealT> (nx+2, 1.0) );
136 Teuchos::RCP<std::vector<RealT> > gz_rcp
137 = Teuchos::rcp(
new std::vector<RealT> (nx+2, 1.0) );
138 Teuchos::RCP<std::vector<RealT> > yz_rcp
139 = Teuchos::rcp(
new std::vector<RealT> (nx+2, 1.0) );
140 for (
int i=0; i<nx+2; i++) {
141 (*yz_rcp)[i] = 2.0*random<RealT>(comm)-1.0;
143 Teuchos::RCP<ROL::Vector<RealT> > zp
145 Teuchos::RCP<ROL::Vector<RealT> > gzp
147 Teuchos::RCP<ROL::Vector<RealT> > yzp
149 std::vector<RealT> zvar(1,random<RealT>(comm));
150 std::vector<RealT> gvar(1,random<RealT>(comm));
151 std::vector<RealT> yvar(1,random<RealT>(comm));
154 Teuchos::RCP<std::vector<RealT> > u_rcp
155 = Teuchos::rcp(
new std::vector<RealT> (nx, 1.0) );
156 Teuchos::RCP<std::vector<RealT> > gu_rcp
157 = Teuchos::rcp(
new std::vector<RealT> (nx, 1.0) );
158 Teuchos::RCP<ROL::Vector<RealT> > up
160 Teuchos::RCP<ROL::Vector<RealT> > gup
163 Teuchos::RCP<std::vector<RealT> > c_rcp
164 = Teuchos::rcp(
new std::vector<RealT> (nx, 1.0) );
165 Teuchos::RCP<std::vector<RealT> > l_rcp
166 = Teuchos::rcp(
new std::vector<RealT> (nx, 1.0) );
167 for (
int i=0; i<nx; i++) {
168 (*l_rcp)[i] = random<RealT>(comm);
170 Teuchos::RCP<ROL::Vector<RealT> > cp
172 Teuchos::RCP<ROL::Vector<RealT> > lp
177 int dim = 4, nSamp = 1000;
178 std::vector<RealT> tmp(2,0.0); tmp[0] = -1.0; tmp[1] = 1.0;
179 std::vector<std::vector<RealT> > bounds(dim,tmp);
180 Teuchos::RCP<ROL::BatchManager<RealT> > bman
182 Teuchos::RCP<ROL::SampleGenerator<RealT> > sampler
184 nSamp,bounds,bman,
false,
false,100));
188 bool storage =
true, fdhess =
false;
189 Teuchos::RCP<ROL::Objective<RealT> > robj
191 pobj,pcon,up,lp,gup,cp,storage,fdhess));
192 RealT order = 2.0, threshold = -0.85*(1.0-x);
193 Teuchos::RCP<ROL::Objective<RealT> > obj
195 robj,order,threshold,sampler,storage));
199 std::vector<RealT> Zlo(nx+2,0.0), Zhi(nx+2,10.0);
200 for (
int i = 0; i < nx+2; i++) {
201 if ( i < (
int)((nx+2)/3) ) {
205 if ( i >= (
int)((nx+2)/3) && i < (
int)(2*(nx+2)/3) ) {
209 if ( i >= (
int)(2*(nx+2)/3) ) {
214 Teuchos::RCP<ROL::BoundConstraint<RealT> > Zbnd
216 Teuchos::ParameterList list;
217 list.sublist(
"SOL").set(
"Stochastic Optimization Type",
"BPOE");
218 Teuchos::RCP<ROL::BoundConstraint<RealT> > bnd
224 bool derivcheck =
false;
226 int nranks = sampler->numBatches();
227 for (
int pid = 0; pid < nranks; pid++) {
228 if ( pid == sampler->batchID() ) {
229 for (
int i = sampler->start(); i < sampler->numMySamples(); i++) {
230 *outStream <<
"Sample " << i <<
" Rank " << sampler->batchID() <<
"\n";
231 *outStream <<
"(" << sampler->getMyPoint(i)[0] <<
", " 232 << sampler->getMyPoint(i)[1] <<
", " 233 << sampler->getMyPoint(i)[2] <<
", " 234 << sampler->getMyPoint(i)[3] <<
")\n";
235 pcon->setParameter(sampler->getMyPoint(i));
236 pcon->checkSolve(*up,*zp,*cp,print,*outStream);
237 robj->setParameter(sampler->getMyPoint(i));
239 robj->checkGradient(*zp,*gzp,*yzp,print,*outStream);
240 robj->checkHessVec(*zp,*gzp,*yzp,print,*outStream);
241 *outStream <<
"\n\n";
247 obj->checkGradient(z,g,y,print0,*outStream0);
248 obj->checkHessVec(z,g,y,print0,*outStream0);
253 std::string filename =
"input.xml";
254 Teuchos::RCP<Teuchos::ParameterList> parlist
255 = Teuchos::rcp(
new Teuchos::ParameterList() );
256 Teuchos::updateParametersFromXmlFile( filename, parlist.ptr() );
260 algo.run(z, g, *obj, *bnd, print0, *outStream0);
266 ofs.open(
"output_example_09.txt",std::ofstream::out);
267 for (
int i = 0; i < nx+2; i++ ) {
268 ofs << std::scientific << std::setprecision(10);
269 ofs << std::setw(20) << std::left << (
RealT)i/((
RealT)nx+1.0);
270 ofs << std::setw(20) << std::left << (*z_rcp)[i];
275 *outStream0 <<
"Scalar Parameter: " << z.getStatistic(0) <<
"\n\n";
277 catch (std::logic_error err) {
278 *outStream << err.what() <<
"\n";
284 std::cout <<
"End Result: TEST FAILED\n";
286 std::cout <<
"End Result: TEST PASSED\n";
H1VectorDual< RealT > PrimalConstraintVector
int main(int argc, char *argv[])
H1VectorPrimal< RealT > DualConstraintVector
L2VectorDual< RealT > DualControlVector
Provides an interface to run optimization algorithms.
H1VectorDual< RealT > DualStateVector
L2VectorPrimal< RealT > PrimalControlVector
H1VectorPrimal< RealT > PrimalStateVector