![]() |
00001 // Copyright (C) 2002 Johan Hoffman and Anders Logg. 00002 // Licensed under the GNU GPL Version 2. 00003 // 00004 // Modified by: Georgios Foufas 2002, 2003 00005 // Erik Svensson, 2003 00006 00007 #ifndef __SPARSE_MATRIX_H 00008 #define __SPARSE_MATRIX_H 00009 00010 #include <dolfin/dolfin_log.h> 00011 #include <dolfin/constants.h> 00012 #include <dolfin/GenericMatrix.h> 00013 00014 namespace dolfin { 00015 00016 class DenseMatrix; 00017 00018 class SparseMatrix : public GenericMatrix { 00019 public: 00020 00021 SparseMatrix (); 00022 SparseMatrix (unsigned int m, unsigned int n); 00023 SparseMatrix (const SparseMatrix& A); 00024 SparseMatrix (const DenseMatrix& A); 00025 ~SparseMatrix (); 00026 00027 void init(unsigned int m, unsigned int n); 00028 void clear(); 00029 00030 unsigned int size(unsigned int dim) const; 00031 unsigned int size() const; 00032 unsigned int rowsize(unsigned int i) const; 00033 unsigned int bytes() const; 00034 00035 real operator()(unsigned int i, unsigned int j) const; 00036 real* operator[](unsigned int i); 00037 real operator()(unsigned int i, unsigned int& j, unsigned int pos) const; 00038 00039 void operator= (real a); 00040 void operator= (const DenseMatrix& A); 00041 void operator= (const SparseMatrix& A); 00042 void operator+= (const DenseMatrix& A); 00043 void operator+= (const SparseMatrix& A); 00044 void operator-= (const DenseMatrix& A); 00045 void operator-= (const SparseMatrix& A); 00046 void operator*= (real a); 00047 00048 real norm() const; 00049 00050 real mult (const Vector& x, unsigned int i) const; 00051 void mult (const Vector& x, Vector& Ax) const; 00052 void multt (const Vector& x, Vector& Ax) const; 00053 void mult (const SparseMatrix& B, SparseMatrix& AB) const; 00054 real multrow (const Vector& x, unsigned int i) const; 00055 real multcol (const Vector& x, unsigned int j) const; 00056 00057 void resize(); 00058 void ident(unsigned int i); 00059 void lump(Vector& a) const; 00060 void addrow(); 00061 void addrow(const Vector& x); 00062 void initrow(unsigned int i, unsigned int rowsize); 00063 bool endrow(unsigned int i, unsigned int pos) const; 00064 void settransp(const DenseMatrix& A); 00065 void settransp(const SparseMatrix& A); 00066 real rowmax(unsigned int i) const; 00067 real colmax(unsigned int i) const; 00068 real rowmin(unsigned int i) const; 00069 real colmin(unsigned int i) const; 00070 real rowsum(unsigned int i) const; 00071 real colsum(unsigned int i) const; 00072 real rownorm(unsigned int i, unsigned int type) const; 00073 real colnorm(unsigned int i, unsigned int type) const; 00074 00075 void show() const; 00076 friend LogStream& operator<< (LogStream& stream, const SparseMatrix& A); 00077 00078 friend class DenseMatrix; 00079 00080 protected: 00081 00082 void alloc(unsigned int m, unsigned int n); 00083 00084 real read (unsigned int i, unsigned int j) const; 00085 void write (unsigned int i, unsigned int j, real value); 00086 void add (unsigned int i, unsigned int j, real value); 00087 void sub (unsigned int i, unsigned int j, real value); 00088 void mult (unsigned int i, unsigned int j, real value); 00089 void div (unsigned int i, unsigned int j, real value); 00090 00091 real** getvalues(); 00092 real** const getvalues() const; 00093 00094 void initperm(); 00095 void clearperm(); 00096 00097 unsigned int* getperm(); 00098 unsigned int* const getperm() const; 00099 00100 private: 00101 00102 void resizeRow(unsigned int i,unsigned int rowsize); 00103 00104 // Data 00105 unsigned int* rowsizes; 00106 int** columns; 00107 real** values; 00108 00109 // Additional size to allocate when needed 00110 unsigned int allocsize; 00111 00112 }; 00113 00114 } 00115 00116 #endif
Documentation automatically generated with Doxygen on 10 Sep 2004.