60 #include "Teuchos_GlobalMPISession.hpp"
61 #include "Teuchos_XMLParameterListHelpers.hpp"
86 if ( (state.
gnorm > this->gtol_) &&
87 (state.
snorm > this->stol_) &&
88 (state.
iter < this->max_iter_) ) {
92 if ( state.
iter < 2 ) {
103 int main(
int argc,
char *argv[]) {
105 typedef std::vector<RealT> vector;
113 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
116 int iprint = argc - 1;
117 ROL::Ptr<std::ostream> outStream;
120 outStream = ROL::makePtrFromRef(std::cout);
122 outStream = ROL::makePtrFromRef(bhs);
133 ROL::Ptr<vector> l_ptr = ROL::makePtr<vector>(
dim);
134 ROL::Ptr<vector> u_ptr = ROL::makePtr<vector>(
dim);
136 ROL::Ptr<V> lo = ROL::makePtr<SV>(l_ptr);
137 ROL::Ptr<V> up = ROL::makePtr<SV>(u_ptr);
139 for ( uint i = 0; i <
dim; i++ ) {
140 if ( i < dim/3.0 || i > 2*dim/3.0 ) {
152 std::string filename =
"input.xml";
153 auto parlist = ROL::getParametersFromXmlFile( filename );
156 parlist->sublist(
"General").sublist(
"Krylov").set(
"Absolute Tolerance",1.e-4);
157 parlist->sublist(
"General").sublist(
"Krylov").set(
"Relative Tolerance",1.e-2);
158 parlist->sublist(
"General").sublist(
"Krylov").set(
"Iteration Limit",50);
161 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Step Tolerance",1.e-8);
162 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Gradient Tolerance",1.e-6);
163 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Iteration Limit", 1);
164 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Dual Scaling",(alpha>0.0)?alpha:1.e-4);
167 parlist->sublist(
"Status Test").set(
"Gradient Tolerance",1.e-12);
168 parlist->sublist(
"Status Test").set(
"Step Tolerance",1.e-14);
169 parlist->sublist(
"Status Test").set(
"Iteration Limit",100);
172 ROL::Ptr<ROL::Step<RealT>> step = ROL::makePtr<ROL::PrimalDualActiveSetStep<RealT>>(*parlist);
173 ROL::Ptr<ROL::StatusTest<RealT>> status = ROL::makePtr<ROL::StatusTest<RealT>>(*parlist);
174 ROL::Ptr<ROL::Algorithm<RealT>> algo = ROL::makePtr<ROL::Algorithm<RealT>>(step,status,
false);
177 ROL::Ptr<vector> x_ptr = ROL::makePtr<vector>(
dim, 0.0);
182 algo->run(x, obj, icon,
true, *outStream);
184 file.open(
"control_PDAS.txt");
186 for ( uint i = 0; i <
dim; i++ ) {
187 file << (*x_ptr)[i] <<
"\n";
193 Teuchos::updateParametersFromXmlFile( filename, parlist.ptr() );
195 step = ROL::makePtr<ROL::TrustRegionStep<RealT>>(*parlist);
196 status = ROL::makePtr<ROL::StatusTest<RealT>>(*parlist);
197 algo = ROL::makePtr<ROL::Algorithm<RealT>>(step,status,
false);
199 ROL::Ptr<vector> y_ptr = ROL::makePtr<vector>(
dim, 0.0);
204 algo->run(y, obj, icon,
true, *outStream);
206 std::ofstream file_tr;
207 file_tr.open(
"control_TR.txt");
208 for ( uint i = 0; i <
dim; i++ ) {
209 file_tr << (*y_ptr)[i] <<
"\n";
213 ROL::Ptr<V> error = x.clone();
216 *outStream <<
"\nError between PDAS solution and TR solution is " << error->norm() <<
"\n";
217 errorFlag = ((error->norm() > 1e2*std::sqrt(ROL::ROL_EPSILON<RealT>())) ? 1 : 0);
219 catch (std::logic_error& err) {
220 *outStream << err.what() <<
"\n";
225 std::cout <<
"End Result: TEST FAILED\n";
227 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...
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.
basic_nullstream< char, char_traits< char >> nullstream
int main(int argc, char *argv[])
virtual ~StatusTest_PDAS()
virtual bool check(ROL::AlgorithmState< Real > &state)
Check algorithm status.