OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "simpleMatrix.H"
00028 
00029 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00030 
00031 template<class Type>
00032 Foam::simpleMatrix<Type>::simpleMatrix(const label mSize)
00033 :
00034     scalarSquareMatrix(mSize),
00035     source_(mSize, pTraits<Type>::zero)
00036 {}
00037 
00038 
00039 template<class Type>
00040 Foam::simpleMatrix<Type>::simpleMatrix
00041 (
00042     const scalarSquareMatrix& matrix,
00043     const Field<Type>& source
00044 )
00045 :
00046     scalarSquareMatrix(matrix),
00047     source_(source)
00048 {}
00049 
00050 
00051 template<class Type>
00052 Foam::simpleMatrix<Type>::simpleMatrix(Istream& is)
00053 :
00054     scalarSquareMatrix(is),
00055     source_(is)
00056 {}
00057 
00058 
00059 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00060 
00061 template<class Type>
00062 Foam::Field<Type> Foam::simpleMatrix<Type>::solve() const
00063 {
00064     scalarSquareMatrix tmpMatrix = *this;
00065     Field<Type> sourceSol = source_;
00066 
00067     Foam::solve(tmpMatrix, sourceSol);
00068 
00069     return sourceSol;
00070 }
00071 
00072 
00073 template<class Type>
00074 Foam::Field<Type> Foam::simpleMatrix<Type>::LUsolve() const
00075 {
00076     scalarSquareMatrix luMatrix = *this;
00077     Field<Type> sourceSol = source_;
00078 
00079     Foam::LUsolve(luMatrix, sourceSol);
00080 
00081     return sourceSol;
00082 }
00083 
00084 
00085 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00086 
00087 template<class Type>
00088 void Foam::simpleMatrix<Type>::operator=(const simpleMatrix<Type>& m)
00089 {
00090     if (this == &m)
00091     {
00092         FatalErrorIn("simpleMatrix<Type>::operator=(const simpleMatrix<Type>&)")
00093             << "Attempted assignment to self"
00094             << abort(FatalError);
00095     }
00096 
00097     if (n() != m.n())
00098     {
00099         FatalErrorIn("simpleMatrix<Type>::operator=(const simpleMatrix<Type>&)")
00100             << "Different size matrices"
00101             << abort(FatalError);
00102     }
00103 
00104     if (source_.size() != m.source_.size())
00105     {
00106         FatalErrorIn("simpleMatrix<Type>::operator=(const simpleMatrix<Type>&)")
00107             << "Different size source vectors"
00108             << abort(FatalError);
00109     }
00110 
00111     scalarSquareMatrix::operator=(m);
00112     source_ = m.source_;
00113 }
00114 
00115 
00116 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00117 
00118 template<class Type>
00119 Foam::simpleMatrix<Type> Foam::operator+
00120 (
00121     const simpleMatrix<Type>& m1,
00122     const simpleMatrix<Type>& m2
00123 )
00124 {
00125     return simpleMatrix<Type>
00126     (
00127         static_cast<const scalarSquareMatrix&>(m1)
00128       + static_cast<const scalarSquareMatrix&>(m2),
00129         m1.source_ + m2.source_
00130     );
00131 }
00132 
00133 
00134 template<class Type>
00135 Foam::simpleMatrix<Type> Foam::operator-
00136 (
00137     const simpleMatrix<Type>& m1,
00138     const simpleMatrix<Type>& m2
00139 )
00140 {
00141     return simpleMatrix<Type>
00142     (
00143         static_cast<const scalarSquareMatrix&>(m1)
00144       - static_cast<const scalarSquareMatrix&>(m2),
00145         m1.source_ - m2.source_
00146     );
00147 }
00148 
00149 
00150 template<class Type>
00151 Foam::simpleMatrix<Type> Foam::operator*(const scalar s, const simpleMatrix<Type>& m)
00152 {
00153     return simpleMatrix<Type>(s*m.matrix_, s*m.source_);
00154 }
00155 
00156 
00157 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
00158 
00159 template<class Type>
00160 Foam::Ostream& Foam::operator<<(Ostream& os, const simpleMatrix<Type>& m)
00161 {
00162     os << static_cast<const scalarSquareMatrix&>(m) << nl << m.source_;
00163     return os;
00164 }
00165 
00166 
00167 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd