1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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"
37 #include "syncTools.H"
39 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
43 defineTypeNameAndDebug(faceZone, 0);
44 defineRunTimeSelectionTable(faceZone, dictionary);
45 addToRunTimeSelectionTable(faceZone, faceZone, dictionary);
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
50 void Foam::faceZone::calcFaceZonePatch() const
54 Info<< "void faceZone::calcFaceZonePatch() const : "
55 << "Calculating primitive patch"
63 "void faceZone::calcFaceZonePatch() const"
64 ) << "primitive face zone patch already calculated"
69 new primitiveFacePatch
72 zoneMesh().mesh().points()
75 primitiveFacePatch& patch = *patchPtr_;
77 const faceList& f = zoneMesh().mesh().faces();
79 const labelList& addr = *this;
80 const boolList& flip = flipMap();
86 patch[faceI] = f[addr[faceI]].reverseFace();
90 patch[faceI] = f[addr[faceI]];
96 Info<< "void faceZone::calcFaceZonePatch() const : "
97 << "Finished calculating primitive patch"
103 const Foam::Map<Foam::label>& Foam::faceZone::faceLookupMap() const
105 if (!faceLookupMapPtr_)
110 return *faceLookupMapPtr_;
114 void Foam::faceZone::calcFaceLookupMap() const
118 Info<< "void faceZone::calcFaceLookupMap() const : "
119 << "Calculating face lookup map"
123 if (faceLookupMapPtr_)
127 "void faceZone::calcFaceLookupMap() const"
128 ) << "face lookup map already calculated"
129 << abort(FatalError);
132 const labelList& addr = *this;
134 faceLookupMapPtr_ = new Map<label>(2*addr.size());
135 Map<label>& flm = *faceLookupMapPtr_;
139 flm.insert(addr[faceI], faceI);
144 Info<< "void faceZone::calcFaceLookupMap() const : "
145 << "Finished calculating face lookup map"
151 void Foam::faceZone::calcCellLayers() const
155 Info<< "void Foam::faceZone::calcCellLayers() const : "
156 << "calculating master cells"
160 // It is an error to attempt to recalculate edgeCells
161 // if the pointer is already set
162 if (masterCellsPtr_ || slaveCellsPtr_)
164 FatalErrorIn("void faceZone::calcCellLayers() const")
165 << "cell layers already calculated"
166 << abort(FatalError);
170 // Go through all the faces in the master zone. Choose the
171 // master or slave cell based on the face flip
173 const labelList& own = zoneMesh().mesh().faceOwner();
174 const labelList& nei = zoneMesh().mesh().faceNeighbour();
176 const labelList& mf = *this;
178 const boolList& faceFlip = flipMap();
180 masterCellsPtr_ = new labelList(mf.size());
181 labelList& mc = *masterCellsPtr_;
183 slaveCellsPtr_ = new labelList(mf.size());
184 labelList& sc = *slaveCellsPtr_;
188 if (!faceFlip[faceI])
190 // Face is oriented correctly, no flip needed
191 mc[faceI] = nei[mf[faceI]];
192 sc[faceI] = own[mf[faceI]];
196 mc[faceI] = own[mf[faceI]];
197 sc[faceI] = nei[mf[faceI]];
200 //Info << "masterCells: " << mc << endl;
201 //Info << "slaveCells: " << sc << endl;
206 void Foam::faceZone::checkAddressing() const
208 if (size() != flipMap_.size())
210 FatalErrorIn("void Foam::faceZone::checkAddressing() const")
211 << "Different sizes of the addressing and flipMap arrays. "
212 << "Size of addressing: " << size()
213 << " size of flip map: " << flipMap_.size()
214 << abort(FatalError);
219 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
221 // Construct from components
222 Foam::faceZone::faceZone
225 const labelList& addr,
228 const faceZoneMesh& zm
237 masterCellsPtr_(NULL),
238 slaveCellsPtr_(NULL),
240 faceLookupMapPtr_(NULL)
246 Foam::faceZone::faceZone
249 const Xfer<labelList>& addr,
250 const Xfer<boolList>& fm,
252 const faceZoneMesh& zm
261 masterCellsPtr_(NULL),
262 slaveCellsPtr_(NULL),
264 faceLookupMapPtr_(NULL)
270 // Construct from dictionary
271 Foam::faceZone::faceZone
274 const dictionary& dict,
276 const faceZoneMesh& zm
279 labelList(dict.lookup("faceLabels")),
281 flipMap_(dict.lookup("flipMap")),
285 masterCellsPtr_(NULL),
286 slaveCellsPtr_(NULL),
288 faceLookupMapPtr_(NULL)
294 // Construct given the original zone and resetting the
295 // face list and zone mesh information
296 Foam::faceZone::faceZone
299 const labelList& addr,
302 const faceZoneMesh& zm
311 masterCellsPtr_(NULL),
312 slaveCellsPtr_(NULL),
314 faceLookupMapPtr_(NULL)
320 Foam::faceZone::faceZone
323 const Xfer<labelList>& addr,
324 const Xfer<boolList>& fm,
326 const faceZoneMesh& zm
335 masterCellsPtr_(NULL),
336 slaveCellsPtr_(NULL),
338 faceLookupMapPtr_(NULL)
344 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
346 Foam::faceZone::~faceZone()
352 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
354 Foam::label Foam::faceZone::whichFace(const label globalFaceID) const
356 const Map<label>& flm = faceLookupMap();
358 Map<label>::const_iterator flmIter = flm.find(globalFaceID);
360 if (flmIter == flm.end())
371 const Foam::faceZoneMesh& Foam::faceZone::zoneMesh() const
377 const Foam::primitiveFacePatch& Foam::faceZone::operator()() const
388 const Foam::labelList& Foam::faceZone::masterCells() const
390 if (!masterCellsPtr_)
395 return *masterCellsPtr_;
399 const Foam::labelList& Foam::faceZone::slaveCells() const
406 return *slaveCellsPtr_;
410 const Foam::labelList& Foam::faceZone::meshEdges() const
414 //labelList faceCells(size());
416 //const labelList& own = zoneMesh().mesh().faceOwner();
418 //const labelList& faceLabels = *this;
420 //forAll (faceCells, faceI)
422 // faceCells[faceI] = own[faceLabels[faceI]];
428 // operator()().meshEdges
430 // zoneMesh().mesh().edges(),
431 // zoneMesh().mesh().cellEdges(),
439 operator()().meshEdges
441 zoneMesh().mesh().edges(),
442 zoneMesh().mesh().pointEdges()
451 void Foam::faceZone::clearAddressing()
453 deleteDemandDrivenData(patchPtr_);
455 deleteDemandDrivenData(masterCellsPtr_);
456 deleteDemandDrivenData(slaveCellsPtr_);
458 deleteDemandDrivenData(mePtr_);
459 deleteDemandDrivenData(faceLookupMapPtr_);
463 void Foam::faceZone::resetAddressing
465 const labelList& addr,
466 const boolList& flipMap
470 labelList::operator=(addr);
475 void Foam::faceZone::updateMesh(const mapPolyMesh& mpm)
479 labelList newAddressing(size());
480 boolList newFlipMap(flipMap_.size());
483 const labelList& faceMap = mpm.reverseFaceMap();
487 label faceI = operator[](i);
489 if (faceMap[faceI] >= 0)
491 newAddressing[nFaces] = faceMap[faceI];
492 newFlipMap[nFaces] = flipMap_[i]; // Keep flip map.
497 newAddressing.setSize(nFaces);
498 newFlipMap.setSize(nFaces);
500 transfer(newAddressing);
501 flipMap_.transfer(newFlipMap);
505 bool Foam::faceZone::checkDefinition(const bool report) const
507 const labelList& addr = *this;
509 bool boundaryError = false;
513 if (addr[i] < 0 || addr[i] >= zoneMesh().mesh().faces().size())
515 boundaryError = true;
521 "bool faceZone::checkDefinition("
522 "const bool report) const"
523 ) << "Zone " << name()
524 << " contains invalid face label " << addr[i] << nl
525 << "Valid face labels are 0.."
526 << zoneMesh().mesh().faces().size()-1 << endl;
530 return boundaryError;
534 bool Foam::faceZone::checkParallelSync(const bool report) const
536 const polyMesh& mesh = zoneMesh().mesh();
537 const polyBoundaryMesh& bm = mesh.boundaryMesh();
539 bool boundaryError = false;
542 // Check that zone faces are synced
543 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
546 boolList neiZoneFace(mesh.nFaces()-mesh.nInternalFaces(), false);
547 boolList neiZoneFlip(mesh.nFaces()-mesh.nInternalFaces(), false);
550 label faceI = operator[](i);
552 if (!mesh.isInternalFace(faceI))
554 neiZoneFace[faceI-mesh.nInternalFaces()] = true;
555 neiZoneFlip[faceI-mesh.nInternalFaces()] = flipMap()[i];
558 boolList myZoneFace(neiZoneFace);
559 syncTools::swapBoundaryFaceList(mesh, neiZoneFace, false);
560 boolList myZoneFlip(neiZoneFlip);
561 syncTools::swapBoundaryFaceList(mesh, neiZoneFlip, false);
565 label faceI = operator[](i);
567 label patchI = bm.whichPatch(faceI);
569 if (patchI != -1 && bm[patchI].coupled())
571 label bFaceI = faceI-mesh.nInternalFaces();
573 // Check face in zone on both sides
574 if (myZoneFace[bFaceI] != neiZoneFace[bFaceI])
576 boundaryError = true;
580 Pout<< " ***Problem with faceZone " << index()
581 << " named " << name()
582 << ". Face " << faceI
583 << " on coupled patch "
585 << " is not consistent with its coupled neighbour."
590 // Flip state should be opposite.
591 if (myZoneFlip[bFaceI] == neiZoneFlip[bFaceI])
593 boundaryError = true;
597 Pout<< " ***Problem with faceZone " << index()
598 << " named " << name()
599 << ". Face " << faceI
600 << " on coupled patch "
602 << " does not have consistent flipMap"
603 << " across coupled faces."
611 return returnReduce(boundaryError, orOp<bool>());
615 void Foam::faceZone::movePoints(const pointField& p)
619 patchPtr_->movePoints(p);
623 void Foam::faceZone::write(Ostream& os) const
626 << nl << static_cast<const labelList&>(*this)
631 void Foam::faceZone::writeDict(Ostream& os) const
633 os << nl << name() << nl << token::BEGIN_BLOCK << nl
634 << " type " << type() << token::END_STATEMENT << nl;
636 writeEntry("faceLabels", os);
637 flipMap().writeEntry("flipMap", os);
639 os << token::END_BLOCK << endl;
643 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
645 Foam::Ostream& Foam::operator<<(Ostream& os, const faceZone& p)
648 os.check("Ostream& operator<<(Ostream& f, const faceZone& p");
653 // ************************************************************************* //