initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / matrices / lduMatrix / solvers / GAMG / interfaces / processorGAMGInterface / processorGAMGInterface.C
bloba3af7064eea9f01125955d53d48671710ec6d2a3
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 "processorGAMGInterface.H"
28 #include "addToRunTimeSelectionTable.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 namespace Foam
34     defineTypeNameAndDebug(processorGAMGInterface, 0);
35     addToRunTimeSelectionTable
36     (
37         GAMGInterface,
38         processorGAMGInterface,
39         lduInterface
40     );
44 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
46 Foam::processorGAMGInterface::processorGAMGInterface
48     const lduInterface& fineInterface,
49     const labelField& localRestrictAddressing,
50     const labelField& neighbourRestrictAddressing
53     GAMGInterface
54     (
55         fineInterface,
56         localRestrictAddressing,
57         neighbourRestrictAddressing
58     ),
59     fineProcInterface_(refCast<const processorLduInterface>(fineInterface))
61     // Make a lookup table of entries for owner/neighbour
62     HashTable<SLList<label>, label, Hash<label> > neighboursTable
63     (
64         localRestrictAddressing.size()
65     );
67     // Table of face-sets to be agglomerated
68     HashTable<SLList<SLList<label> >, label, Hash<label> > faceFaceTable
69     (
70         localRestrictAddressing.size()
71     );
73     label nCoarseFaces = 0;
75     forAll (localRestrictAddressing, ffi)
76     {
77         label curMaster = -1;
78         label curSlave = -1;
80         // Do switching on master/slave indexes based on the owner/neighbour of
81         // the processor index such that both sides get the same answer.
82         if (myProcNo() < neighbProcNo())
83         {
84             // Master side
85             curMaster = localRestrictAddressing[ffi];
86             curSlave = neighbourRestrictAddressing[ffi];
87         }
88         else
89         {
90             // Slave side
91             curMaster = neighbourRestrictAddressing[ffi];
92             curSlave = localRestrictAddressing[ffi];
93         }
95         // Look for the master cell.  If it has already got a face,
96         // add the coefficient to the face.  If not, create a new face.
97         if (neighboursTable.found(curMaster))
98         {
99             // Check all current neighbours to see if the current slave already
100             // exists and if so, add the fine face to the agglomeration.
102             SLList<label>& curNbrs = neighboursTable.find(curMaster)();
104             SLList<SLList<label> >& curFaceFaces =
105                 faceFaceTable.find(curMaster)();
107             bool nbrFound = false;
109             SLList<label>::iterator nbrsIter = curNbrs.begin();
111             SLList<SLList<label> >::iterator faceFacesIter =
112                 curFaceFaces.begin();
114             for
115             (
116                 ;
117                 nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
118                 ++nbrsIter, ++faceFacesIter
119             )
120             {
121                 if (nbrsIter() == curSlave)
122                 {
123                     nbrFound = true;
124                     faceFacesIter().append(ffi);
125                     break;
126                 }
127             }
129             if (!nbrFound)
130             {
131                 curNbrs.append(curSlave);
132                 curFaceFaces.append(ffi);
134                 // New coarse face created
135                 nCoarseFaces++;
136             }
137         }
138         else
139         {
140             // This master has got no neighbours yet.  Add a neighbour
141             // and a coefficient, thus creating a new face
142             neighboursTable.insert(curMaster, SLList<label>(curSlave));
143             faceFaceTable.insert(curMaster, SLList<SLList<label> >(ffi));
145             // New coarse face created
146             nCoarseFaces++;
147         }
148     } // end for all fine faces
152     faceCells_.setSize(nCoarseFaces, -1);
153     faceRestrictAddressing_.setSize(localRestrictAddressing.size());
155     labelList contents = neighboursTable.toc();
157     // Reset face counter for re-use
158     nCoarseFaces = 0;
160     if (myProcNo() < neighbProcNo())
161     {
162         // On master side, the owner addressing is stored in table of contents
163         forAll (contents, masterI)
164         {
165             SLList<label>& curNbrs = neighboursTable.find(contents[masterI])();
167             SLList<SLList<label> >& curFaceFaces =
168                 faceFaceTable.find(contents[masterI])();
170             SLList<label>::iterator nbrsIter = curNbrs.begin();
172             SLList<SLList<label> >::iterator faceFacesIter =
173                 curFaceFaces.begin();
175             for
176             (
177                 ;
178                 nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
179                 ++nbrsIter, ++faceFacesIter
180             )
181             {
182                 faceCells_[nCoarseFaces] = contents[masterI];
184                 for
185                 (
186                     SLList<label>::iterator facesIter = faceFacesIter().begin();
187                     facesIter != faceFacesIter().end();
188                     ++facesIter
189                 )
190                 {
191                     faceRestrictAddressing_[facesIter()] = nCoarseFaces;
192                 }
194                 nCoarseFaces++;
195             }
196         }
197     }
198     else
199     {
200         // On slave side, the owner addressing is stored in linked lists
201         forAll (contents, masterI)
202         {
203             SLList<label>& curNbrs = neighboursTable.find(contents[masterI])();
205             SLList<SLList<label> >& curFaceFaces =
206                 faceFaceTable.find(contents[masterI])();
208             SLList<label>::iterator nbrsIter = curNbrs.begin();
210             SLList<SLList<label> >::iterator faceFacesIter =
211                 curFaceFaces.begin();
213             for
214             (
215                 ;
216                 nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
217                 ++nbrsIter, ++faceFacesIter
218             )
219             {
220                 faceCells_[nCoarseFaces] = nbrsIter();
222                 for
223                 (
224                     SLList<label>::iterator facesIter = faceFacesIter().begin();
225                     facesIter != faceFacesIter().end();
226                     ++facesIter
227                 )
228                 {
229                     faceRestrictAddressing_[facesIter()] = nCoarseFaces;
230                 }
232                 nCoarseFaces++;
233             }
234         }
235     }
239 // * * * * * * * * * * * * * * * * Desstructor * * * * * * * * * * * * * * * //
241 Foam::processorGAMGInterface::~processorGAMGInterface()
245 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
247 void Foam::processorGAMGInterface::initTransfer
249     const Pstream::commsTypes commsType,
250     const unallocLabelList& interfaceData
251 ) const
253     send(commsType, interfaceData);
257 Foam::tmp<Foam::labelField> Foam::processorGAMGInterface::transfer
259     const Pstream::commsTypes commsType,
260     const unallocLabelList& interfaceData
261 ) const
263     return receive<label>(commsType, this->size());
267 void Foam::processorGAMGInterface::initInternalFieldTransfer
269     const Pstream::commsTypes commsType,
270     const unallocLabelList& iF
271 ) const
273     send(commsType, interfaceInternalField(iF)());
277 Foam::tmp<Foam::labelField> Foam::processorGAMGInterface::internalFieldTransfer
279     const Pstream::commsTypes commsType,
280     const unallocLabelList& iF
281 ) const
283     return receive<label>(commsType, this->size());
287 // ************************************************************************* //