1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM 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 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 A templated 2D matrix of objects of \<T\>, where the n x m matrix
30 dimensions are known and used for subscript bounds checking, etc.
37 \*---------------------------------------------------------------------------*/
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 // Forward declaration of friend functions and operators
55 template<class Form, class Type> class Matrix;
57 template<class Form, class Type> Istream& operator>>
63 template<class Form, class Type> Ostream& operator<<
66 const Matrix<Form, Type>&
70 /*---------------------------------------------------------------------------*\
71 Class Matrix Declaration
72 \*---------------------------------------------------------------------------*/
74 template<class Form, class Type>
79 //- Number of rows and columns in Matrix.
83 Type** __restrict__ v_;
85 //- Allocate the storage for the row-pointers and the data
86 // and set the row pointers
92 // Static Member Functions
94 //- Return a null Matrix
95 inline static const Matrix<Form, Type>& null();
100 //- Null constructor.
103 //- Construct given number of rows and columns.
104 Matrix(const label n, const label m);
106 //- Construct with given number of rows and columns
107 // and value for all elements.
108 Matrix(const label n, const label m, const Type&);
110 //- Copy constructor.
111 Matrix(const Matrix<Form, Type>&);
113 //- Construct from Istream.
117 inline autoPtr<Matrix<Form, Type> > clone() const;
129 //- Return the number of rows
130 inline label n() const;
132 //- Return the number of columns
133 inline label m() const;
135 //- Return the number of elements in matrix (n*m)
136 inline label size() const;
141 //- Check index i is within valid range (0 ... n-1).
142 inline void checki(const label i) const;
144 //- Check index j is within valid range (0 ... m-1).
145 inline void checkj(const label j) const;
150 //- Clear the Matrix, i.e. set sizes to zero.
153 //- Transfer the contents of the argument Matrix into this Matrix
154 // and annull the argument Matrix.
155 void transfer(Matrix<Form, Type>&);
158 //- Return the transpose of the matrix
164 //- Return subscript-checked element of Matrix.
165 inline Type* operator[](const label);
167 //- Return subscript-checked element of constant Matrix.
168 inline const Type* operator[](const label) const;
170 //- Assignment operator. Takes linear time.
171 void operator=(const Matrix<Form, Type>&);
173 //- Assignment of all entries to the given value
174 void operator=(const Type&);
177 // IOstream operators
179 //- Read Matrix from Istream, discarding contents of existing Matrix.
180 friend Istream& operator>> <Form, Type>(Istream&, Matrix<Form, Type>&);
182 // Write Matrix to Ostream.
183 friend Ostream& operator<< <Form, Type>(Ostream&, const Matrix<Form, Type>&);
187 // Global functions and operators
189 template<class Form, class Type> const Type& max(const Matrix<Form, Type>&);
190 template<class Form, class Type> const Type& min(const Matrix<Form, Type>&);
192 template<class Form, class Type> Form operator-(const Matrix<Form, Type>&);
194 template<class Form, class Type> Form operator+
196 const Matrix<Form, Type>&,
197 const Matrix<Form, Type>&
200 template<class Form, class Type> Form operator-
202 const Matrix<Form, Type>&,
203 const Matrix<Form, Type>&
206 template<class Form, class Type> Form operator*
209 const Matrix<Form, Type>&
213 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 } // End namespace Foam
217 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219 # include "MatrixI.H"
221 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
231 // ************************************************************************* //