MatrixI.H 3.27 KB
Newer Older
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
    Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM; if not, write to the Free Software Foundation,
    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

\*---------------------------------------------------------------------------*/

// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

29 30
template<class Type>
inline Foam::Matrix<Type>::Matrix()
31 32 33 34 35 36 37
:
    n_(0),
    m_(0),
    v_(NULL)
{}


38 39
template<class Type>
inline Foam::autoPtr<Foam::Matrix<Type> > Foam::Matrix<Type>::clone() const
40
{
41
    return autoPtr<Matrix<Type> >(new Matrix<Type>(*this));
42 43 44 45 46 47
}


// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

//- Return the number of rows
48 49
template<class Type>
inline Foam::label Foam::Matrix<Type>::n() const
50 51 52 53 54
{
    return n_;
}


55 56
template<class Type>
inline Foam::label Foam::Matrix<Type>::m() const
57 58 59 60 61
{
    return m_;
}


62 63
template<class Type>
inline Foam::label Foam::Matrix<Type>::size() const
64 65 66 67 68
{
    return n_*m_;
}


69 70
template<class Type>
inline void Foam::Matrix<Type>::checki(const label i) const
71 72 73
{
    if (!n_)
    {
74
        FatalErrorIn("Matrix<Type>::checki(const label)")
75 76 77 78 79
            << "attempt to access element from zero sized row"
            << abort(FatalError);
    }
    else if (i<0 || i>=n_)
    {
80
        FatalErrorIn("Matrix<Type>::checki(const label)")
81 82 83 84 85 86
            << "index " << i << " out of range 0 ... " << n_-1
            << abort(FatalError);
    }
}


87 88
template<class Type>
inline void Foam::Matrix<Type>::checkj(const label j) const
89 90 91
{
    if (!m_)
    {
92
        FatalErrorIn("Matrix<Type>::checkj(const label)")
93 94 95 96 97
            << "attempt to access element from zero sized column"
            << abort(FatalError);
    }
    else if (j<0 || j>=m_)
    {
98
        FatalErrorIn("Matrix<Type>::checkj(const label)")
99 100 101 102 103 104 105 106
            << "index " << j << " out of range 0 ... " << m_-1
            << abort(FatalError);
    }
}


// * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //

107 108
template<class Type>
inline Type* Foam::Matrix<Type>::operator[](const label i)
109 110 111 112 113 114 115 116
{
#   ifdef FULLDEBUG
    checki(i);
#   endif
    return v_[i];
}


117 118
template<class Type>
inline const Type* Foam::Matrix<Type>::operator[](const label i) const
119 120 121 122 123 124 125 126 127
{
#   ifdef FULLDEBUG
    checki(i);
#   endif
    return v_[i];
}


// ************************************************************************* //