63 #include "Teuchos_GlobalMPISession.hpp"
67 int main(
int argc,
char *argv[]) {
71 typedef std::vector<RealT> vector;
78 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
81 int iprint = argc - 1;
82 ROL::Ptr<std::ostream> outStream;
85 outStream = ROL::makePtrFromRef(std::cout);
87 outStream = ROL::makePtrFromRef(bhs);
91 oldFormatState.copyfmt(std::cout);
99 ROL::Ptr<vector> a_ptr = ROL::makePtr<vector>(
100 std::initializer_list<RealT>{4.0,2.0,1.0,3.0});
101 ROL::Ptr<vector> ai_ptr = ROL::makePtr<vector>(
102 std::initializer_list<RealT>{3.0/10.0, -2.0/10.0, -1.0/10.0, 4.0/10.0});
104 ROL::Ptr<vector> x1_ptr = ROL::makePtr<vector>(
105 std::initializer_list<RealT>{1.0,-1.0});
106 ROL::Ptr<vector> b1_ptr = ROL::makePtr<vector>(2);
108 ROL::Ptr<vector> x2_ptr = ROL::makePtr<vector>(2);
109 ROL::Ptr<vector> b2_ptr = ROL::makePtr<vector>(
110 std::initializer_list<RealT>{3.0,-1.0});
112 ROL::Ptr<vector> y3_ptr = ROL::makePtr<vector>(
113 std::initializer_list<RealT>{-2.0,1.0});
114 ROL::Ptr<vector> c3_ptr = ROL::makePtr<vector>(2);
116 ROL::Ptr<vector> y4_ptr = ROL::makePtr<vector>(2);
117 ROL::Ptr<vector> c4_ptr = ROL::makePtr<vector>(
118 std::initializer_list<RealT>{-6.0,1.0});
120 StdLinearOperator A(a_ptr);
121 StdLinearOperator Ai(ai_ptr);
123 SV x1(x1_ptr); SV x2(x2_ptr); SV y3(y3_ptr); SV y4(y4_ptr);
124 SV b1(b1_ptr); SV b2(b2_ptr); SV c3(c3_ptr); SV c4(c4_ptr);
126 RealT tol = ROL::ROL_EPSILON<RealT>();
129 *outStream <<
"\nTest 1: Matrix multiplication" << std::endl;
131 *outStream <<
"x = [" << (*x1_ptr)[0] <<
"," << (*x1_ptr)[1] <<
"]" << std::endl;
132 *outStream <<
"b = [" << (*b1_ptr)[0] <<
"," << (*b1_ptr)[1] <<
"]" << std::endl;
135 RealT error1 = b1.norm();
136 errorFlag += error1 > tol;
137 *outStream <<
"Error = " << error1 << std::endl;
140 *outStream <<
"\nTest 2: Linear solve" << std::endl;
141 A.applyInverse(*x2_ptr,*b2_ptr,tol);
142 *outStream <<
"x = [" << (*x2_ptr)[0] <<
"," << (*x2_ptr)[1] <<
"]" << std::endl;
143 *outStream <<
"b = [" << (*b2_ptr)[0] <<
"," << (*b2_ptr)[1] <<
"]" << std::endl;
146 RealT error2 = x2.norm();
147 errorFlag += error2 > tol;
148 *outStream <<
"Error = " << error2 << std::endl;
151 *outStream <<
"\nTest 3: Transposed matrix multiplication" << std::endl;
152 A.applyAdjoint(*c3_ptr,*y3_ptr,tol);
153 *outStream <<
"y = [" << (*y3_ptr)[0] <<
"," << (*y3_ptr)[1] <<
"]" << std::endl;
154 *outStream <<
"c = [" << (*c3_ptr)[0] <<
"," << (*c3_ptr)[1] <<
"]" << std::endl;
157 RealT error3 = c3.norm();
158 errorFlag += error3 > tol;
159 *outStream <<
"Error = " << error3 << std::endl;
162 *outStream <<
"\nTest 4: Linear solve with transpose" << std::endl;
163 A.applyAdjointInverse(y4,c4,tol);
164 *outStream <<
"y = [" << (*y4_ptr)[0] <<
"," << (*y4_ptr)[1] <<
"]" << std::endl;
165 *outStream <<
"c = [" << (*c4_ptr)[0] <<
"," << (*c4_ptr)[1] <<
"]" << std::endl;
168 RealT error4 = y4.norm();
169 errorFlag += error4 > tol;
170 *outStream <<
"Error = " << error4 << std::endl;
172 *outStream <<
"x1 = "; x1.print(*outStream);
173 Ai.applyInverse(b1,x1,tol);
174 *outStream <<
"b1 = "; b1.print(*outStream);
176 *outStream <<
"b1 = "; b1.print(*outStream);
177 A.applyInverse(x1,b1,tol);
178 *outStream <<
"x1 = "; x1.print(*outStream);
180 *outStream <<
"x1 = "; x1.print(*outStream);
184 catch (std::logic_error& err) {
185 *outStream << err.what() <<
"\n";
190 std::cout <<
"End Result: TEST FAILED\n";
192 std::cout <<
"End Result: TEST PASSED\n";
195 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...
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
basic_nullstream< char, char_traits< char >> nullstream
int main(int argc, char *argv[])