dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #02353
Re: More thoughts on the linear algebra
On Thu, Apr 06, 2006 at 04:33:14PM -0500, Anders Logg wrote:
> I thought about the linear algebra some more...
>
> If we make the main interface a template, doesn't that mean we need to
> template all the assembly routines?
>
> My suggestion would therefore be to do the usual envelope-letter design
> that we have in other places with a class Matrix as the common
> interface, but at the same time allow users to work with the
> DenseMatrix class. If someone needs to do something which is more
> efficient with the DenseMatrix class or do something which is not
> supported by the common interface, then use a DenseMatrix.
>
> If we then supply constructors in Matrix that accept as arguments
> either SparseMatrix or DenseMatrix, one can call the assembly routines
> (which take as input a Matrix) with a DenseMatrix as well as with a
> Matrix.
>
> This way, there would be no overhead in accessing individual elements
> (if you work through the DenseMatrix interface) and there would be a
> common interface Matrix which can be used whenever someone does not
> have special need for individual accessing.
>
> /Anders
More thoughts:
In Matrix we add copy constructors (and assignment) for the types
SparseMatrix and DenseMatrix, which enables the following:
DenseMatrix A;
Matrix B(A);
SparseMatrix A;
Matrix B(A);
These copy constructors take a (non-const) reference and just use the
data provided. No copying. This is the same as for the Function class
where one can create a Function from a Vector (and using the storage
provided by the given Vector).
We can also create copy constructors (and assignment) in the other
direction:
Matrix A;
DenseMatrix B(A);
Matrix A;
SparseMatrix B(A);
These would copy the values (not just pick the data).
One should also be able to convert between SparseMatrix and
DenseMatrix:
DenseMatrix A;
SparseMatrix B(A);
SparseMatrix A;
DenseMatrix B(A);
These also copy the values.
The thing that might be missing from the picture is how to get the
DenseMatrix storage from a given Matrix, something like
Matrix A;
DenseMatrix& B = A.denseMatrixStorage();
I'd like to say that we don't need this. If someone wants to work with
dense matrices, then just use DenseMatrix all the time. A DenseMatrix
can be given as argument to the assembly routines, solvers etc, so
there is no need to create a Matrix and then get the DenseMatrix
behind it.
What do think?
It would be more work to maintain than the template solution, but it
looks simpler to the user and it doesn't propagate like the template
solution does (forcing everything to be a template).
We can also pick a minimum of functions to put in the common interface
Matrix.
/Anders
Follow ups
References