1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 A subset of mesh faces.
28 \*---------------------------------------------------------------------------*/
31 #include "addToRunTimeSelectionTable.H"
32 #include "faceZoneMesh.H"
34 #include "primitiveMesh.H"
35 #include "demandDrivenData.H"
36 #include "mapPolyMesh.H"
38 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
42 defineTypeNameAndDebug(faceZone, 0);
43 defineRunTimeSelectionTable(faceZone, dictionary);
44 addToRunTimeSelectionTable(faceZone, faceZone, dictionary);
47 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 void Foam::faceZone::calcFaceZonePatch() const
53 Info<< "void faceZone::calcFaceZonePatch() const : "
54 << "Calculating primitive patch"
62 "void faceZone::calcFaceZonePatch() const"
63 ) << "primitive face zone patch already calculated"
68 new primitiveFacePatch
71 zoneMesh().mesh().points()
74 primitiveFacePatch& patch = *patchPtr_;
76 const faceList& f = zoneMesh().mesh().faces();
78 const labelList& addr = *this;
79 const boolList& flip = flipMap();
85 patch[faceI] = f[addr[faceI]].reverseFace();
89 patch[faceI] = f[addr[faceI]];
95 Info<< "void faceZone::calcFaceZonePatch() const : "
96 << "Finished calculating primitive patch"
102 const Foam::Map<Foam::label>& Foam::faceZone::faceLookupMap() const
104 if (!faceLookupMapPtr_)
109 return *faceLookupMapPtr_;
113 void Foam::faceZone::calcFaceLookupMap() const
117 Info<< "void faceZone::calcFaceLookupMap() const : "
118 << "Calculating face lookup map"
122 if (faceLookupMapPtr_)
126 "void faceZone::calcFaceLookupMap() const"
127 ) << "face lookup map already calculated"
128 << abort(FatalError);
131 const labelList& addr = *this;
133 faceLookupMapPtr_ = new Map<label>(2*addr.size());
134 Map<label>& flm = *faceLookupMapPtr_;
138 flm.insert(addr[faceI], faceI);
143 Info<< "void faceZone::calcFaceLookupMap() const : "
144 << "Finished calculating face lookup map"
150 void Foam::faceZone::calcCellLayers() const
154 Info<< "void Foam::faceZone::calcCellLayers() const : "
155 << "calculating master cells"
159 // It is an error to attempt to recalculate edgeCells
160 // if the pointer is already set
161 if (masterCellsPtr_ || slaveCellsPtr_)
163 FatalErrorIn("void faceZone::calcCellLayers() const")
164 << "cell layers already calculated"
165 << abort(FatalError);
169 // Go through all the faces in the master zone. Choose the
170 // master or slave cell based on the face flip
172 const labelList& own = zoneMesh().mesh().faceOwner();
173 const labelList& nei = zoneMesh().mesh().faceNeighbour();
175 const labelList& mf = *this;
177 const boolList& faceFlip = flipMap();
179 masterCellsPtr_ = new labelList(mf.size());
180 labelList& mc = *masterCellsPtr_;
182 slaveCellsPtr_ = new labelList(mf.size());
183 labelList& sc = *slaveCellsPtr_;
187 if (!faceFlip[faceI])
189 // Face is oriented correctly, no flip needed
190 mc[faceI] = nei[mf[faceI]];
191 sc[faceI] = own[mf[faceI]];
195 mc[faceI] = own[mf[faceI]];
196 sc[faceI] = nei[mf[faceI]];
199 //Info << "masterCells: " << mc << endl;
200 //Info << "slaveCells: " << sc << endl;
205 void Foam::faceZone::checkAddressing() const
207 if (size() != flipMap_.size())
209 FatalErrorIn("void Foam::faceZone::checkAddressing() const")
210 << "Different sizes of the addressing and flipMap arrays. "
211 << "Size of addressing: " << size()
212 << " size of flip map: " << flipMap_.size()
213 << abort(FatalError);
218 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
220 // Construct from components
221 Foam::faceZone::faceZone
224 const labelList& addr,
227 const faceZoneMesh& zm
236 masterCellsPtr_(NULL),
237 slaveCellsPtr_(NULL),
239 faceLookupMapPtr_(NULL)
245 // Construct from dictionary
246 Foam::faceZone::faceZone
249 const dictionary& dict,
251 const faceZoneMesh& zm
254 labelList(dict.lookup("faceLabels")),
256 flipMap_(dict.lookup("flipMap")),
260 masterCellsPtr_(NULL),
261 slaveCellsPtr_(NULL),
263 faceLookupMapPtr_(NULL)
269 // Construct given the original zone and resetting the
270 // face list and zone mesh information
271 Foam::faceZone::faceZone
274 const labelList& addr,
277 const faceZoneMesh& zm
286 masterCellsPtr_(NULL),
287 slaveCellsPtr_(NULL),
289 faceLookupMapPtr_(NULL)
295 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
297 Foam::faceZone::~faceZone()
303 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
305 Foam::label Foam::faceZone::whichFace(const label globalFaceID) const
307 const Map<label>& flm = faceLookupMap();
309 Map<label>::const_iterator flmIter = flm.find(globalFaceID);
311 if (flmIter == flm.end())
322 const Foam::faceZoneMesh& Foam::faceZone::zoneMesh() const
328 const Foam::primitiveFacePatch& Foam::faceZone::operator()() const
339 const Foam::labelList& Foam::faceZone::masterCells() const
341 if (!masterCellsPtr_)
346 return *masterCellsPtr_;
350 const Foam::labelList& Foam::faceZone::slaveCells() const
357 return *slaveCellsPtr_;
361 const Foam::labelList& Foam::faceZone::meshEdges() const
365 labelList faceCells(size());
367 const labelList& own = zoneMesh().mesh().faceOwner();
369 const labelList& faceLabels = *this;
371 forAll (faceCells, faceI)
373 faceCells[faceI] = own[faceLabels[faceI]];
379 operator()().meshEdges
381 zoneMesh().mesh().edges(),
382 zoneMesh().mesh().cellEdges(),
392 void Foam::faceZone::clearAddressing()
394 deleteDemandDrivenData(patchPtr_);
396 deleteDemandDrivenData(masterCellsPtr_);
397 deleteDemandDrivenData(slaveCellsPtr_);
399 deleteDemandDrivenData(mePtr_);
400 deleteDemandDrivenData(faceLookupMapPtr_);
404 void Foam::faceZone::resetAddressing
406 const labelList& addr,
407 const boolList& flipMap
411 labelList::operator=(addr);
416 void Foam::faceZone::updateMesh(const mapPolyMesh& mpm)
420 labelList newAddressing(size());
421 boolList newFlipMap(flipMap_.size());
424 const labelList& faceMap = mpm.reverseFaceMap();
428 label faceI = operator[](i);
430 if (faceMap[faceI] >= 0)
432 newAddressing[nFaces] = faceMap[faceI];
433 newFlipMap[nFaces] = flipMap_[i]; // Keep flip map.
438 newAddressing.setSize(nFaces);
439 newFlipMap.setSize(nFaces);
441 transfer(newAddressing);
442 flipMap_.transfer(newFlipMap);
446 bool Foam::faceZone::checkDefinition(const bool report) const
448 const labelList& addr = *this;
450 bool boundaryError = false;
454 if (addr[i] < 0 || addr[i] >= zoneMesh().mesh().faces().size())
456 boundaryError = true;
462 "bool faceZone::checkDefinition("
463 "const bool report) const"
464 ) << "Zone " << name()
465 << " contains invalid face label " << addr[i] << nl
466 << "Valid face labels are 0.."
467 << zoneMesh().mesh().faces().size()-1 << endl;
471 return boundaryError;
475 void Foam::faceZone::movePoints(const pointField& p)
479 patchPtr_->movePoints(p);
483 void Foam::faceZone::write(Ostream& os) const
486 << nl << static_cast<const labelList&>(*this)
491 void Foam::faceZone::writeDict(Ostream& os) const
493 os << nl << name() << nl << token::BEGIN_BLOCK << nl
494 << " type " << type() << token::END_STATEMENT << nl;
496 writeEntry("faceLabels", os);
497 flipMap().writeEntry("flipMap", os);
499 os << token::END_BLOCK << endl;
503 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
505 Foam::Ostream& Foam::operator<<(Ostream& os, const faceZone& p)
508 os.check("Ostream& operator<<(Ostream& f, const faceZone& p");
513 // ************************************************************************* //