1
// Copyright (C) 2006-2007 Anders Logg and Garth N. Wells.
2
// Licensed under the GNU LGPL Version 2.1.
4
// Modified by Ola Skavhaug, 2007.
6
// First added: 2006-05-15
7
// Last changed: 2007-12-07
12
#include "GenericMatrix.h"
13
#include <dolfin/main/dolfin_main.h>
15
#include "default_la_types.h"
20
/// This class provides an interface to the default DOLFIN
21
/// matrix implementation as decided in default_la_types.h.
23
class Matrix : public GenericMatrix, public Variable
28
Matrix() : GenericMatrix(), Variable("A", "DOLFIN matrix"),
29
matrix(new DefaultMatrix()) {}
32
Matrix(uint M, uint N) : GenericMatrix(), Variable("A", "DOLFIN matrix"),
33
matrix(new DefaultMatrix(M, N)) {}
36
~Matrix() { delete matrix; }
38
/// Initialize M x N matrix
39
inline void init(uint M, uint N)
40
{ matrix->init(M, N); }
42
/// Initialize zero matrix using sparsity pattern
43
inline void init(const GenericSparsityPattern& sparsity_pattern)
44
{ matrix->init(sparsity_pattern); }
46
/// Create uninitialized matrix
47
inline Matrix* create() const
48
{ return new Matrix(); }
50
/// Create copy of matrix
51
inline Matrix* copy() const
53
Matrix* Mcopy = create();
54
Mcopy->matrix = matrix->copy();
56
// DefaultMatrix* mcopy = matrix->copy();
57
// delete Mcopy->matrix;
58
// Mcopy->matrix = mcopy;
61
/// Return size of given dimension
62
inline uint size(uint dim) const
63
{ return matrix->size(dim); }
65
/// Get block of values
66
inline void get(real* block, uint m, const uint* rows, uint n, const uint* cols) const
67
{ matrix->get(block, m, rows, n, cols); }
69
/// Set block of values
70
inline void set(const real* block, uint m, const uint* rows, uint n, const uint* cols)
71
{ matrix->set(block, m, rows, n, cols); }
73
/// Add block of values
74
inline void add(const real* block, uint m, const uint* rows, uint n, const uint* cols)
75
{ matrix->add(block, m, rows, n, cols); }
77
/// Set all entries to zero and keep any sparse structure (implemented by sub class)
81
/// Set given rows to identity matrix
82
inline void ident(uint m, const uint* rows)
83
{ matrix->ident(m, rows); }
85
/// Finalise assembly of matrix
89
/// Display matrix (sparse output is default)
90
void disp(uint precision = 2) const
91
{ matrix->disp(precision); }
93
/// FIXME: Functions below are not in the GenericVector interface.
94
/// FIXME: Should these be removed or added to the interface?
96
/// Get non-zero values of row i
97
inline void getRow(uint i, int& ncols, Array<int>& columns, Array<real>& values)
98
{ matrix->getRow(i, ncols, columns, values); }
100
/// Return const reference to implementation
101
inline const DefaultMatrix& mat() const
104
/// Return const reference to implementation
105
inline DefaultMatrix& mat()
108
inline LinearAlgebraFactory& factory() const
109
{ return matrix->factory(); }
113
DefaultMatrix* matrix;