29 #include "Teuchos_GlobalMPISession.hpp"
33 int main(
int argc,
char *argv[]) {
37 typedef std::vector<RealT> vector;
44 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
47 int iprint = argc - 1;
48 ROL::Ptr<std::ostream> outStream;
51 outStream = ROL::makePtrFromRef(std::cout);
53 outStream = ROL::makePtrFromRef(bhs);
57 oldFormatState.copyfmt(std::cout);
65 ROL::Ptr<vector> a_ptr = ROL::makePtr<vector>(
66 std::initializer_list<RealT>{4.0,2.0,1.0,3.0});
67 ROL::Ptr<vector> ai_ptr = ROL::makePtr<vector>(
68 std::initializer_list<RealT>{3.0/10.0, -2.0/10.0, -1.0/10.0, 4.0/10.0});
70 ROL::Ptr<vector> x1_ptr = ROL::makePtr<vector>(
71 std::initializer_list<RealT>{1.0,-1.0});
72 ROL::Ptr<vector> b1_ptr = ROL::makePtr<vector>(2);
74 ROL::Ptr<vector> x2_ptr = ROL::makePtr<vector>(2);
75 ROL::Ptr<vector> b2_ptr = ROL::makePtr<vector>(
76 std::initializer_list<RealT>{3.0,-1.0});
78 ROL::Ptr<vector> y3_ptr = ROL::makePtr<vector>(
79 std::initializer_list<RealT>{-2.0,1.0});
80 ROL::Ptr<vector> c3_ptr = ROL::makePtr<vector>(2);
82 ROL::Ptr<vector> y4_ptr = ROL::makePtr<vector>(2);
83 ROL::Ptr<vector> c4_ptr = ROL::makePtr<vector>(
84 std::initializer_list<RealT>{-6.0,1.0});
86 StdLinearOperator A(a_ptr);
87 StdLinearOperator Ai(ai_ptr);
89 SV x1(x1_ptr); SV x2(x2_ptr); SV y3(y3_ptr); SV y4(y4_ptr);
90 SV b1(b1_ptr); SV b2(b2_ptr); SV c3(c3_ptr); SV c4(c4_ptr);
92 RealT tol = ROL::ROL_EPSILON<RealT>();
95 *outStream <<
"\nTest 1: Matrix multiplication" << std::endl;
97 *outStream <<
"x = [" << (*x1_ptr)[0] <<
"," << (*x1_ptr)[1] <<
"]" << std::endl;
98 *outStream <<
"b = [" << (*b1_ptr)[0] <<
"," << (*b1_ptr)[1] <<
"]" << std::endl;
101 RealT error1 = b1.norm();
102 errorFlag += error1 > tol;
103 *outStream <<
"Error = " << error1 << std::endl;
106 *outStream <<
"\nTest 2: Linear solve" << std::endl;
107 A.applyInverse(*x2_ptr,*b2_ptr,tol);
108 *outStream <<
"x = [" << (*x2_ptr)[0] <<
"," << (*x2_ptr)[1] <<
"]" << std::endl;
109 *outStream <<
"b = [" << (*b2_ptr)[0] <<
"," << (*b2_ptr)[1] <<
"]" << std::endl;
112 RealT error2 = x2.norm();
113 errorFlag += error2 > tol;
114 *outStream <<
"Error = " << error2 << std::endl;
117 *outStream <<
"\nTest 3: Transposed matrix multiplication" << std::endl;
118 A.applyAdjoint(*c3_ptr,*y3_ptr,tol);
119 *outStream <<
"y = [" << (*y3_ptr)[0] <<
"," << (*y3_ptr)[1] <<
"]" << std::endl;
120 *outStream <<
"c = [" << (*c3_ptr)[0] <<
"," << (*c3_ptr)[1] <<
"]" << std::endl;
123 RealT error3 = c3.norm();
124 errorFlag += error3 > tol;
125 *outStream <<
"Error = " << error3 << std::endl;
128 *outStream <<
"\nTest 4: Linear solve with transpose" << std::endl;
129 A.applyAdjointInverse(y4,c4,tol);
130 *outStream <<
"y = [" << (*y4_ptr)[0] <<
"," << (*y4_ptr)[1] <<
"]" << std::endl;
131 *outStream <<
"c = [" << (*c4_ptr)[0] <<
"," << (*c4_ptr)[1] <<
"]" << std::endl;
134 RealT error4 = y4.norm();
135 errorFlag += error4 > tol;
136 *outStream <<
"Error = " << error4 << std::endl;
138 *outStream <<
"x1 = "; x1.print(*outStream);
139 Ai.applyInverse(b1,x1,tol);
140 *outStream <<
"b1 = "; b1.print(*outStream);
142 *outStream <<
"b1 = "; b1.print(*outStream);
143 A.applyInverse(x1,b1,tol);
144 *outStream <<
"x1 = "; x1.print(*outStream);
146 *outStream <<
"x1 = "; x1.print(*outStream);
150 catch (std::logic_error& err) {
151 *outStream << err.what() <<
"\n";
156 std::cout <<
"End Result: TEST FAILED\n";
158 std::cout <<
"End Result: TEST PASSED\n";
161 std::cout.copyfmt(oldFormatState);
Provides the std::vector implementation to apply a linear operator, which is a std::vector representa...
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
basic_nullstream< char, std::char_traits< char >> nullstream
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
int main(int argc, char *argv[])