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 <OPS_Globals.h>
00043
00044 class Vector;
00045 class ID;
00046 class Message;
00047
00048 #include <Tensor.h>
00049
00050
00051 #define MATRIX_VERY_LARGE_VALUE 1.0e213
00052
00053 class Matrix
00054 {
00055 public:
00056
00057 Matrix();
00058 Matrix(int nrows, int ncols);
00059 Matrix(double *data, int nrows, int ncols);
00060 Matrix(const Matrix &M);
00061 ~Matrix();
00062
00063
00064 int setData(double *newData, int nRows, int nCols);
00065 inline int noRows() const;
00066 inline int noCols() const;
00067 void Zero(void);
00068 int resize(int numRow, int numCol);
00069
00070 int Assemble(const Matrix &,const ID &rows, const ID &cols,
00071 double fact = 1.0);
00072
00073 int Solve(const Vector &V, Vector &res) const;
00074 int Solve(const Matrix &M, Matrix &res) const;
00075 int Invert(Matrix &res) const;
00076
00077 int addMatrix(double factThis, const Matrix &other, double factOther);
00078 int addMatrixProduct(double factThis, const Matrix &A, const Matrix &B, double factOther);
00079 int addMatrixTripleProduct(double factThis, const Matrix &A, const Matrix &B, double factOther);
00080
00081
00082
00083 inline double &operator()(int row, int col);
00084 inline double operator()(int row, int col) const;
00085 Matrix operator()(const ID &rows, const ID & cols) const;
00086
00087 Matrix &operator=(const Matrix &M);
00088 Matrix &operator=(const Tensor &T);
00089
00090
00091
00092
00093
00094 Matrix &operator+=(double fact);
00095 Matrix &operator-=(double fact);
00096 Matrix &operator*=(double fact);
00097 Matrix &operator/=(double fact);
00098
00099
00100
00101
00102
00103
00104 Matrix operator+(double fact) const;
00105 Matrix operator-(double fact) const;
00106 Matrix operator*(double fact) const;
00107 Matrix operator/(double fact) const;
00108
00109
00110 Vector operator*(const Vector &V) const;
00111 Vector operator^(const Vector &V) const;
00112
00113
00114
00115 Matrix operator+(const Matrix &M) const;
00116 Matrix operator-(const Matrix &M) const;
00117 Matrix operator*(const Matrix &M) const;
00118
00119 Matrix operator^(const Matrix &M) const;
00120 Matrix &operator+=(const Matrix &M);
00121 Matrix &operator-=(const Matrix &M);
00122
00123
00124 void Output(OPS_Stream &s) const;
00125
00126
00127
00128 int Assemble(const Matrix &V, int init_row, int init_col, double fact = 1.0);
00129 int AssembleTranspose(const Matrix &V, int init_row, int init_col, double fact = 1.0);
00130 int Extract (const Matrix &V, int init_row, int init_col, double fact = 1.0);
00131
00132 friend OPS_Stream &operator<<(OPS_Stream &s, const Matrix &M);
00133
00134 friend Matrix operator*(double a, const Matrix &M);
00135
00136
00137 friend class Vector;
00138 friend class Message;
00139 friend class TCP_Socket;
00140 friend class TCP_SocketNoDelay;
00141 friend class UDP_Socket;
00142 friend class MPI_Channel;
00143 friend class MySqlDatastore;
00144 friend class BerkeleyDbDatastore;
00145
00146 protected:
00147
00148 private:
00149 static double MATRIX_NOT_VALID_ENTRY;
00150 static double *matrixWork;
00151 static int *intWork;
00152 static int sizeDoubleWork;
00153 static int sizeIntWork;
00154
00155 int numRows;
00156 int numCols;
00157 int dataSize;
00158 double *data;
00159 int fromFree;
00160 };
00161
00162
00163
00164 inline int
00165 Matrix::noRows() const
00166 {
00167 return numRows;
00168 }
00169
00170 inline int
00171 Matrix::noCols() const
00172 {
00173 return numCols;
00174 }
00175
00176
00177 inline double &
00178 Matrix::operator()(int row, int col)
00179 {
00180 #ifdef _G3DEBUG
00181 if ((row < 0) || (row >= numRows)) {
00182 opserr << "Matrix::operator() - row " << row << " our of range [0, " << numRows-1 << endln;
00183 return data[0];
00184 } else if ((col < 0) || (col >= numCols)) {
00185 opserr << "Matrix::operator() - row " << col << " our of range [0, " << numCols-1 << endln;
00186 return MATRIX_NOT_VALID_ENTRY;
00187 }
00188 #endif
00189 return data[col*numRows + row];
00190 }
00191
00192
00193 inline double
00194 Matrix::operator()(int row, int col) const
00195 {
00196 #ifdef _G3DEBUG
00197 if ((row < 0) || (row >= numRows)) {
00198 opserr << "Matrix::operator() - row " << row << " our of range [0, " << numRows-1 << endln;
00199 return data[0];
00200 } else if ((col < 0) || (col >= numCols)) {
00201 opserr << "Matrix::operator() - row " << col << " our of range [0, " << numCols-1 << endln;
00202 return MATRIX_NOT_VALID_ENTRY;
00203 }
00204 #endif
00205 return data[col*numRows + row];
00206 }
00207
00208 #endif
00209
00210
00211
00212