FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

simpleMatrix.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include <OpenFOAM/simpleMatrix.H>
00027 
00028 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00029 
00030 template<class Type>
00031 Foam::simpleMatrix<Type>::simpleMatrix(const label mSize)
00032 :
00033     scalarSquareMatrix(mSize),
00034     source_(mSize)
00035 {}
00036 
00037 
00038 template<class Type>
00039 Foam::simpleMatrix<Type>::simpleMatrix
00040 (
00041     const label mSize,
00042     const scalar coeffVal,
00043     const Type& sourceVal
00044 )
00045 :
00046     scalarSquareMatrix(mSize, mSize, coeffVal),
00047     source_(mSize, sourceVal)
00048 {}
00049 
00050 
00051 template<class Type>
00052 Foam::simpleMatrix<Type>::simpleMatrix
00053 (
00054     const scalarSquareMatrix& matrix,
00055     const Field<Type>& source
00056 )
00057 :
00058     scalarSquareMatrix(matrix),
00059     source_(source)
00060 {}
00061 
00062 
00063 template<class Type>
00064 Foam::simpleMatrix<Type>::simpleMatrix(Istream& is)
00065 :
00066     scalarSquareMatrix(is),
00067     source_(is)
00068 {}
00069 
00070 
00071 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00072 
00073 template<class Type>
00074 Foam::Field<Type> Foam::simpleMatrix<Type>::solve() const
00075 {
00076     scalarSquareMatrix tmpMatrix = *this;
00077     Field<Type> sourceSol = source_;
00078 
00079     Foam::solve(tmpMatrix, sourceSol);
00080 
00081     return sourceSol;
00082 }
00083 
00084 
00085 template<class Type>
00086 Foam::Field<Type> Foam::simpleMatrix<Type>::LUsolve() const
00087 {
00088     scalarSquareMatrix luMatrix = *this;
00089     Field<Type> sourceSol = source_;
00090 
00091     Foam::LUsolve(luMatrix, sourceSol);
00092 
00093     return sourceSol;
00094 }
00095 
00096 
00097 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00098 
00099 template<class Type>
00100 void Foam::simpleMatrix<Type>::operator=(const simpleMatrix<Type>& m)
00101 {
00102     if (this == &m)
00103     {
00104         FatalErrorIn("simpleMatrix<Type>::operator=(const simpleMatrix<Type>&)")
00105             << "Attempted assignment to self"
00106             << abort(FatalError);
00107     }
00108 
00109     if (n() != m.n())
00110     {
00111         FatalErrorIn("simpleMatrix<Type>::operator=(const simpleMatrix<Type>&)")
00112             << "Different size matrices"
00113             << abort(FatalError);
00114     }
00115 
00116     if (source_.size() != m.source_.size())
00117     {
00118         FatalErrorIn("simpleMatrix<Type>::operator=(const simpleMatrix<Type>&)")
00119             << "Different size source vectors"
00120             << abort(FatalError);
00121     }
00122 
00123     scalarSquareMatrix::operator=(m);
00124     source_ = m.source_;
00125 }
00126 
00127 
00128 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00129 
00130 template<class Type>
00131 Foam::simpleMatrix<Type> Foam::operator+
00132 (
00133     const simpleMatrix<Type>& m1,
00134     const simpleMatrix<Type>& m2
00135 )
00136 {
00137     return simpleMatrix<Type>
00138     (
00139         static_cast<const scalarSquareMatrix&>(m1)
00140       + static_cast<const scalarSquareMatrix&>(m2),
00141         m1.source_ + m2.source_
00142     );
00143 }
00144 
00145 
00146 template<class Type>
00147 Foam::simpleMatrix<Type> Foam::operator-
00148 (
00149     const simpleMatrix<Type>& m1,
00150     const simpleMatrix<Type>& m2
00151 )
00152 {
00153     return simpleMatrix<Type>
00154     (
00155         static_cast<const scalarSquareMatrix&>(m1)
00156       - static_cast<const scalarSquareMatrix&>(m2),
00157         m1.source_ - m2.source_
00158     );
00159 }
00160 
00161 
00162 template<class Type>
00163 Foam::simpleMatrix<Type> Foam::operator*(const scalar s, const simpleMatrix<Type>& m)
00164 {
00165     return simpleMatrix<Type>(s*m.matrix_, s*m.source_);
00166 }
00167 
00168 
00169 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
00170 
00171 template<class Type>
00172 Foam::Ostream& Foam::operator<<(Ostream& os, const simpleMatrix<Type>& m)
00173 {
00174     os << static_cast<const scalarSquareMatrix&>(m) << nl << m.source_;
00175     return os;
00176 }
00177 
00178 
00179 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines