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::ParametrizedObjective_SimOpt<RealT> > pobj
128 Teuchos::RCP<ROL::ParametrizedEqualityConstraint_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::ParametrizedObjective<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::RCP<ROL::BoundConstraint<RealT> > bnd
222 bool derivcheck =
false;
224 int nranks = sampler->numBatches();
225 for (
int pid = 0; pid < nranks; pid++) {
226 if ( pid == sampler->batchID() ) {
227 for (
int i = sampler->start(); i < sampler->numMySamples(); i++) {
228 *outStream <<
"Sample " << i <<
" Rank " << sampler->batchID() <<
"\n";
229 *outStream <<
"(" << sampler->getMyPoint(i)[0] <<
", " 230 << sampler->getMyPoint(i)[1] <<
", " 231 << sampler->getMyPoint(i)[2] <<
", " 232 << sampler->getMyPoint(i)[3] <<
")\n";
233 pcon->setParameter(sampler->getMyPoint(i));
234 pcon->checkSolve(*up,*zp,*cp,print,*outStream);
235 robj->setParameter(sampler->getMyPoint(i));
237 robj->checkGradient(*zp,*gzp,*yzp,print,*outStream);
238 robj->checkHessVec(*zp,*gzp,*yzp,print,*outStream);
239 *outStream <<
"\n\n";
245 obj->checkGradient(z,g,y,print0,*outStream0);
246 obj->checkHessVec(z,g,y,print0,*outStream0);
251 std::string filename =
"input.xml";
252 Teuchos::RCP<Teuchos::ParameterList> parlist
253 = Teuchos::rcp(
new Teuchos::ParameterList() );
254 Teuchos::updateParametersFromXmlFile( filename, parlist.ptr() );
258 algo.run(z, g, *obj, *bnd, print0, *outStream0);
264 ofs.open(
"output_example_09.txt",std::ofstream::out);
265 for (
int i = 0; i < nx+2; i++ ) {
266 ofs << std::scientific << std::setprecision(10);
267 ofs << std::setw(20) << std::left << (
RealT)i/((
RealT)nx+1.0);
268 ofs << std::setw(20) << std::left << (*z_rcp)[i];
273 *outStream0 <<
"Scalar Parameter: " << z.getStatistic() <<
"\n\n";
275 catch (std::logic_error err) {
276 *outStream << err.what() <<
"\n";
282 std::cout <<
"End Result: TEST FAILED\n";
284 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