1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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 "faceMapper.H"
27 #include "demandDrivenData.H"
29 #include "mapPolyMesh.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36 void Foam::faceMapper::calcAddressing() const
41 || interpolationAddrPtr_
43 || insertedFaceLabelsPtr_
46 FatalErrorIn("void faceMapper::calcAddressing() const")
47 << "Addressing already calculated."
53 // Direct addressing, no weights
55 directAddrPtr_ = new labelList(mpm_.faceMap());
56 labelList& directAddr = *directAddrPtr_;
58 // Reset the size of addressing list to contain only live faces
59 directAddr.setSize(mesh_.nFaces());
61 insertedFaceLabelsPtr_ = new labelList(mesh_.nFaces());
62 labelList& insertedFaces = *insertedFaceLabelsPtr_;
64 label nInsertedFaces = 0;
66 forAll(directAddr, faceI)
68 if (directAddr[faceI] < 0)
70 // Found inserted face
71 directAddr[faceI] = 0;
72 insertedFaces[nInsertedFaces] = faceI;
77 insertedFaces.setSize(nInsertedFaces);
81 // Interpolative addressing
83 interpolationAddrPtr_ = new labelListList(mesh_.nFaces());
84 labelListList& addr = *interpolationAddrPtr_;
86 weightsPtr_ = new scalarListList(mesh_.nFaces());
87 scalarListList& w = *weightsPtr_;
89 const List<objectMap>& ffp = mpm_.facesFromPointsMap();
94 const labelList& mo = ffp[ffpI].masterObjects();
96 label faceI = ffp[ffpI].index();
98 if (addr[faceI].size())
100 FatalErrorIn("void faceMapper::calcAddressing() const")
101 << "Master face " << faceI
102 << " mapped from point faces " << mo
103 << " already destination of mapping." << abort(FatalError);
106 // Map from masters, uniform weights
108 w[faceI] = scalarList(mo.size(), 1.0/mo.size());
111 const List<objectMap>& ffe = mpm_.facesFromEdgesMap();
116 const labelList& mo = ffe[ffeI].masterObjects();
118 label faceI = ffe[ffeI].index();
120 if (addr[faceI].size())
122 FatalErrorIn("void faceMapper::calcAddressing() const")
123 << "Master face " << faceI
124 << " mapped from edge faces " << mo
125 << " already destination of mapping." << abort(FatalError);
128 // Map from masters, uniform weights
130 w[faceI] = scalarList(mo.size(), 1.0/mo.size());
133 const List<objectMap>& fff = mpm_.facesFromFacesMap();
138 const labelList& mo = fff[fffI].masterObjects();
140 label faceI = fff[fffI].index();
142 if (addr[faceI].size())
144 FatalErrorIn("void faceMapper::calcAddressing() const")
145 << "Master face " << faceI
146 << " mapped from face faces " << mo
147 << " already destination of mapping." << abort(FatalError);
150 // Map from masters, uniform weights
152 w[faceI] = scalarList(mo.size(), 1.0/mo.size());
156 // Do mapped faces. Note that can already be set from facesFromFaces
157 // so check if addressing size still zero.
158 const labelList& fm = mpm_.faceMap();
162 if (fm[faceI] > -1 && addr[faceI].empty())
164 // Mapped from a single face
165 addr[faceI] = labelList(1, fm[faceI]);
166 w[faceI] = scalarList(1, 1.0);
171 // Grab inserted points (for them the size of addressing is still zero)
173 insertedFaceLabelsPtr_ = new labelList(mesh_.nFaces());
174 labelList& insertedFaces = *insertedFaceLabelsPtr_;
176 label nInsertedFaces = 0;
180 if (addr[faceI].empty())
182 // Mapped from a dummy face
183 addr[faceI] = labelList(1, 0);
184 w[faceI] = scalarList(1, 1.0);
186 insertedFaces[nInsertedFaces] = faceI;
191 insertedFaces.setSize(nInsertedFaces);
196 void Foam::faceMapper::clearOut()
198 deleteDemandDrivenData(directAddrPtr_);
199 deleteDemandDrivenData(interpolationAddrPtr_);
200 deleteDemandDrivenData(weightsPtr_);
201 deleteDemandDrivenData(insertedFaceLabelsPtr_);
205 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
207 // Construct from components
208 Foam::faceMapper::faceMapper(const mapPolyMesh& mpm)
212 insertedFaces_(true),
214 directAddrPtr_(NULL),
215 interpolationAddrPtr_(NULL),
217 insertedFaceLabelsPtr_(NULL)
219 // Check for possibility of direct mapping
222 mpm_.facesFromPointsMap().empty()
223 && mpm_.facesFromEdgesMap().empty()
224 && mpm_.facesFromFacesMap().empty()
234 // Check for inserted faces
235 if (direct_ && (mpm_.faceMap().empty() || min(mpm_.faceMap()) > -1))
237 insertedFaces_ = false;
241 // Need to check all 3 lists to see if there are inserted faces
244 // Make a copy of the face map, add the entries for faces from points
245 // and faces from edges and check for left-overs
246 labelList fm(mesh_.nFaces(), -1);
248 const List<objectMap>& ffp = mpm_.facesFromPointsMap();
252 fm[ffp[ffpI].index()] = 0;
255 const List<objectMap>& ffe = mpm_.facesFromEdgesMap();
259 fm[ffe[ffeI].index()] = 0;
262 const List<objectMap>& fff = mpm_.facesFromFacesMap();
266 fm[fff[fffI].index()] = 0;
271 insertedFaces_ = true;
277 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
279 Foam::faceMapper::~faceMapper()
285 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
287 Foam::label Foam::faceMapper::size() const
289 return mesh_.nFaces();
293 Foam::label Foam::faceMapper::sizeBeforeMapping() const
295 return mpm_.nOldFaces();
299 Foam::label Foam::faceMapper::internalSizeBeforeMapping() const
301 return mpm_.nOldInternalFaces();
305 const Foam::labelUList& Foam::faceMapper::directAddressing() const
311 "const labelUList& faceMapper::directAddressing() const"
312 ) << "Requested direct addressing for an interpolative mapper."
313 << abort(FatalError);
316 if (!insertedObjects())
318 // No inserted faces. Re-use faceMap
319 return mpm_.faceMap();
328 return *directAddrPtr_;
333 const Foam::labelListList& Foam::faceMapper::addressing() const
339 "const labelListList& faceMapper::addressing() const"
340 ) << "Requested interpolative addressing for a direct mapper."
341 << abort(FatalError);
344 if (!interpolationAddrPtr_)
349 return *interpolationAddrPtr_;
353 const Foam::scalarListList& Foam::faceMapper::weights() const
359 "const scalarListList& faceMapper::weights() const"
360 ) << "Requested interpolative weights for a direct mapper."
361 << abort(FatalError);
373 const Foam::labelList& Foam::faceMapper::insertedObjectLabels() const
375 if (!insertedFaceLabelsPtr_)
377 if (!insertedObjects())
379 // There are no inserted faces
380 insertedFaceLabelsPtr_ = new labelList(0);
388 return *insertedFaceLabelsPtr_;
392 const Foam::labelHashSet& Foam::faceMapper::flipFaceFlux() const
394 return mpm_.flipFaceFlux();
398 Foam::label Foam::faceMapper::nOldInternalFaces() const
400 return mpm_.nOldInternalFaces();
404 const Foam::labelList& Foam::faceMapper::oldPatchStarts() const
406 return mpm_.oldPatchStarts();
410 const Foam::labelList& Foam::faceMapper::oldPatchSizes() const
412 return mpm_.oldPatchSizes();
416 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
419 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
422 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
425 // ************************************************************************* //