![]() |
|
00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2005 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software; you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by the 00013 Free Software Foundation; either version 2 of the License, or (at your 00014 option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM; if not, write to the Free Software Foundation, 00023 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00024 00025 Class 00026 Matrix<T> 00027 00028 Description 00029 Matrix<T> is a 2D matrix of objects of type T, where the n x m size of 00030 the matrix is known and used for subscript bounds checking, etc. 00031 00032 SourceFiles 00033 Matrix.C 00034 MatrixI.H 00035 MatrixIO.C 00036 00037 \*---------------------------------------------------------------------------*/ 00038 00039 #ifndef Matrix_H 00040 #define Matrix_H 00041 00042 #include "List.H" 00043 #include "label.H" 00044 #include "bool.H" 00045 #include "autoPtr.H" 00046 00047 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00048 00049 namespace Foam 00050 { 00051 00052 // * * * * * * Forward declaration of template friend fuctions * * * * * * * // 00053 00054 template<class T> class Matrix; 00055 00056 template<class T> const T& max(const Matrix<T>&); 00057 template<class T> const T& min(const Matrix<T>&); 00058 00059 template<class T> Matrix<T> operator-(const Matrix<T>&); 00060 template<class T> Matrix<T> operator+(const Matrix<T>&, const Matrix<T>&); 00061 template<class T> Matrix<T> operator-(const Matrix<T>&, const Matrix<T>&); 00062 template<class T> Matrix<T> operator*(const scalar, const Matrix<T>&); 00063 00064 template<class T> Istream& operator>>(Istream&, Matrix<T>&); 00065 template<class T> Ostream& operator<<(Ostream&, const Matrix<T>&); 00066 00067 00068 /*---------------------------------------------------------------------------*\ 00069 Class Matrix Declaration 00070 \*---------------------------------------------------------------------------*/ 00071 00072 template<class T> 00073 class Matrix 00074 { 00075 // Private data 00076 00077 //- Number of rows and columns in Matrix. 00078 label n_, m_; 00079 00080 //- Row pointers 00081 T** restrict v_; 00082 00083 //- Allocate the storage for the row-pointers and the data 00084 // and set the row pointers 00085 void allocate(); 00086 00087 00088 public: 00089 00090 // Constructors 00091 00092 //- Null constructor. 00093 inline Matrix(); 00094 00095 //- Construct given number of rows and columns. 00096 Matrix(const label n, const label m); 00097 00098 //- Construct with given number of rows and columns 00099 // and value for all elements. 00100 Matrix(const label n, const label m, const T&); 00101 00102 //- Copy constructor. 00103 Matrix(const Matrix<T>&); 00104 00105 //- Construct from Istream. 00106 Matrix(Istream&); 00107 00108 //- Clone 00109 inline autoPtr<Matrix<T> > clone() const; 00110 00111 00112 // Destructor 00113 00114 ~Matrix(); 00115 00116 00117 // Member functions 00118 00119 //- Return a null Matrix 00120 static Matrix<T>& null(); 00121 00122 00123 // Access 00124 00125 //- Return the number of rows 00126 inline label n() const; 00127 00128 //- Return the number of columns 00129 inline label m() const; 00130 00131 //- Return the number of elements in matrix (n*m) 00132 inline label size() const; 00133 00134 00135 // Check 00136 00137 //- Check index i is within valid range (0 ... n-1). 00138 inline void checki(const label i) const; 00139 00140 //- Check index j is within valid range (0 ... m-1). 00141 inline void checkj(const label j) const; 00142 00143 00144 // Edit 00145 00146 //- Clear the Matrix, i.e. set sizes to zero. 00147 void clear(); 00148 00149 //- Transfer the contents of the argument Matrix into this Matrix 00150 // and annull the argument Matrix. 00151 void transfer(Matrix<T>&); 00152 00153 00154 // Member operators 00155 00156 //- Return subscript-checked element of Matrix. 00157 inline T* operator[](const label); 00158 00159 //- Return subscript-checked element of constant Matrix. 00160 inline const T* operator[](const label) const; 00161 00162 //- Assignment operator. Takes linear time. 00163 void operator=(const Matrix<T>&); 00164 00165 //- Assignment of all entries to the given value 00166 void operator=(const T&); 00167 00168 00169 // Friend functions 00170 00171 friend const T& max<T>(const Matrix<T>&); 00172 friend const T& min<T>(const Matrix<T>&); 00173 00174 00175 // Friend operators 00176 00177 friend Matrix<T> operator-<T>(const Matrix<T>&); 00178 friend Matrix<T> operator+<T>(const Matrix<T>&, const Matrix<T>&); 00179 friend Matrix<T> operator-<T>(const Matrix<T>&, const Matrix<T>&); 00180 friend Matrix<T> operator*<T>(const scalar, const Matrix<T>&); 00181 00182 00183 // IOstream operators 00184 00185 //- Read Matrix from Istream, discarding contents of existing Matrix. 00186 friend Istream& operator>> <T>(Istream&, Matrix<T>&); 00187 00188 // Write Matrix to Ostream. 00189 friend Ostream& operator<< <T>(Ostream&, const Matrix<T>&); 00190 }; 00191 00192 00193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00194 00195 } // End namespace Foam 00196 00197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00198 00199 # include "MatrixI.H" 00200 00201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00202 00203 #ifdef NoRepository 00204 # include "Matrix.C" 00205 #endif 00206 00207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00208 00209 #endif 00210 00211 // ************************************************************************* //