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

LUscalarMatrixTemplates.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/LUscalarMatrix.H>
00027 
00028 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00029 
00030 template<class Type>
00031 void Foam::LUscalarMatrix::solve(Field<Type>& sourceSol) const
00032 {
00033     if (Pstream::parRun())
00034     {
00035         Field<Type> completeSourceSol(n());
00036 
00037         if (Pstream::master())
00038         {
00039             typename Field<Type>::subField
00040             (
00041                 completeSourceSol,
00042                 sourceSol.size()
00043             ).assign(sourceSol);
00044 
00045             for
00046             (
00047                 int slave=Pstream::firstSlave();
00048                 slave<=Pstream::lastSlave();
00049                 slave++
00050             )
00051             {
00052                 IPstream::read
00053                 (
00054                     Pstream::scheduled,
00055                     slave,
00056                     reinterpret_cast<char*>
00057                     (
00058                         &(completeSourceSol[procOffsets_[slave]])
00059                     ),
00060                     (procOffsets_[slave + 1] - procOffsets_[slave])*sizeof(Type)
00061                 );
00062             }
00063         }
00064         else
00065         {
00066             OPstream::write
00067             (
00068                 Pstream::scheduled,
00069                 Pstream::masterNo(),
00070                 reinterpret_cast<const char*>(sourceSol.begin()),
00071                 sourceSol.byteSize()
00072             );
00073         }
00074 
00075         if (Pstream::master())
00076         {
00077             LUBacksubstitute(*this, pivotIndices_, completeSourceSol);
00078 
00079             sourceSol = typename Field<Type>::subField
00080             (
00081                 completeSourceSol,
00082                 sourceSol.size()
00083             );
00084 
00085             for
00086             (
00087                 int slave=Pstream::firstSlave();
00088                 slave<=Pstream::lastSlave();
00089                 slave++
00090             )
00091             {
00092                 OPstream::write
00093                 (
00094                     Pstream::blocking,
00095                     slave,
00096                     reinterpret_cast<const char*>
00097                     (
00098                         &(completeSourceSol[procOffsets_[slave]])
00099                     ),
00100                     (procOffsets_[slave + 1] - procOffsets_[slave])*sizeof(Type)
00101                 );
00102             }
00103         }
00104         else
00105         {
00106             IPstream::read
00107             (
00108                 Pstream::blocking,
00109                 Pstream::masterNo(),
00110                 reinterpret_cast<char*>(sourceSol.begin()),
00111                 sourceSol.byteSize()
00112             );
00113         }
00114     }
00115     else
00116     {
00117         LUBacksubstitute(*this, pivotIndices_, sourceSol);
00118     }
00119 }
00120 
00121 
00122 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines