OPM/opm-core — pull request #704 by jorgekva (2014-12-12 04:28:19+00:00)
Title: Support for multiple linear solver library containers

More details are found in the commit messages and source file comments, but a short summary:

These three patches implement support for a unified linear solver interface for programmers. For most cases they should act as thin wrappers to whatever native type want, with the option of quickly replacing said native type at a later stage (if that type is supported).

The first patch commits the interface itself, the second and third implements the CSR reference implementation and Dune BCRS respectively.

In addition this introduces the similar SparseMatrixBuilder. A lot of linear solver libraries use the same class and type for matrices in the building phase and matrices that are "ready" and fixed. My proposal is that these processes are to be separated explicitly so we don't have to juggle state and sometimes-legal-operations. Safer & nicer code.

This is a part of the process to support multiple linear solvers backends in OPM. The idea is that LinearSolverInterface and friends later can be aware of these interfaces and give them to their algorithms as desired.

I have done as much as I can to abstract away all nastiness from user-facing code, although the files themselves are quite daunting. Most of the complexity comes from trying to be both type safe, flexible and easy to use at once.

In user code it is as simple as:

SparseMatrix< CSR< double > /* or some other type */ > matrix;
matrix[ i ][ j ] *= 2;

The use of auto should make it even more pleasant to use.

The implementation itself is not quite yet complete - a few things must still be figured out, such as Dune::BCRSMatrix as storage for MatrixBuilder and move semantics, but most of the implementation should be ok for experimental use.