FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

MatrixI.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00027 
00028 template<class Form, class Type>
00029 inline Foam::Matrix<Form, Type>::Matrix()
00030 :
00031     n_(0),
00032     m_(0),
00033     v_(NULL)
00034 {}
00035 
00036 
00037 template<class Form, class Type>
00038 inline Foam::autoPtr<Foam::Matrix<Form, Type> > Foam::Matrix<Form, Type>::clone() const
00039 {
00040     return autoPtr<Matrix<Form, Type> >(new Matrix<Form, Type>(*this));
00041 }
00042 
00043 
00044 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00045 
00046 template<class Form, class Type>
00047 inline const Foam::Matrix<Form, Type>& Foam::Matrix<Form, Type>::null()
00048 {
00049     return *reinterpret_cast< Matrix<Form, Type>* >(0);
00050 }
00051 
00052 
00053 //- Return the number of rows
00054 template<class Form, class Type>
00055 inline Foam::label Foam::Matrix<Form, Type>::n() const
00056 {
00057     return n_;
00058 }
00059 
00060 
00061 template<class Form, class Type>
00062 inline Foam::label Foam::Matrix<Form, Type>::m() const
00063 {
00064     return m_;
00065 }
00066 
00067 
00068 template<class Form, class Type>
00069 inline Foam::label Foam::Matrix<Form, Type>::size() const
00070 {
00071     return n_*m_;
00072 }
00073 
00074 
00075 template<class Form, class Type>
00076 inline void Foam::Matrix<Form, Type>::checki(const label i) const
00077 {
00078     if (!n_)
00079     {
00080         FatalErrorIn("Matrix<Form, Type>::checki(const label)")
00081             << "attempt to access element from zero sized row"
00082             << abort(FatalError);
00083     }
00084     else if (i<0 || i>=n_)
00085     {
00086         FatalErrorIn("Matrix<Form, Type>::checki(const label)")
00087             << "index " << i << " out of range 0 ... " << n_-1
00088             << abort(FatalError);
00089     }
00090 }
00091 
00092 
00093 template<class Form, class Type>
00094 inline void Foam::Matrix<Form, Type>::checkj(const label j) const
00095 {
00096     if (!m_)
00097     {
00098         FatalErrorIn("Matrix<Form, Type>::checkj(const label)")
00099             << "attempt to access element from zero sized column"
00100             << abort(FatalError);
00101     }
00102     else if (j<0 || j>=m_)
00103     {
00104         FatalErrorIn("Matrix<Form, Type>::checkj(const label)")
00105             << "index " << j << " out of range 0 ... " << m_-1
00106             << abort(FatalError);
00107     }
00108 }
00109 
00110 
00111 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00112 
00113 template<class Form, class Type>
00114 inline Type* Foam::Matrix<Form, Type>::operator[](const label i)
00115 {
00116 #   ifdef FULLDEBUG
00117     checki(i);
00118 #   endif
00119     return v_[i];
00120 }
00121 
00122 
00123 template<class Form, class Type>
00124 inline const Type* Foam::Matrix<Form, Type>::operator[](const label i) const
00125 {
00126 #   ifdef FULLDEBUG
00127     checki(i);
00128 #   endif
00129     return v_[i];
00130 }
00131 
00132 
00133 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines