1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 A templated 2D matrix of objects of \<T\>, where the n x m matrix
29 dimensions are known and used for subscript bounds checking, etc.
36 \*---------------------------------------------------------------------------*/
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 // Forward declaration of friend functions and operators
53 template<class Form, class Type> class Matrix;
55 template<class Form, class Type> Istream& operator>>
61 template<class Form, class Type> Ostream& operator<<
64 const Matrix<Form, Type>&
68 /*---------------------------------------------------------------------------*\
69 Class Matrix Declaration
70 \*---------------------------------------------------------------------------*/
72 template<class Form, class Type>
78 Type** __restrict__ v_;
80 //- Number of rows and columns in Matrix.
83 //- Allocate the storage for the row-pointers and the data
84 // and set the row pointers
90 // Static data members
93 static const Matrix<Form, Type> zero;
96 // Static Member Functions
98 //- Return a null Matrix
99 inline static const Matrix<Form, Type>& null();
104 //- Null constructor.
107 //- Construct given number of rows and columns.
108 Matrix(const label n, const label m);
110 //- Construct with given number of rows and columns
111 // and value for all elements.
112 Matrix(const label n, const label m, const Type&);
114 //- Copy constructor.
115 Matrix(const Matrix<Form, Type>&);
117 //- Construct from Istream.
121 inline autoPtr<Matrix<Form, Type> > clone() const;
133 //- Return the number of rows
134 inline label n() const;
136 //- Return the number of columns
137 inline label m() const;
139 //- Return the number of elements in matrix (n*m)
140 inline label size() const;
145 //- Check index i is within valid range (0 ... n-1).
146 inline void checki(const label i) const;
148 //- Check index j is within valid range (0 ... m-1).
149 inline void checkj(const label j) const;
154 //- Clear the Matrix, i.e. set sizes to zero.
157 //- Transfer the contents of the argument Matrix into this Matrix
158 // and annull the argument Matrix.
159 void transfer(Matrix<Form, Type>&);
162 //- Return the transpose of the matrix
168 //- Return subscript-checked element of Matrix.
169 inline Type* operator[](const label);
171 //- Return subscript-checked element of constant Matrix.
172 inline const Type* operator[](const label) const;
174 //- Assignment operator. Takes linear time.
175 void operator=(const Matrix<Form, Type>&);
177 //- Assignment of all entries to the given value
178 void operator=(const Type&);
181 // IOstream operators
183 //- Read Matrix from Istream, discarding contents of existing Matrix.
184 friend Istream& operator>> <Form, Type>
190 // Write Matrix to Ostream.
191 friend Ostream& operator<< <Form, Type>
194 const Matrix<Form, Type>&
199 // Global functions and operators
201 template<class Form, class Type> const Type& max(const Matrix<Form, Type>&);
202 template<class Form, class Type> const Type& min(const Matrix<Form, Type>&);
204 template<class Form, class Type> Form operator-(const Matrix<Form, Type>&);
206 template<class Form, class Type> Form operator+
208 const Matrix<Form, Type>&,
209 const Matrix<Form, Type>&
212 template<class Form, class Type> Form operator-
214 const Matrix<Form, Type>&,
215 const Matrix<Form, Type>&
218 template<class Form, class Type> Form operator*
221 const Matrix<Form, Type>&
225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
227 } // End namespace Foam
229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
231 # include "MatrixI.H"
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
239 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
243 // ************************************************************************* //