ddemidov / amgcl

C++ library for solving large sparse linear systems with algebraic multigrid method
http://amgcl.readthedocs.org/
MIT License
723 stars 110 forks source link

Matrix Assembly #245

Open karabelaselias opened 1 year ago

karabelaselias commented 1 year ago

I'm recently saw this amazing lib for AMG. Tried the examples and they perform very well so I wanted to use the lib for my own FE implementation as solver backend, however up til now I was using Petsc for matrix assembly, and I was wondering if there is a possibility to assemble a distributed matrix also with this code, as all the examples used to read in a MatrixMarket format?

To formulate it more precise: Is there an equivalent to https://petsc.org/release/docs/manualpages/Mat/MatSetValues/ from Petsc?

ddemidov commented 1 year ago

Matrix assembly is outside of the library scope, the library expect the user to provide assembled matrices in CSR format. The MM reader is only provided to facilitate examples and experimenting. Here is an example of direct assembly:

https://github.com/ddemidov/amgcl/blob/master/examples/mpi/mpi_solver.cpp#L47

There is also trilinos.epetra adapter that allows using matrices in epetra format as input:

https://github.com/ddemidov/amgcl/blob/master/amgcl/adapter/epetra.hpp

There are other adapters (e.g. eigen adapter) that allow to use assembled matrices in third-party formats.

If PETSc provides direct access to the underlying CSR format, it should be possible to use a similar approach for PETSc matrices.