cyclicPolyPatch.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2015 OpenFOAM Foundation
9 Copyright (C) 2019 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::cyclicPolyPatch
29
30Description
31 Cyclic plane patch.
32
33 Note: morph patch face ordering uses geometric matching so with the
34 following restrictions:
35 -coupled patches should be flat planes.
36 -no rotation in patch plane
37
38 Uses coupledPolyPatch::calcFaceTol to calculate
39 tolerance per face which might need tweaking.
40
41 Switch on 'cyclicPolyPatch' debug flag to write .obj files to show
42 the matching.
43
44SourceFiles
45 cyclicPolyPatch.C
46
47\*---------------------------------------------------------------------------*/
48
49#ifndef cyclicPolyPatch_H
50#define cyclicPolyPatch_H
51
52#include "coupledPolyPatch.H"
53#include "edgeList.H"
54#include "polyBoundaryMesh.H"
55#include "diagTensorField.H"
57
58// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59
60namespace Foam
61{
62
63/*---------------------------------------------------------------------------*\
64 Class cyclicPolyPatch Declaration
65\*---------------------------------------------------------------------------*/
68:
69 public coupledPolyPatch
70{
71 // Private data
72
73 //- Name of other half
74 mutable word neighbPatchName_;
75
76 //- Optional patchGroup to find neighbPatch
77 const coupleGroupIdentifier coupleGroup_;
78
79 //- Index of other half
80 mutable label neighbPatchID_;
81
82 // For rotation
83
84 //- Axis of rotation for rotational cyclics
85 vector rotationAxis_;
86
87 //- Point on axis of rotation for rotational cyclics
88 point rotationCentre_;
89
90 // For translation
91
92 //- Translation vector
93 vector separationVector_;
94
95
96 //- List of edges formed from connected points. e[0] is the point on
97 // the first half of the patch, e[1] the corresponding point on the
98 // second half.
99 mutable edgeList* coupledPointsPtr_;
100
101 //- List of connected edges. e[0] is the edge on the first half of the
102 // patch, e[1] the corresponding edge on the second half.
103 mutable edgeList* coupledEdgesPtr_;
104
105 //- Temporary storage of owner side patch during ordering.
106 mutable autoPtr<primitivePatch> ownerPatchPtr_;
107
108
109 // Private Member Functions
110
111 //- Find amongst selected faces the one with the largest area
112 static label findMaxArea(const pointField&, const faceList&);
113
114 void calcTransforms
115 (
116 const primitivePatch& half0,
117 const pointField& half0Ctrs,
118 const vectorField& half0Areas,
119 const pointField& half1Ctrs,
120 const vectorField& half1Areas
121 );
122
123 // Face ordering
124
125 // Given a split of faces into left and right half calculate the
126 // centres and anchor points. Transform the left points so they
127 // align with the right ones
128 void getCentresAndAnchors
129 (
130 const primitivePatch& pp0,
131 const primitivePatch& pp1,
132
133 pointField& half0Ctrs,
134 pointField& half1Ctrs,
135 pointField& anchors0,
136 scalarField& tols
137 ) const;
138
139 //- Return normal of face at max distance from rotation axis
140 vector findFaceMaxRadius(const pointField& faceCentres) const;
141
142
143protected:
144
145 // Protected Member functions
146
147 //- Recalculate the transformation tensors
148 virtual void calcTransforms();
149
150 //- Initialise the calculation of the patch geometry
151 virtual void initGeometry(PstreamBuffers&);
152
153 //- Initialise the calculation of the patch geometry
154 virtual void initGeometry
155 (
156 const primitivePatch& referPatch,
157 pointField& nbrCtrs,
158 vectorField& nbrAreas,
159 pointField& nbrCc
160 );
161
162 //- Calculate the patch geometry
163 virtual void calcGeometry(PstreamBuffers&);
164
165 //- Calculate the patch geometry
166 virtual void calcGeometry
167 (
168 const primitivePatch& referPatch,
169 const pointField& thisCtrs,
170 const vectorField& thisAreas,
171 const pointField& thisCc,
172 const pointField& nbrCtrs,
173 const vectorField& nbrAreas,
174 const pointField& nbrCc
175 );
176
177 //- Initialise the patches for moving points
178 virtual void initMovePoints(PstreamBuffers&, const pointField&);
179
180 //- Correct patches after moving points
181 virtual void movePoints(PstreamBuffers&, const pointField&);
182
183 //- Initialise the update of the patch topology
184 virtual void initUpdateMesh(PstreamBuffers&);
185
186 //- Update of the patch topology
187 virtual void updateMesh(PstreamBuffers&);
188
189public:
190
191 //- Declare friendship with processorCyclicPolyPatch
192 friend class processorCyclicPolyPatch;
193
194
195 //- Runtime type information
196 TypeName("cyclic");
197
198
199 // Constructors
200
201 //- Construct from components
203 (
204 const word& name,
205 const label size,
206 const label start,
207 const label index,
208 const polyBoundaryMesh& bm,
209 const word& patchType,
211 );
212
213 //- Construct from components
215 (
216 const word& name,
217 const label size,
218 const label start,
219 const label index,
220 const polyBoundaryMesh& bm,
221 const word& neighbPatchName,
222 const transformType transform, // transformation type
223 const vector& rotationAxis, // for rotation only
224 const point& rotationCentre, // for rotation only
225 const vector& separationVector // for translation only
226 );
227
228 //- Construct from dictionary
230 (
231 const word& name,
232 const dictionary& dict,
233 const label index,
234 const polyBoundaryMesh& bm,
235 const word& patchType
236 );
237
238 //- Copy construct, resetting the boundary mesh
240
241 //- Copy construct, resetting nbrPatchID and faceCells
243 (
244 const cyclicPolyPatch&,
245 label nbrPatchID,
246 const labelList& faceCells
247 );
248
249 //- Construct given the original patch and resetting the
250 //- face list and boundary mesh information
252 (
253 const cyclicPolyPatch& pp,
254 const polyBoundaryMesh& bm,
255 const label index,
256 const label newSize,
257 const label newStart,
258 const word& neighbPatchName
259 );
260
261 //- Construct given the original patch and a map
263 (
264 const cyclicPolyPatch& pp,
265 const polyBoundaryMesh& bm,
266 const label index,
267 const labelUList& mapAddressing,
268 const label newStart
269 );
270
271 //- Construct and return a clone, resetting the boundary mesh
272 virtual autoPtr<polyPatch> clone(const polyBoundaryMesh& bm) const
273 {
274 return autoPtr<polyPatch>(new cyclicPolyPatch(*this, bm));
275 }
276
277 //- Construct and return a clone, resetting the face list
278 // and boundary mesh
280 (
281 const polyBoundaryMesh& bm,
282 const label index,
283 const label newSize,
284 const label newStart
285 ) const
286 {
287 return autoPtr<polyPatch>
288 (
290 (
291 *this,
292 bm,
293 index,
294 newSize,
295 newStart,
296 neighbPatchName_
297 )
298 );
299 }
300
301 //- Construct and return a clone, resetting the face list
302 // and boundary mesh
304 (
305 const polyBoundaryMesh& bm,
306 const label index,
307 const labelUList& mapAddressing,
308 const label newStart
309 ) const
310 {
311 return autoPtr<polyPatch>
312 (
313 new cyclicPolyPatch(*this, bm, index, mapAddressing, newStart)
314 );
315 }
316
317
318 //- Destructor
319 virtual ~cyclicPolyPatch();
320
321
322 // Member Functions
323
324 // Implicit Functions
325
326 //- Return number of new internal of this polyPatch faces
327 virtual void newInternalProcFaces
328 (
329 label& newFaces,
330 label& newProcFaces
331 ) const
332 {
333 newFaces = this->size();
334 newProcFaces = neighbPatch().size() - this->size();
335 }
336
337 //- Return nbrCells
338 virtual const labelUList& nbrCells() const
339 {
340 return neighbPatch().faceCells();
341 }
343 virtual label neighbPolyPatchID() const
344 {
345 return this->neighbPatchID();
346 }
349 {
350 refPtr<labelListList> tMap(new labelListList(this->size()));
351 labelListList& map = tMap.ref();
352 forAll (map, i)
353 {
354 labelList& subMap = map[i];
355 subMap.setSize(1);
356 subMap[0] = i;
357 }
358 return tMap;
359 }
360
361 //- Return implicit master
362 virtual bool masterImplicit() const
363 {
364 return owner();
365 }
366
367 //- Neighbour patch name
368 const word& neighbPatchName() const;
369
370 //- Neighbour patchID
371 virtual label neighbPatchID() const;
373 virtual bool owner() const
374 {
375 return index() < neighbPatchID();
376 }
378 virtual bool neighbour() const
379 {
380 return !owner();
381 }
383 const cyclicPolyPatch& neighbPatch() const
384 {
385 const polyPatch& pp = this->boundaryMesh()[neighbPatchID()];
386 return refCast<const cyclicPolyPatch>(pp);
387 }
388
389 //- Return connected points (from patch local to neighbour patch local)
390 // Demand driven calculation. Does primitivePatch::clearOut after
391 // calculation!
392 const edgeList& coupledPoints() const;
393
394 //- Return connected edges (from patch local to neighbour patch local).
395 // Demand driven calculation. Does primitivePatch::clearOut after
396 // calculation!
397 const edgeList& coupledEdges() const;
398
399 //- Transform a patch-based position from other side to this side
400 virtual void transformPosition(pointField& l) const;
401
402 //- Transform a patch-based position from other side to this side
403 virtual void transformPosition(point&, const label facei) const;
404
405
406 // Transformation
408 label transformGlobalFace(const label facei) const
409 {
410 label offset = facei-start();
411 label neighbStart = neighbPatch().start();
412
413 if (offset >= 0 && offset < size())
414 {
415 return neighbStart+offset;
416 }
417 else
418 {
420 << "Face " << facei << " not in patch " << name()
421 << exit(FatalError);
422 return -1;
423 }
424 }
425
426 //- Axis of rotation for rotational cyclics
427 const vector& rotationAxis() const
428 {
429 return rotationAxis_;
430 }
431
432 //- Point on axis of rotation for rotational cyclics
433 const point& rotationCentre() const
434 {
435 return rotationCentre_;
436 }
437
438 //- Translation vector for translational cyclics
439 const vector& separationVector() const
440 {
441 return separationVector_;
442 }
443
444
445 //- Initialize ordering for primitivePatch. Does not
446 // refer to *this (except for name() and type() etc.)
447 virtual void initOrder(PstreamBuffers&, const primitivePatch&) const;
448
449 //- Return new ordering for primitivePatch.
450 // Ordering is -faceMap: for every face
451 // index of the new face -rotation:for every new face the clockwise
452 // shift of the original face. Return false if nothing changes
453 // (faceMap is identity, rotation is 0), true otherwise.
454 virtual bool order
455 (
457 const primitivePatch&,
459 labelList& rotation
460 ) const;
461
462
463 //- Write the polyPatch data as a dictionary
464 virtual void write(Ostream&) const;
465};
466
467
468// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
469
470} // End namespace Foam
471
472// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
473
474#endif
475
476// ************************************************************************* //
void setSize(const label n)
Alias for resize()
Definition: List.H:218
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A list of faces which address into the list of points.
Buffers for inter-processor communications streams (UOPstream, UIPstream).
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Definition: boundaryMesh.H:63
Encapsulates using "patchGroups" to specify coupled patch.
The coupledPolyPatch is an abstract base class for patches that couple regions of the computational d...
virtual transformType transform() const
Type of transform.
Cyclic plane patch.
virtual autoPtr< polyPatch > clone(const polyBoundaryMesh &bm) const
Construct and return a clone, resetting the boundary mesh.
virtual void updateMesh(PstreamBuffers &)
Update of the patch topology.
const point & rotationCentre() const
Point on axis of rotation for rotational cyclics.
const word & neighbPatchName() const
Neighbour patch name.
virtual void initMovePoints(PstreamBuffers &, const pointField &)
Initialise the patches for moving points.
virtual label neighbPolyPatchID() const
Return nbr patchID.
virtual bool owner() const
Does this side own the patch ?
virtual void newInternalProcFaces(label &newFaces, label &newProcFaces) const
Return number of new internal of this polyPatch faces.
const vector & rotationAxis() const
Axis of rotation for rotational cyclics.
virtual bool masterImplicit() const
Return implicit master.
const edgeList & coupledEdges() const
Return connected edges (from patch local to neighbour patch local).
virtual void calcGeometry(PstreamBuffers &)
Calculate the patch geometry.
const edgeList & coupledPoints() const
Return connected points (from patch local to neighbour patch local)
virtual void initGeometry(PstreamBuffers &)
Initialise the calculation of the patch geometry.
virtual void initOrder(PstreamBuffers &, const primitivePatch &) const
Initialize ordering for primitivePatch. Does not.
const vector & separationVector() const
Translation vector for translational cyclics.
virtual const labelUList & nbrCells() const
Return nbrCells.
virtual refPtr< labelListList > mapCollocatedFaces() const
Return mapped collocated faces.
label transformGlobalFace(const label facei) const
virtual bool order(PstreamBuffers &, const primitivePatch &, labelList &faceMap, labelList &rotation) const
Return new ordering for primitivePatch.
virtual void movePoints(PstreamBuffers &, const pointField &)
Correct patches after moving points.
const cyclicPolyPatch & neighbPatch() const
TypeName("cyclic")
Runtime type information.
virtual void transformPosition(pointField &l) const
Transform a patch-based position from other side to this side.
virtual void initUpdateMesh(PstreamBuffers &)
Initialise the update of the patch topology.
virtual ~cyclicPolyPatch()
Destructor.
virtual bool neighbour() const
Does the coupled side own the patch ?
virtual void calcTransforms()
Recalculate the transformation tensors.
virtual label neighbPatchID() const
Neighbour patchID.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:59
label index() const noexcept
The index of this patch in the boundaryMesh.
const word & name() const noexcept
The patch name.
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:75
label offset() const
The offset where this patch starts in the boundary face list.
Definition: polyPatch.C:309
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:364
const vectorField::subField faceCentres() const
Return face centres.
Definition: polyPatch.C:321
const labelUList & faceCells() const
Return face-cell addressing.
Definition: polyPatch.C:371
A class for managing references or pointers (no reference counting)
Definition: refPtr.H:58
T & ref() const
Definition: refPtrI.H:203
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Namespace for OpenFOAM.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
UList< label > labelUList
A UList of labels.
Definition: UList.H:85
runTime write()
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73