MatrixI.H 3.57 KB
Newer Older
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2011-2014 OpenFOAM Foundation
6 7 8 9 10
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

11 12 13 14
    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 3 of the License, or
    (at your option) any later version.
15 16 17 18 19 20 21

    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
22
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
23 24 25 26 27

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

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

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


37
template<class Form, class Type>
38 39
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
template<class Form, class Type>
inline const Foam::Matrix<Form, Type>& Foam::Matrix<Form, Type>::null()
{
50
    return NullObjectRef<Matrix<Form, Type> >();
51 52 53
}


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];
}


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