1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 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
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
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"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 defineTypeNameAndDebug(processorGAMGInterface, 0);
35 addToRunTimeSelectionTable
38 processorGAMGInterface,
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 Foam::processorGAMGInterface::processorGAMGInterface
49 const lduInterfacePtrsList& coarseInterfaces,
50 const lduInterface& fineInterface,
51 const labelField& localRestrictAddressing,
52 const labelField& neighbourRestrictAddressing
60 localRestrictAddressing,
61 neighbourRestrictAddressing
63 fineProcInterface_(refCast<const processorLduInterface>(fineInterface))
65 // Make a lookup table of entries for owner/neighbour
66 Map<SLList<label> > neighboursTable
68 localRestrictAddressing.size()
71 // Table of face-sets to be agglomerated
72 Map<SLList<SLList<label> > > faceFaceTable
74 localRestrictAddressing.size()
77 label nCoarseFaces = 0;
79 forAll(localRestrictAddressing, ffi)
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())
89 curMaster = localRestrictAddressing[ffi];
90 curSlave = neighbourRestrictAddressing[ffi];
95 curMaster = neighbourRestrictAddressing[ffi];
96 curSlave = localRestrictAddressing[ffi];
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))
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();
121 nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
122 ++nbrsIter, ++faceFacesIter
125 if (nbrsIter() == curSlave)
128 faceFacesIter().append(ffi);
135 curNbrs.append(curSlave);
136 curFaceFaces.append(ffi);
138 // New coarse face created
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
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
164 if (myProcNo() < neighbProcNo())
166 // On master side, the owner addressing is stored in table of contents
167 forAll(contents, masterI)
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();
182 nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
183 ++nbrsIter, ++faceFacesIter
186 faceCells_[nCoarseFaces] = contents[masterI];
188 forAllConstIter(SLList<label>, faceFacesIter(), facesIter)
190 faceRestrictAddressing_[facesIter()] = nCoarseFaces;
199 // On slave side, the owner addressing is stored in linked lists
200 forAll(contents, masterI)
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();
215 nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
216 ++nbrsIter, ++faceFacesIter
219 faceCells_[nCoarseFaces] = nbrsIter();
221 forAllConstIter(SLList<label>, faceFacesIter(), facesIter)
223 faceRestrictAddressing_[facesIter()] = nCoarseFaces;
233 // * * * * * * * * * * * * * * * * Desstructor * * * * * * * * * * * * * * * //
235 Foam::processorGAMGInterface::~processorGAMGInterface()
239 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
241 void Foam::processorGAMGInterface::initInternalFieldTransfer
243 const Pstream::commsTypes commsType,
247 send(commsType, interfaceInternalField(iF)());
251 Foam::tmp<Foam::labelField> Foam::processorGAMGInterface::internalFieldTransfer
253 const Pstream::commsTypes commsType,
257 return receive<label>(commsType, this->size());
261 // ************************************************************************* //