1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, 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 \*---------------------------------------------------------------------------*/
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 // Forward declaration of friend functions and operators
54 template<class Form, class Type> class Matrix;
56 template<class Form, class Type> Istream& operator>>
62 template<class Form, class Type> Ostream& operator<<
65 const Matrix<Form, Type>&
69 /*---------------------------------------------------------------------------*\
70 Class Matrix Declaration
71 \*---------------------------------------------------------------------------*/
73 template<class Form, class Type>
78 //- Number of rows and columns in Matrix.
82 Type** __restrict__ v_;
84 //- Allocate the storage for the row-pointers and the data
85 // and set the row pointers
91 // Static Member Functions
93 //- Return a null Matrix
94 inline static const Matrix<Form, Type>& null();
102 //- Construct given number of rows and columns.
103 Matrix(const label n, const label m);
105 //- Construct with given number of rows and columns
106 // and value for all elements.
107 Matrix(const label n, const label m, const Type&);
109 //- Copy constructor.
110 Matrix(const Matrix<Form, Type>&);
112 //- Construct from Istream.
116 inline autoPtr<Matrix<Form, Type> > clone() const;
127 //- Return the number of rows
128 inline label n() const;
130 //- Return the number of columns
131 inline label m() const;
133 //- Return the number of elements in matrix (n*m)
134 inline label size() const;
139 //- Check index i is within valid range (0 ... n-1).
140 inline void checki(const label i) const;
142 //- Check index j is within valid range (0 ... m-1).
143 inline void checkj(const label j) const;
148 //- Clear the Matrix, i.e. set sizes to zero.
151 //- Transfer the contents of the argument Matrix into this Matrix
152 // and annul the argument Matrix.
153 void transfer(Matrix<Form, Type>&);
156 //- Return the transpose of the matrix
162 //- Return subscript-checked row of Matrix.
163 inline Type* operator[](const label);
165 //- Return subscript-checked row of constant Matrix.
166 inline const Type* operator[](const label) const;
168 //- Assignment operator. Takes linear time.
169 void operator=(const Matrix<Form, Type>&);
171 //- Assignment of all entries to the given value
172 void operator=(const Type&);
175 // IOstream operators
177 //- Read Matrix from Istream, discarding contents of existing Matrix.
178 friend Istream& operator>> <Form, Type>
184 // Write Matrix to Ostream.
185 friend Ostream& operator<< <Form, Type>
188 const Matrix<Form, Type>&
193 // Global functions and operators
195 template<class Form, class Type> const Type& max(const Matrix<Form, Type>&);
196 template<class Form, class Type> const Type& min(const Matrix<Form, Type>&);
198 template<class Form, class Type> Form operator-(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-
208 const Matrix<Form, Type>&,
209 const Matrix<Form, Type>&
212 template<class Form, class Type> Form operator*
215 const Matrix<Form, Type>&
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
221 } // End namespace Foam
223 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225 # include "MatrixI.H"
227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
237 // ************************************************************************* //