~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to dolfin/la/Matrix.h

  • Committer: Johannes Ring
  • Date: 2008-03-05 22:43:06 UTC
  • Revision ID: johannr@simula.no-20080305224306-2npsdyhfdpl2esji
The BIG commit!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2006-2007 Anders Logg and Garth N. Wells.
 
2
// Licensed under the GNU LGPL Version 2.1.
 
3
//
 
4
// Modified by Ola Skavhaug, 2007.
 
5
//
 
6
// First added:  2006-05-15
 
7
// Last changed: 2007-12-07
 
8
 
 
9
#ifndef __MATRIX_H
 
10
#define __MATRIX_H
 
11
 
 
12
#include "GenericMatrix.h"
 
13
#include <dolfin/main/dolfin_main.h>
 
14
 
 
15
#include "default_la_types.h"
 
16
 
 
17
namespace dolfin
 
18
{
 
19
  
 
20
  /// This class provides an interface to the default DOLFIN
 
21
  /// matrix implementation as decided in default_la_types.h.
 
22
  
 
23
  class Matrix : public GenericMatrix, public Variable
 
24
  {
 
25
  public:
 
26
    
 
27
    /// Constructor
 
28
    Matrix() : GenericMatrix(), Variable("A", "DOLFIN matrix"),
 
29
               matrix(new DefaultMatrix()) {}
 
30
    
 
31
    /// Constructor
 
32
    Matrix(uint M, uint N) : GenericMatrix(), Variable("A", "DOLFIN matrix"),
 
33
                             matrix(new DefaultMatrix(M, N)) {}
 
34
    
 
35
    /// Destructor
 
36
    ~Matrix() { delete matrix; }
 
37
    
 
38
    /// Initialize M x N matrix
 
39
    inline void init(uint M, uint N) 
 
40
    { matrix->init(M, N); }
 
41
    
 
42
    /// Initialize zero matrix using sparsity pattern
 
43
    inline void init(const GenericSparsityPattern& sparsity_pattern)
 
44
    { matrix->init(sparsity_pattern); }
 
45
    
 
46
    /// Create uninitialized matrix
 
47
    inline Matrix* create() const
 
48
    { return new Matrix(); }
 
49
 
 
50
    /// Create copy of matrix
 
51
    inline Matrix* copy() const
 
52
    {
 
53
      Matrix* Mcopy = create();
 
54
      Mcopy->matrix = matrix->copy();
 
55
      return Mcopy;
 
56
//       DefaultMatrix* mcopy = matrix->copy();
 
57
//       delete Mcopy->matrix;
 
58
//       Mcopy->matrix = mcopy;
 
59
    }
 
60
 
 
61
    /// Return size of given dimension
 
62
    inline uint size(uint dim) const
 
63
    { return matrix->size(dim); }
 
64
 
 
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); }
 
68
    
 
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); }
 
72
    
 
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); }
 
76
 
 
77
    /// Set all entries to zero and keep any sparse structure (implemented by sub class)
 
78
    inline void zero()
 
79
    { matrix->zero(); }
 
80
    
 
81
    /// Set given rows to identity matrix
 
82
    inline void ident(uint m, const uint* rows)
 
83
    { matrix->ident(m, rows); }
 
84
        
 
85
    /// Finalise assembly of matrix
 
86
    inline void apply()
 
87
    { matrix->apply(); }
 
88
    
 
89
    /// Display matrix (sparse output is default)
 
90
    void disp(uint precision = 2) const
 
91
    { matrix->disp(precision); }
 
92
 
 
93
    /// FIXME: Functions below are not in the GenericVector interface.
 
94
    /// FIXME: Should these be removed or added to the interface?
 
95
 
 
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); }
 
99
    
 
100
    /// Return const reference to implementation
 
101
    inline const DefaultMatrix& mat() const
 
102
    { return *matrix; }
 
103
    
 
104
    /// Return const reference to implementation
 
105
    inline DefaultMatrix& mat()
 
106
    { return *matrix; }
 
107
 
 
108
    inline LinearAlgebraFactory& factory() const
 
109
    { return matrix->factory(); }
 
110
    
 
111
  private:
 
112
 
 
113
    DefaultMatrix* matrix;
 
114
    
 
115
  };
 
116
 
 
117
}
 
118
 
 
119
#endif