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 "faceMapper.H"
27 #include "demandDrivenData.H"
29 #include "mapPolyMesh.H"
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 void Foam::faceMapper::calcAddressing() const
38 || interpolationAddrPtr_
40 || insertedFaceLabelsPtr_
43 FatalErrorIn("void faceMapper::calcAddressing() const")
44 << "Addressing already calculated."
50 // Direct addressing, no weights
52 directAddrPtr_ = new labelList(mpm_.faceMap());
53 labelList& directAddr = *directAddrPtr_;
55 // Reset the size of addressing list to contain only live faces
56 directAddr.setSize(mesh_.nFaces());
58 insertedFaceLabelsPtr_ = new labelList(mesh_.nFaces());
59 labelList& insertedFaces = *insertedFaceLabelsPtr_;
61 label nInsertedFaces = 0;
63 forAll (directAddr, faceI)
65 if (directAddr[faceI] < 0)
67 // Found inserted face
68 directAddr[faceI] = 0;
69 insertedFaces[nInsertedFaces] = faceI;
74 insertedFaces.setSize(nInsertedFaces);
78 // Interpolative addressing
80 interpolationAddrPtr_ = new labelListList(mesh_.nFaces());
81 labelListList& addr = *interpolationAddrPtr_;
83 weightsPtr_ = new scalarListList(mesh_.nFaces());
84 scalarListList& w = *weightsPtr_;
86 const List<objectMap>& ffp = mpm_.facesFromPointsMap();
91 const labelList& mo = ffp[ffpI].masterObjects();
93 label faceI = ffp[ffpI].index();
95 if (addr[faceI].size())
97 FatalErrorIn("void faceMapper::calcAddressing() const")
98 << "Master face " << faceI
99 << " mapped from point faces " << mo
100 << " already destination of mapping." << abort(FatalError);
103 // Map from masters, uniform weights
105 w[faceI] = scalarList(mo.size(), 1.0/mo.size());
108 const List<objectMap>& ffe = mpm_.facesFromEdgesMap();
113 const labelList& mo = ffe[ffeI].masterObjects();
115 label faceI = ffe[ffeI].index();
117 if (addr[faceI].size())
119 FatalErrorIn("void faceMapper::calcAddressing() const")
120 << "Master face " << faceI
121 << " mapped from edge faces " << mo
122 << " already destination of mapping." << abort(FatalError);
125 // Map from masters, uniform weights
127 w[faceI] = scalarList(mo.size(), 1.0/mo.size());
130 const List<objectMap>& fff = mpm_.facesFromFacesMap();
135 const labelList& mo = fff[fffI].masterObjects();
137 label faceI = fff[fffI].index();
139 if (addr[faceI].size())
141 FatalErrorIn("void faceMapper::calcAddressing() const")
142 << "Master face " << faceI
143 << " mapped from face faces " << mo
144 << " already destination of mapping." << abort(FatalError);
147 // Map from masters, uniform weights
149 w[faceI] = scalarList(mo.size(), 1.0/mo.size());
153 // Do mapped faces. Note that can already be set from facesFromFaces
154 // so check if addressing size still zero.
155 const labelList& fm = mpm_.faceMap();
159 if (fm[faceI] > -1 && addr[faceI].empty())
161 // Mapped from a single face
162 addr[faceI] = labelList(1, fm[faceI]);
163 w[faceI] = scalarList(1, 1.0);
168 // Grab inserted faces (for them the size of addressing is still zero)
170 insertedFaceLabelsPtr_ = new labelList(mesh_.nFaces());
171 labelList& insertedFaces = *insertedFaceLabelsPtr_;
173 label nInsertedFaces = 0;
177 if (addr[faceI].empty())
179 // Mapped from a dummy face
180 addr[faceI] = labelList(1, 0);
181 w[faceI] = scalarList(1, 1.0);
183 insertedFaces[nInsertedFaces] = faceI;
188 insertedFaces.setSize(nInsertedFaces);
193 void Foam::faceMapper::clearOut()
195 deleteDemandDrivenData(directAddrPtr_);
196 deleteDemandDrivenData(interpolationAddrPtr_);
197 deleteDemandDrivenData(weightsPtr_);
198 deleteDemandDrivenData(insertedFaceLabelsPtr_);
202 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
204 // Construct from components
205 Foam::faceMapper::faceMapper(const mapPolyMesh& mpm)
209 insertedFaces_(true),
211 directAddrPtr_(NULL),
212 interpolationAddrPtr_(NULL),
214 insertedFaceLabelsPtr_(NULL)
216 // Check for possibility of direct mapping
219 mpm_.facesFromPointsMap().empty()
220 && mpm_.facesFromEdgesMap().empty()
221 && mpm_.facesFromFacesMap().empty()
231 // Check for inserted faces
232 // Bug fix: mapping with insertion or truncation. HJ, 5/Sep/2007
236 && (mpm_.faceMap().size() || min(mpm_.faceMap()) > -1)
237 && mpm_.faceMap().size() == mesh_.nFaces()
240 insertedFaces_ = false;
244 // Need to check all 3 lists to see if there are inserted faces
247 // Make a copy of the face map, add the entries for faces from points
248 // and faces from edges and check for left-overs
249 labelList fm(mesh_.nFaces(), -1);
251 const List<objectMap>& ffp = mpm_.facesFromPointsMap();
255 fm[ffp[ffpI].index()] = 0;
258 const List<objectMap>& ffe = mpm_.facesFromEdgesMap();
262 fm[ffe[ffeI].index()] = 0;
265 const List<objectMap>& fff = mpm_.facesFromFacesMap();
269 fm[fff[fffI].index()] = 0;
274 insertedFaces_ = true;
280 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
282 Foam::faceMapper::~faceMapper()
288 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
290 Foam::label Foam::faceMapper::size() const
292 return mesh_.nFaces();
296 Foam::label Foam::faceMapper::sizeBeforeMapping() const
298 return mpm_.nOldFaces();
302 Foam::label Foam::faceMapper::internalSizeBeforeMapping() const
304 return mpm_.nOldInternalFaces();
308 const Foam::unallocLabelList& Foam::faceMapper::directAddressing() const
314 "const unallocLabelList& faceMapper::directAddressing() const"
315 ) << "Requested direct addressing for an interpolative mapper."
316 << abort(FatalError);
319 if (!insertedObjects())
321 // No inserted faces. Re-use faceMap
322 return mpm_.faceMap();
331 return *directAddrPtr_;
336 const Foam::labelListList& Foam::faceMapper::addressing() const
342 "const labelListList& faceMapper::addressing() const"
343 ) << "Requested interpolative addressing for a direct mapper."
344 << abort(FatalError);
347 if (!interpolationAddrPtr_)
352 return *interpolationAddrPtr_;
356 const Foam::scalarListList& Foam::faceMapper::weights() const
362 "const scalarListList& faceMapper::weights() const"
363 ) << "Requested interpolative weights for a direct mapper."
364 << abort(FatalError);
376 const Foam::labelList& Foam::faceMapper::insertedObjectLabels() const
378 if (!insertedFaceLabelsPtr_)
380 if (!insertedObjects())
382 // There are no inserted faces
383 insertedFaceLabelsPtr_ = new labelList(0);
391 return *insertedFaceLabelsPtr_;
395 const Foam::labelHashSet& Foam::faceMapper::flipFaceFlux() const
397 return mpm_.flipFaceFlux();
401 Foam::label Foam::faceMapper::nOldInternalFaces() const
403 return mpm_.nOldInternalFaces();
407 const Foam::labelList& Foam::faceMapper::oldPatchStarts() const
409 return mpm_.oldPatchStarts();
413 const Foam::labelList& Foam::faceMapper::oldPatchSizes() const
415 return mpm_.oldPatchSizes();
419 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
422 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
425 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
428 // ************************************************************************* //