1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 "processorGAMGInterface.H"
28 #include "addToRunTimeSelectionTable.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 defineTypeNameAndDebug(processorGAMGInterface, 0);
35 addToRunTimeSelectionTable
38 processorGAMGInterface,
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 Foam::processorGAMGInterface::processorGAMGInterface
48 const lduInterface& fineInterface,
49 const labelField& localRestrictAddressing,
50 const labelField& neighbourRestrictAddressing
56 localRestrictAddressing,
57 neighbourRestrictAddressing
59 fineProcInterface_(refCast<const processorLduInterface>(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 forAll (localRestrictAddressing, ffi)
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())
85 curMaster = localRestrictAddressing[ffi];
86 curSlave = neighbourRestrictAddressing[ffi];
91 curMaster = neighbourRestrictAddressing[ffi];
92 curSlave = localRestrictAddressing[ffi];
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))
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();
117 nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
118 ++nbrsIter, ++faceFacesIter
121 if (nbrsIter() == curSlave)
124 faceFacesIter().append(ffi);
131 curNbrs.append(curSlave);
132 curFaceFaces.append(ffi);
134 // New coarse face created
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
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
160 if (myProcNo() < neighbProcNo())
162 // On master side, the owner addressing is stored in table of contents
163 forAll (contents, masterI)
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();
178 nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
179 ++nbrsIter, ++faceFacesIter
182 faceCells_[nCoarseFaces] = contents[masterI];
186 SLList<label>::iterator facesIter = faceFacesIter().begin();
187 facesIter != faceFacesIter().end();
191 faceRestrictAddressing_[facesIter()] = nCoarseFaces;
200 // On slave side, the owner addressing is stored in linked lists
201 forAll (contents, masterI)
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();
216 nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
217 ++nbrsIter, ++faceFacesIter
220 faceCells_[nCoarseFaces] = nbrsIter();
224 SLList<label>::iterator facesIter = faceFacesIter().begin();
225 facesIter != faceFacesIter().end();
229 faceRestrictAddressing_[facesIter()] = nCoarseFaces;
239 // * * * * * * * * * * * * * * * * Desstructor * * * * * * * * * * * * * * * //
241 Foam::processorGAMGInterface::~processorGAMGInterface()
245 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
247 void Foam::processorGAMGInterface::initTransfer
249 const Pstream::commsTypes commsType,
250 const unallocLabelList& interfaceData
253 send(commsType, interfaceData);
257 Foam::tmp<Foam::labelField> Foam::processorGAMGInterface::transfer
259 const Pstream::commsTypes commsType,
260 const unallocLabelList& interfaceData
263 return receive<label>(commsType, this->size());
267 void Foam::processorGAMGInterface::initInternalFieldTransfer
269 const Pstream::commsTypes commsType,
270 const unallocLabelList& iF
273 send(commsType, interfaceInternalField(iF)());
277 Foam::tmp<Foam::labelField> Foam::processorGAMGInterface::internalFieldTransfer
279 const Pstream::commsTypes commsType,
280 const unallocLabelList& iF
283 return receive<label>(commsType, this->size());
287 // ************************************************************************* //