OpenFOAM logo
Open Source CFD Toolkit

simpleMatrix.H

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-2005 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 Class
00026     simpleMatrix
00027 
00028 Description
00029 
00030 SourceFiles
00031     simpleMatrix.C
00032 
00033 \*---------------------------------------------------------------------------*/
00034 
00035 #ifndef simpleMatrix_H
00036 #define simpleMatrix_H
00037 
00038 #include "Matrix.H"
00039 #include "Field.H"
00040 #include "scalar.H"
00041 #include "labelList.H"
00042 
00043 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00044 
00045 namespace Foam
00046 {
00047 
00048 class Istream;
00049 class Ostream;
00050 
00051 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
00052 
00053 template<class T>
00054 class simpleMatrix;
00055 
00056 template<class T>
00057 simpleMatrix<T> operator+
00058 (
00059     const simpleMatrix<T>&,
00060     const simpleMatrix<T>&
00061 );
00062 
00063 template<class T>
00064 simpleMatrix<T> operator-
00065 (
00066     const simpleMatrix<T>&,
00067     const simpleMatrix<T>&
00068 );
00069 
00070 template<class T>
00071 simpleMatrix<T> operator*
00072 (
00073     const scalar,
00074     const simpleMatrix<T>&
00075 );
00076 
00077 template<class T>
00078 Ostream& operator<<
00079 (
00080     Ostream&,
00081     const simpleMatrix<T>&
00082 );
00083 
00084 
00085 /*---------------------------------------------------------------------------*\
00086                            Class simpleMatrix Declaration
00087 \*---------------------------------------------------------------------------*/
00088 
00089 template<class T>
00090 class simpleMatrix
00091 {
00092     // Private data
00093 
00094         Matrix<scalar> matrix_;
00095         Field<T> source_;
00096 
00097 
00098 public:
00099 
00100     // Constructors
00101 
00102         //- Construct given size
00103         simpleMatrix(const label);
00104 
00105         //- Construct from components
00106         simpleMatrix(const Matrix<scalar>&, const Field<T>&);
00107 
00108         //- Construct from Istream
00109         simpleMatrix(Istream&);
00110 
00111         //- Construct as copy
00112         simpleMatrix(const simpleMatrix<T>&);
00113 
00114 
00115     // Member Functions
00116 
00117         // Access
00118 
00119             Matrix<scalar>& matrix()
00120             {
00121                 return matrix_;
00122             }
00123 
00124             Field<T>& source()
00125             {
00126                 return source_;
00127             }
00128 
00129             const Matrix<scalar>& matrix() const
00130             {
00131                 return matrix_;
00132             }
00133 
00134             const Field<T>& source() const
00135             {
00136                 return source_;
00137             }
00138 
00139 
00140         //- Solve the matrix using Gaussian elimination with pivoting
00141         static void solve(Matrix<scalar>& matrix, Field<T>& source);
00142 
00143         //- Solve the matrix using Gaussian elimination with pivoting
00144         //  and return the solution
00145         Field<T> solve() const;
00146 
00147 
00148         //- LU decompose the matrix with pivoting
00149         static void LUDecompose
00150         (
00151             Matrix<scalar>& matrix,
00152             labelList& pivotIndices
00153         );
00154 
00155         //- LU back-substitution with given source, returning the solution
00156         //  in the source
00157         static void LUBacksubstitute
00158         (
00159             const Matrix<scalar>& luMmatrix,
00160             const labelList& pivotIndices,
00161             Field<T>& source
00162         );
00163 
00164         //- Solve the matrix using LU decomposition with pivoting
00165         //  returning the LU form of the matrix and the solution in the source
00166         static void LUsolve(Matrix<scalar>& matrix, Field<T>& source);
00167 
00168         //- Solve the matrix using LU decomposition with pivoting
00169         //  and return the solution
00170         Field<T> LUsolve() const;
00171 
00172 
00173     // Member Operators
00174 
00175         void operator=(const simpleMatrix<T>&);
00176 
00177 
00178     // Friend Operators
00179 
00180         friend simpleMatrix<T> operator+ <T>
00181         (
00182             const simpleMatrix<T>&,
00183             const simpleMatrix<T>&
00184         );
00185 
00186         friend simpleMatrix<T> operator- <T>
00187         (
00188             const simpleMatrix<T>&,
00189             const simpleMatrix<T>&
00190         );
00191 
00192         friend simpleMatrix<T> operator* <T>
00193         (
00194             const scalar,
00195             const simpleMatrix<T>&
00196         );
00197 
00198 
00199     // Ostream Operator
00200 
00201         friend Ostream& operator<< <T>
00202         (
00203             Ostream&,
00204             const simpleMatrix<T>&
00205         );
00206 };
00207 
00208 
00209 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00210 
00211 } // End namespace Foam
00212 
00213 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00214 
00215 #ifdef NoRepository
00216 #   include "simpleMatrix.C"
00217 #endif
00218 
00219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00220 
00221 #endif
00222 
00223 // ************************************************************************* //
For further information go to www.openfoam.org