syncTools.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-2016 OpenFOAM Foundation
9 Copyright (C) 2015-2021 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::syncTools
29
30Description
31 Various tools to aid synchronizing lists across coupled patches. WIP.
32
33 Require
34 - combineOperator (e.g. sumEqOp - not sumOp!) that is defined for the
35 type be defined.
36 - null value which gets overridden by any valid value.
37 - transform function
38
39SourceFiles
40 syncTools.C
41 syncToolsTemplates.C
42
43\*---------------------------------------------------------------------------*/
44
45#ifndef syncTools_H
46#define syncTools_H
47
48#include "Pstream.H"
49#include "edgeHashes.H"
50#include "bitSet.H"
51#include "polyMesh.H"
52#include "coupledPolyPatch.H"
53#include "mapDistribute.H"
54
55// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56
57namespace Foam
58{
59
60// Forward Declarations
61class polyBoundaryMesh;
62
63/*---------------------------------------------------------------------------*\
64 Class syncTools Declaration
65\*---------------------------------------------------------------------------*/
67class syncTools
68{
69 // Private Member Functions
70
71 //- Combine val with existing value in pointValues map at given index
72 template<class T, class CombineOp>
73 static void combine
74 (
75 Map<T>& pointValues,
76 const CombineOp& cop,
77 const label index,
78 const T& val
79 );
80
81 //- Combine val with existing value in edgeValues at edge index
82 template<class T, class CombineOp>
83 static void combine
84 (
85 EdgeMap<T>& edgeValues,
86 const CombineOp& cop,
87 const edge& index,
88 const T& val
89 );
90
91
92public:
93
94 // Basic routines with user-supplied transformation.
95 // Preferably use specialisations below.
96
97 //- Synchronize values on selected points.
98 template<class T, class CombineOp, class TransformOp>
99 static void syncPointMap
100 (
101 const polyMesh& mesh,
102 Map<T>& pointValues,
103 const CombineOp& cop,
104 const TransformOp& top
105 );
106
107 //- Synchronize values on selected edges.
108 template<class T, class CombineOp, class TransformOp>
109 static void syncEdgeMap
110 (
111 const polyMesh& mesh,
112 EdgeMap<T>& edgeValues,
113 const CombineOp& cop,
114 const TransformOp& top
115 );
116
117 //- Synchronize values on all mesh points.
118 template<class T, class CombineOp, class TransformOp>
119 static void syncPointList
120 (
121 const polyMesh& mesh,
122 List<T>& pointValues,
123 const CombineOp& cop,
124 const T& nullValue,
125 const TransformOp& top
126 );
127
128 //- Synchronize values on selected mesh points.
129 template<class T, class CombineOp, class TransformOp>
130 static void syncPointList
131 (
132 const polyMesh& mesh,
133 const labelUList& meshPoints,
134 List<T>& pointValues,
135 const CombineOp& cop,
136 const T& nullValue,
137 const TransformOp& top
138 );
139
140 //- Synchronize values on all mesh edges.
141 template<class T, class CombineOp, class TransformOp, class FlipOp>
142 static void syncEdgeList
143 (
144 const polyMesh& mesh,
145 List<T>& edgeValues,
146 const CombineOp& cop,
147 const T& nullValue,
148 const TransformOp& top,
149 const FlipOp& fop
150 );
151
152 //- Synchronize values on selected mesh edges.
153 template<class T, class CombineOp, class TransformOp, class FlipOp>
154 static void syncEdgeList
155 (
156 const polyMesh& mesh,
157 const labelList& meshEdges,
158 List<T>& edgeValues,
159 const CombineOp& cop,
160 const T& nullValue,
161 const TransformOp& top,
162 const FlipOp& fop
163 );
164
165 //- Synchronize values on boundary faces only.
166 template<class T, class CombineOp, class TransformOp>
167 static void syncBoundaryFaceList
168 (
169 const polyMesh& mesh,
170 UList<T>& faceValues,
171 const CombineOp& cop,
172 const TransformOp& top,
173 const bool parRun = Pstream::parRun()
174 );
175
176
177 // Synchronise point-wise data
178
179 //- Synchronize values on all mesh points.
180 template<class T, class CombineOp>
181 static void syncPointList
182 (
183 const polyMesh& mesh,
184 List<T>& pointValues,
185 const CombineOp& cop,
186 const T& nullValue
187 )
188 {
190 (
191 mesh,
192 pointValues,
193 cop,
194 nullValue,
196 );
197 }
198
199 //- Synchronize locations on all mesh points.
200 template<class CombineOp>
201 static void syncPointPositions
202 (
203 const polyMesh& mesh,
204 List<point>& positions,
205 const CombineOp& cop,
206 const point& nullValue
207 )
208 {
210 (
211 mesh,
212 positions,
213 cop,
214 nullValue,
216 );
217 }
218
219 //- Synchronize values on selected mesh points.
220 template<class T, class CombineOp>
221 static void syncPointList
222 (
223 const polyMesh& mesh,
224 const labelList& meshPoints,
225 List<T>& pointValues,
226 const CombineOp& cop,
227 const T& nullValue
228 )
229 {
231 (
232 mesh,
233 meshPoints,
234 pointValues,
235 cop,
236 nullValue,
238 );
239 }
240
241 //- Synchronize locations on selected mesh points.
242 template<class CombineOp>
243 static void syncPointPositions
244 (
245 const polyMesh& mesh,
246 const labelList& meshPoints,
247 List<point>& positions,
248 const CombineOp& cop,
249 const point& nullValue
250 )
251 {
253 (
254 mesh,
255 meshPoints,
256 positions,
257 cop,
258 nullValue,
260 );
261 }
262
263
264 // Synchronise edge-wise data
265
266 //- Synchronize values on all mesh edges.
267 template<class T, class CombineOp>
268 static void syncEdgeList
269 (
270 const polyMesh& mesh,
271 List<T>& edgeValues,
272 const CombineOp& cop,
273 const T& nullValue
274 )
275 {
277 (
278 mesh,
279 edgeValues,
280 cop,
281 nullValue,
283 identityOp() // No flipping
284 );
285 }
286
287 //- Synchronize locations on all mesh edges.
288 template<class CombineOp>
289 static void syncEdgePositions
290 (
291 const polyMesh& mesh,
292 List<point>& positions,
293 const CombineOp& cop,
294 const point& nullValue
295 )
296 {
298 (
299 mesh,
300 positions,
301 cop,
302 nullValue,
304 identityOp() // No flipping
305 );
306 }
307
308 //- Synchronize values on selected mesh edges.
309 template<class T, class CombineOp>
310 static void syncEdgeList
311 (
312 const polyMesh& mesh,
313 const labelList& meshEdges,
314 List<T>& edgeValues,
315 const CombineOp& cop,
316 const T& nullValue
317 )
318 {
320 (
321 mesh,
322 meshEdges,
323 edgeValues,
324 cop,
325 nullValue,
327 identityOp() // No flipping
328 );
329 }
330
331 //- Synchronize locations on selected mesh edges.
332 template<class CombineOp>
333 static void syncEdgePositions
334 (
335 const polyMesh& mesh,
336 const labelList& meshEdges,
337 List<point>& positions,
338 const CombineOp& cop,
339 const point& nullValue
340 )
341 {
343 (
344 mesh,
345 meshEdges,
346 positions,
347 cop,
348 nullValue,
350 identityOp() // No flipping
351 );
352 }
353
354
355
356 // Synchronise face-wise data
357
358 //- Synchronize values on boundary faces only.
359 template<class T, class CombineOp>
360 static void syncBoundaryFaceList
361 (
362 const polyMesh& mesh,
363 UList<T>& faceValues,
364 const CombineOp& cop
365 )
366 {
368 (
369 mesh,
370 faceValues,
371 cop,
373 );
374 }
375
376 //- Synchronize locations on boundary faces only.
377 template<class CombineOp>
378 static void syncBoundaryFacePositions
379 (
380 const polyMesh& mesh,
381 UList<point>& positions,
382 const CombineOp& cop
383 )
384 {
386 (
387 mesh,
388 positions,
389 cop,
391 );
392 }
393
394 //- Synchronize values on all mesh faces.
395 template<class T, class CombineOp>
396 static void syncFaceList
397 (
398 const polyMesh& mesh,
399 UList<T>& faceValues,
400 const CombineOp& cop
401 )
402 {
403 SubList<T> bndValues
404 (
405 faceValues,
408 );
409
411 (
412 mesh,
413 bndValues,
414 cop,
416 );
417 }
418
419 //- Synchronize locations on all mesh faces.
420 template<class CombineOp>
421 static void syncFacePositions
422 (
423 const polyMesh& mesh,
424 UList<point>& positions,
425 const CombineOp& cop
426 )
427 {
428 SubList<point> bndValues
429 (
430 positions,
433 );
435 (
436 mesh,
437 bndValues,
438 cop,
440 );
441 }
442
443 //- Swap coupled boundary face values. Uses eqOp
444 template<class T>
445 static void swapBoundaryFaceList
446 (
447 const polyMesh& mesh,
448 UList<T>& faceValues
449 )
450 {
452 (
453 mesh,
454 faceValues,
455 eqOp<T>(),
457 );
458 }
459
460 //- Swap coupled positions. Uses eqOp
461 static void swapBoundaryFacePositions
462 (
463 const polyMesh& mesh,
464 UList<point>& positions
465 )
466 {
468 (
469 mesh,
470 positions,
471 eqOp<point>(),
473 );
474 }
475
476 //- Swap coupled face values. Uses eqOp
477 template<class T>
478 static void swapFaceList
479 (
480 const polyMesh& mesh,
481 UList<T>& faceValues
482 )
483 {
484 SubList<T> bndValues
485 (
486 faceValues,
489 );
491 (
492 mesh,
493 bndValues,
494 eqOp<T>(),
496 );
497 }
498
499 //- Swap to obtain neighbour cell values for all boundary faces
500 template<class T>
501 static void swapBoundaryCellList
502 (
503 const polyMesh& mesh,
504 const UList<T>& cellData,
505 List<T>& neighbourCellData
506 );
507
508 //- Swap to obtain neighbour cell positions for all boundary faces
509 static void swapBoundaryCellPositions
510 (
511 const polyMesh& mesh,
512 const UList<point>& cellData,
513 List<point>& neighbourCellData
514 );
515
516
517 // Sparse versions
518
519 //- Synchronize values on selected points.
520 template<class T, class CombineOp>
521 static void syncPointMap
522 (
523 const polyMesh& mesh,
524 Map<T>& pointValues,
525 const CombineOp& cop
526 )
527 {
529 (
530 mesh,
531 pointValues,
532 cop,
534 );
535 }
536
537 //- Synchronize locations on selected points.
538 template<class CombineOp>
539 static void syncPointPositions
540 (
541 const polyMesh& mesh,
542 Map<point>& positions,
543 const CombineOp& cop
544 )
545 {
547 (
548 mesh,
549 positions,
550 cop,
552 );
553 }
554
555 //- Synchronize values on selected edges. Edges are represented
556 // by the two vertices that make it up so global edges never get
557 // constructed.
558 template<class T, class CombineOp>
559 static void syncEdgeMap
560 (
561 const polyMesh& mesh,
562 EdgeMap<T>& edgeValues,
563 const CombineOp& cop
564 )
565 {
567 (
568 mesh,
569 edgeValues,
570 cop,
572 );
573 }
574
575 //- Synchronize locations on selected edges.
576 template<class CombineOp>
577 static void syncEdgePositions
578 (
579 const polyMesh& mesh,
580 EdgeMap<point>& edgePositions,
581 const CombineOp& cop
582 )
583 {
585 (
586 mesh,
587 edgePositions,
588 cop,
590 );
591 }
592
593
594 // PackedList versions
595
596 //- Synchronize face values from PackedList/bitSet
597 //
598 // \param mesh The mesh
599 // \param isBoundaryOnly True if faceValues are for the boundary
600 // only and not the entire mesh. This determines the face
601 // offset when accessing values.
602 // \param faceValues The face values to synchronize
603 // \param cop The combine operation
604 // \param parRun True if this is a parallel simulation
605 template<unsigned Width, class CombineOp>
606 static void syncFaceList
607 (
608 const polyMesh& mesh,
609 const bool isBoundaryOnly,
610 PackedList<Width>& faceValues,
611 const CombineOp& cop,
612 const bool parRun = Pstream::parRun()
613 );
614
615 //- Synchronize mesh face values from PackedList/bitSet
616 template<unsigned Width, class CombineOp>
617 static void syncFaceList
618 (
619 const polyMesh& mesh,
620 PackedList<Width>& faceValues,
621 const CombineOp& cop,
622 const bool parRun = Pstream::parRun()
623 );
624
625 //- Synchronize boundary face values from PackedList/bitSet
626 template<unsigned Width, class CombineOp>
627 static void syncBoundaryFaceList
628 (
629 const polyMesh& mesh,
630 PackedList<Width>& faceValues,
631 const CombineOp& cop,
632 const bool parRun = Pstream::parRun()
633 );
634
635 //- Swap coupled face values. Uses eqOp
636 template<unsigned Width>
637 static void swapFaceList
638 (
639 const polyMesh& mesh,
640 PackedList<Width>& faceValues
641 );
642
643 //- Swap coupled boundary face values. Uses eqOp
644 template<unsigned Width>
645 static void swapBoundaryFaceList
646 (
647 const polyMesh& mesh,
648 PackedList<Width>& faceValues
649 );
650
651 template<unsigned Width, class CombineOp>
652 static void syncPointList
653 (
654 const polyMesh& mesh,
655 PackedList<Width>& pointValues,
656 const CombineOp& cop,
657 const unsigned int nullValue
658 );
659
660 template<unsigned Width, class CombineOp>
661 static void syncEdgeList
662 (
663 const polyMesh& mesh,
664 PackedList<Width>& edgeValues,
665 const CombineOp& cop,
666 const unsigned int nullValue
667 );
668
669
670 // Other
671
672 //- Get per point whether it is uncoupled or a master of a
673 //- coupled set of points
674 static bitSet getMasterPoints(const polyMesh& mesh);
675
676 //- Get per edge whether it is uncoupled or a master of a
677 //- coupled set of edges
678 static bitSet getMasterEdges(const polyMesh& mesh);
679
680 //- Get per face whether it is uncoupled or a master of a
681 //- coupled set of faces
682 static bitSet getMasterFaces(const polyMesh& mesh);
683
684 //- Get per face whether it is internal or a master of a
685 //- coupled set of faces
687
688 //- Get per face whether it is internal or coupled
690};
691
692
693// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
694
695} // End namespace Foam
696
697// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
698
699#ifdef NoRepository
700 #include "syncToolsTemplates.C"
701#endif
702
703// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
704
705#endif
706
707// ************************************************************************* //
Map from edge (expressed as its endpoints) to value. For easier forward declaration it is currently i...
Definition: EdgeMap.H:54
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
A HashTable to objects of type <T> with a label key.
Definition: Map.H:60
A dynamic list of packed unsigned integers, with the number of bits per item specified by the <Width>...
Definition: PackedList.H:129
A List obtained as a section of another List.
Definition: SubList.H:70
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:66
Default transformation behaviour for position.
Default transformation behaviour.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
label nBoundaryFaces() const noexcept
Number of boundary faces (== nFaces - nInternalFaces)
label nInternalFaces() const noexcept
Number of internal faces.
Various tools to aid synchronizing lists across coupled patches. WIP.
Definition: syncTools.H:67
static bitSet getMasterFaces(const polyMesh &mesh)
Definition: syncTools.C:126
static void swapBoundaryFacePositions(const polyMesh &mesh, UList< point > &positions)
Swap coupled positions. Uses eqOp.
Definition: syncTools.H:461
static bitSet getInternalOrCoupledFaces(const polyMesh &mesh)
Get per face whether it is internal or coupled.
Definition: syncTools.C:176
static bitSet getMasterPoints(const polyMesh &mesh)
Definition: syncTools.C:68
static void syncEdgeList(const polyMesh &mesh, const labelList &meshEdges, List< T > &edgeValues, const CombineOp &cop, const T &nullValue)
Synchronize values on selected mesh edges.
Definition: syncTools.H:310
static void syncEdgeList(const polyMesh &mesh, List< T > &edgeValues, const CombineOp &cop, const T &nullValue)
Synchronize values on all mesh edges.
Definition: syncTools.H:268
static void syncEdgeMap(const polyMesh &mesh, EdgeMap< T > &edgeValues, const CombineOp &cop, const TransformOp &top)
Synchronize values on selected edges.
static void syncPointList(const polyMesh &mesh, const labelList &meshPoints, List< T > &pointValues, const CombineOp &cop, const T &nullValue)
Synchronize values on selected mesh points.
Definition: syncTools.H:221
static void syncEdgePositions(const polyMesh &mesh, EdgeMap< point > &edgePositions, const CombineOp &cop)
Synchronize locations on selected edges.
Definition: syncTools.H:577
static bitSet getMasterEdges(const polyMesh &mesh)
Definition: syncTools.C:97
static void syncPointMap(const polyMesh &mesh, Map< T > &pointValues, const CombineOp &cop, const TransformOp &top)
Synchronize values on selected points.
static void syncEdgePositions(const polyMesh &mesh, List< point > &positions, const CombineOp &cop, const point &nullValue)
Synchronize locations on all mesh edges.
Definition: syncTools.H:289
static void syncBoundaryFaceList(const polyMesh &mesh, UList< T > &faceValues, const CombineOp &cop)
Synchronize values on boundary faces only.
Definition: syncTools.H:360
static void syncPointPositions(const polyMesh &mesh, const labelList &meshPoints, List< point > &positions, const CombineOp &cop, const point &nullValue)
Synchronize locations on selected mesh points.
Definition: syncTools.H:243
static void swapFaceList(const polyMesh &mesh, UList< T > &faceValues)
Swap coupled face values. Uses eqOp.
Definition: syncTools.H:478
static void syncFaceList(const polyMesh &mesh, UList< T > &faceValues, const CombineOp &cop)
Synchronize values on all mesh faces.
Definition: syncTools.H:396
static void syncPointPositions(const polyMesh &mesh, List< point > &positions, const CombineOp &cop, const point &nullValue)
Synchronize locations on all mesh points.
Definition: syncTools.H:201
static void syncPointList(const polyMesh &mesh, List< T > &pointValues, const CombineOp &cop, const T &nullValue)
Synchronize values on all mesh points.
Definition: syncTools.H:181
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &faceValues)
Swap coupled boundary face values. Uses eqOp.
Definition: syncTools.H:445
static void syncEdgePositions(const polyMesh &mesh, const labelList &meshEdges, List< point > &positions, const CombineOp &cop, const point &nullValue)
Synchronize locations on selected mesh edges.
Definition: syncTools.H:333
static bitSet getInternalOrMasterFaces(const polyMesh &mesh)
Definition: syncTools.C:148
static void swapBoundaryCellList(const polyMesh &mesh, const UList< T > &cellData, List< T > &neighbourCellData)
Swap to obtain neighbour cell values for all boundary faces.
static void syncFacePositions(const polyMesh &mesh, UList< point > &positions, const CombineOp &cop)
Synchronize locations on all mesh faces.
Definition: syncTools.H:421
static void syncEdgeMap(const polyMesh &mesh, EdgeMap< T > &edgeValues, const CombineOp &cop)
Synchronize values on selected edges. Edges are represented.
Definition: syncTools.H:559
static void syncPointMap(const polyMesh &mesh, Map< T > &pointValues, const CombineOp &cop)
Synchronize values on selected points.
Definition: syncTools.H:521
static void swapBoundaryCellPositions(const polyMesh &mesh, const UList< point > &cellData, List< point > &neighbourCellData)
Swap to obtain neighbour cell positions for all boundary faces.
Definition: syncTools.C:34
static void syncPointPositions(const polyMesh &mesh, Map< point > &positions, const CombineOp &cop)
Synchronize locations on selected points.
Definition: syncTools.H:539
static void syncPointList(const polyMesh &mesh, List< T > &pointValues, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh points.
static void syncBoundaryFacePositions(const polyMesh &mesh, UList< point > &positions, const CombineOp &cop)
Synchronize locations on boundary faces only.
Definition: syncTools.H:378
static void syncEdgeList(const polyMesh &mesh, List< T > &edgeValues, const CombineOp &cop, const T &nullValue, const TransformOp &top, const FlipOp &fop)
Synchronize values on all mesh edges.
static void syncBoundaryFaceList(const polyMesh &mesh, UList< T > &faceValues, const CombineOp &cop, const TransformOp &top, const bool parRun=Pstream::parRun())
Synchronize values on boundary faces only.
const volScalarField & T
dynamicFvMesh & mesh
Namespace for OpenFOAM.
Definition: ops.H:71