polyMeshGenFaces.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | cfMesh: A library for mesh generation
4  \\ / O peration |
5  \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6  \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of cfMesh.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "polyMeshGenFaces.H"
29 #include "faceIOList.H"
30 #include "IOPtrList.H"
31 #include "IOobjectList.H"
32 #include "faceSet.H"
33 #include "demandDrivenData.H"
34 #include "stringListOps.H"
35 
36 namespace Foam
37 {
38 
39 // * * * * * * * * * * Private member functions * * * * * * * * * * * * * * * //
40 
42 {
45 }
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 // Constructors
49 //- Null constructor
51 :
52  polyMeshGenPoints(runTime),
53  faces_
54  (
55  IOobject
56  (
57  "faces",
58  runTime.constant(),
59  "polyMesh",
60  runTime
61  ),
62  0
63  ),
64  procBoundaries_(),
65  boundaries_(),
66  faceSubsets_(),
67  nIntFaces_(0),
68  ownerPtr_(NULL),
69  neighbourPtr_(NULL)
70 {}
71 
72 //- Construct from components without the boundary
74 (
75  const Time& runTime,
76  const pointField& points,
77  const faceList& faces
78 )
79 :
80  polyMeshGenPoints(runTime, points),
81  faces_
82  (
83  IOobject
84  (
85  "faces",
86  runTime.constant(),
87  "polyMesh",
88  runTime
89  ),
90  faces
91  ),
92  procBoundaries_(),
93  boundaries_(),
94  faceSubsets_(),
95  nIntFaces_(0),
96  ownerPtr_(NULL),
97  neighbourPtr_(NULL)
98 {}
99 
100 //- Construct from components with the boundary
102 (
103  const Time& runTime,
104  const pointField& points,
105  const faceList& faces,
106  const wordList& patchNames,
107  const labelList& patchStart,
108  const labelList& nFacesInPatch
109 )
110 :
111  polyMeshGenPoints(runTime, points),
112  faces_
113  (
114  IOobject
115  (
116  "faces",
117  runTime.constant(),
118  "polyMesh",
119  runTime
120  ),
121  faces
122  ),
123  procBoundaries_(),
124  boundaries_(),
125  faceSubsets_(),
126  nIntFaces_(0),
127  ownerPtr_(NULL),
128  neighbourPtr_(NULL)
129 {
130  if( Pstream::parRun() )
132  (
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);
141 
142  boundaries_.setSize(patchNames.size());
143  forAll(patchNames, patchI)
144  {
145  boundaries_.set
146  (
147  patchI,
148  new boundaryPatch
149  (
150  patchNames[patchI],
151  "patch",
152  nFacesInPatch[patchI],
153  patchStart[patchI]
154  )
155  );
156  }
157 }
158 
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 // Destructor
162 {
163  clearOut();
164 }
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
169 {
170  const label i = procBoundaries_.size() - 1;
171  if(
172  (i < 0) ||
173  (
174  faceLabel >=
175  (
176  procBoundaries_[i].patchStart() +
177  procBoundaries_[i].patchSize()
178  )
179  )
180  )
181  return -1;
182 
184  if( faceLabel >= procBoundaries_[patchI].patchStart() )
185  return patchI;
186 
187  return -1;
188 }
189 
191 {
192  const label i = boundaries_.size() - 1;
193  if( faceLabel >= (boundaries_[i].patchStart()+boundaries_[i].patchSize()) )
194  return -1;
195 
196  forAllReverse(boundaries_, patchI)
197  if( faceLabel >= boundaries_[patchI].patchStart() )
198  return patchI;
199 
200  return -1;
201 }
202 
204 {
205  wordList t(boundaries_.size());
206 
207  forAll(boundaries_, patchI)
208  {
209  t[patchI] = boundaries_[patchI].patchName();
210  }
211 
212  return t;
213 }
214 
215 label polyMeshGenFaces::getPatchID(const word& patchName) const
216 {
217  forAll(boundaries_, patchI)
218  {
219  if(boundaries_.set(patchI))
220  {
221  if(boundaries_[patchI].patchName() == patchName)
222  {
223  return patchI;
224  }
225  }
226  }
227 
228  // If the code gets here, it implies that the patch was not found.
229  // return a -1 in this case
230  return -1;
231 }
232 
234 {
235  if((patchID < 0) || (patchID >= boundaries_.size()))
236  {
238  (
239  "polyMeshGenFaces::getPatchName(const label patchID) const"
240  ) << "invalid patch ID supplied"
241  << abort(FatalError);
242  }
243 
244  return boundaries_[patchID].patchName();
245 }
246 
248 {
249  wordList allPatches = patchNames();
250 
251  labelList patchIDs = findStrings(patchName, allPatches);
252 
253  if(patchIDs.empty())
254  {
255  WarningIn("polyMeshGenFaces::findPatches(const word&)")
256  << "Cannot find any patch names matching " << patchName << endl;
257  }
258 
259  return patchIDs;
260 }
261 
263 {
264  label id = faceSubsetIndex(setName);
265  if( id >= 0 )
266  {
267  Warning << "Face subset " << setName << " already exists!" << endl;
268  return id;
269  }
270 
271  id = 0;
272  for
273  (
274  std::map<label, meshSubset>::const_iterator it=faceSubsets_.begin();
275  it!=faceSubsets_.end();
276  ++it
277  )
278  id = Foam::max(id, it->first+1);
279 
280  faceSubsets_.insert
281  (
282  std::make_pair
283  (
284  id,
286  )
287  );
288 
289  return id;
290 }
291 
293 {
294  if( faceSubsets_.find(setI) == faceSubsets_.end() )
295  return;
296 
297  faceSubsets_.erase(setI);
298 }
299 
301 {
302  std::map<label, meshSubset>::const_iterator it =
303  faceSubsets_.find(setI);
304  if( it == faceSubsets_.end() )
305  {
306  Warning << "Subset " << setI << " is not a face subset" << endl;
307  return word();
308  }
309 
310  return it->second.name();
311 }
312 
314 {
315  std::map<label, meshSubset>::const_iterator it;
316  for(it=faceSubsets_.begin();it!=faceSubsets_.end();++it)
317  {
318  if( it->second.name() == setName )
319  return it->first;
320  }
321 
322  return -1;
323 }
324 
326 {
328 
329  faceIOList fcs
330  (
331  IOobject
332  (
333  "faces",
334  runTime_.constant(),
335  "polyMesh",
336  runTime_,
338  )
339  );
340  faces_ = fcs;
341 
344 
345  ownerPtr_ =
346  new labelIOList
347  (
348  IOobject
349  (
350  "owner",
351  runTime_.constant(),
352  "polyMesh",
353  runTime_,
355  )
356  );
357 
358  neighbourPtr_ =
359  new labelIOList
360  (
361  IOobject
362  (
363  "neighbour",
364  runTime_.constant(),
365  "polyMesh",
366  runTime_,
368  )
369  );
370 
371  if( neighbourPtr_->size() != ownerPtr_->size() )
373 
374  //- read boundary information
376  (
377  IOobject
378  (
379  "boundary",
380  runTime_.constant(),
381  "polyMesh",
382  runTime_,
384  )
385  );
386 
387  label i(0);
388  forAll(patches, patchI)
389  if( patches[patchI].type() == "processor" )
390  ++i;
391 
392  procBoundaries_.setSize(i);
393  boundaries_.setSize(patches.size()-i);
394 
395  i=0;
396  forAll(patches, patchI)
397  if( patches[patchI].type() != "processor" )
398  {
399  boundaries_.set
400  (
401  i,
402  new boundaryPatch
403  (
404  patches[patchI].patchName(),
405  patches[patchI].patchType(),
406  patches[patchI].patchSize(),
407  patches[patchI].patchStart()
408  )
409  );
410  ++i;
411  }
412 
413  i = 0;
414  forAll(patches, patchI)
415  if( patches[patchI].type() == "processor" )
416  {
417  procBoundaries_.set
418  (
419  i++,
421  (
422  patches[patchI].patchName(),
423  patches[patchI].dict()
424  )
425  );
426  }
427 
428  nIntFaces_ = boundaries_[0].patchStart();
429 
430  //- read face subsets
431  IOobjectList allSets
432  (
433  runTime_,
434  runTime_.constant(),
435  "polyMesh/sets"
436  );
437 
438  wordList setNames = allSets.names("faceSet");
439  forAll(setNames, setI)
440  {
441  IOobject* obj = allSets.lookup(setNames[setI]);
442 
443  faceSet fSet(*obj);
444  const labelList content = fSet.toc();
445  const label id = addFaceSubset(setNames[setI]);
446 
447  faceSubsets_[id].updateSubset(content);
448  }
449 }
450 
452 {
454 
455  faces_.write();
456 
457  if( !ownerPtr_ || !neighbourPtr_ )
459  ownerPtr_->write();
460  neighbourPtr_->write();
461 
462  //- write boundary data
464  (
465  procBoundaries_.size() + boundaries_.size()
466  );
467 
468  label i(0);
469 
470  //- ordinary patches come first
471  forAll(boundaries_, patchI)
472  {
474  dict.add("type", boundaries_[patchI].patchType());
475  dict.add("nFaces", boundaries_[patchI].patchSize());
476  dict.add("startFace", boundaries_[patchI].patchStart());
477  ptchs.set
478  (
479  i++,
481  (
482  boundaries_[patchI].patchName(),
483  dict
484  )
485  );
486  }
487 
488  //- processor patches are at the end
489  forAll(procBoundaries_, patchI)
490  {
491  ptchs.set
492  (
493  i++,
495  (
496  procBoundaries_[patchI].patchName(),
497  procBoundaries_[patchI].dict()
498  )
499  );
500  }
501 
503  (
504  IOobject
505  (
506  "boundary",
507  runTime_.constant(),
508  "polyMesh",
509  runTime_,
512  ),
513  ptchs
514  );
515 
516  patches.write();
517 
518  //- write face subsets
519  std::map<label, meshSubset>::const_iterator setIt;
520  for(setIt=faceSubsets_.begin();setIt!=faceSubsets_.end();++setIt)
521  {
522  faceSet set
523  (
524  IOobject
525  (
526  setIt->second.name(),
527  runTime_.constant(),
528  "polyMesh/sets",
529  runTime_,
532  )
533  );
534 
535  labelLongList containedElements;
536  setIt->second.containedElements(containedElements);
537 
538  forAll(containedElements, i)
539  set.insert(containedElements[i]);
540  set.write();
541  }
542 }
543 
544 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
545 
546 } // End namespace Foam
547 
548 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::polyMeshGenFaces::ownerPtr_
labelIOList * ownerPtr_
Definition: polyMeshGenFaces.H:73
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::polyMeshGenFaces::faceSubsetName
word faceSubsetName(const label) const
Definition: polyMeshGenFaces.C:300
Foam::polyMeshGenFaces::removeFaceSubset
void removeFaceSubset(const label)
Definition: polyMeshGenFaces.C:292
Foam::IOPtrList
A PtrList of objects of type <T> with automated input and output.
Definition: IOPtrList.H:50
Foam::IOobject::AUTO_WRITE
@ AUTO_WRITE
Definition: IOobject.H:117
Foam::HashTable::toc
List< Key > toc() const
Return the table of contents.
Definition: HashTable.C:201
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::polyMeshGenFaces::findPatches
labelList findPatches(const word &patchName) const
return a list of patch indices corresponding to the given
Definition: polyMeshGenFaces.C:247
Foam::polyMeshGenFaces::patchNames
wordList patchNames() const
return list of patches in the boundary
Definition: polyMeshGenFaces.C:203
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::polyMeshGenFaces::faceSubsetIndex
label faceSubsetIndex(const word &) const
Definition: polyMeshGenFaces.C:313
Foam::Warning
messageStream Warning
Foam::meshSubset::FACESUBSET
@ FACESUBSET
Definition: meshSubset.H:76
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:377
Foam::polyMeshGenFaces::addFaceSubset
label addFaceSubset(const word &)
Definition: polyMeshGenFaces.C:262
Foam::regIOobject::write
virtual bool write() const
Write using setting from DB.
Definition: regIOobjectWrite.C:126
Foam::faceSet
A list of face labels.
Definition: faceSet.H:48
Foam::polyMeshGenFaces::faceSubsets_
std::map< label, meshSubset > faceSubsets_
face subsets
Definition: polyMeshGenFaces.H:68
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:108
IOobjectList.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::polyMeshGenFaces::faceIsInPatch
label faceIsInPatch(const label faceLabel) const
return patch label for the given face label
Definition: polyMeshGenFaces.C:190
Foam::IOobjectList::names
wordList names() const
Return the list of names of the IOobjects.
Definition: IOobjectList.C:221
Foam::polyMeshGenPoints
Definition: polyMeshGenPoints.H:55
Foam::polyMeshGenPoints::write
void write() const
Definition: polyMeshGenPoints.C:184
Foam::labelIOList
IOList< label > labelIOList
Label container classes.
Definition: labelIOList.H:42
Foam::polyMeshGenPoints::read
void read()
Definition: polyMeshGenPoints.C:147
constant
Constant dispersed-phase particle diameter model.
Foam::polyMeshGenFaces::read
void read()
Definition: polyMeshGenFaces.C:325
Foam::boundaryPatch
Like polyPatch but without reference to mesh. patchIdentifier::index is not used. Used in boundaryMes...
Definition: boundaryPatch.H:50
Foam::LongList< label >
Foam::deleteDemandDrivenData
void deleteDemandDrivenData(DataPtr &dataPtr)
Definition: demandDrivenData.H:40
Foam::meshSubset
Definition: meshSubset.H:55
Foam::PtrList::set
bool set(const label) const
Is element set.
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::polyMeshGenFaces::getPatchID
label getPatchID(const word &patchName) const
return the index of a patch given its name
Definition: polyMeshGenFaces.C:215
Foam::polyMeshGenFaces::procBoundaries_
PtrList< processorBoundaryPatch > procBoundaries_
Definition: polyMeshGenFaces.H:62
IOPtrList.H
Foam::polyMeshGenFaces::faceIsInProcPatch
label faceIsInProcPatch(const label faceLabel) const
return processor patch label for the given face label
Definition: polyMeshGenFaces.C:168
Foam::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:111
faceSet.H
Foam::polyMeshGenFaces::~polyMeshGenFaces
virtual ~polyMeshGenFaces()
Definition: polyMeshGenFaces.C:161
Foam::PtrList
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
Foam::polyMeshGenFaces::getPatchName
word getPatchName(const label patchID) const
return the name of a patch given its ID
Definition: polyMeshGenFaces.C:233
patchNames
wordList patchNames(nPatches)
Foam::polyMeshGenFaces::polyMeshGenFaces
polyMeshGenFaces(const polyMeshGenFaces &)
Foam::polyMeshGenFaces::neighbourPtr_
labelIOList * neighbourPtr_
Definition: polyMeshGenFaces.H:74
Foam::polyMeshGenFaces::write
void write() const
Definition: polyMeshGenFaces.C:451
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::IOobjectList::lookup
IOobject * lookup(const word &name) const
Lookup a given name and return IOobject ptr if found else NULL.
Definition: IOobjectList.C:128
Foam::boundaryPatchBase::New
static autoPtr< boundaryPatchBase > New(const word &name, const dictionary &dict)
Definition: boundaryPatchBase.C:53
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
forAllReverse
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: UList.H:418
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::processorBoundaryPatch
Definition: processorBoundaryPatch.H:47
faceIOList.H
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:50
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::polyMeshGenFaces::nIntFaces_
label nIntFaces_
number of internal faces, owner and neighbour
Definition: polyMeshGenFaces.H:72
Foam::findStrings
bool findStrings(const wordReListMatcher &matcher, const std::string &str)
Return true if string matches one of the regular expressions.
Definition: stringListOps.H:52
Foam::polyMeshGenFaces::calculateOwnersAndNeighbours
virtual void calculateOwnersAndNeighbours() const =0
calculate owner and neighbour addressing
Foam::polyMeshGenFaces::faces_
faceListPMG faces_
list of faces
Definition: polyMeshGenFaces.H:57
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePaths.H:130
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::IOList
A List of objects of type <T> with automated input and output.
Definition: IOList.H:50
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:116
Foam::polyMeshGenPoints::runTime_
const Time & runTime_
reference to the Time registry
Definition: polyMeshGenPoints.H:61
stringListOps.H
Operations on lists of strings.
patches
patches[0]
Definition: createSingleCellMesh.H:36
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
WarningIn
#define WarningIn(functionName)
Report a warning using Foam::Warning.
Definition: messageStream.H:254
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
polyMeshGenFaces.H
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::polyMeshGenFaces::clearOut
void clearOut() const
clear all pointer data
Definition: polyMeshGenFaces.C:41
Foam::polyMeshGenFaces::boundaries_
PtrList< boundaryPatch > boundaries_
boundary data
Definition: polyMeshGenFaces.H:65