52 #include "Teuchos_oblackholestream.hpp" 53 #include "Teuchos_GlobalMPISession.hpp" 54 #include "Teuchos_ParameterList.hpp" 59 int main(
int argc,
char *argv[]) {
64 typedef std::vector<RealT> vector;
68 typedef typename vector::size_type uint;
70 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
73 int iprint = argc - 1;
74 Teuchos::RCP<std::ostream> outStream;
75 Teuchos::oblackholestream bhs;
77 outStream = Teuchos::rcp(&std::cout,
false);
79 outStream = Teuchos::rcp(&bhs,
false);
82 Teuchos::oblackholestream oldFormatState;
83 oldFormatState.copyfmt(std::cout);
97 RCP<vector> x_rcp = rcp(
new vector(dim,0.0) );
98 RCP<vector> g_rcp = rcp(
new vector(dim,0.0) );
99 RCP<vector> v_rcp = rcp(
new vector(dim,0.0) );
100 RCP<vector> hv_rcp = rcp(
new vector(dim,0.0) );
102 RCP<vector> l_rcp = rcp(
new vector(dim,1.0) );
103 RCP<vector> u_rcp = rcp(
new vector(dim,2.0) );
105 RCP<vector> xlog0_rcp = rcp(
new vector(dim,0.0) );
106 RCP<vector> xlog1_rcp = rcp(
new vector(dim,0.0) );
107 RCP<vector> xlog2_rcp = rcp(
new vector(dim,0.0) );
109 RCP<vector> xquad0_rcp = rcp(
new vector(dim,0.0) );
110 RCP<vector> xquad1_rcp = rcp(
new vector(dim,0.0) );
111 RCP<vector> xquad2_rcp = rcp(
new vector(dim,0.0) );
113 RCP<vector> xdwell0_rcp = rcp(
new vector(dim,0.0) );
114 RCP<vector> xdwell1_rcp = rcp(
new vector(dim,0.0) );
115 RCP<vector> xdwell2_rcp = rcp(
new vector(dim,0.0) );
124 RCP<SV> xlog0 = rcp(
new SV(xlog0_rcp) );
125 RCP<SV> xlog1 = rcp(
new SV(xlog1_rcp) );
126 RCP<SV> xlog2 = rcp(
new SV(xlog2_rcp) );
128 RCP<SV> xquad0 = rcp(
new SV(xquad0_rcp) );
129 RCP<SV> xquad1 = rcp(
new SV(xquad1_rcp) );
130 RCP<SV> xquad2 = rcp(
new SV(xquad2_rcp) );
132 RCP<SV> xdwell0 = rcp(
new SV(xdwell0_rcp) );
133 RCP<SV> xdwell1 = rcp(
new SV(xdwell1_rcp) );
134 RCP<SV> xdwell2 = rcp(
new SV(xdwell2_rcp) );
136 RCP<V> lo = rcp(
new SV(l_rcp) );
137 RCP<V> up = rcp(
new SV(u_rcp) );
139 for(uint i=0; i<dim; ++i) {
140 RealT t =
static_cast<RealT>(i)/static_cast<RealT>(dim-1);
141 (*x_rcp)[i] = xmin*(1-t) + xmax*t;
147 Teuchos::ParameterList logList;
148 Teuchos::ParameterList quadList;
149 Teuchos::ParameterList dwellList;
151 logList.sublist(
"Barrier Function").set(
"Type",
"Logarithmic");
152 quadList.sublist(
"Barrier Function").set(
"Type",
"Quadratic");
153 dwellList.sublist(
"Barrier Function").set(
"Type",
"Double Well");
172 quadObj.
value(x,tol);
182 dwellObj.
value(x,tol);
192 *outStream << std::setw(14) <<
"x" 193 << std::setw(14) <<
"log" 194 << std::setw(14) <<
"D(log)" 195 << std::setw(14) <<
"D2(log)" 196 << std::setw(14) <<
"quad" 197 << std::setw(14) <<
"D(quad)" 198 << std::setw(14) <<
"D2(quad)" 199 << std::setw(14) <<
"dwell" 200 << std::setw(14) <<
"D(dwell)" 201 << std::setw(14) <<
"D2(dwell)" 203 *outStream << std::string(140,
'-') << std::endl;
205 for(uint i=0; i<dim; ++i) {
206 *outStream << std::setw(14) << (*x_rcp)[i]
207 << std::setw(14) << (*xlog0_rcp)[i]
208 << std::setw(14) << (*xlog1_rcp)[i]
209 << std::setw(14) << (*xlog2_rcp)[i]
210 << std::setw(14) << (*xquad0_rcp)[i]
211 << std::setw(14) << (*xquad1_rcp)[i]
212 << std::setw(14) << (*xquad2_rcp)[i]
213 << std::setw(14) << (*xdwell0_rcp)[i]
214 << std::setw(14) << (*xdwell1_rcp)[i]
215 << std::setw(14) << (*xdwell2_rcp)[i]
223 *outStream <<
"\n\n";
224 *outStream <<
"Test of logarithmic penalty objective" << std::endl;
225 logObj.
checkGradient(x,v,
true,*outStream); *outStream << std::endl;
226 logObj.
checkHessVec(x,v,
true,*outStream); *outStream << std::endl;
231 *outStream <<
"\n\n";
232 *outStream <<
"Test of piecewise quadratic penalty objective" << std::endl;
233 quadObj.
checkGradient(x,v,
true,*outStream); *outStream << std::endl;
234 quadObj.
checkHessVec(x,v,
true,*outStream); *outStream << std::endl;
237 *outStream <<
"\n\n";
238 *outStream <<
"Test of double well penalty objective" << std::endl;
239 dwellObj.
checkGradient(x,v,
true,*outStream); *outStream << std::endl;
240 dwellObj.
checkHessVec(x,v,
true,*outStream); *outStream << std::endl;
247 catch (std::logic_error err) {
248 *outStream << err.what() <<
"\n";
253 std::cout <<
"End Result: TEST FAILED\n";
255 std::cout <<
"End Result: TEST PASSED\n";
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.
Teuchos::RCP< Vector< Real > > getBarrierVector(void)
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 std::vector implementation of the ROL::Vector interface.
Provides the interface to apply upper and lower bound constraints.
int main(int argc, char *argv[])
Real value(const Vector< Real > &x, Real &tol)
Compute value.
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.