45 #include "Teuchos_GlobalMPISession.hpp"
64 template<
typename Real>
77 template<
typename Real>
104 int main(
int argc,
char* argv[] ) {
106 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
109 int iprint = argc - 1;
110 ROL::Ptr<std::ostream> outStream;
113 outStream = ROL::makePtrFromRef(std::cout);
115 outStream = ROL::makePtrFromRef(bhs);
118 RealT errtol = ROL::ROL_THRESHOLD<RealT>();
125 auto xp = ROL::makePtr<std::vector<RealT>>(N);
126 auto x = ROL::makePtr<ROL::StdVector<RealT>>(xp);
127 auto yp = ROL::makePtr<std::vector<RealT>>(M);
128 auto y = ROL::makePtr<ROL::StdVector<RealT>>(yp);
142 auto value1 = test_single_1.
value(*x);
143 RealT err1 = std::abs(N-value1);
145 *outStream <<
"\nTesting single VectorClone of same size and type: ";
146 if (err1<errtol) { *outStream <<
"Works!" << std::endl; }
148 errorFlag += err1>errtol;
149 *outStream <<
"Incorrect result!" << std::endl;
155 bool passed_test_2 =
false;
156 *outStream <<
"Throw exception on mismatched dimension : ";
158 try { test_single_1.
value(*y); }
159 catch( std::logic_error size_mismatch ) { passed_test_2 =
true; }
161 if( passed_test_2 ) { *outStream <<
"Works!" << std::endl; }
163 *outStream <<
"Failed to throw!" << std::endl;
169 bool passed_test_3 =
false;
170 *outStream <<
"Throw exception on mismatched type : ";
172 try { test_single_1.
value(*y); }
173 catch( std::logic_error dim_mismatch ) { passed_test_3 =
true; }
175 if( passed_test_3 ) { *outStream <<
"Works!" << std::endl; }
177 *outStream <<
"Failed to throw!" << std::endl;
183 *outStream <<
"\n\nTesting with ProfiledVector. # calls to clone: ";
184 for(
int i=0; i<10; ++i ) {
185 test_single_2.
value(xprofile);
189 *outStream << calls.clone_ << std::endl;
190 if( calls.clone_ > 1 ) { errorFlag++; }
198 bool vcm_pass =
true;
200 *outStream <<
"Testing VectorCloneMap: ";
202 auto x_value = test_multi.
value_x(*x);
203 auto y_value = test_multi.
value_y(*y);
204 auto z_value = test_multi.
value_z(*z);
206 auto errx = std::abs(x_value-20.0);
207 auto erry = std::abs(y_value-40.0);
208 auto errz = std::abs(z_value-80.0);
210 if( errx>errtol ) { vcm_pass =
false; errorFlag++; }
211 if( erry>errtol ) { vcm_pass =
false; errorFlag++; }
212 if( errz>errtol ) { vcm_pass =
false; errorFlag++; }
214 if( vcm_pass ) { *outStream <<
"Works!" << std::endl; }
216 *outStream <<
"Error tolerance exceeded!" << std::endl;
217 *outStream <<
"x_value was " << x_value <<
", should be 20." << std::endl;
218 *outStream <<
"y_value was " << y_value <<
", should be 40." << std::endl;
219 *outStream <<
"z_value was " << z_value <<
", should be 80." << std::endl;
223 catch (std::logic_error err) {
224 *outStream << err.what() <<
"\n";
229 std::cout <<
"End Result: TEST FAILED\n";
231 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_
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
basic_nullstream< char, char_traits< char >> nullstream
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_