MatrixI.H 3.63 KB
Newer Older
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
Mark Olesen's avatar
Mark Olesen committed
5
    \\  /    A nd           | Copyright (C) 1991-2009 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 Form, class Type>
inline Foam::Matrix<Form, Type>::Matrix()
31 32 33 34 35 36 37
:
    n_(0),
    m_(0),
    v_(NULL)
{}


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


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

47 48 49 50 51 52 53
template<class Form, class Type>
inline const Foam::Matrix<Form, Type>& Foam::Matrix<Form, Type>::null()
{
    return *reinterpret_cast< Matrix<Form, Type>* >(0);
}


54
//- Return the number of rows
55 56
template<class Form, class Type>
inline Foam::label Foam::Matrix<Form, Type>::n() const
57 58 59 60 61
{
    return n_;
}


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


69 70
template<class Form, class Type>
inline Foam::label Foam::Matrix<Form, Type>::size() const
71 72 73 74 75
{
    return n_*m_;
}


76 77
template<class Form, class Type>
inline void Foam::Matrix<Form, Type>::checki(const label i) const
78 79 80
{
    if (!n_)
    {
81
        FatalErrorIn("Matrix<Form, Type>::checki(const label)")
82 83 84 85 86
            << "attempt to access element from zero sized row"
            << abort(FatalError);
    }
    else if (i<0 || i>=n_)
    {
87
        FatalErrorIn("Matrix<Form, Type>::checki(const label)")
88 89 90 91 92 93
            << "index " << i << " out of range 0 ... " << n_-1
            << abort(FatalError);
    }
}


94 95
template<class Form, class Type>
inline void Foam::Matrix<Form, Type>::checkj(const label j) const
96 97 98
{
    if (!m_)
    {
99
        FatalErrorIn("Matrix<Form, Type>::checkj(const label)")
100 101 102 103 104
            << "attempt to access element from zero sized column"
            << abort(FatalError);
    }
    else if (j<0 || j>=m_)
    {
105
        FatalErrorIn("Matrix<Form, Type>::checkj(const label)")
106 107 108 109 110 111 112 113
            << "index " << j << " out of range 0 ... " << m_-1
            << abort(FatalError);
    }
}


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

114 115
template<class Form, class Type>
inline Type* Foam::Matrix<Form, Type>::operator[](const label i)
116 117 118 119 120 121 122 123
{
#   ifdef FULLDEBUG
    checki(i);
#   endif
    return v_[i];
}


124 125
template<class Form, class Type>
inline const Type* Foam::Matrix<Form, Type>::operator[](const label i) const
126 127 128 129 130 131 132 133 134
{
#   ifdef FULLDEBUG
    checki(i);
#   endif
    return v_[i];
}


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