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) && !(comm->getRank());
88 Teuchos::RCP<std::ostream> outStream;
89 Teuchos::oblackholestream bhs;
91 outStream = Teuchos::rcp(&std::cout,
false);
93 outStream = Teuchos::rcp(&bhs,
false);
108 Teuchos::RCP<BurgersFEM<RealT> > fem
110 fem->test_inverse_mass(*outStream);
111 fem->test_inverse_H1(*outStream);
115 Teuchos::RCP<ROL::ParametrizedObjective_SimOpt<RealT> > pobj
121 Teuchos::RCP<ROL::ParametrizedEqualityConstraint_SimOpt<RealT> > pcon
127 Teuchos::RCP<std::vector<RealT> > z_rcp
128 = Teuchos::rcp(
new std::vector<RealT> (nx+2, 1.0) );
129 Teuchos::RCP<std::vector<RealT> > gz_rcp
130 = Teuchos::rcp(
new std::vector<RealT> (nx+2, 1.0) );
131 Teuchos::RCP<std::vector<RealT> > yz_rcp
132 = Teuchos::rcp(
new std::vector<RealT> (nx+2, 1.0) );
133 for (
int i=0; i<nx+2; i++) {
134 (*z_rcp)[i] = 2.0*random<RealT>(comm)-1.0;
135 (*yz_rcp)[i] = 2.0*random<RealT>(comm)-1.0;
137 Teuchos::RCP<ROL::Vector<RealT> > zp
139 Teuchos::RCP<ROL::Vector<RealT> > gzp
141 Teuchos::RCP<ROL::Vector<RealT> > yzp
143 RealT zvar = random<RealT>(comm);
144 RealT gvar = random<RealT>(comm);
145 RealT yvar = random<RealT>(comm);
148 Teuchos::RCP<std::vector<RealT> > u_rcp
149 = Teuchos::rcp(
new std::vector<RealT> (nx, 1.0) );
150 Teuchos::RCP<std::vector<RealT> > gu_rcp
151 = Teuchos::rcp(
new std::vector<RealT> (nx, 1.0) );
152 for (
int i=0; i<nx; i++) {
153 (*u_rcp)[i] = 2.0*random<RealT>(comm)-1.0;
155 Teuchos::RCP<ROL::Vector<RealT> > up
157 Teuchos::RCP<ROL::Vector<RealT> > gup
160 Teuchos::RCP<std::vector<RealT> > c_rcp
161 = Teuchos::rcp(
new std::vector<RealT> (nx, 1.0) );
162 Teuchos::RCP<std::vector<RealT> > l_rcp
163 = Teuchos::rcp(
new std::vector<RealT> (nx, 1.0) );
164 for (
int i=0; i<nx; i++) {
165 (*l_rcp)[i] = random<RealT>(comm);
167 Teuchos::RCP<ROL::Vector<RealT> > cp
169 Teuchos::RCP<ROL::Vector<RealT> > lp
174 int dim = 4, nSamp = 10000;
175 std::vector<RealT> tmp(2,0.0); tmp[0] = -1.0; tmp[1] = 1.0;
176 std::vector<std::vector<RealT> > bounds(dim,tmp);
177 Teuchos::RCP<ROL::BatchManager<RealT> > bman
179 Teuchos::RCP<ROL::SampleGenerator<RealT> > sampler
181 nSamp,bounds,bman,
false,
false,100));
185 bool storage =
true, fdhess =
false;
186 Teuchos::RCP<ROL::ParametrizedObjective<RealT> > robj
188 pobj,pcon,up,lp,gup,cp,storage,fdhess));
189 RealT order = 2.0, threshold = -0.85*(1.0-x);
190 Teuchos::RCP<ROL::Objective<RealT> > obj
192 robj,order,threshold,sampler,storage));
196 std::vector<RealT> Zlo(nx+2,0.0), Zhi(nx+2,10.0);
197 for (
int i = 0; i < nx+2; i++) {
198 if ( i < (
int)((nx+2)/3) ) {
202 if ( i >= (
int)((nx+2)/3) && i < (
int)(2*(nx+2)/3) ) {
206 if ( i >= (
int)(2*(nx+2)/3) ) {
211 Teuchos::RCP<ROL::BoundConstraint<RealT> > Zbnd
213 Teuchos::RCP<ROL::BoundConstraint<RealT> > bnd
219 bool derivcheck =
false;
221 for (
int i = sampler->start(); i < sampler->numMySamples(); i++) {
222 *outStream <<
"Sample " << i <<
" Rank " << sampler->batchID() <<
"\n";
223 *outStream <<
"(" << sampler->getMyPoint(i)[0] <<
", " 224 << sampler->getMyPoint(i)[1] <<
", " 225 << sampler->getMyPoint(i)[2] <<
", " 226 << sampler->getMyPoint(i)[3] <<
")\n";
227 pcon->setParameter(sampler->getMyPoint(i));
228 pcon->checkSolve(*up,*zp,*cp,print,*outStream);
229 robj->setParameter(sampler->getMyPoint(i));
230 robj->checkGradient(*zp,*gzp,*yzp,print,*outStream);
231 robj->checkHessVec(*zp,*gzp,*yzp,print,*outStream);
234 obj->checkGradient(z,g,y,print,*outStream);
235 obj->checkHessVec(z,g,y,print,*outStream);
240 std::string filename =
"input.xml";
241 Teuchos::RCP<Teuchos::ParameterList> parlist
242 = Teuchos::rcp(
new Teuchos::ParameterList() );
243 Teuchos::updateParametersFromXmlFile( filename, parlist.ptr() );
247 algo.run(z, g, *obj, *bnd, print, *outStream);
253 ofs.open(
"output_example_09.txt",std::ofstream::out);
254 for (
int i = 0; i < nx+2; i++ ) {
255 ofs << std::scientific << std::setprecision(10);
256 ofs << std::setw(20) << std::left << (
RealT)i/((
RealT)nx+1.0);
257 ofs << std::setw(20) << std::left << (*z_rcp)[i];
262 *outStream <<
"Scalar Parameter: " << z.getVaR() <<
"\n\n";
264 catch (std::logic_error err) {
265 *outStream << err.what() <<
"\n";
271 std::cout <<
"End Result: TEST FAILED\n";
273 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