1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | cfMesh: A library for mesh generation
5 \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6 \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of cfMesh.
11 cfMesh 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 cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
26 \*---------------------------------------------------------------------------*/
28 #include "polyMeshGenFaces.H"
29 #include "faceIOList.H"
30 #include "IOPtrList.H"
31 #include "IOobjectList.H"
33 #include "demandDrivenData.H"
34 #include "stringListOps.H"
39 // * * * * * * * * * * Private member functions * * * * * * * * * * * * * * * //
41 void polyMeshGenFaces::clearOut() const
43 deleteDemandDrivenData(ownerPtr_);
44 deleteDemandDrivenData(neighbourPtr_);
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 polyMeshGenFaces::polyMeshGenFaces(const Time& runTime)
52 polyMeshGenPoints(runTime),
72 //- Construct from components without the boundary
73 polyMeshGenFaces::polyMeshGenFaces
76 const pointField& points,
80 polyMeshGenPoints(runTime, points),
100 //- Construct from components with the boundary
101 polyMeshGenFaces::polyMeshGenFaces
104 const pointField& points,
105 const faceList& faces,
106 const wordList& patchNames,
107 const labelList& patchStart,
108 const labelList& nFacesInPatch
111 polyMeshGenPoints(runTime, points),
130 if( Pstream::parRun() )
133 "polyMeshGenFaces::polyMeshGenFaces("
134 "const Time& runTime,"
135 "const pointField& points,"
136 "const faceList& faces,"
137 "const wordList& patchNames,"
138 "const labelList& patchStart,"
139 "const labelList& nFacesInPatch)"
140 ) << "Cannot do this in parallel!" << exit(FatalError);
142 boundaries_.setSize(patchNames.size());
143 forAll(patchNames, patchI)
152 nFacesInPatch[patchI],
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161 polyMeshGenFaces::~polyMeshGenFaces()
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168 label polyMeshGenFaces::faceIsInProcPatch(const label faceLabel) const
170 const label i = procBoundaries_.size() - 1;
176 procBoundaries_[i].patchStart() +
177 procBoundaries_[i].patchSize()
183 forAllReverse(procBoundaries_, patchI)
184 if( faceLabel >= procBoundaries_[patchI].patchStart() )
190 label polyMeshGenFaces::faceIsInPatch(const label faceLabel) const
192 const label i = boundaries_.size() - 1;
193 if( faceLabel >= (boundaries_[i].patchStart()+boundaries_[i].patchSize()) )
196 forAllReverse(boundaries_, patchI)
197 if( faceLabel >= boundaries_[patchI].patchStart() )
203 wordList polyMeshGenFaces::patchNames() const
205 wordList t(boundaries_.size());
207 forAll(boundaries_, patchI)
209 t[patchI] = boundaries_[patchI].patchName();
215 label polyMeshGenFaces::getPatchID(const word& patchName) const
217 forAll(boundaries_, patchI)
219 if(boundaries_.set(patchI))
221 if(boundaries_[patchI].patchName() == patchName)
228 // If the code gets here, it implies that the patch was not found.
229 // return a -1 in this case
233 word polyMeshGenFaces::getPatchName(const label patchID) const
235 if((patchID < 0) || (patchID >= boundaries_.size()))
239 "polyMeshGenFaces::getPatchName(const label patchID) const"
240 ) << "invalid patch ID supplied"
241 << abort(FatalError);
244 return boundaries_[patchID].patchName();
247 labelList polyMeshGenFaces::findPatches(const word& patchName) const
249 wordList allPatches = patchNames();
251 labelList patchIDs = findStrings(patchName, allPatches);
255 WarningIn("polyMeshGenFaces::findPatches(const word&)")
256 << "Cannot find any patch names matching " << patchName << endl;
262 label polyMeshGenFaces::addFaceSubset(const word& setName)
264 label id = faceSubsetIndex(setName);
267 Warning << "Face subset " << setName << " already exists!" << endl;
274 std::map<label, meshSubset>::const_iterator it=faceSubsets_.begin();
275 it!=faceSubsets_.end();
278 id = Foam::max(id, it->first+1);
285 meshSubset(setName, meshSubset::FACESUBSET)
292 void polyMeshGenFaces::removeFaceSubset(const label setI)
294 if( faceSubsets_.find(setI) == faceSubsets_.end() )
297 faceSubsets_.erase(setI);
300 word polyMeshGenFaces::faceSubsetName(const label setI) const
302 std::map<label, meshSubset>::const_iterator it =
303 faceSubsets_.find(setI);
304 if( it == faceSubsets_.end() )
306 Warning << "Subset " << setI << " is not a face subset" << endl;
310 return it->second.name();
313 label polyMeshGenFaces::faceSubsetIndex(const word& setName) const
315 std::map<label, meshSubset>::const_iterator it;
316 for(it=faceSubsets_.begin();it!=faceSubsets_.end();++it)
318 if( it->second.name() == setName )
325 void polyMeshGenFaces::read()
327 polyMeshGenPoints::read();
342 deleteDemandDrivenData(ownerPtr_);
343 deleteDemandDrivenData(neighbourPtr_);
371 if( neighbourPtr_->size() != ownerPtr_->size() )
372 neighbourPtr_->setSize(ownerPtr_->size(), -1);
374 //- read boundary information
375 IOPtrList<boundaryPatchBase> patches
388 forAll(patches, patchI)
389 if( patches[patchI].type() == "processor" )
392 procBoundaries_.setSize(i);
393 boundaries_.setSize(patches.size()-i);
396 forAll(patches, patchI)
397 if( patches[patchI].type() != "processor" )
404 patches[patchI].patchName(),
405 patches[patchI].patchType(),
406 patches[patchI].patchSize(),
407 patches[patchI].patchStart()
414 forAll(patches, patchI)
415 if( patches[patchI].type() == "processor" )
420 new processorBoundaryPatch
422 patches[patchI].patchName(),
423 patches[patchI].dict()
428 nIntFaces_ = boundaries_[0].patchStart();
430 //- read face subsets
438 wordList setNames = allSets.names("faceSet");
439 forAll(setNames, setI)
441 IOobject* obj = allSets.lookup(setNames[setI]);
444 const labelList content = fSet.toc();
445 const label id = addFaceSubset(setNames[setI]);
447 faceSubsets_[id].updateSubset(content);
451 void polyMeshGenFaces::write() const
453 polyMeshGenPoints::write();
457 if( !ownerPtr_ || !neighbourPtr_ )
458 calculateOwnersAndNeighbours();
460 neighbourPtr_->write();
462 //- write boundary data
463 PtrList<boundaryPatchBase> ptchs
465 procBoundaries_.size() + boundaries_.size()
470 //- ordinary patches come first
471 forAll(boundaries_, patchI)
474 dict.add("type", boundaries_[patchI].patchType());
475 dict.add("nFaces", boundaries_[patchI].patchSize());
476 dict.add("startFace", boundaries_[patchI].patchStart());
480 boundaryPatchBase::New
482 boundaries_[patchI].patchName(),
488 //- processor patches are at the end
489 forAll(procBoundaries_, patchI)
494 boundaryPatchBase::New
496 procBoundaries_[patchI].patchName(),
497 procBoundaries_[patchI].dict()
502 IOPtrList<boundaryPatchBase> patches
518 //- write face subsets
519 std::map<label, meshSubset>::const_iterator setIt;
520 for(setIt=faceSubsets_.begin();setIt!=faceSubsets_.end();++setIt)
526 setIt->second.name(),
535 labelLongList containedElements;
536 setIt->second.containedElements(containedElements);
538 forAll(containedElements, i)
539 set.insert(containedElements[i]);
544 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
546 } // End namespace Foam
548 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //