Dec 26, 2010 at 3:15 PM
Edited Dec 26, 2010 at 3:16 PM

Hello,
I am using the iterative solvers like
GpBiCg solver = new GpBiCg();
solver.SetIterator(Iterator.CreateDefault());
solver.SetPreconditioner(new Diagonal());
solution = (Vector)solver.Solve(A, b);
Now I wanted to use the ISolver interface to easily exchange the solver, something like
// Test program
void Test()
{
ISolver<double> solver = new GpBiCg();
solver.SetIterator(Iterator.CreateDefault());
solver.SetPreconditioner(new Diagonal());
Vector c = fem.Solve(solver);
}
// In FEM library
Vector Solve(ISolver<double> solver)
{
return (Vector)solver.Solve(A, b);
}
At the moment it's not working. But I hope I'm doing things like you intended with the interface!?
I guess it's just a missing method signature, like
Vector<T> Solve(Matrix<T> A, Vector<T> b);
Regards,
Chris


Dec 27, 2010 at 12:26 PM
Edited Dec 27, 2010 at 12:30 PM

Hi Chris,
I think the problem is that GpBiCg implements IIterativeSolver, not I Solver. Below compiles:
void Test()
{
var solver = new GpBiCg();
solver.SetIterator(Iterator.CreateDefault());
solver.SetPreconditioner(new Diagonal());
Vector c = Solve(solver);
}
// In FEM library
Vector Solve(IIterativeSolver<double> solver)
{
var A = new SparseMatrix(2, 2);
var b = new SparseVector(2);
return (Vector)solver.Solve(A, b);
}
Note I'm not using IIterativceSolver<double> solver = new GpBiCg(), since SetPreconditioner is not part of the IIterativeSolver or ISolver interface.
I guess the question is should IIterativeSolver extend ISolver? The person who initial designed this interface is no longer with the project. But I'm assuming he had a reason not extending ISolver, I just need to figure what it was.
Regards,
Marcus



Now I recall the conversation. ISolver is for direct solvers, such as factorization based solvers  given a factorized matrix and b vector, solve for x. You could call solve multiple times with different x vectors and A wouldn't have to be factored
more than once. Hence the lack of a Vector Solve(Matrix A, vector b) method in ISolver.

