11 #include "Teuchos_GlobalMPISession.hpp"
30 template<
typename Real>
43 template<
typename Real>
70 int main(
int argc,
char* argv[] ) {
72 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
75 int iprint = argc - 1;
76 ROL::Ptr<std::ostream> outStream;
79 outStream = ROL::makePtrFromRef(std::cout);
81 outStream = ROL::makePtrFromRef(bhs);
84 RealT errtol = ROL::ROL_THRESHOLD<RealT>();
91 auto xp = ROL::makePtr<std::vector<RealT>>(N);
92 auto x = ROL::makePtr<ROL::StdVector<RealT>>(xp);
93 auto yp = ROL::makePtr<std::vector<RealT>>(M);
94 auto y = ROL::makePtr<ROL::StdVector<RealT>>(yp);
108 auto value1 = test_single_1.
value(*x);
109 RealT err1 = std::abs(N-value1);
111 *outStream <<
"\nTesting single VectorClone of same size and type: ";
112 if (err1<errtol) { *outStream <<
"Works!" << std::endl; }
114 errorFlag += err1>errtol;
115 *outStream <<
"Incorrect result!" << std::endl;
121 bool passed_test_2 =
false;
122 *outStream <<
"Throw exception on mismatched dimension : ";
124 try { test_single_1.
value(*y); }
125 catch( std::logic_error& size_mismatch ) { passed_test_2 =
true; }
127 if( passed_test_2 ) { *outStream <<
"Works!" << std::endl; }
129 *outStream <<
"Failed to throw!" << std::endl;
135 bool passed_test_3 =
false;
136 *outStream <<
"Throw exception on mismatched type : ";
138 try { test_single_1.
value(*y); }
139 catch( std::logic_error& dim_mismatch ) { passed_test_3 =
true; }
141 if( passed_test_3 ) { *outStream <<
"Works!" << std::endl; }
143 *outStream <<
"Failed to throw!" << std::endl;
149 *outStream <<
"\n\nTesting with ProfiledVector. # calls to clone: ";
150 for(
int i=0; i<10; ++i ) {
151 test_single_2.
value(xprofile);
155 *outStream << calls.clone_ << std::endl;
156 if( calls.clone_ > 1 ) { errorFlag++; }
164 bool vcm_pass =
true;
166 *outStream <<
"Testing VectorCloneMap: ";
168 auto x_value = test_multi.
value_x(*x);
169 auto y_value = test_multi.
value_y(*y);
170 auto z_value = test_multi.
value_z(*z);
172 auto errx = std::abs(x_value-20.0);
173 auto erry = std::abs(y_value-40.0);
174 auto errz = std::abs(z_value-80.0);
176 if( errx>errtol ) { vcm_pass =
false; errorFlag++; }
177 if( erry>errtol ) { vcm_pass =
false; errorFlag++; }
178 if( errz>errtol ) { vcm_pass =
false; errorFlag++; }
180 if( vcm_pass ) { *outStream <<
"Works!" << std::endl; }
182 *outStream <<
"Error tolerance exceeded!" << std::endl;
183 *outStream <<
"x_value was " << x_value <<
", should be 20." << std::endl;
184 *outStream <<
"y_value was " << y_value <<
", should be 40." << std::endl;
185 *outStream <<
"z_value was " << z_value <<
", should be 80." << std::endl;
189 catch (std::logic_error& err) {
190 *outStream << err.what() <<
"\n";
195 std::cout <<
"End Result: TEST FAILED\n";
197 std::cout <<
"End Result: TEST PASSED\n";
static Ptr< PartitionedVector > create(std::initializer_list< Vp > vs)
typename PV< Real >::size_type size_type
Real value_y(const ROL::Vector< Real > &y) const
Real value(const ROL::Vector< Real > &x) const
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...
ROL::VectorClone< Real > xclone_
basic_nullstream< char, std::char_traits< char >> nullstream
void printVectorFunctionCalls(const ProfiledVector< Ordinal, Real > &x, std::ostream &outStream=std::cout)
By keeping a pointer to this in a derived Vector class, a tally of all methods is kept for profiling ...
Real value_x(const ROL::Vector< Real > &x) const
int main(int argc, char *argv[])
Real value_z(const ROL::Vector< Real > &z) const
VectorFunctionCalls< Ordinal > getVectorFunctionCalls(const ProfiledVector< Ordinal, Real > &x)
ROL::VectorCloneMap< Real > clones_