MatrixI.H 4.05 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
template<class Form, class Type>
55
inline Foam::label Foam::Matrix<Form, Type>::m() const
56
{
57
    return nRows_;
58 59 60
}


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


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


75 76
template<class Form, class Type>
inline void Foam::Matrix<Form, Type>::checki(const label i) const
77
{
78
    #ifdef FULLDEBUG
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
            << abort(FatalError);
    }
91
    #endif
92 93 94
}


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


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

117
template<class Form, class Type>
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
inline const Type* Foam::Matrix<Form, Type>::v() const
{
    return v_;
}


template<class Form, class Type>
inline Type* Foam::Matrix<Form, Type>::v()
{
    return v_;
}


template<class Form, class Type>
inline const Type& Foam::Matrix<Form, Type>::operator()
(
    const label i,
    const label j
) const
137 138
{
    checki(i);
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
    checki(j);
    return v_[i*nCols_ + j];
}


template<class Form, class Type>
inline Type& Foam::Matrix<Form, Type>::operator()
(
    const label i,
    const label j
)
{
    checki(i);
    checki(j);
    return v_[i*nCols_ + j];
154 155 156
}


157 158
template<class Form, class Type>
inline const Type* Foam::Matrix<Form, Type>::operator[](const label i) const
159 160
{
    checki(i);
161 162 163 164 165 166 167 168 169
    return v_ + i*nCols_;
}


template<class Form, class Type>
inline Type* Foam::Matrix<Form, Type>::operator[](const label i)
{
    checki(i);
    return v_ + i*nCols_;
170 171 172 173
}


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