polyPatch.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "polyPatch.H"
28 #include "polyBoundaryMesh.H"
29 #include "polyMesh.H"
30 #include "primitiveMesh.H"
31 #include "SubField.H"
32 #include "entry.H"
33 #include "dictionary.H"
34 #include "pointPatchField.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  defineTypeNameAndDebug(polyPatch, 0);
41 
43  (
44  debug::debugSwitch("disallowGenericPolyPatch", 0)
45  );
46 
47  defineRunTimeSelectionTable(polyPatch, word);
48  defineRunTimeSelectionTable(polyPatch, dictionary);
49 
50  addToRunTimeSelectionTable(polyPatch, polyPatch, word);
51  addToRunTimeSelectionTable(polyPatch, polyPatch, dictionary);
52 }
53 
54 
55 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
56 
58 {
60 }
61 
62 
64 {
66  clearAddressing();
67 }
68 
69 
71 {
73 }
74 
75 
76 void Foam::polyPatch::rename(const wordList& newNames)
77 {
78  name_ = newNames[index_];
79 }
80 
81 
82 void Foam::polyPatch::reorder(const labelUList& newToOldIndex)
83 {
84  index_ = findIndex(newToOldIndex, index_);
85 }
86 
87 
88 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
89 
91 (
92  const word& name,
93  const label size,
94  const label start,
95  const label index,
96  const polyBoundaryMesh& bm,
97  const word& patchType
98 )
99 :
100  patchIdentifier(name, index),
102  (
103  faceSubList(bm.mesh().faces(), size, start),
104  bm.mesh().points()
105  ),
106  start_(start),
107  boundaryMesh_(bm),
108  faceCellsPtr_(nullptr),
109  mePtr_(nullptr)
110 {
111  if
112  (
113  patchType != word::null
114  && constraintType(patchType)
115  && findIndex(inGroups(), patchType) == -1
116  )
117  {
118  inGroups().append(patchType);
119  }
120 }
121 
122 
124 (
125  const word& name,
126  const dictionary& dict,
127  const label index,
128  const polyBoundaryMesh& bm,
129  const word& patchType
130 )
131 :
132  patchIdentifier(name, dict, index),
134  (
136  (
137  bm.mesh().faces(),
138  dict.lookup<label>("nFaces"),
139  dict.lookup<label>("startFace")
140  ),
141  bm.mesh().points()
142  ),
143  start_(dict.lookup<label>("startFace")),
144  boundaryMesh_(bm),
145  faceCellsPtr_(nullptr),
146  mePtr_(nullptr)
147 {
148  if
149  (
150  patchType != word::null
151  && constraintType(patchType)
152  && findIndex(inGroups(), patchType) == -1
153  )
154  {
155  inGroups().append(patchType);
156  }
157 }
158 
159 
161 (
162  const polyPatch& pp,
163  const polyBoundaryMesh& bm
164 )
165 :
166  patchIdentifier(pp),
168  (
170  (
171  bm.mesh().faces(),
172  pp.size(),
173  pp.start()
174  ),
175  bm.mesh().points()
176  ),
177  start_(pp.start()),
178  boundaryMesh_(bm),
179  faceCellsPtr_(nullptr),
180  mePtr_(nullptr)
181 {}
182 
183 
185 (
186  const polyPatch& pp,
187  const polyBoundaryMesh& bm,
188  const label index,
189  const label newSize,
190  const label newStart
191 )
192 :
193  patchIdentifier(pp, index),
195  (
197  (
198  bm.mesh().faces(),
199  newSize,
200  newStart
201  ),
202  bm.mesh().points()
203  ),
204  start_(newStart),
205  boundaryMesh_(bm),
206  faceCellsPtr_(nullptr),
207  mePtr_(nullptr)
208 {}
209 
210 
212 (
213  const polyPatch& pp,
214  const polyBoundaryMesh& bm,
215  const label index,
216  const labelUList& mapAddressing,
217  const label newStart
218 )
219 :
220  patchIdentifier(pp, index),
222  (
224  (
225  bm.mesh().faces(),
226  mapAddressing.size(),
227  newStart
228  ),
229  bm.mesh().points()
230  ),
231  start_(newStart),
232  boundaryMesh_(bm),
233  faceCellsPtr_(nullptr),
234  mePtr_(nullptr)
235 {}
236 
237 
239 :
240  patchIdentifier(p),
241  primitivePatch(p),
242  start_(p.start_),
243  boundaryMesh_(p.boundaryMesh_),
244  faceCellsPtr_(nullptr),
245  mePtr_(nullptr)
246 {}
247 
248 
249 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
250 
252 {
253  clearAddressing();
254 }
255 
256 
257 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
258 
260 {
262 }
263 
264 
266 {
267  wordList cTypes(dictionaryConstructorTablePtr_->size());
268 
269  label i = 0;
270 
271  for
272  (
273  dictionaryConstructorTable::iterator cstrIter =
274  dictionaryConstructorTablePtr_->begin();
275  cstrIter != dictionaryConstructorTablePtr_->end();
276  ++cstrIter
277  )
278  {
279  if (constraintType(cstrIter.key()))
280  {
281  cTypes[i++] = cstrIter.key();
282  }
283  }
284 
285  cTypes.setSize(i);
286 
287  return cTypes;
288 }
289 
290 
292 {
293  return boundaryMesh_;
294 }
295 
296 
298 {
299  return patchSlice(boundaryMesh().mesh().faceCentres());
300 }
301 
302 
304 {
305  return patchSlice(boundaryMesh().mesh().faceAreas());
306 }
307 
308 
310 {
312 }
313 
314 
316 {
317  tmp<vectorField> tcc(new vectorField(size()));
318  vectorField& cc = tcc.ref();
319 
320  // get reference to global cell centres
321  const vectorField& gcc = boundaryMesh_.mesh().cellCentres();
322 
323  const labelUList& faceCells = this->faceCells();
324 
325  forAll(faceCells, facei)
326  {
327  cc[facei] = gcc[faceCells[facei]];
328  }
329 
330  return tcc;
331 }
332 
333 
335 {
336  if (!faceCellsPtr_)
337  {
338  faceCellsPtr_ = new labelList::subList
339  (
340  patchSlice(boundaryMesh().mesh().faceOwner())
341  );
342  }
343 
344  return *faceCellsPtr_;
345 }
346 
347 
349 {
350  if (!mePtr_)
351  {
352  mePtr_ =
353  new labelList
354  (
356  (
357  boundaryMesh().mesh().edges(),
359  )
360  );
361  }
362 
363  return *mePtr_;
364 }
365 
366 
368 {
371  deleteDemandDrivenData(faceCellsPtr_);
372  deleteDemandDrivenData(mePtr_);
373 }
374 
375 
377 {
378  writeEntry(os, "type", type());
380  writeEntry(os, "nFaces", size());
381  writeEntry(os, "startFace", start());
382 }
383 
384 
386 {}
387 
388 
390 (
392  const primitivePatch&,
393  labelList& faceMap,
394  labelList& rotation
395 ) const
396 {
397  // Nothing changed.
398  return false;
399 }
400 
401 
402 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
403 
405 {
406  clearAddressing();
407 
408  patchIdentifier::operator=(p);
410  start_ = p.start_;
411 }
412 
413 
414 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
415 
417 {
418  p.write(os);
419  os.check("Ostream& operator<<(Ostream& os, const polyPatch& p");
420  return os;
421 }
422 
423 
424 // ************************************************************************* //
const labelListList & pointEdges() const
Return point-edge addressing.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
virtual void movePoints(const Field< PointType > &)
Correct patch after moving points.
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
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
static int disallowGenericPolyPatch
Debug switch to disallow the use of genericPolyPatch.
Definition: polyPatch.H:137
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
Identifies patch by name, patch index and physical type.
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:291
SubList< label > subList
Declare type of subList.
Definition: List.H:199
virtual void clearAddressing()
Clear addressing.
Definition: polyPatch.C:367
Pre-declare related SubField type.
Definition: Field.H:60
Macros for easy insertion into run-time selection tables.
virtual void clearGeom()
Clear geometry.
Definition: polyPatch.C:70
virtual void write(Ostream &) const
Write the polyPatch data as a dictionary.
Definition: polyPatch.C:376
virtual void movePoints(PstreamBuffers &, const pointField &p)
Correct patches after moving points.
Definition: polyPatch.C:57
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1131
static bool constraintType(const word &pt)
Return true if the given type is a constraint type.
Definition: polyPatch.C:259
Abstract base class for point-mesh patch fields.
A list of faces which address into the list of points.
A List obtained as a section of another List.
Definition: SubList.H:53
dynamicFvMesh & mesh
const labelUList & faceCells() const
Return face-cell addressing.
Definition: polyPatch.C:334
A class for handling words, derived from string.
Definition: word.H:59
virtual ~polyPatch()
Destructor.
Definition: polyPatch.C:251
virtual void rename(const wordList &newNames)
Reset the patch name.
Definition: polyPatch.C:76
int debugSwitch(const char *name, const int defaultValue=0)
Lookup debug switch or add default value.
Definition: debug.C:211
static const word null
An empty word.
Definition: word.H:77
const polyMesh & mesh() const
Return the mesh reference.
virtual void reorder(const labelUList &newToOldIndex)
Reset the patch index.
Definition: polyPatch.C:82
tmp< vectorField > faceCellCentres() const
Return face cell centres.
Definition: polyPatch.C:315
const edgeList & edges() const
Return list of edges, address into LOCAL point list.
List< label > labelList
A List of labels.
Definition: labelList.H:56
virtual void updateMesh(PstreamBuffers &)
Update of the patch topology.
Definition: polyPatch.C:63
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1156
polyPatch(const word &name, const label size, const label start, const label index, const polyBoundaryMesh &bm, const word &patchType)
Construct from components.
Definition: polyPatch.C:91
const vectorField & cellCentres() const
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
void operator=(const polyPatch &)
Assignment.
Definition: polyPatch.C:404
Foam::polyBoundaryMesh.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
const vectorField::subField faceAreas() const
Return face areas.
Definition: polyPatch.C:303
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
defineTypeNameAndDebug(combustionModel, 0)
const labelList & meshEdges() const
Return global edge index for local edges.
Definition: polyPatch.C:348
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
Buffers for inter-processor communications streams (UOPstream, UIPstream).
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
PrimitivePatch< SubList< face >, const pointField & > primitivePatch
Addressing for a faceList slice.
void write(Ostream &) const
Write patchIdentifier as a dictionary.
static wordList constraintTypes()
Return a list of all the constraint patch types.
Definition: polyPatch.C:265
void setSize(const label)
Reset size of List.
Definition: List.C:281
const scalarField::subField magFaceAreas() const
Return face area magnitudes.
Definition: polyPatch.C:309
virtual bool order(PstreamBuffers &, const primitivePatch &, labelList &faceMap, labelList &rotation) const
Return new ordering for primitivePatch.
Definition: polyPatch.C:390
labelList meshEdges(const edgeList &allEdges, const labelListList &cellEdges, const labelList &faceCells) const
Return labels of patch edges in the global edge list using.
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:309
Ostream & operator<<(Ostream &, const ensightPart &)
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
SubList< face > faceSubList
Definition: faceListFwd.H:44
Field< vector > vectorField
Specialisation of Field<T> for vector.
virtual void initOrder(PstreamBuffers &, const primitivePatch &) const
Initialise ordering for primitivePatch. Does not.
Definition: polyPatch.C:385
volScalarField & p
A class for managing temporary objects.
Definition: PtrList.H:53
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311
void deleteDemandDrivenData(DataPtr &dataPtr)
void operator=(const PrimitivePatch< FaceList, PointField > &)
Assignment operator.
const List< T >::subList patchSlice(const UList< T > &l) const
Slice list to patch.
Definition: polyPatch.H:342
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:844
const vectorField::subField faceCentres() const
Return face centres.
Definition: polyPatch.C:297