26 #include "Teuchos_GlobalMPISession.hpp"
27 #include "Teuchos_XMLParameterListHelpers.hpp"
52 if ( (state.
gnorm > this->gtol_) &&
53 (state.
snorm > this->stol_) &&
54 (state.
iter < this->max_iter_) ) {
58 if ( state.
iter < 2 ) {
69 int main(
int argc,
char *argv[]) {
71 typedef std::vector<RealT> vector;
79 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
82 int iprint = argc - 1;
83 ROL::Ptr<std::ostream> outStream;
86 outStream = ROL::makePtrFromRef(std::cout);
88 outStream = ROL::makePtrFromRef(bhs);
99 ROL::Ptr<vector> l_ptr = ROL::makePtr<vector>(
dim);
100 ROL::Ptr<vector> u_ptr = ROL::makePtr<vector>(
dim);
102 ROL::Ptr<V> lo = ROL::makePtr<SV>(l_ptr);
103 ROL::Ptr<V> up = ROL::makePtr<SV>(u_ptr);
105 for ( uint i = 0; i <
dim; i++ ) {
106 if ( i < dim/3.0 || i > 2*dim/3.0 ) {
118 std::string filename =
"input.xml";
119 auto parlist = ROL::getParametersFromXmlFile( filename );
122 parlist->sublist(
"General").sublist(
"Krylov").set(
"Absolute Tolerance",1.e-4);
123 parlist->sublist(
"General").sublist(
"Krylov").set(
"Relative Tolerance",1.e-2);
124 parlist->sublist(
"General").sublist(
"Krylov").set(
"Iteration Limit",50);
127 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Step Tolerance",1.e-8);
128 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Gradient Tolerance",1.e-6);
129 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Iteration Limit", 1);
130 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Dual Scaling",(alpha>0.0)?alpha:1.e-4);
133 parlist->sublist(
"Status Test").set(
"Gradient Tolerance",1.e-12);
134 parlist->sublist(
"Status Test").set(
"Step Tolerance",1.e-14);
135 parlist->sublist(
"Status Test").set(
"Iteration Limit",100);
138 ROL::Ptr<ROL::Step<RealT>> step = ROL::makePtr<ROL::PrimalDualActiveSetStep<RealT>>(*parlist);
139 ROL::Ptr<ROL::StatusTest<RealT>> status = ROL::makePtr<ROL::StatusTest<RealT>>(*parlist);
140 ROL::Ptr<ROL::Algorithm<RealT>> algo = ROL::makePtr<ROL::Algorithm<RealT>>(step,status,
false);
143 ROL::Ptr<vector> x_ptr = ROL::makePtr<vector>(
dim, 0.0);
148 algo->run(x, obj, icon,
true, *outStream);
150 file.open(
"control_PDAS.txt");
152 for ( uint i = 0; i <
dim; i++ ) {
153 file << (*x_ptr)[i] <<
"\n";
159 Teuchos::updateParametersFromXmlFile( filename, parlist.ptr() );
161 step = ROL::makePtr<ROL::TrustRegionStep<RealT>>(*parlist);
162 status = ROL::makePtr<ROL::StatusTest<RealT>>(*parlist);
163 algo = ROL::makePtr<ROL::Algorithm<RealT>>(step,status,
false);
165 ROL::Ptr<vector> y_ptr = ROL::makePtr<vector>(
dim, 0.0);
170 algo->run(y, obj, icon,
true, *outStream);
172 std::ofstream file_tr;
173 file_tr.open(
"control_TR.txt");
174 for ( uint i = 0; i <
dim; i++ ) {
175 file_tr << (*y_ptr)[i] <<
"\n";
179 ROL::Ptr<V> error = x.clone();
182 *outStream <<
"\nError between PDAS solution and TR solution is " << error->norm() <<
"\n";
183 errorFlag = ((error->norm() > 1e2*std::sqrt(ROL::ROL_EPSILON<RealT>())) ? 1 : 0);
185 catch (std::logic_error& err) {
186 *outStream << err.what() <<
"\n";
191 std::cout <<
"End Result: TEST FAILED\n";
193 std::cout <<
"End Result: TEST PASSED\n";
typename PV< Real >::size_type size_type
StatusTest_PDAS(Real gtol=1.e-6, Real stol=1.e-12, int max_iter=100)
Contains definitions of custom data types in ROL.
Contains definitions for Poisson optimal control.
Defines the linear algebra or vector space interface.
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
basic_nullstream< char, std::char_traits< char >> nullstream
State for algorithm class. Will be used for restarts.
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Poisson distributed control.
Provides the elementwise interface to apply upper and lower bound constraints.
Provides an interface to check status of optimization algorithms.
int main(int argc, char *argv[])
virtual ~StatusTest_PDAS()
virtual bool check(ROL::AlgorithmState< Real > &state)
Check algorithm status.