Loading...
Searching...
No Matches
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-2023 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 Foam_cyclicPolyPatch_H
50#define Foam_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{
63/*---------------------------------------------------------------------------*\
64 Class cyclicPolyPatch Declaration
65\*---------------------------------------------------------------------------*/
66
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.
97 // From first half of the patch to the corresponding point
98 // on the second half.
99 mutable std::unique_ptr<edgeList> coupledPointsPtr_;
100
101 //- List of connected edges.
102 // From first half of the patch to the corresponding edge
103 // on the second half.
104 mutable std::unique_ptr<edgeList> coupledEdgesPtr_;
105
106 //- Temporary storage of owner side patch during ordering.
107 // Saved as autoPtr instead of std::unique_ptr to allow
108 // extra nullptr checking
109 mutable autoPtr<primitivePatch> ownerPatchPtr_;
110
111
112 // Private Member Functions
113
114 //- Find amongst selected faces the one with the largest area
115 static label findMaxArea(const UList<point>&, const UList<face>&);
116
117 void calcTransforms
118 (
119 const primitivePatch& half0,
120 const pointField& half0Ctrs,
121 const vectorField& half0Areas,
122 const pointField& half1Ctrs,
123 const vectorField& half1Areas
124 );
125
126 // Face ordering
127
128 // Given a split of faces into left and right half calculate the
129 // centres and anchor points. Transform the left points so they
130 // align with the right ones
131 void getCentresAndAnchors
132 (
133 const primitivePatch& pp0,
134 const primitivePatch& pp1,
135
136 pointField& half0Ctrs,
137 pointField& half1Ctrs,
138 pointField& anchors0,
139 scalarField& tols
140 ) const;
141
142 //- Return normal of face at max distance from rotation axis
143 vector findFaceMaxRadius(const pointField& faceCentres) const;
144
145
146protected:
147
148 // Protected Member functions
149
150 //- Recalculate the transformation tensors
151 virtual void calcTransforms();
152
153 //- Initialise the calculation of the patch geometry
154 virtual void initGeometry(PstreamBuffers&);
155
156 //- Initialise the calculation of the patch geometry
157 virtual void initGeometry
158 (
159 const primitivePatch& referPatch,
160 pointField& nbrCtrs,
161 vectorField& nbrAreas,
162 pointField& nbrCc
163 );
164
165 //- Calculate the patch geometry
166 virtual void calcGeometry(PstreamBuffers&);
167
168 //- Calculate the patch geometry
169 virtual void calcGeometry
170 (
171 const primitivePatch& referPatch,
172 const pointField& thisCtrs,
173 const vectorField& thisAreas,
174 const pointField& thisCc,
175 const pointField& nbrCtrs,
176 const vectorField& nbrAreas,
177 const pointField& nbrCc
178 );
179
180 //- Initialise the patches for moving points
181 virtual void initMovePoints(PstreamBuffers&, const pointField&);
182
183 //- Correct patches after moving points
184 virtual void movePoints(PstreamBuffers&, const pointField&);
185
186 //- Initialise the update of the patch topology
187 virtual void initUpdateMesh(PstreamBuffers&);
188
189 //- Update of the patch topology
190 virtual void updateMesh(PstreamBuffers&);
191
192public:
193
194 //- Declare friendship with processorCyclicPolyPatch
195 friend class processorCyclicPolyPatch;
196
197
198 //- Runtime type information
199 TypeName("cyclic");
200
201
202 // Constructors
203
204 //- Construct from components
206 (
207 const word& name,
208 const label size,
209 const label start,
210 const label index,
211 const polyBoundaryMesh& bm,
212 const word& patchType,
214 );
215
216 //- Construct from components
218 (
219 const word& name,
220 const label size,
221 const label start,
222 const label index,
223 const polyBoundaryMesh& bm,
224 const word& neighbPatchName,
225 const transformType transform, // transformation type
226 const vector& rotationAxis, // for rotation only
227 const point& rotationCentre, // for rotation only
228 const vector& separationVector // for translation only
229 );
230
231 //- Construct from dictionary
233 (
234 const word& name,
236 const label index,
237 const polyBoundaryMesh& bm,
238 const word& patchType
239 );
240
241 //- Copy construct, resetting the boundary mesh
243
244 //- Copy construct, resetting nbrPatchID and faceCells
246 (
247 const cyclicPolyPatch&,
248 label nbrPatchID,
249 const labelList& faceCells
250 );
251
252 //- Construct given the original patch and resetting the
253 //- face list and boundary mesh information
255 (
256 const cyclicPolyPatch& pp,
257 const polyBoundaryMesh& bm,
258 const label index,
259 const label newSize,
260 const label newStart,
261 const word& neighbPatchName
262 );
263
264 //- Construct given the original patch and a map
266 (
267 const cyclicPolyPatch& pp,
268 const polyBoundaryMesh& bm,
269 const label index,
270 const labelUList& mapAddressing,
271 const label newStart
272 );
273
274 //- Construct and return a clone, resetting the boundary mesh
275 virtual autoPtr<polyPatch> clone(const polyBoundaryMesh& bm) const
276 {
277 return autoPtr<polyPatch>(new cyclicPolyPatch(*this, bm));
278 }
279
280 //- Construct and return a clone, resetting the face list
281 // and boundary mesh
283 (
284 const polyBoundaryMesh& bm,
285 const label index,
286 const label newSize,
287 const label newStart
288 ) const
289 {
290 return autoPtr<polyPatch>
291 (
293 (
294 *this,
295 bm,
296 index,
297 newSize,
298 newStart,
299 neighbPatchName_
300 )
301 );
302 }
303
304 //- Construct and return a clone, resetting the face list
305 // and boundary mesh
306 virtual autoPtr<polyPatch> clone
307 (
308 const polyBoundaryMesh& bm,
309 const label index,
310 const labelUList& mapAddressing,
311 const label newStart
312 ) const
313 {
314 return autoPtr<polyPatch>
315 (
316 new cyclicPolyPatch(*this, bm, index, mapAddressing, newStart)
317 );
318 }
319
320
321 //- Destructor
322 virtual ~cyclicPolyPatch();
323
324
325 // Member Functions
326
327 // Implicit Functions
328
329 //- Return number of new internal of this polyPatch faces
330 virtual void newInternalProcFaces
331 (
332 label& newFaces,
333 label& newProcFaces
334 ) const
335 {
336 newFaces = this->size();
337 newProcFaces = neighbPatch().size() - this->size();
338 }
339
340 //- Return nbrCells
341 virtual const labelUList& nbrCells() const
342 {
344 }
345
346 virtual label neighbPolyPatchID() const
347 {
348 return this->neighbPatchID();
349 }
350
351 virtual refPtr<labelListList> mapCollocatedFaces() const
352 {
353 refPtr<labelListList> tMap(new labelListList(this->size()));
354 labelListList& map = tMap.ref();
355 forAll (map, i)
356 {
357 labelList& subMap = map[i];
358 subMap.setSize(1);
359 subMap[0] = i;
360 }
361 return tMap;
362 }
363
364 //- Return implicit master
365 virtual bool masterImplicit() const
366 {
367 return owner();
368 }
369
370 //- Neighbour patch name
371 const word& neighbPatchName() const;
372
373 //- Neighbour patchID
374 virtual label neighbPatchID() const;
375
376 virtual bool owner() const
377 {
378 return index() < neighbPatchID();
379 }
380
381 virtual bool neighbour() const
382 {
383 return !owner();
384 }
385
386 const cyclicPolyPatch& neighbPatch() const
387 {
388 const polyPatch& pp = this->boundaryMesh()[neighbPatchID()];
390 }
391
392 //- Return connected points (from patch local to neighbour patch local)
393 // Demand driven calculation. Does primitivePatch::clearOut after
394 // calculation!
395 const edgeList& coupledPoints() const;
396
397 //- Return connected edges (from patch local to neighbour patch local).
398 // Demand driven calculation. Does primitivePatch::clearOut after
399 // calculation!
400 const edgeList& coupledEdges() const;
401
402 //- Transform a patch-based position from other side to this side
403 virtual void transformPosition(pointField& l) const;
404
405 //- Transform a patch-based position from other side to this side
406 virtual void transformPosition(point&, const label facei) const;
407
408
409 // Transformation
410
411 label transformGlobalFace(const label facei) const
412 {
413 label offset = facei-start();
414 label neighbStart = neighbPatch().start();
415
416 if (offset >= 0 && offset < size())
417 {
418 return neighbStart+offset;
419 }
420 else
423 << "Face " << facei << " not in patch " << name()
424 << exit(FatalError);
425 return -1;
426 }
427 }
428
429 //- Axis of rotation for rotational cyclics
430 const vector& rotationAxis() const noexcept
431 {
432 return rotationAxis_;
433 }
434
435 //- Point on axis of rotation for rotational cyclics
436 const point& rotationCentre() const noexcept
438 return rotationCentre_;
439 }
440
441 //- Translation vector for translational cyclics
442 const vector& separationVector() const noexcept
443 {
444 return separationVector_;
445 }
446
447
448 //- Initialize ordering for primitivePatch. Does not
449 // refer to *this (except for name() and type() etc.)
450 virtual void initOrder(PstreamBuffers&, const primitivePatch&) const;
451
452 //- Return new ordering for primitivePatch.
453 // Ordering is -faceMap: for every face
454 // index of the new face -rotation:for every new face the clockwise
455 // shift of the original face. Return false if nothing changes
456 // (faceMap is identity, rotation is 0), true otherwise.
457 virtual bool order
458 (
460 const primitivePatch&,
462 labelList& rotation
463 ) const;
464
465
466 //- Write the polyPatch data as a dictionary
467 virtual void write(Ostream&) const;
468};
469
470
471// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
472
473} // End namespace Foam
474
475// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
476
477#endif
478
479// ************************************************************************* //
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
void setSize(label n)
Alias for resize().
Definition List.H:536
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Buffers for inter-processor communications streams (UOPstream, UIPstream).
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
label size() const noexcept
Definition UList.H:706
void size(const label n)
Definition UList.H:118
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
Encapsulates using "patchGroups" to specify coupled patch.
virtual transformType transform() const
Type of transform.
coupledPolyPatch(const word &name, const label size, const label start, const label index, const polyBoundaryMesh &bm, const word &patchType, const transformType transform)
Construct from components.
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 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.
virtual bool masterImplicit() const
Return implicit master.
const edgeList & coupledEdges() const
Return connected edges (from patch local to neighbour patch local).
cyclicPolyPatch(const word &name, const label size, const label start, const label index, const polyBoundaryMesh &bm, const word &patchType, const transformType transform=UNKNOWN)
Construct from components.
virtual void calcGeometry(PstreamBuffers &)
Calculate the patch geometry.
friend class processorCyclicPolyPatch
Declare friendship with processorCyclicPolyPatch.
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 noexcept
Translation vector for translational cyclics.
virtual autoPtr< polyPatch > clone(const polyBoundaryMesh &bm, const label index, const label newSize, const label newStart) const
Construct and return a clone, resetting the face list.
virtual const labelUList & nbrCells() const
Return nbrCells.
virtual refPtr< labelListList > mapCollocatedFaces() const
Return mapped collocated faces.
virtual autoPtr< polyPatch > clone(const polyBoundaryMesh &bm, const label index, const labelUList &mapAddressing, const label newStart) const
Construct and return a clone, resetting the face list.
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 ?
const point & rotationCentre() const noexcept
Point on axis of rotation for rotational cyclics.
virtual void calcTransforms()
Recalculate the transformation tensors.
const vector & rotationAxis() const noexcept
Axis of rotation for rotational cyclics.
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:133
Smooth ATC in cells next to a set of patches supplied by type.
Definition faceCells.H:55
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 registered IO, a reference to the associated polyMesh,...
A patch is a list of labels that address the faces in the global face list.
Definition polyPatch.H:73
friend class polyBoundaryMesh
Definition polyPatch.H:112
label offset() const noexcept
The offset where this patch starts in the boundary face list.
Definition polyPatch.C:288
const vectorField::subField faceCentres() const
Return face centres.
Definition polyPatch.C:320
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundaryMesh reference.
Definition polyPatch.C:295
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:75
label start() const noexcept
Return start label of this patch in the polyMesh face list.
Definition polyPatch.H:446
const labelUList & faceCells() const
Return face-cell addressing.
Definition polyPatch.C:401
A class for managing references or pointers (no reference counting).
Definition refPtr.H:54
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
Definition refPtrI.H:230
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
A class for handling words, derived from Foam::string.
Definition word.H:66
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
Namespace for OpenFOAM.
List< edge > edgeList
List of edge.
Definition edgeList.H:32
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
Definition typeInfo.H:172
List< labelList > labelListList
List of labelList.
Definition labelList.H:38
List< label > labelList
A List of labels.
Definition List.H:62
PrimitivePatch< SubList< face >, const pointField & > primitivePatch
A PrimitivePatch with a SubList addressing for the faces, const reference for the point field.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Field< vector > vectorField
Specialisation of Field<T> for vector.
vector point
Point is a vector.
Definition point.H:37
const direction noexcept
Definition scalarImpl.H:265
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
vectorField pointField
pointField is a vectorField.
Vector< scalar > vector
Definition vector.H:57
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
UList< label > labelUList
A UList of labels.
Definition UList.H:75
runTime write()
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68