1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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 "cyclicGAMGInterface.H"
28 #include "addToRunTimeSelectionTable.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 defineTypeNameAndDebug(cyclicGAMGInterface, 0);
35 addToRunTimeSelectionTable
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 Foam::cyclicGAMGInterface::cyclicGAMGInterface
48 const lduInterface& fineInterface,
49 const labelField& localRestrictAddressing,
50 const labelField& neighbourRestrictAddressing
56 localRestrictAddressing,
57 neighbourRestrictAddressing
59 fineCyclicInterface_(refCast<const cyclicLduInterface>(fineInterface))
61 // Make a lookup table of entries for owner/neighbour
62 HashTable<SLList<label>, label, Hash<label> > neighboursTable
64 localRestrictAddressing.size()
67 // Table of face-sets to be agglomerated
68 HashTable<SLList<SLList<label> >, label, Hash<label> > faceFaceTable
70 localRestrictAddressing.size()
73 label nCoarseFaces = 0;
75 label sizeBy2 = localRestrictAddressing.size()/2;
77 for (label ffi=0; ffi<sizeBy2; ffi++)
79 label curMaster = localRestrictAddressing[ffi];
80 label curSlave = localRestrictAddressing[ffi + sizeBy2];
82 // Look for the master cell. If it has already got a face,
83 // add the coefficient to the face. If not, create a new
85 if (neighboursTable.found(curMaster))
87 // Check all current neighbours to see if the current
88 // slave already exists. If so, add the coefficient.
90 SLList<label>& curNbrs = neighboursTable.find(curMaster)();
92 SLList<SLList<label> >& curFaceFaces =
93 faceFaceTable.find(curMaster)();
95 bool nbrFound = false;
97 SLList<label>::iterator nbrsIter = curNbrs.begin();
99 SLList<SLList<label> >::iterator faceFacesIter =
100 curFaceFaces.begin();
105 nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
106 ++nbrsIter, ++faceFacesIter
109 if (nbrsIter() == curSlave)
112 faceFacesIter().append(ffi);
119 curNbrs.append(curSlave);
120 curFaceFaces.append(ffi);
122 // New coarse face created
128 // This master has got no neighbours yet. Add a neighbour
129 // and a coefficient, thus creating a new face
130 neighboursTable.insert(curMaster, SLList<label>(curSlave));
131 faceFaceTable.insert(curMaster, SLList<SLList<label> >(ffi));
133 // New coarse face created
136 } // end for all fine faces
139 faceCells_.setSize(2*nCoarseFaces, -1);
140 faceRestrictAddressing_.setSize(localRestrictAddressing.size(), -1);
142 labelList contents = neighboursTable.toc();
144 // Reset face counter for re-use
147 // On master side, the owner addressing is stored in table of contents
148 forAll (contents, masterI)
150 SLList<label>& curNbrs = neighboursTable.find(contents[masterI])();
152 SLList<SLList<label> >& curFaceFaces =
153 faceFaceTable.find(contents[masterI])();
155 SLList<label>::iterator nbrsIter = curNbrs.begin();
156 SLList<SLList<label> >::iterator faceFacesIter = curFaceFaces.begin();
161 nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
162 ++nbrsIter, ++faceFacesIter
165 faceCells_[nCoarseFaces] = contents[masterI];
169 SLList<label>::iterator facesIter = faceFacesIter().begin();
170 facesIter != faceFacesIter().end();
174 faceRestrictAddressing_[facesIter()] = nCoarseFaces;
181 // On slave side, the owner addressing is stored in linked lists
182 forAll (contents, masterI)
184 SLList<label>& curNbrs = neighboursTable.find(contents[masterI])();
186 SLList<SLList<label> >& curFaceFaces =
187 faceFaceTable.find(contents[masterI])();
189 SLList<label>::iterator nbrsIter = curNbrs.begin();
190 SLList<SLList<label> >::iterator faceFacesIter = curFaceFaces.begin();
195 nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
196 ++nbrsIter, ++faceFacesIter
199 faceCells_[nCoarseFaces] = nbrsIter();
203 SLList<label>::iterator facesIter = faceFacesIter().begin();
204 facesIter != faceFacesIter().end();
208 faceRestrictAddressing_[facesIter() + sizeBy2] = nCoarseFaces;
217 // * * * * * * * * * * * * * * * * Desstructor * * * * * * * * * * * * * * * //
219 Foam::cyclicGAMGInterface::~cyclicGAMGInterface()
223 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
225 Foam::tmp<Foam::labelField> Foam::cyclicGAMGInterface::transfer
227 const Pstream::commsTypes,
228 const unallocLabelList& interfaceData
231 tmp<labelField> tpnf(new labelField(size()));
232 labelField& pnf = tpnf();
234 label sizeby2 = size()/2;
236 for (label facei=0; facei<sizeby2; facei++)
238 pnf[facei] = interfaceData[facei + sizeby2];
239 pnf[facei + sizeby2] = interfaceData[facei];
246 Foam::tmp<Foam::labelField> Foam::cyclicGAMGInterface::internalFieldTransfer
248 const Pstream::commsTypes,
249 const unallocLabelList& iF
252 tmp<labelField> tpnf(new labelField(size()));
253 labelField& pnf = tpnf();
255 label sizeby2 = size()/2;
257 for (label facei=0; facei<sizeby2; facei++)
259 pnf[facei] = iF[faceCells_[facei + sizeby2]];
260 pnf[facei + sizeby2] = iF[faceCells_[facei]];
267 // ************************************************************************* //