![]() |
00001 // Copyright (C) 2002 Johan Hoffman and Anders Logg. 00002 // Licensed under the GNU GPL Version 2. 00003 // 00004 // Modified by Erik Svensson, 2003, 2004. 00005 00006 #ifndef __MATRIX_H 00007 #define __MATRIX_H 00008 00009 #include <dolfin/dolfin_log.h> 00010 #include <dolfin/constants.h> 00011 #include <dolfin/Variable.h> 00012 #include <dolfin/General.h> 00013 00014 namespace dolfin { 00015 00016 class Vector; 00017 class GenericMatrix; 00018 00031 00032 class Matrix : public Variable { 00033 public: 00034 00036 enum Type {sparse, dense, generic}; 00037 00039 Matrix(Type type = sparse); 00040 00042 Matrix(unsigned int m, unsigned int n, Type type = sparse); 00043 00045 Matrix(const Matrix& A); 00046 00048 virtual ~Matrix(); 00049 00050 // Forward declaration of nested classes 00051 class Element; 00052 class Row; 00053 class Column; 00054 00056 00058 virtual void init(unsigned int m, unsigned int n, Type type = sparse); 00059 00061 virtual void clear(); 00062 00064 00066 virtual Type type() const; 00067 00069 virtual unsigned int size(unsigned int dim) const; 00070 00072 virtual unsigned int size() const; 00073 00075 virtual unsigned int rowsize(unsigned int i) const; 00076 00078 virtual unsigned int bytes() const; 00079 00081 00083 virtual real operator()(unsigned int i, unsigned int j) const; 00084 00086 virtual Element operator()(unsigned int i, unsigned int j); 00087 00089 virtual Row operator()(unsigned int i, Range j); 00090 00092 virtual Row operator()(Index i, Range j); 00093 00095 virtual Column operator()(Range i, unsigned int j); 00096 00098 virtual Column operator()(Range i, Index j); 00099 00101 virtual real* operator[](unsigned int i) const; 00102 00104 virtual real operator()(unsigned int i, unsigned int& j, unsigned int pos) const; 00105 00107 virtual void operator=(real a); 00108 00110 virtual void operator=(const Matrix& A); 00111 00113 virtual void operator+=(const Matrix& A); 00114 00116 virtual void operator-=(const Matrix& A); 00117 00119 virtual void operator*=(real a); 00120 00122 00124 virtual real norm() const; 00125 00127 virtual real mult(const Vector& x, unsigned int i) const; 00128 00130 virtual void mult(const Vector& x, Vector& Ax) const; 00131 00133 virtual void multt(const Vector& x, Vector &Ax) const; 00134 00136 virtual void mult(const Matrix& B, Matrix& AB) const; 00137 00139 virtual real multrow(const Vector& x, unsigned int i) const; 00140 00142 virtual real multcol(const Vector& x, unsigned int j) const; 00143 00145 virtual void transp(Matrix& At) const; 00146 00148 virtual void solve(Vector& x, const Vector& b); 00149 00151 virtual void inverse(Matrix& Ainv); 00152 00154 virtual void hpsolve(Vector& x, const Vector& b) const; 00155 00157 virtual void lu(); 00158 00160 virtual void solveLU(Vector& x, const Vector& b) const; 00161 00163 virtual void inverseLU(Matrix& Ainv) const; 00164 00166 virtual void hpsolveLU(const Matrix& LU, Vector& x, const Vector& b) const; 00167 00169 00171 virtual void resize(); 00172 00174 virtual void ident(unsigned int i); 00175 00177 virtual void lump(Vector& a) const; 00178 00180 virtual void addrow(); 00181 00183 virtual void addrow(const Vector& x); 00184 00186 virtual void initrow(unsigned int i, unsigned int rowsize); 00187 00189 virtual bool endrow(unsigned int i, unsigned int pos) const; 00190 00192 virtual void settransp(const Matrix& A); 00193 00195 virtual real rowmax(unsigned int i) const; 00196 00198 virtual real colmax(unsigned int i) const; 00199 00201 virtual real rowmin(unsigned int i) const; 00202 00204 virtual real colmin(unsigned int i) const; 00205 00207 virtual real rowsum(unsigned int i) const; 00208 00210 virtual real colsum(unsigned int i) const; 00211 00213 virtual real rownorm(unsigned int i,unsigned int type) const; 00214 00216 virtual real colnorm(unsigned int i,unsigned int type) const; 00217 00219 00221 virtual void show() const; 00222 00224 friend LogStream& operator<< (LogStream& stream, const Matrix& A); 00225 00227 00229 class Element { 00230 public: 00231 00232 Element(Matrix& matrix, unsigned int i, unsigned int j); 00233 00234 operator real() const; 00235 00236 void operator= (real a); 00237 void operator= (const Element& e); 00238 void operator+= (real a); 00239 void operator-= (real a); 00240 void operator*= (real a); 00241 void operator/= (real a); 00242 00243 00244 protected: 00245 00246 Matrix& A; 00247 unsigned int i; 00248 unsigned int j; 00249 00250 }; 00251 00253 class Row { 00254 public: 00255 00256 Row(Matrix& matrix, unsigned int i, Range j); 00257 Row(Matrix& matrix, Index i, Range j); 00258 00259 unsigned int size() const; 00260 00261 real max() const; 00262 real min() const; 00263 real sum() const; 00264 real norm(unsigned int type) const; 00265 00266 real operator() (unsigned int j) const; 00267 Element operator()(unsigned int j); 00268 00269 void operator= (const Row& row); 00270 void operator= (const Column& col); 00271 void operator= (const Vector& x); 00272 00273 real operator* (const Vector& x) const; 00274 00275 friend class Column; 00276 00277 private: 00278 00279 Matrix& A; 00280 unsigned int i; 00281 Range j; 00282 00283 }; 00284 00286 class Column { 00287 public: 00288 00289 Column(Matrix& matrix, Range i, unsigned int j); 00290 Column(Matrix& matrix, Range i, Index j); 00291 00292 unsigned int size() const; 00293 00294 real max() const; 00295 real min() const; 00296 real sum() const; 00297 real norm(unsigned int type) const; 00298 00299 real operator() (unsigned int i) const; 00300 Element operator()(unsigned int i); 00301 00302 void operator= (const Column& col); 00303 void operator= (const Row& row); 00304 void operator= (const Vector& x); 00305 00306 real operator* (const Vector& x) const; 00307 00308 friend class Row; 00309 00310 private: 00311 00312 Matrix& A; 00313 Range i; 00314 unsigned int j; 00315 00316 }; 00317 00318 friend class DirectSolver; 00319 friend class Element; 00320 00321 private: 00322 00324 real** values(); 00325 00327 real** const values() const; 00328 00330 void initperm(); 00331 00333 void clearperm(); 00334 00336 unsigned int* permutation(); 00337 00339 unsigned int* const permutation() const; 00340 00341 GenericMatrix* A; 00342 Type _type; 00343 00344 }; 00345 00346 } 00347 00348 #endif
Documentation automatically generated with Doxygen on 10 Sep 2004.