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-2022 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 {
41 
43  (
44  debug::debugSwitch("disallowGenericPolyPatch", 0)
45  );
46 
49 
52 }
53 
54 
55 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
56 
58 {
60 }
61 
62 
64 {
66 }
67 
68 
70 {
72  clearAddressing();
73 }
74 
75 
77 {
79 }
80 
81 
82 void Foam::polyPatch::rename(const wordList& newNames)
83 {
84  name_ = newNames[index_];
85 }
86 
87 
88 void Foam::polyPatch::reorder(const labelUList& newToOldIndex)
89 {
90  index_ = findIndex(newToOldIndex, index_);
91 }
92 
93 
94 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
95 
97 (
98  const word& name,
99  const label size,
100  const label start,
101  const label index,
102  const polyBoundaryMesh& bm,
103  const word& patchType
104 )
105 :
106  patchIdentifier(name, index),
108  (
109  faceSubList(bm.mesh().faces(), size, start),
110  bm.mesh().points()
111  ),
112  start_(start),
113  boundaryMesh_(bm),
114  faceCellsPtr_(nullptr),
115  mePtr_(nullptr)
116 {
117  if
118  (
119  patchType != word::null
120  && constraintType(patchType)
121  && findIndex(inGroups(), patchType) == -1
122  )
123  {
124  inGroups().append(patchType);
125  }
126 }
127 
128 
130 (
131  const word& name,
132  const dictionary& dict,
133  const label index,
134  const polyBoundaryMesh& bm,
135  const word& patchType
136 )
137 :
138  patchIdentifier(name, dict, index),
140  (
142  (
143  bm.mesh().faces(),
144  dict.lookup<label>("nFaces"),
145  dict.lookup<label>("startFace")
146  ),
147  bm.mesh().points()
148  ),
149  start_(dict.lookup<label>("startFace")),
150  boundaryMesh_(bm),
151  faceCellsPtr_(nullptr),
152  mePtr_(nullptr)
153 {
154  if
155  (
156  patchType != word::null
157  && constraintType(patchType)
158  && findIndex(inGroups(), patchType) == -1
159  )
160  {
161  inGroups().append(patchType);
162  }
163 }
164 
165 
167 (
168  const polyPatch& pp,
169  const polyBoundaryMesh& bm
170 )
171 :
172  patchIdentifier(pp),
174  (
176  (
177  bm.mesh().faces(),
178  pp.size(),
179  pp.start()
180  ),
181  bm.mesh().points()
182  ),
183  start_(pp.start()),
184  boundaryMesh_(bm),
185  faceCellsPtr_(nullptr),
186  mePtr_(nullptr)
187 {}
188 
189 
191 (
192  const polyPatch& pp,
193  const polyBoundaryMesh& bm,
194  const label index,
195  const label newSize,
196  const label newStart
197 )
198 :
199  patchIdentifier(pp, index),
201  (
203  (
204  bm.mesh().faces(),
205  newSize,
206  newStart
207  ),
208  bm.mesh().points()
209  ),
210  start_(newStart),
211  boundaryMesh_(bm),
212  faceCellsPtr_(nullptr),
213  mePtr_(nullptr)
214 {}
215 
216 
218 :
220  primitivePatch(p),
221  start_(p.start_),
222  boundaryMesh_(p.boundaryMesh_),
223  faceCellsPtr_(nullptr),
224  mePtr_(nullptr)
225 {}
226 
227 
228 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
229 
231 {
232  clearAddressing();
233 }
234 
235 
236 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
237 
239 {
241 }
242 
243 
245 {
246  wordList cTypes(dictionaryConstructorTablePtr_->size());
247 
248  label i = 0;
249 
250  for
251  (
252  dictionaryConstructorTable::iterator cstrIter =
253  dictionaryConstructorTablePtr_->begin();
254  cstrIter != dictionaryConstructorTablePtr_->end();
255  ++cstrIter
256  )
257  {
258  if (constraintType(cstrIter.key()))
259  {
260  cTypes[i++] = cstrIter.key();
261  }
262  }
263 
264  cTypes.setSize(i);
265 
266  return cTypes;
267 }
268 
269 
271 {
272  return boundaryMesh_;
273 }
274 
275 
277 {
278  return patchSlice(boundaryMesh().mesh().faceCentres());
279 }
280 
281 
283 {
284  return patchSlice(boundaryMesh().mesh().faceAreas());
285 }
286 
287 
289 {
290  return patchSlice(boundaryMesh().mesh().magFaceAreas());
291 }
292 
293 
295 {
296  tmp<vectorField> tcc(new vectorField(size()));
297  vectorField& cc = tcc.ref();
298 
299  // get reference to global cell centres
300  const vectorField& gcc = boundaryMesh_.mesh().cellCentres();
301 
302  const labelUList& faceCells = this->faceCells();
303 
304  forAll(faceCells, facei)
305  {
306  cc[facei] = gcc[faceCells[facei]];
307  }
308 
309  return tcc;
310 }
311 
312 
314 {
315  if (!faceCellsPtr_)
316  {
317  faceCellsPtr_ = new labelList::subList
318  (
319  patchSlice(boundaryMesh().mesh().faceOwner())
320  );
321  }
322 
323  return *faceCellsPtr_;
324 }
325 
326 
328 {
329  if (!mePtr_)
330  {
331  mePtr_ =
332  new labelList
333  (
335  (
336  boundaryMesh().mesh().edges(),
337  boundaryMesh().mesh().pointEdges()
338  )
339  );
340  }
341 
342  return *mePtr_;
343 }
344 
345 
347 {
350  deleteDemandDrivenData(faceCellsPtr_);
351  deleteDemandDrivenData(mePtr_);
352 }
353 
354 
356 {
357  writeEntry(os, "type", type());
359  writeEntry(os, "nFaces", size());
360  writeEntry(os, "startFace", start());
361 }
362 
363 
365 {}
366 
367 
369 (
371  const primitivePatch&,
373  labelList& rotation
374 ) const
375 {
376  // Nothing changed.
377  return false;
378 }
379 
380 
381 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
382 
384 {
385  clearAddressing();
386 
387  patchIdentifier::operator=(p);
389  start_ = p.start_;
390 }
391 
392 
393 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
394 
396 {
397  p.write(os);
398  os.check("Ostream& operator<<(Ostream& os, const polyPatch& p");
399  return os;
400 }
401 
402 
403 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
SubList< label > subList
Declare type of subList.
Definition: List.H:195
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:178
void setSize(const label)
Reset size of List.
Definition: List.C:281
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
labelList meshEdges(const edgeList &allEdges, const labelListList &cellEdges, const labelList &faceCells) const
Return labels of patch edges in the global edge list using.
void operator=(const PrimitivePatch< SubList< face >, const pointField & > &)
Assignment operator.
Buffers for inter-processor communications streams (UOPstream, UIPstream).
Pre-declare related SubField type.
Definition: SubField.H:63
A List obtained as a section of another List.
Definition: SubList.H:56
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Identifies patch by name, patch index and physical type.
void write(Ostream &) const
Write patchIdentifier as a dictionary.
const wordList & inGroups() const
Return the optional groups patch belongs to.
Abstract base class for point-mesh patch fields.
Foam::polyBoundaryMesh.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:70
static wordList constraintTypes()
Return a list of all the constraint patch types.
Definition: polyPatch.C:244
const vectorField::subField faceAreas() const
Return face areas.
Definition: polyPatch.C:282
virtual void write(Ostream &) const
Write the polyPatch data as a dictionary.
Definition: polyPatch.C:355
virtual void rename(const wordList &newNames)
Reset the patch name.
Definition: polyPatch.C:82
virtual void clearGeom()
Clear geometry.
Definition: polyPatch.C:76
virtual void reorder(const labelUList &newToOldIndex)
Reset the patch index.
Definition: polyPatch.C:88
virtual void initOrder(PstreamBuffers &, const primitivePatch &) const
Initialise ordering for primitivePatch. Does not.
Definition: polyPatch.C:364
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:270
const vectorField::subField faceCentres() const
Return face centres.
Definition: polyPatch.C:276
virtual void movePoints(const pointField &p)
Correct patches after moving points.
Definition: polyPatch.C:57
virtual ~polyPatch()
Destructor.
Definition: polyPatch.C:230
static bool constraintType(const word &pt)
Return true if the given type is a constraint type.
Definition: polyPatch.C:238
void operator=(const polyPatch &)
Assignment.
Definition: polyPatch.C:383
virtual bool order(PstreamBuffers &, const primitivePatch &, labelList &faceMap, labelList &rotation) const
Return new ordering for primitivePatch.
Definition: polyPatch.C:369
virtual void clearAddressing()
Clear addressing.
Definition: polyPatch.C:346
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:97
static int disallowGenericPolyPatch
Debug switch to disallow the use of genericPolyPatch.
Definition: polyPatch.H:137
tmp< vectorField > faceCellCentres() const
Return face cell centres.
Definition: polyPatch.C:294
const scalarField::subField magFaceAreas() const
Return face area magnitudes.
Definition: polyPatch.C:288
virtual void topoChange(PstreamBuffers &)
Update of the patch topology.
Definition: polyPatch.C:69
const labelUList & faceCells() const
Return face-cell addressing.
Definition: polyPatch.C:313
const labelList & meshEdges() const
Return global edge index for local edges.
Definition: polyPatch.C:327
virtual bool write(const bool write=true) const
Write using setting from DB.
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
A class for handling words, derived from string.
Definition: word.H:62
static const word null
An empty word.
Definition: word.H:77
const pointField & points
int debugSwitch(const char *name, const int defaultValue=0)
Lookup debug switch or add default value.
Definition: debug.C:211
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: labelList.H:56
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
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
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
void deleteDemandDrivenData(DataType *&dataPtr)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
defineTypeNameAndDebug(combustionModel, 0)
Field< vector > vectorField
Specialisation of Field<T> for vector.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
dictionary dict
volScalarField & p