1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 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
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 \*---------------------------------------------------------------------------*/
27 #include "addToRunTimeSelectionTable.H"
28 #include "faceZoneMesh.H"
30 #include "primitiveMesh.H"
31 #include "demandDrivenData.H"
32 #include "mapPolyMesh.H"
33 #include "syncTools.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 defineTypeNameAndDebug(faceZone, 0);
40 defineRunTimeSelectionTable(faceZone, dictionary);
41 addToRunTimeSelectionTable(faceZone, faceZone, dictionary);
44 const char* const Foam::faceZone::labelsName = "faceLabels";
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 void Foam::faceZone::calcFaceZonePatch() const
52 Info<< "void faceZone::calcFaceZonePatch() const : "
53 << "Calculating primitive patch"
61 "void faceZone::calcFaceZonePatch() const"
62 ) << "primitive face zone patch already calculated"
67 new primitiveFacePatch
70 zoneMesh().mesh().points()
73 primitiveFacePatch& patch = *patchPtr_;
75 const faceList& f = zoneMesh().mesh().faces();
77 const labelList& addr = *this;
78 const boolList& flip = flipMap();
84 patch[faceI] = f[addr[faceI]].reverseFace();
88 patch[faceI] = f[addr[faceI]];
94 Info<< "void faceZone::calcFaceZonePatch() const : "
95 << "Finished calculating primitive patch"
101 void Foam::faceZone::calcCellLayers() const
105 Info<< "void Foam::faceZone::calcCellLayers() const : "
106 << "calculating master cells"
110 // It is an error to attempt to recalculate edgeCells
111 // if the pointer is already set
112 if (masterCellsPtr_ || slaveCellsPtr_)
114 FatalErrorIn("void faceZone::calcCellLayers() const")
115 << "cell layers already calculated"
116 << abort(FatalError);
120 // Go through all the faces in the master zone. Choose the
121 // master or slave cell based on the face flip
123 const labelList& own = zoneMesh().mesh().faceOwner();
124 const labelList& nei = zoneMesh().mesh().faceNeighbour();
126 const labelList& mf = *this;
128 const boolList& faceFlip = flipMap();
130 masterCellsPtr_ = new labelList(mf.size());
131 labelList& mc = *masterCellsPtr_;
133 slaveCellsPtr_ = new labelList(mf.size());
134 labelList& sc = *slaveCellsPtr_;
138 label ownCellI = own[mf[faceI]];
141 zoneMesh().mesh().isInternalFace(mf[faceI])
146 if (!faceFlip[faceI])
148 // Face is oriented correctly, no flip needed
149 mc[faceI] = neiCellI;
150 sc[faceI] = ownCellI;
154 mc[faceI] = ownCellI;
155 sc[faceI] = neiCellI;
158 //Info<< "masterCells: " << mc << endl;
159 //Info<< "slaveCells: " << sc << endl;
164 void Foam::faceZone::checkAddressing() const
166 if (size() != flipMap_.size())
168 FatalErrorIn("void Foam::faceZone::checkAddressing() const")
169 << "Different sizes of the addressing and flipMap arrays. "
170 << "Size of addressing: " << size()
171 << " size of flip map: " << flipMap_.size()
172 << abort(FatalError);
177 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
179 // Construct from components
180 Foam::faceZone::faceZone
183 const labelUList& addr,
186 const faceZoneMesh& zm
189 zone(name, addr, index),
193 masterCellsPtr_(NULL),
194 slaveCellsPtr_(NULL),
201 Foam::faceZone::faceZone
204 const Xfer<labelList>& addr,
205 const Xfer<boolList>& fm,
207 const faceZoneMesh& zm
210 zone(name, addr, index),
214 masterCellsPtr_(NULL),
215 slaveCellsPtr_(NULL),
222 Foam::faceZone::faceZone
225 const dictionary& dict,
227 const faceZoneMesh& zm
230 zone(name, dict, this->labelsName, index),
231 flipMap_(dict.lookup("flipMap")),
234 masterCellsPtr_(NULL),
235 slaveCellsPtr_(NULL),
242 Foam::faceZone::faceZone
245 const labelUList& addr,
248 const faceZoneMesh& zm
251 zone(fz, addr, index),
255 masterCellsPtr_(NULL),
256 slaveCellsPtr_(NULL),
263 Foam::faceZone::faceZone
266 const Xfer<labelList>& addr,
267 const Xfer<boolList>& fm,
269 const faceZoneMesh& zm
272 zone(fz, addr, index),
276 masterCellsPtr_(NULL),
277 slaveCellsPtr_(NULL),
284 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
286 Foam::faceZone::~faceZone()
292 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
294 const Foam::faceZoneMesh& Foam::faceZone::zoneMesh() const
300 Foam::label Foam::faceZone::whichFace(const label globalFaceID) const
302 return zone::localID(globalFaceID);
306 const Foam::primitiveFacePatch& Foam::faceZone::operator()() const
317 const Foam::labelList& Foam::faceZone::masterCells() const
319 if (!masterCellsPtr_)
324 return *masterCellsPtr_;
328 const Foam::labelList& Foam::faceZone::slaveCells() const
335 return *slaveCellsPtr_;
339 const Foam::labelList& Foam::faceZone::meshEdges() const
343 //labelList faceCells(size());
345 //const labelList& own = zoneMesh().mesh().faceOwner();
347 //const labelList& faceLabels = *this;
349 //forAll(faceCells, faceI)
351 // faceCells[faceI] = own[faceLabels[faceI]];
357 // operator()().meshEdges
359 // zoneMesh().mesh().edges(),
360 // zoneMesh().mesh().cellEdges(),
368 operator()().meshEdges
370 zoneMesh().mesh().edges(),
371 zoneMesh().mesh().pointEdges()
380 void Foam::faceZone::clearAddressing()
382 zone::clearAddressing();
384 deleteDemandDrivenData(patchPtr_);
386 deleteDemandDrivenData(masterCellsPtr_);
387 deleteDemandDrivenData(slaveCellsPtr_);
389 deleteDemandDrivenData(mePtr_);
393 void Foam::faceZone::resetAddressing
395 const labelUList& addr,
396 const boolList& flipMap
400 labelList::operator=(addr);
405 void Foam::faceZone::updateMesh(const mapPolyMesh& mpm)
409 labelList newAddressing(size());
410 boolList newFlipMap(flipMap_.size());
413 const labelList& faceMap = mpm.reverseFaceMap();
417 const label faceI = operator[](i);
419 if (faceMap[faceI] >= 0)
421 newAddressing[nFaces] = faceMap[faceI];
422 newFlipMap[nFaces] = flipMap_[i]; // Keep flip map.
427 newAddressing.setSize(nFaces);
428 newFlipMap.setSize(nFaces);
430 transfer(newAddressing);
431 flipMap_.transfer(newFlipMap);
435 bool Foam::faceZone::checkDefinition(const bool report) const
437 return zone::checkDefinition(zoneMesh().mesh().faces().size(), report);
441 bool Foam::faceZone::checkParallelSync(const bool report) const
443 const polyMesh& mesh = zoneMesh().mesh();
444 const polyBoundaryMesh& bm = mesh.boundaryMesh();
446 bool hasError = false;
449 // Check that zone faces are synced
450 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
453 boolList neiZoneFace(mesh.nFaces()-mesh.nInternalFaces(), false);
454 boolList neiZoneFlip(mesh.nFaces()-mesh.nInternalFaces(), false);
457 const label faceI = operator[](i);
459 if (!mesh.isInternalFace(faceI))
461 neiZoneFace[faceI-mesh.nInternalFaces()] = true;
462 neiZoneFlip[faceI-mesh.nInternalFaces()] = flipMap()[i];
465 boolList myZoneFace(neiZoneFace);
466 syncTools::swapBoundaryFaceList(mesh, neiZoneFace);
467 boolList myZoneFlip(neiZoneFlip);
468 syncTools::swapBoundaryFaceList(mesh, neiZoneFlip);
472 const label faceI = operator[](i);
473 const label patchI = bm.whichPatch(faceI);
475 if (patchI != -1 && bm[patchI].coupled())
477 const label bFaceI = faceI-mesh.nInternalFaces();
479 // Check face in zone on both sides
480 if (myZoneFace[bFaceI] != neiZoneFace[bFaceI])
486 Pout<< " ***Problem with faceZone " << index()
487 << " named " << name()
488 << ". Face " << faceI
489 << " on coupled patch "
491 << " is not consistent with its coupled neighbour."
496 // w/o report - can stop checking now
500 else if (myZoneFlip[bFaceI] == neiZoneFlip[bFaceI])
502 // Flip state should be opposite.
507 Pout<< " ***Problem with faceZone " << index()
508 << " named " << name()
509 << ". Face " << faceI
510 << " on coupled patch "
512 << " does not have consistent flipMap"
513 << " across coupled faces."
518 // w/o report - can stop checking now
526 return returnReduce(hasError, orOp<bool>());
530 void Foam::faceZone::movePoints(const pointField& p)
534 patchPtr_->movePoints(p);
538 void Foam::faceZone::write(Ostream& os) const
541 << nl << static_cast<const labelList&>(*this)
546 void Foam::faceZone::writeDict(Ostream& os) const
548 os << nl << name() << nl << token::BEGIN_BLOCK << nl
549 << " type " << type() << token::END_STATEMENT << nl;
551 writeEntry(this->labelsName, os);
552 flipMap().writeEntry("flipMap", os);
554 os << token::END_BLOCK << endl;
558 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
560 Foam::Ostream& Foam::operator<<(Ostream& os, const faceZone& zn)
563 os.check("Ostream& operator<<(Ostream&, const faceZone&");
568 // ************************************************************************* //