cpmech / gosl

Linear algebra, eigenvalues, FFT, Bessel, elliptic, orthogonal polys, geometry, NURBS, numerical quadrature, 3D transfinite interpolation, random numbers, Mersenne twister, probability distributions, optimisation, differential equations.
BSD 3-Clause "New" or "Revised" License
1.83k stars 145 forks source link

Iterative solver for sparse linear systems with supporting of initial guess. #28

Closed hleb-albau closed 6 years ago

hleb-albau commented 6 years ago

Hi @cpmech, is there any iterative solver for sparce linear systems with supporting of linitial guess?

For example, something like scipy scipy.sparse.linalg.bicgstab method.

P.S. If no, I am interested in contributing.

cpmech commented 6 years ago

Hi, we don't have this kind of solver yet and YES: your contribution is very welcome. Thanks. Dorival

hleb-albau commented 6 years ago

@cpmech Could you, please, give me a short start point? what module should I extend (or create)? Also as far, as I understand, scipy generate Python code from FORTRAN bicgstab implementation using f2py.

If it is so complicated, instead of writing code myself, I can attach bounty using gitcoin.

cpmech commented 6 years ago

Sure and thanks!

The sparse solver follows the interface given here: https://github.com/cpmech/gosl/blob/master/la/sparse_solver.go

It's actually pretty straightforward:

type SparseSolver interface {
    Init(t *Triplet, symmetric, verbose bool, ordering, scaling string, comm *mpi.Communicator)
    Free()
    Fact()
    Solve(x, b Vector, bIsDistr bool)
}

Usage is something like this:

    // initialise solver
    mysolver.Init(mytriplet, false, false, "", "", nil)

    // factorise
    mysolver.Fact()

    // solve
    x := NewVector(len(b))
    mysolve.Solve(x, b, false) // x := inv(A) * b

I would suggesting copying https://github.com/cpmech/gosl/blob/master/la/sparse_solver_umfpack.go and renaming to sparse_solver_bicgstab.go Then, it's just a matter of filling the gaps.

Also, I'd suggest using https://github.com/cpmech/gosl/blob/master/la/t_sp_solver_umfpack_test.go as an example to implement unit tests.

Please feel free to contact me again (direct message by email is fine) with your files then I can have a look and provide help.

cpmech commented 6 years ago

By the way, as you've mentioned, support for an initial guess would have to be considered as well. To do so, we would have to change the SparseSolver interface and this would require changes to UMFPACK and MUMPS solvers. I'm happy to do that as soon as we known what kind of interface is required. Thanks. D

cpmech commented 6 years ago

All right! SparseSolver.Init now takes SpArgs as input which includes a Guess field that can be used with iterative solvers. Also, in this way, it's easier to expand the capabilities of SparseSolver. See changes here: https://github.com/cpmech/gosl/commit/a1ea1401470848da6ab86058348147e72711c337

hleb-albau commented 6 years ago

Hi @cpmech, thanks for fast responses. I will pick up it next week.

cpmech commented 6 years ago

no worries! and thanks!