Giter Site home page Giter Site logo

faer-gmres's Introduction

About

Crates.io status

GMRES in rust using faer.

Solves linear systems of the form: Ax=b, where A is sparse. Depends on faer for sparse matrix implementation.

Use

Example use:

use faer_gmres::gmres;
use faer::prelude::*;
use faer::sparse::*;
use faer::mat;

// create faer sparse mat from triplets
let a_test_triplets = vec![
    (0, 0, 1.0),
    (1, 1, 2.0),
    (2, 2, 3.0),
    ];
let a_test = SparseColMat::<usize, f64>::try_new_from_triplets(
    3, 3,
    &a_test_triplets).unwrap();

// rhs
let b = faer::mat![
    [2.0],
    [2.0],
    [2.0],
    ];

// init sol guess
// Note: x is modified in-place, the result is stored in x
let mut x = faer::mat![
    [0.0],
    [0.0],
    [0.0],
    ];

// the final None arg means do not apply left preconditioning
let (err, iters) = gmres(a_test.as_ref(), b.as_ref(), x.as_mut(), 10, 1e-8, None).unwrap();
println!("Result x: {:?}", x);
println!("Error x: {:?}", err);
println!("Iters : {:?}", iters);

Preconditioned GMRES:

A preconditioner can be supplied:

// continued from above...
use faer_gmres::{JacobiPreconLinOp};
let jacobi_pre = JacobiPreconLinOp::new(a_test.as_ref());
let (err, iters) = gmres(a_test.as_ref(), b.as_ref(), x.as_mut(), 10, 1e-8, Some(&jacobi_pre)).unwrap();

Restarted GMRES:

A restarted GMRES routine is provided:

use faer_gmres::restarted_gmres;
let max_inner = 30;
let max_outer = 50;
let (err, iters) = restarted_gmres(
    a_test.as_ref(), b.as_ref(), x.as_mut(), max_inner, max_outer, 1e-8, None).unwrap();

This will repeatedly call the inner GMRES routine, using the previous outer iteration's solution as the inital guess for the next outer solve. The current implementation of restarted GMRES in this package can reduce the memory requirements needed, but slow convergence.

TODO

  • Python bindings
  • Additional tests
  • Benchmarks
  • Performance improvements

References and Credits

This package is an adaptation of GMRES implementation by RLando:

License

MIT

faer-gmres's People

Contributors

wgurecky avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.