54 #include "Teuchos_GlobalMPISession.hpp"
55 #include "ROL_ParameterList.hpp"
60 int main(
int argc,
char *argv[]) {
62 typedef std::vector<RealT> vector;
68 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
71 int iprint = argc - 1;
72 ROL::Ptr<std::ostream> outStream;
75 outStream = ROL::makePtrFromRef(std::cout);
77 outStream = ROL::makePtrFromRef(bhs);
81 oldFormatState.copyfmt(std::cout);
95 ROL::Ptr<vector> x_ptr = ROL::makePtr<vector>(dim,0.0);
96 ROL::Ptr<vector> g_ptr = ROL::makePtr<vector>(dim,0.0);
97 ROL::Ptr<vector> v_ptr = ROL::makePtr<vector>(dim,0.0);
98 ROL::Ptr<vector> hv_ptr = ROL::makePtr<vector>(dim,0.0);
100 ROL::Ptr<vector> l_ptr = ROL::makePtr<vector>(dim,1.0);
101 ROL::Ptr<vector> u_ptr = ROL::makePtr<vector>(dim,2.0);
103 ROL::Ptr<vector> xlog0_ptr = ROL::makePtr<vector>(dim,0.0);
104 ROL::Ptr<vector> xlog1_ptr = ROL::makePtr<vector>(dim,0.0);
105 ROL::Ptr<vector> xlog2_ptr = ROL::makePtr<vector>(dim,0.0);
107 ROL::Ptr<vector> xquad0_ptr = ROL::makePtr<vector>(dim,0.0);
108 ROL::Ptr<vector> xquad1_ptr = ROL::makePtr<vector>(dim,0.0);
109 ROL::Ptr<vector> xquad2_ptr = ROL::makePtr<vector>(dim,0.0);
111 ROL::Ptr<vector> xdwell0_ptr = ROL::makePtr<vector>(dim,0.0);
112 ROL::Ptr<vector> xdwell1_ptr = ROL::makePtr<vector>(dim,0.0);
113 ROL::Ptr<vector> xdwell2_ptr = ROL::makePtr<vector>(dim,0.0);
122 ROL::Ptr<SV> xlog0 = ROL::makePtr<SV>(xlog0_ptr);
123 ROL::Ptr<SV> xlog1 = ROL::makePtr<SV>(xlog1_ptr);
124 ROL::Ptr<SV> xlog2 = ROL::makePtr<SV>(xlog2_ptr);
126 ROL::Ptr<SV> xquad0 = ROL::makePtr<SV>(xquad0_ptr);
127 ROL::Ptr<SV> xquad1 = ROL::makePtr<SV>(xquad1_ptr);
128 ROL::Ptr<SV> xquad2 = ROL::makePtr<SV>(xquad2_ptr);
130 ROL::Ptr<SV> xdwell0 = ROL::makePtr<SV>(xdwell0_ptr);
131 ROL::Ptr<SV> xdwell1 = ROL::makePtr<SV>(xdwell1_ptr);
132 ROL::Ptr<SV> xdwell2 = ROL::makePtr<SV>(xdwell2_ptr);
134 ROL::Ptr<V> lo = ROL::makePtr<SV>(l_ptr);
135 ROL::Ptr<V> up = ROL::makePtr<SV>(u_ptr);
137 for(uint i=0; i<dim; ++i) {
138 RealT t =
static_cast<RealT>(i)/static_cast<RealT>(dim-1);
139 (*x_ptr)[i] = xmin*(1-t) + xmax*t;
145 ROL::ParameterList logList;
146 ROL::ParameterList quadList;
147 ROL::ParameterList dwellList;
149 logList.sublist(
"Barrier Function").set(
"Type",
"Logarithmic");
150 quadList.sublist(
"Barrier Function").set(
"Type",
"Quadratic");
151 dwellList.sublist(
"Barrier Function").set(
"Type",
"Double Well");
170 quadObj.
value(x,tol);
180 dwellObj.
value(x,tol);
190 *outStream << std::setw(14) <<
"x"
191 << std::setw(14) <<
"log"
192 << std::setw(14) <<
"D(log)"
193 << std::setw(14) <<
"D2(log)"
194 << std::setw(14) <<
"quad"
195 << std::setw(14) <<
"D(quad)"
196 << std::setw(14) <<
"D2(quad)"
197 << std::setw(14) <<
"dwell"
198 << std::setw(14) <<
"D(dwell)"
199 << std::setw(14) <<
"D2(dwell)"
201 *outStream << std::string(140,
'-') << std::endl;
203 for(uint i=0; i<dim; ++i) {
204 *outStream << std::setw(14) << (*x_ptr)[i]
205 << std::setw(14) << (*xlog0_ptr)[i]
206 << std::setw(14) << (*xlog1_ptr)[i]
207 << std::setw(14) << (*xlog2_ptr)[i]
208 << std::setw(14) << (*xquad0_ptr)[i]
209 << std::setw(14) << (*xquad1_ptr)[i]
210 << std::setw(14) << (*xquad2_ptr)[i]
211 << std::setw(14) << (*xdwell0_ptr)[i]
212 << std::setw(14) << (*xdwell1_ptr)[i]
213 << std::setw(14) << (*xdwell2_ptr)[i]
221 *outStream <<
"\n\n";
222 *outStream <<
"Test of logarithmic penalty objective" << std::endl;
223 logObj.
checkGradient(x,v,
true,*outStream); *outStream << std::endl;
224 logObj.
checkHessVec(x,v,
true,*outStream); *outStream << std::endl;
229 *outStream <<
"\n\n";
230 *outStream <<
"Test of piecewise quadratic penalty objective" << std::endl;
231 quadObj.
checkGradient(x,v,
true,*outStream); *outStream << std::endl;
232 quadObj.
checkHessVec(x,v,
true,*outStream); *outStream << std::endl;
235 *outStream <<
"\n\n";
236 *outStream <<
"Test of double well penalty objective" << std::endl;
237 dwellObj.
checkGradient(x,v,
true,*outStream); *outStream << std::endl;
238 dwellObj.
checkHessVec(x,v,
true,*outStream); *outStream << std::endl;
245 catch (std::logic_error err) {
246 *outStream << err.what() <<
"\n";
251 std::cout <<
"End Result: TEST FAILED\n";
253 std::cout <<
"End Result: TEST PASSED\n";
typename PV< Real >::size_type size_type
ROL::Ptr< Vector< Real > > getBarrierVector(void)
void RandomizeVector(Vector< Real > &x, const Real &lower=0.0, const Real &upper=1.0)
Fill a ROL::Vector with uniformly-distributed random numbers in the interval [lower,upper].
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...
virtual std::vector< std::vector< Real > > checkGradient(const Vector< Real > &x, const Vector< Real > &d, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Finite-difference gradient check.
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Provides the elementwise interface to apply upper and lower bound constraints.
Real value(const Vector< Real > &x, Real &tol)
Compute value.
basic_nullstream< char, char_traits< char >> nullstream
int main(int argc, char *argv[])
virtual std::vector< std::vector< Real > > checkHessVec(const Vector< Real > &x, const Vector< Real > &v, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Finite-difference Hessian-applied-to-vector check.
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Create a penalty objective from upper and lower bound vectors.