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 "cyclicGAMGInterface.H"
27 #include "addToRunTimeSelectionTable.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 defineTypeNameAndDebug(cyclicGAMGInterface, 0);
35 addToRunTimeSelectionTable
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 Foam::cyclicGAMGInterface::cyclicGAMGInterface
49 const lduInterfacePtrsList& coarseInterfaces,
50 const lduInterface& fineInterface,
51 const labelField& localRestrictAddressing,
52 const labelField& neighbourRestrictAddressing
60 localRestrictAddressing,
61 neighbourRestrictAddressing
63 fineCyclicInterface_(refCast<const cyclicLduInterface>(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.
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
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();
175 SLList<SLList<label> >::iterator faceFacesIter =
176 curFaceFaces.begin();
181 nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
182 ++nbrsIter, ++faceFacesIter
185 faceCells_[nCoarseFaces] = contents[masterI];
189 SLList<label>::iterator facesIter = faceFacesIter().begin();
190 facesIter != faceFacesIter().end();
194 faceRestrictAddressing_[facesIter()] = nCoarseFaces;
203 // On slave side, the owner addressing is stored in linked lists
204 forAll(contents, masterI)
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();
219 nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
220 ++nbrsIter, ++faceFacesIter
223 faceCells_[nCoarseFaces] = nbrsIter();
227 SLList<label>::iterator facesIter = faceFacesIter().begin();
228 facesIter != faceFacesIter().end();
232 faceRestrictAddressing_[facesIter()] = nCoarseFaces;
242 // * * * * * * * * * * * * * * * * Desstructor * * * * * * * * * * * * * * * //
244 Foam::cyclicGAMGInterface::~cyclicGAMGInterface()
248 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
250 Foam::tmp<Foam::labelField> Foam::cyclicGAMGInterface::internalFieldTransfer
252 const Pstream::commsTypes,
256 const cyclicGAMGInterface& nbr = dynamic_cast<const cyclicGAMGInterface&>
260 const labelUList& nbrFaceCells = nbr.faceCells();
262 tmp<labelField> tpnf(new labelField(size()));
263 labelField& pnf = tpnf();
267 pnf[facei] = iF[nbrFaceCells[facei]];
274 // ************************************************************************* //