46 #include <tests/myratest.h> 54 template<
class InstantiatedNumber>
class solveL_Action
57 typedef InstantiatedNumber Number;
59 : solver(in_solver) { }
60 std::pair<int,int> size()
const 61 {
int N = solver.size();
return std::pair<int,int>(N,N); }
63 { X.
assign(B); solver.solveL(X,
'L',
'N'); }
69 template<
class InstantiatedNumber>
class solveU_Action
72 typedef InstantiatedNumber Number;
74 : solver(in_solver) { }
75 std::pair<int,int> size()
const 76 {
int N = solver.size();
return std::pair<int,int>(N,N); }
78 { X.
assign(B); solver.solveU(X,
'L',
'N'); }
84 template<
class InstantiatedNumber>
class gmres_Action
89 typedef InstantiatedNumber Number;
93 gmres_Action(
const Action<Number>& in_A, Precision in_tol,
int in_iter)
94 : A(in_A), tol(in_tol), iter(in_iter) { M = make_IdentityAction<Number>(A.
size().first); }
97 std::pair<int,int> size()
const 102 { X.
zero();
auto output = gmres(M,A,B,X,tol,iter); }
117 myra::out() << typestring<Number>() << std::endl;
120 Precision sigma = 2.0;
121 for (
int n = 0; n < N; ++n)
128 auto a = make_GemmAction(A);
129 auto i = make_IdentityAction<Number>(N);
138 auto result = gmres(z,a,b,x,tolerance,500);
139 Precision error = euclidean(A*x-b) / euclidean(b);
140 myra::out() <<
"gmres, left ILU:" << std::endl;
141 myra::out() <<
" |Ax-b| = " << error << std::endl;
142 myra::out() <<
" iteration count = " << result.history.size() << std::endl;
143 myra::out() << std::endl;
144 REQUIRE(error < tolerance*100);
150 auto result = fgmres(z,a,i,b,x,tolerance,500);
151 Precision error = euclidean(A*x-b) / euclidean(b);
152 myra::out() <<
"fgmres, left ILU:" << std::endl;
153 myra::out() <<
" |Ax-b| = " << error << std::endl;
154 myra::out() <<
" iteration count = " << result.history.size() << std::endl;
155 myra::out() << std::endl;
156 REQUIRE(error < tolerance*100);
162 auto result = fgmres(i,a,z,b,x,tolerance,500);
163 Precision error = euclidean(A*x-b) / euclidean(b);
164 myra::out() <<
"fgmres, right ILU:" << std::endl;
165 myra::out() <<
" |Ax-b| = " << error << std::endl;
166 myra::out() <<
" iteration count = " << result.history.size() << std::endl;
167 myra::out() << std::endl;
168 REQUIRE(error < tolerance*100);
174 auto result = fgmres(l,a,u,b,x,tolerance,500);
175 Precision error = euclidean(A*x-b) / euclidean(b);
176 myra::out() <<
"fgmres, split ILU:" << std::endl;
177 myra::out() <<
" |Ax-b| = " << error << std::endl;
178 myra::out() <<
" iteration count = " << result.history.size() << std::endl;
179 myra::out() << std::endl;
180 REQUIRE(error < tolerance*100);
186 auto result = gmres(z,a,b,x,tolerance,20,20);
187 Precision error = euclidean(A*x-b) / euclidean(b);
188 myra::out() <<
"restarted gmres, left ILU:" << std::endl;
189 myra::out() <<
" |Ax-b| = " << error << std::endl;
190 myra::out() <<
" iteration count = " << result.history.size() << std::endl;
191 myra::out() << std::endl;
198 auto result = fgmres(z,a,g,b,x,tolerance,500);
199 Precision error = euclidean(A*x-b) / euclidean(b);
200 myra::out() <<
"fgmres, left ILU and right inner gmres:" << std::endl;
201 myra::out() <<
" |Ax-b| = " << error << std::endl;
202 myra::out() <<
" iteration count = " << result.history.size() << std::endl;
203 myra::out() << std::endl;
204 REQUIRE(error < tolerance*100);
213 auto result = gmres(z,a,g,b,x,tolerance,500);
214 Precision error = euclidean(A*x-b) / euclidean(b);
215 myra::out() <<
"gmres, left ILU and right inner gmres:" << std::endl;
216 myra::out() <<
" |Ax-b| = " << error << std::endl;
217 myra::out() <<
" iteration count = " << result.history.size() << std::endl;
218 myra::out() << std::endl;
226 ADD_TEST(
"fgmres",
"[iterative]")
228 test<NumberD>(20,20,1.0e-8);
229 test<NumberZ>(20,20,1.0e-8);
232 ADD_TEST(
"fgmres_big",
"[iterative][.]")
234 test<NumberD>(100,50,1.0e-8);
235 test<NumberZ>(100,50,1.0e-8);
Routines for computing euclidean norm of a Vector/VectorRange, or normalizing a Vector/VectorRange to...
Action< typename UserClass::Number > make_UserAction(const UserClass &u)
Helper function to adapt some user code (encapsulated in a class) into an Action. ...
Definition: UserAction.h:61
Incompletely factors A ~= L*U, presents approximate solve() method.
Definition: ILUSolver.h:28
Interface class for representing subranges of dense Matrix's.
Interface class for representing subranges of dense Vector's.
Applies the "Action" of a linear operator, b := A*x, used in iterative solution algorithms.
Variety of routines for mixed dense*sparse or dense*sparse matrix multiplies. The dense*dense case is...
void assign(const CMatrixRange< Number > &that) const
Assigns the values in *this with the values in that.
Definition: MatrixRange.cpp:268
Linear system solution via gmres (for invertible action A)
Simplistic timing class, might dispatch to platform specific timers depending upon environment...
static SparseMatrix< Number > random(int I, int J, int N)
Generates a random SparseMatrix with size IxJ and (approximately) N nonzeros.
Definition: SparseMatrix.cpp:493
Linear system solution via (flexible) fgmres (for invertible action A)
General purpose compressed-sparse-column (CSC) container.
static Vector< Number > random(int N)
Generates a random Vector of specified size.
Definition: Vector.cpp:276
Represents a const MatrixRange.
Definition: bothcat.h:22
An Action that is just the identity operator.
Definition: stlprint.h:32
Adapts user code (encapsulated in a class) into an Action.
Action< typename ReflectNumber< Solver >::type > make_SolveAction(const Solver &solver, char op='N')
Free function for making SolveAction's.
Definition: SolveAction.h:67
Routines for printing the contents of various std::container's to a std::ostream using operator <<...
Various utility functions/classes related to scalar Number types.
Signatures for sparse matrix * dense vector multiplies. All delegate to gemm() under the hood...
Represents a mutable MatrixRange.
Definition: conjugate.h:26
static Vector< Number > zeros(int N)
Generates a zeros Vector of specified size.
Definition: Vector.cpp:280
Composes two Action's A and B, yielding an Action that cascades A*(B*X)
General purpose dense matrix container, O(i*j) storage.
Range/Iterator types associated with Pattern.
Applies the "Action" of a linear operator, b := A*x.
Definition: Action.h:29
Container for either a column vector or row vector (depends upon the usage context) ...
Reflects Precision trait for a Number, scalar Number types should specialize it.
Definition: Number.h:33
Container class for a sparse nonzero pattern, used in reordering/symbolic analysis.
Overwrites a LowerMatrix, DiagonalMatrix, or square Matrix with its own inverse. Or, returns it as a copy.
Adapts a class with a .solve() method into an Action.
An Action for multiplying by a dense Matrix or SparseMatrix using gemm().
Returns frobenius norm of a SparseMatrix.
std::pair< int, int > size() const
Size inspector.
Definition: Matrix.cpp:116
Incomplete LU preconditioner. Presents a solve() function, but it's only approximate.
Returns cumulative sum of a std::vector<T>. Reversible by diff()
void zero() const
Assigns zero to every entry.
Definition: MatrixRange.cpp:362
Helper routines for reordering/filling 2D structured grids. Used by many unit tests.
Range/Iterator types associated with SparseMatrix.