00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef Matrix_h
00027 #define Matrix_h
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include <iostream.h>
00043 #include <G3Globals.h>
00044
00045 #include <Vector.h>
00046 #include <ID.h>
00047 #include <Message.h>
00048 #include <Tensor.h>
00049
00050 #define MATRIX_VERY_LARGE_VALUE 1.0e213
00051
00081 class Matrix
00082 {
00083 public:
00085 Matrix();
00090 Matrix(int nrows, int ncols);
00091
00100 Matrix(double *data, int nrows, int ncols);
00101
00111 Matrix(const Matrix &M);
00112
00122 ~Matrix();
00123
00124
00126 inline int noRows() const;
00130 inline int noCols() const;
00131
00138 void Zero(void);
00139
00141 int resize(int numRow, int numCol);
00142
00143
00145 int Assemble(const Matrix &,const ID &rows, const ID &cols,
00146 double fact = 1.0);
00147
00149 int Solve(const Vector &V, Vector &res) const;
00151 int Solve(const Matrix &M, Matrix &res) const;
00152
00154 int addMatrix(double factThis, const Matrix &other, double factOther);
00156 int addMatrixProduct(double factThis, const Matrix &A, const Matrix &B, double factOther);
00157 int addMatrixTripleProduct(double factThis, const Matrix &A, const Matrix &B, double factOther);
00158
00159
00161 inline double &operator()(int row, int col);
00163 inline double operator()(int row, int col) const;
00165 Matrix operator()(const ID &rows, const ID & cols) const;
00166
00168 Matrix &operator=(const Matrix &M);
00170 Matrix &operator=(const Tensor &T);
00171
00172
00173
00174
00176 Matrix &operator+=(double fact);
00178 Matrix &operator-=(double fact);
00180 Matrix &operator*=(double fact);
00182 Matrix &operator/=(double fact);
00183
00184
00185
00186
00187
00189 Matrix operator+(double fact) const;
00191 Matrix operator-(double fact) const;
00193 Matrix operator*(double fact) const;
00195 Matrix operator/(double fact) const;
00196
00198 Vector operator*(const Vector &V) const;
00200 Vector operator^(const Vector &V) const;
00201
00202
00204 Matrix operator+(const Matrix &M) const;
00206 Matrix operator-(const Matrix &M) const;
00208 Matrix operator*(const Matrix &M) const;
00210 Matrix operator^(const Matrix &M) const;
00212 Matrix &operator+=(const Matrix &M);
00214 Matrix &operator-=(const Matrix &M);
00215
00217 void Output(ostream &s) const;
00219 void Input(istream &s);
00220
00222 int Assemble(const Matrix &V, int init_row, int init_col, double fact = 1.0);
00224 int AssembleTranspose(const Matrix &V, int init_row, int init_col, double fact = 1.0);
00226 int Extract (const Matrix &V, int init_row, int init_col, double fact = 1.0);
00227
00229 friend ostream &operator<<(ostream &s, const Matrix &M);
00231 friend istream &operator>>(istream &s, Matrix &M);
00233 friend Matrix operator*(double a, const Matrix &M);
00234
00235
00237 friend #include <Vector.h>
00238 friend #include <Message.h>
00239 friend #include <TCP_Socket.h>
00240 friend #include <TCP_SocketNoDelay.h>
00241 friend #include <UDP_Socket.h>
00242 friend #include <MPI_Channel.h>
00243
00244 protected:
00245
00246 private:
00247 static double MATRIX_NOT_VALID_ENTRY;
00249 static double *matrixWork;
00251 static int *intWork;
00253 int numRows;
00255 int numCols;
00257 int dataSize;
00259 double *data;
00261 int fromFree;
00262 };
00263
00264
00265
00266 inline int
00267 Matrix::noRows() const
00268 {
00269 return numRows;
00270 }
00271
00273 inline int
00274 Matrix::noCols() const
00275 {
00276 return numCols;
00277 }
00278
00279
00281 inline double &
00282 Matrix::operator()(int row, int col)
00283 {
00284 #ifdef _G3DEBUG
00285 if ((row < 0) || (row >= numRows)) {
00286 g3ErrorHandler->warning("Matrix::operator() - row %d our of range [0, %d]\n",
00287 row, numRows-1);
00288 return data[0];
00289 } else if ((col < 0) || (col >= numCols)) {
00290 g3ErrorHandler->warning("Matrix::operator() - col %d our of range [0, %d]\n",
00291 col, numCols-1);
00292 return MATRIX_NOT_VALID_ENTRY;
00293 }
00294 #endif
00295 return data[col*numRows + row];
00296 }
00297
00298
00300 inline double
00301 Matrix::operator()(int row, int col) const
00302 {
00303 #ifdef _G3DEBUG
00304 if ((row < 0) || (row >= numRows)) {
00305 g3ErrorHandler->warning("Matrix::operator(row, col) - row %d our of range [0, %d]\n",
00306 row, numRows-1);
00307 return data[0];
00308 } else if ((col < 0) || (col >= numCols)) {
00309 g3ErrorHandler->warning("Matrix::operator(row, col) - col %d our of range [0, %d]\n",
00310 col, numCols-1);
00311 return MATRIX_NOT_VALID_ENTRY;
00312 }
00313 #endif
00314 return data[col*numRows + row];
00315 }
00316
00317 #endif
00318
00319
00320
00321