Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / OpenFOAM / matrices / lduMatrix / solvers / GAMG / interfaces / processorGAMGInterface / processorGAMGInterface.C
blob236eb52141a7cd91172d600e204313ac4c1c90a7
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "processorGAMGInterface.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "Map.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 label index,
49     const lduInterfacePtrsList& coarseInterfaces,
50     const lduInterface& fineInterface,
51     const labelField& localRestrictAddressing,
52     const labelField& neighbourRestrictAddressing
55     GAMGInterface
56     (
57         index,
58         coarseInterfaces,
59         fineInterface,
60         localRestrictAddressing,
61         neighbourRestrictAddressing
62     ),
63     fineProcInterface_(refCast<const processorLduInterface>(fineInterface))
65     // Make a lookup table of entries for owner/neighbour
66     Map<SLList<label> > neighboursTable
67     (
68         localRestrictAddressing.size()
69     );
71     // Table of face-sets to be agglomerated
72     Map<SLList<SLList<label> > > faceFaceTable
73     (
74         localRestrictAddressing.size()
75     );
77     label nCoarseFaces = 0;
79     forAll(localRestrictAddressing, ffi)
80     {
81         label curMaster = -1;
82         label curSlave = -1;
84         // Do switching on master/slave indexes based on the owner/neighbour of
85         // the processor index such that both sides get the same answer.
86         if (myProcNo() < neighbProcNo())
87         {
88             // Master side
89             curMaster = localRestrictAddressing[ffi];
90             curSlave = neighbourRestrictAddressing[ffi];
91         }
92         else
93         {
94             // Slave side
95             curMaster = neighbourRestrictAddressing[ffi];
96             curSlave = localRestrictAddressing[ffi];
97         }
99         // Look for the master cell.  If it has already got a face,
100         // add the coefficient to the face.  If not, create a new face.
101         if (neighboursTable.found(curMaster))
102         {
103             // Check all current neighbours to see if the current slave already
104             // exists and if so, add the fine face to the agglomeration.
106             SLList<label>& curNbrs = neighboursTable.find(curMaster)();
108             SLList<SLList<label> >& curFaceFaces =
109                 faceFaceTable.find(curMaster)();
111             bool nbrFound = false;
113             SLList<label>::iterator nbrsIter = curNbrs.begin();
115             SLList<SLList<label> >::iterator faceFacesIter =
116                 curFaceFaces.begin();
118             for
119             (
120                 ;
121                 nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
122                 ++nbrsIter, ++faceFacesIter
123             )
124             {
125                 if (nbrsIter() == curSlave)
126                 {
127                     nbrFound = true;
128                     faceFacesIter().append(ffi);
129                     break;
130                 }
131             }
133             if (!nbrFound)
134             {
135                 curNbrs.append(curSlave);
136                 curFaceFaces.append(ffi);
138                 // New coarse face created
139                 nCoarseFaces++;
140             }
141         }
142         else
143         {
144             // This master has got no neighbours yet.  Add a neighbour
145             // and a coefficient, thus creating a new face
146             neighboursTable.insert(curMaster, SLList<label>(curSlave));
147             faceFaceTable.insert(curMaster, SLList<SLList<label> >(ffi));
149             // New coarse face created
150             nCoarseFaces++;
151         }
152     } // end for all fine faces
156     faceCells_.setSize(nCoarseFaces, -1);
157     faceRestrictAddressing_.setSize(localRestrictAddressing.size());
159     labelList contents = neighboursTable.toc();
161     // Reset face counter for re-use
162     nCoarseFaces = 0;
164     if (myProcNo() < neighbProcNo())
165     {
166         // On master side, the owner addressing is stored in table of contents
167         forAll(contents, masterI)
168         {
169             SLList<label>& curNbrs = neighboursTable.find(contents[masterI])();
171             SLList<SLList<label> >& curFaceFaces =
172                 faceFaceTable.find(contents[masterI])();
174             SLList<label>::iterator nbrsIter = curNbrs.begin();
176             SLList<SLList<label> >::iterator faceFacesIter =
177                 curFaceFaces.begin();
179             for
180             (
181                 ;
182                 nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
183                 ++nbrsIter, ++faceFacesIter
184             )
185             {
186                 faceCells_[nCoarseFaces] = contents[masterI];
188                 forAllConstIter(SLList<label>, faceFacesIter(), facesIter)
189                 {
190                     faceRestrictAddressing_[facesIter()] = nCoarseFaces;
191                 }
193                 nCoarseFaces++;
194             }
195         }
196     }
197     else
198     {
199         // On slave side, the owner addressing is stored in linked lists
200         forAll(contents, masterI)
201         {
202             SLList<label>& curNbrs = neighboursTable.find(contents[masterI])();
204             SLList<SLList<label> >& curFaceFaces =
205                 faceFaceTable.find(contents[masterI])();
207             SLList<label>::iterator nbrsIter = curNbrs.begin();
209             SLList<SLList<label> >::iterator faceFacesIter =
210                 curFaceFaces.begin();
212             for
213             (
214                 ;
215                 nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
216                 ++nbrsIter, ++faceFacesIter
217             )
218             {
219                 faceCells_[nCoarseFaces] = nbrsIter();
221                 forAllConstIter(SLList<label>, faceFacesIter(), facesIter)
222                 {
223                     faceRestrictAddressing_[facesIter()] = nCoarseFaces;
224                 }
226                 nCoarseFaces++;
227             }
228         }
229     }
233 // * * * * * * * * * * * * * * * * Desstructor * * * * * * * * * * * * * * * //
235 Foam::processorGAMGInterface::~processorGAMGInterface()
239 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
241 void Foam::processorGAMGInterface::initInternalFieldTransfer
243     const Pstream::commsTypes commsType,
244     const labelUList& iF
245 ) const
247     send(commsType, interfaceInternalField(iF)());
251 Foam::tmp<Foam::labelField> Foam::processorGAMGInterface::internalFieldTransfer
253     const Pstream::commsTypes commsType,
254     const labelUList& iF
255 ) const
257     return receive<label>(commsType, this->size());
261 // ************************************************************************* //