initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / matrices / LUscalarMatrix / LUscalarMatrixTemplates.C
blob5f10a569eea28881a103847a669722a29db93608
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "LUscalarMatrix.H"
29 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
31 template<class Type>
32 void Foam::LUscalarMatrix::solve(Field<Type>& sourceSol) const
34     if (Pstream::parRun())
35     {
36         Field<Type> completeSourceSol(n());
38         if (Pstream::master())
39         {
40             typename Field<Type>::subField
41             (
42                 completeSourceSol,
43                 sourceSol.size()
44             ).assign(sourceSol);
46             for
47             (
48                 int slave=Pstream::firstSlave();
49                 slave<=Pstream::lastSlave();
50                 slave++
51             )
52             {
53                 IPstream::read
54                 (
55                     Pstream::scheduled,
56                     slave,
57                     reinterpret_cast<char*>
58                     (
59                         &(completeSourceSol[procOffsets_[slave]])
60                     ),
61                     (procOffsets_[slave + 1] - procOffsets_[slave])*sizeof(Type)
62                 );
63             }
64         }
65         else
66         {
67             OPstream::write
68             (
69                 Pstream::scheduled,
70                 Pstream::masterNo(),
71                 reinterpret_cast<const char*>(sourceSol.begin()),
72                 sourceSol.byteSize()
73             );
74         }
76         if (Pstream::master())
77         {
78             LUBacksubstitute(*this, pivotIndices_, completeSourceSol);
80             sourceSol = typename Field<Type>::subField
81             (
82                 completeSourceSol,
83                 sourceSol.size()
84             );
86             for
87             (
88                 int slave=Pstream::firstSlave();
89                 slave<=Pstream::lastSlave();
90                 slave++
91             )
92             {
93                 OPstream::write
94                 (
95                     Pstream::blocking,
96                     slave,
97                     reinterpret_cast<const char*>
98                     (
99                         &(completeSourceSol[procOffsets_[slave]])
100                     ),
101                     (procOffsets_[slave + 1] - procOffsets_[slave])*sizeof(Type)
102                 );
103             }
104         }
105         else
106         {
107             IPstream::read
108             (
109                 Pstream::blocking,
110                 Pstream::masterNo(),
111                 reinterpret_cast<char*>(sourceSol.begin()),
112                 sourceSol.byteSize()
113             );
114         }
115     }
116     else
117     {
118         LUBacksubstitute(*this, pivotIndices_, sourceSol);
119     }
123 // ************************************************************************* //