OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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-2009 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 \*---------------------------------------------------------------------------*/
00026 
00027 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00028 
00029 template<class Form, class Type>
00030 inline Foam::Matrix<Form, Type>::Matrix()
00031 :
00032     n_(0),
00033     m_(0),
00034     v_(NULL)
00035 {}
00036 
00037 
00038 template<class Form, class Type>
00039 inline Foam::autoPtr<Foam::Matrix<Form, Type> > Foam::Matrix<Form, Type>::clone() const
00040 {
00041     return autoPtr<Matrix<Form, Type> >(new Matrix<Form, Type>(*this));
00042 }
00043 
00044 
00045 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00046 
00047 template<class Form, class Type>
00048 inline const Foam::Matrix<Form, Type>& Foam::Matrix<Form, Type>::null()
00049 {
00050     return *reinterpret_cast< Matrix<Form, Type>* >(0);
00051 }
00052 
00053 
00054 //- Return the number of rows
00055 template<class Form, class Type>
00056 inline Foam::label Foam::Matrix<Form, Type>::n() const
00057 {
00058     return n_;
00059 }
00060 
00061 
00062 template<class Form, class Type>
00063 inline Foam::label Foam::Matrix<Form, Type>::m() const
00064 {
00065     return m_;
00066 }
00067 
00068 
00069 template<class Form, class Type>
00070 inline Foam::label Foam::Matrix<Form, Type>::size() const
00071 {
00072     return n_*m_;
00073 }
00074 
00075 
00076 template<class Form, class Type>
00077 inline void Foam::Matrix<Form, Type>::checki(const label i) const
00078 {
00079     if (!n_)
00080     {
00081         FatalErrorIn("Matrix<Form, Type>::checki(const label)")
00082             << "attempt to access element from zero sized row"
00083             << abort(FatalError);
00084     }
00085     else if (i<0 || i>=n_)
00086     {
00087         FatalErrorIn("Matrix<Form, Type>::checki(const label)")
00088             << "index " << i << " out of range 0 ... " << n_-1
00089             << abort(FatalError);
00090     }
00091 }
00092 
00093 
00094 template<class Form, class Type>
00095 inline void Foam::Matrix<Form, Type>::checkj(const label j) const
00096 {
00097     if (!m_)
00098     {
00099         FatalErrorIn("Matrix<Form, Type>::checkj(const label)")
00100             << "attempt to access element from zero sized column"
00101             << abort(FatalError);
00102     }
00103     else if (j<0 || j>=m_)
00104     {
00105         FatalErrorIn("Matrix<Form, Type>::checkj(const label)")
00106             << "index " << j << " out of range 0 ... " << m_-1
00107             << abort(FatalError);
00108     }
00109 }
00110 
00111 
00112 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00113 
00114 template<class Form, class Type>
00115 inline Type* Foam::Matrix<Form, Type>::operator[](const label i)
00116 {
00117 #   ifdef FULLDEBUG
00118     checki(i);
00119 #   endif
00120     return v_[i];
00121 }
00122 
00123 
00124 template<class Form, class Type>
00125 inline const Type* Foam::Matrix<Form, Type>::operator[](const label i) const
00126 {
00127 #   ifdef FULLDEBUG
00128     checki(i);
00129 #   endif
00130     return v_[i];
00131 }
00132 
00133 
00134 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd