BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / OpenFOAM / matrices / lduMatrix / solvers / GAMG / interfaces / cyclicGAMGInterface / cyclicGAMGInterface.C
blobe4d56022f0b9aae4028063365b31b6a7394ef0f1
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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 "cyclicGAMGInterface.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "Map.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 namespace Foam
34     defineTypeNameAndDebug(cyclicGAMGInterface, 0);
35     addToRunTimeSelectionTable
36     (
37         GAMGInterface,
38         cyclicGAMGInterface,
39         lduInterface
40     );
44 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
46 Foam::cyclicGAMGInterface::cyclicGAMGInterface
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     fineCyclicInterface_(refCast<const cyclicLduInterface>(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 (owner())
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 (owner())
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();
175             SLList<SLList<label> >::iterator faceFacesIter =
176                 curFaceFaces.begin();
178             for
179             (
180                 ;
181                 nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
182                 ++nbrsIter, ++faceFacesIter
183             )
184             {
185                 faceCells_[nCoarseFaces] = contents[masterI];
187                 for
188                 (
189                     SLList<label>::iterator facesIter = faceFacesIter().begin();
190                     facesIter != faceFacesIter().end();
191                     ++facesIter
192                 )
193                 {
194                     faceRestrictAddressing_[facesIter()] = nCoarseFaces;
195                 }
197                 nCoarseFaces++;
198             }
199         }
200     }
201     else
202     {
203         // On slave side, the owner addressing is stored in linked lists
204         forAll(contents, masterI)
205         {
206             SLList<label>& curNbrs = neighboursTable.find(contents[masterI])();
208             SLList<SLList<label> >& curFaceFaces =
209                 faceFaceTable.find(contents[masterI])();
211             SLList<label>::iterator nbrsIter = curNbrs.begin();
213             SLList<SLList<label> >::iterator faceFacesIter =
214                 curFaceFaces.begin();
216             for
217             (
218                 ;
219                 nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
220                 ++nbrsIter, ++faceFacesIter
221             )
222             {
223                 faceCells_[nCoarseFaces] = nbrsIter();
225                 for
226                 (
227                     SLList<label>::iterator facesIter = faceFacesIter().begin();
228                     facesIter != faceFacesIter().end();
229                     ++facesIter
230                 )
231                 {
232                     faceRestrictAddressing_[facesIter()] = nCoarseFaces;
233                 }
235                 nCoarseFaces++;
236             }
237         }
238     }
242 // * * * * * * * * * * * * * * * * Desstructor * * * * * * * * * * * * * * * //
244 Foam::cyclicGAMGInterface::~cyclicGAMGInterface()
248 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
250 Foam::tmp<Foam::labelField> Foam::cyclicGAMGInterface::internalFieldTransfer
252     const Pstream::commsTypes,
253     const labelUList& iF
254 ) const
256     const cyclicGAMGInterface& nbr = dynamic_cast<const cyclicGAMGInterface&>
257     (
258         neighbPatch()
259     );
260     const labelUList& nbrFaceCells = nbr.faceCells();
262     tmp<labelField> tpnf(new labelField(size()));
263     labelField& pnf = tpnf();
265     forAll(pnf, facei)
266     {
267         pnf[facei] = iF[nbrFaceCells[facei]];
268     }
270     return tpnf;
274 // ************************************************************************* //