MatrixI.H 3.48 KB
Newer Older
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2011-2016 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
    nRows_(0),
    nCols_(0),
33 34 35 36
    v_(NULL)
{}


37
template<class Form, class Type>
38
inline Foam::autoPtr<Foam::Matrix<Form, Type>> Foam::Matrix<Form, Type>::
39
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
    return nRows_;
59 60 61
}


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


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


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


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


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

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


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


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