1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "ggiGAMGInterface.H"
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
36 tmp<Field<Type> > ggiGAMGInterface::fastReduce(const UList<Type>& ff) const
39 // Local processor contains faceCells part of the zone and requires
40 // zoneAddressing part.
41 // For fast communications, each processor will send the faceCells and
42 // zoneAddressing to the master. Master will assemble global zone
43 // and send off messages to all processors containing only
47 if (ff.size() != this->size())
51 "tmp<Field<Type> > ggiGAMGInterface::fastReduce"
53 " const UList<Type>& ff"
55 ) << "Wrong field size. ff: " << ff.size()
56 << " interface: " << this->size()
60 if (localParallel() || !Pstream::parRun())
62 // Field remains identical: no parallel communications required
63 tmp<Field<Type> > tresult(new Field<Type>(ff));
68 // Execute reduce if not already done
74 if (Pstream::master())
76 // Master collects information and distributes data.
77 Field<Type> expandField(zoneSize(), pTraits<Type>::zero);
79 // Insert master processor
80 const labelList& za = zoneAddressing();
84 expandField[za[i]] = ff[i];
87 // Master receives and inserts data from all processors for which
88 // receiveAddr contains entries
89 for (label procI = 1; procI < Pstream::nProcs(); procI++)
91 const labelList& curRAddr = receiveAddr_[procI];
93 if (!curRAddr.empty())
95 Field<Type> receiveBuf(curRAddr.size());
97 // Opt: reconsider mode of communication
102 reinterpret_cast<char*>(receiveBuf.begin()),
103 receiveBuf.byteSize()
106 // Insert received information
109 expandField[curRAddr[i]] = receiveBuf[i];
114 // Expanded field complete, send required data to other processors
115 for (label procI = 1; procI < Pstream::nProcs(); procI++)
117 const labelList& curSAddr = sendAddr_[procI];
119 if (!curSAddr.empty())
121 Field<Type> sendBuf(curSAddr.size());
125 sendBuf[i] = expandField[curSAddr[i]];
128 // Opt: reconsider mode of communication
133 reinterpret_cast<const char*>(sendBuf.begin()),
139 // Note: different from ggi patch: field reduction happens within
140 // fastReduce. HJ, 26/Jun/2011
141 const labelList& sza = shadowInterface().zoneAddressing();
143 tmp<Field<Type> > tredField
145 new Field<Type>(sza.size(), pTraits<Type>::zero)
147 Field<Type>& redField = tredField();
149 // Select elements from shadow zone addressing
152 redField[i] = expandField[sza[i]];
159 // Send local data to master and receive remote data
160 // If patch is empty, communication is avoided
164 // Opt: reconsider mode of communication
169 reinterpret_cast<const char*>(ff.begin()),
174 // Prepare to receive remote data
175 const labelList& sza = shadowInterface().zoneAddressing();
177 tmp<Field<Type> > treceiveBuf
179 new Field<Type>(sza.size(), pTraits<Type>::zero)
181 Field<Type>& receiveBuf = treceiveBuf();
185 // Opt: reconsider mode of communication
190 reinterpret_cast<char*>(receiveBuf.begin()),
191 receiveBuf.byteSize()
194 // Note: different from ggi patch: field reduction happens within
195 // fastReduce. HJ, 26/Jun/2011
204 tmp<Field<Type> > ggiGAMGInterface::expand(const UList<Type>& pd) const
206 // Expand interface data to complete zone
207 tmp<Field<Type> > ted
209 new Field<Type>(zoneSize(), pTraits<Type>::zero)
211 Field<Type>& ed = ted();
213 const labelList& za = zoneAddressing();
220 // Reduce zone data if the patch is distributed
221 if (!localParallel())
223 reduce(ed, sumOp<Field<Type> >());
230 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232 } // End namespace Foam
234 // ************************************************************************* //