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-2026 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 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
40 
42  (
43  debug::debugSwitch("disallowGenericPolyPatch", 0)
44  );
45 
48 
51 }
52 
53 
54 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
55 
57 {
59 }
60 
61 
63 {
65 }
66 
67 
69 {
71  clearAddressing();
72 }
73 
74 
76 {
78 }
79 
80 
81 void Foam::polyPatch::rename(const wordList& newNames)
82 {
83  name_ = newNames[index_];
84 }
85 
86 
87 void Foam::polyPatch::reorder(const labelUList& newToOldIndex)
88 {
89  index_ = findIndex(newToOldIndex, index_);
90 }
91 
92 
93 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
94 
96 (
97  const word& name,
98  const label size,
99  const label start,
100  const label index,
101  const polyBoundaryMesh& bm
102 )
103 :
104  patchIdentifier(name, index),
106  (
107  faceSubList(bm.mesh().faces(), size, start),
108  bm.mesh().points()
109  ),
110  start_(start),
111  boundaryMesh_(bm),
112  faceCellsPtr_(nullptr),
113  mePtr_(nullptr)
114 {}
115 
116 
118 (
119  const word& name,
120  const dictionary& dict,
121  const label index,
122  const polyBoundaryMesh& bm
123 )
124 :
125  patchIdentifier(name, dict, index),
127  (
129  (
130  bm.mesh().faces(),
131  dict.lookup<label>("nFaces"),
132  dict.lookup<label>("startFace")
133  ),
134  bm.mesh().points()
135  ),
136  start_(dict.lookup<label>("startFace")),
137  boundaryMesh_(bm),
138  faceCellsPtr_(nullptr),
139  mePtr_(nullptr)
140 {}
141 
142 
144 (
145  const polyPatch& pp,
146  const polyBoundaryMesh& bm
147 )
148 :
149  patchIdentifier(pp),
151  (
153  (
154  bm.mesh().faces(),
155  pp.size(),
156  pp.start()
157  ),
158  bm.mesh().points()
159  ),
160  start_(pp.start()),
161  boundaryMesh_(bm),
162  faceCellsPtr_(nullptr),
163  mePtr_(nullptr)
164 {}
165 
166 
168 (
169  const polyPatch& pp,
170  const polyBoundaryMesh& bm,
171  const label index,
172  const label newSize,
173  const label newStart
174 )
175 :
176  patchIdentifier(pp, index),
178  (
180  (
181  bm.mesh().faces(),
182  newSize,
183  newStart
184  ),
185  bm.mesh().points()
186  ),
187  start_(newStart),
188  boundaryMesh_(bm),
189  faceCellsPtr_(nullptr),
190  mePtr_(nullptr)
191 {}
192 
193 
195 :
197  primitivePatch(p),
198  start_(p.start_),
199  boundaryMesh_(p.boundaryMesh_),
200  faceCellsPtr_(nullptr),
201  mePtr_(nullptr)
202 {}
203 
204 
205 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
206 
208 {
209  clearAddressing();
210 }
211 
212 
213 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
214 
216 {
217  return boundaryMesh_;
218 }
219 
220 
222 {
223  return boundaryMesh_.mesh();
224 }
225 
226 
228 {
229  return patchSlice(mesh().faceCentres());
230 }
231 
232 
234 {
235  return patchSlice(mesh().faceAreas());
236 }
237 
238 
240 {
241  return patchSlice(mesh().magFaceAreas());
242 }
243 
244 
246 {
247  tmp<vectorField> tcc(new vectorField(size()));
248  vectorField& cc = tcc.ref();
249 
250  // get reference to global cell centres
251  const vectorField& gcc = mesh().cellCentres();
252 
253  const labelUList& faceCells = this->faceCells();
254 
255  forAll(faceCells, facei)
256  {
257  cc[facei] = gcc[faceCells[facei]];
258  }
259 
260  return tcc;
261 }
262 
263 
265 {
266  if (!faceCellsPtr_)
267  {
268  faceCellsPtr_ = new labelList::subList
269  (
270  patchSlice(mesh().faceOwner())
271  );
272  }
273 
274  return *faceCellsPtr_;
275 }
276 
277 
279 {
280  if (!mePtr_)
281  {
282  mePtr_ =
283  new labelList
284  (
286  (
287  mesh().edges(),
288  mesh().pointEdges()
289  )
290  );
291  }
292 
293  return *mePtr_;
294 }
295 
296 
298 {
301  deleteDemandDrivenData(faceCellsPtr_);
302  deleteDemandDrivenData(mePtr_);
303 }
304 
305 
307 {
308  writeEntry(os, "type", type());
310  writeEntry(os, "nFaces", size());
311  writeEntry(os, "startFace", start());
312 }
313 
314 
316 {}
317 
318 
320 (
322  const primitivePatch&,
324  labelList& rotation
325 ) const
326 {
327  // Nothing changed.
328  return false;
329 }
330 
331 
332 void Foam::polyPatch::reset(const label size, const label start)
333 {
334  clearAddressing();
335  start_ = start;
336 
337  const primitivePatch pp
338  (
339  faceSubList(mesh().faces(), size, start),
340  mesh().points()
341  );
343 }
344 
345 
346 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
347 
349 {
350  clearAddressing();
351 
352  patchIdentifier::operator=(p);
354  start_ = p.start_;
355 }
356 
357 
358 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
359 
361 {
362  p.write(os);
363  os.check("Ostream& operator<<(Ostream& os, const polyPatch& p");
364  return os;
365 }
366 
367 
368 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
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:108
SubList< label > subList
Declare type of subList.
Definition: List.H:195
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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Identifies patch by name, patch index and physical type.
void write(Ostream &) const
Write patchIdentifier as a dictionary.
Foam::polyBoundaryMesh.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:71
const vectorField::subField faceAreas() const
Return face areas.
Definition: polyPatch.C:233
virtual void write(Ostream &) const
Write the polyPatch data as a dictionary.
Definition: polyPatch.C:306
void reset(const label size, const label start)
Reset the size and start of the patch.
Definition: polyPatch.C:332
virtual void rename(const wordList &newNames)
Reset the patch name.
Definition: polyPatch.C:81
const polyMesh & mesh() const
Return mesh reference.
Definition: polyPatch.C:221
virtual void clearGeom()
Clear geometry.
Definition: polyPatch.C:75
virtual void reorder(const labelUList &newToOldIndex)
Reset the patch index.
Definition: polyPatch.C:87
virtual void initOrder(PstreamBuffers &, const primitivePatch &) const
Initialise ordering for primitivePatch. Does not.
Definition: polyPatch.C:315
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:215
const vectorField::subField faceCentres() const
Return face centres.
Definition: polyPatch.C:227
virtual void movePoints(const pointField &p)
Correct patches after moving points.
Definition: polyPatch.C:56
polyPatch(const word &name, const label size, const label start, const label index, const polyBoundaryMesh &bm)
Construct from components.
Definition: polyPatch.C:96
virtual ~polyPatch()
Destructor.
Definition: polyPatch.C:207
void operator=(const polyPatch &)
Assignment.
Definition: polyPatch.C:348
virtual bool order(PstreamBuffers &, const primitivePatch &, labelList &faceMap, labelList &rotation) const
Return new ordering for primitivePatch.
Definition: polyPatch.C:320
virtual void clearAddressing()
Clear addressing.
Definition: polyPatch.C:297
static int disallowGenericPolyPatch
Debug switch to disallow the use of genericPolyPatch.
Definition: polyPatch.H:138
tmp< vectorField > faceCellCentres() const
Return face cell centres.
Definition: polyPatch.C:245
const scalarField::subField magFaceAreas() const
Return face area magnitudes.
Definition: polyPatch.C:239
virtual void topoChange(PstreamBuffers &)
Update of the patch topology.
Definition: polyPatch.C:68
const labelUList & faceCells() const
Return face-cell addressing.
Definition: polyPatch.C:264
const labelList & meshEdges() const
Return global edge index for local edges.
Definition: polyPatch.C:278
const vectorField & cellCentres() const
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:197
A class for handling words, derived from string.
Definition: word.H:63
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
const pointField & points
int debugSwitch(const char *name, const int defaultValue=0)
Lookup debug switch or add default value.
Definition: debug.C:243
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: labelList.H:56
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)
SubList< face > faceSubList
Definition: faceListFwd.H:42
void deleteDemandDrivenData(DataType *&dataPtr)
defineRunTimeSelectionTable(fvConstraint, dictionary)
Field< vector > vectorField
Specialisation of Field<T> for vector.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
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)
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)
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