syncTools.H
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 Class
25  Foam::syncTools
26 
27 Description
28  Various tools to aid synchronising lists across coupled patches. WIP.
29 
30  Require
31  - combineOperator (e.g. sumEqOp - not sumOp!) that is defined for the
32  type and combineReduce(UList<T>, combineOperator) should be defined.
33  - null value which gets overridden by any valid value.
34  - transform function
35 
36 SourceFiles
37  syncTools.C
38  syncToolsTemplates.C
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef syncTools_H
43 #define syncTools_H
44 
45 #include "Pstream.H"
46 #include "EdgeMap.H"
47 #include "PackedBoolList.H"
48 #include "polyMesh.H"
49 #include "coupledPolyPatch.H"
50 #include "distributionMap.H"
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 
57 class polyBoundaryMesh;
58 
59 /*---------------------------------------------------------------------------*\
60  Class syncTools Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 class syncTools
64 {
65  // Private Member Functions
66 
67  //- Combine value with existing value in map.
68  template<class T, class CombineOp>
69  static void combine
70  (
71  Map<T>& pointValues,
72  const CombineOp& cop,
73  const label index,
74  const T& val
75  );
76 
77  //- Combine val with existing value at (implicit index) e.
78  template<class T, class CombineOp>
79  static void combine
80  (
81  EdgeMap<T>& edgeValues,
82  const CombineOp& cop,
83  const edge& index,
84  const T& val
85  );
86 
87 
88 public:
89 
90 
91  // Basic routines with user-supplied transformation. Preferably
92  // use specialisations below.
93 
94  //- Synchronise values on selected points.
95  template<class T, class CombineOp, class TransformOp>
96  static void syncPointMap
97  (
98  const polyMesh&,
99  Map<T>& pointValues,
100  const CombineOp& cop,
101  const TransformOp& top
102  );
103 
104  //- Synchronise values on selected edges.
105  template<class T, class CombineOp, class TransformOp>
106  static void syncEdgeMap
107  (
108  const polyMesh&,
109  EdgeMap<T>& edgeValues,
110  const CombineOp& cop,
111  const TransformOp& top
112  );
113 
114  //- Synchronise values on all mesh points.
115  template<class T, class CombineOp, class TransformOp>
116  static void syncPointList
117  (
118  const polyMesh&,
119  List<T>&,
120  const CombineOp& cop,
121  const T& nullValue,
122  const TransformOp& top
123  );
124 
125  //- Synchronise values on selected mesh points.
126  template<class T, class CombineOp, class TransformOp>
127  static void syncPointList
128  (
129  const polyMesh&,
130  const labelList& meshPoints,
131  List<T>&,
132  const CombineOp& cop,
133  const T& nullValue,
134  const TransformOp& top
135  );
136 
137  //- Synchronise values on all mesh edges.
138  template<class T, class CombineOp, class TransformOp>
139  static void syncEdgeList
140  (
141  const polyMesh&,
142  List<T>&,
143  const CombineOp& cop,
144  const T& nullValue,
145  const TransformOp& top
146  );
147 
148  //- Synchronise values on selected mesh edges.
149  template<class T, class CombineOp, class TransformOp>
150  static void syncEdgeList
151  (
152  const polyMesh&,
153  const labelList& meshEdges,
154  List<T>&,
155  const CombineOp& cop,
156  const T& nullValue,
157  const TransformOp& top
158  );
159 
160  //- Synchronise values on boundary faces only.
161  template<class T, class CombineOp, class TransformOp>
162  static void syncBoundaryFaceList
163  (
164  const polyMesh&,
165  UList<T>&,
166  const CombineOp& cop,
167  const TransformOp& top,
168  const bool parRun = Pstream::parRun()
169  );
170 
171 
172  // Synchronise point-wise data
173 
174  //- Synchronise values on all mesh points.
175  template<class T, class CombineOp>
176  static void syncPointList
177  (
178  const polyMesh& mesh,
179  List<T>& l,
180  const CombineOp& cop,
181  const T& nullValue
182  )
183  {
185  (
186  mesh,
187  l,
188  cop,
189  nullValue,
191  );
192  }
193 
194  //- Synchronise locations on all mesh points.
195  template<class CombineOp>
196  static void syncPointPositions
197  (
198  const polyMesh& mesh,
199  List<point>& l,
200  const CombineOp& cop,
201  const point& nullValue
202  )
203  {
205  (
206  mesh,
207  l,
208  cop,
209  nullValue,
211  );
212  }
213 
214  //- Synchronise values on selected mesh points.
215  template<class T, class CombineOp>
216  static void syncPointList
217  (
218  const polyMesh& mesh,
219  const labelList& meshPoints,
220  List<T>& l,
221  const CombineOp& cop,
222  const T& nullValue
223  )
224  {
226  (
227  mesh,
228  meshPoints,
229  l,
230  cop,
231  nullValue,
233  );
234  }
235 
236  //- Synchronise locations on selected mesh points.
237  template<class CombineOp>
238  static void syncPointPositions
239  (
240  const polyMesh& mesh,
241  const labelList& meshPoints,
242  List<point>& l,
243  const CombineOp& cop,
244  const point& nullValue
245  )
246  {
248  (
249  mesh,
250  meshPoints,
251  l,
252  cop,
253  nullValue,
255  );
256  }
257 
258 
259  // Synchronise edge-wise data
260 
261  //- Synchronise values on all mesh edges.
262  template<class T, class CombineOp>
263  static void syncEdgeList
264  (
265  const polyMesh& mesh,
266  List<T>& l,
267  const CombineOp& cop,
268  const T& nullValue
269  )
270  {
272  (
273  mesh,
274  l,
275  cop,
276  nullValue,
278  );
279  }
280 
281  //- Synchronise locations on all mesh edges.
282  template<class CombineOp>
283  static void syncEdgePositions
284  (
285  const polyMesh& mesh,
286  List<point>& l,
287  const CombineOp& cop,
288  const point& nullValue
289  )
290  {
292  (
293  mesh,
294  l,
295  cop,
296  nullValue,
298  );
299  }
300 
301  //- Synchronise values on selected mesh edges.
302  template<class T, class CombineOp>
303  static void syncEdgeList
304  (
305  const polyMesh& mesh,
306  const labelList& meshEdges,
307  List<T>& l,
308  const CombineOp& cop,
309  const T& nullValue
310  )
311  {
313  (
314  mesh,
315  meshEdges,
316  l,
317  cop,
318  nullValue,
320  );
321  }
322 
323  //- Synchronise locations on selected mesh edges.
324  template<class CombineOp>
325  static void syncEdgePositions
326  (
327  const polyMesh& mesh,
328  const labelList& meshEdges,
329  List<point>& l,
330  const CombineOp& cop,
331  const point& nullValue
332  )
333  {
335  (
336  mesh,
337  meshEdges,
338  l,
339  cop,
340  nullValue,
342  );
343  }
344 
345 
346 
347  // Synchronise face-wise data
348 
349  //- Synchronise values on boundary faces only.
350  template<class T, class CombineOp>
352  (
353  const polyMesh& mesh,
354  UList<T>& l,
355  const CombineOp& cop
356  )
357  {
359  (
360  mesh,
361  l,
362  cop,
364  );
365  }
366 
367  //- Synchronise locations on boundary faces only.
368  template<class CombineOp>
370  (
371  const polyMesh& mesh,
372  UList<point>& l,
373  const CombineOp& cop
374  )
375  {
377  (
378  mesh,
379  l,
380  cop,
382  );
383  }
384 
385  //- Synchronise values on all mesh faces.
386  template<class T, class CombineOp>
387  static void syncFaceList
388  (
389  const polyMesh& mesh,
390  UList<T>& l,
391  const CombineOp& cop
392  )
393  {
394  SubList<T> bndValues
395  (
396  l,
397  mesh.nFaces()-mesh.nInternalFaces(),
398  mesh.nInternalFaces()
399  );
400 
402  (
403  mesh,
404  bndValues,
405  cop,
407  );
408  }
409 
410  //- Synchronise locations on all mesh faces.
411  template<class CombineOp>
412  static void syncFacePositions
413  (
414  const polyMesh& mesh,
415  UList<point>& l,
416  const CombineOp& cop
417  )
418  {
419  SubList<point> bndValues
420  (
421  l,
422  mesh.nFaces()-mesh.nInternalFaces(),
423  mesh.nInternalFaces()
424  );
426  (
427  mesh,
428  bndValues,
429  cop,
431  );
432  }
433 
434  //- Swap coupled boundary face values.
435  template<class T>
437  (
438  const polyMesh& mesh,
439  UList<T>& l
440  )
441  {
443  (
444  mesh,
445  l,
446  eqOp<T>(),
448  );
449  }
450 
451  //- Swap coupled positions.
453  (
454  const polyMesh& mesh,
455  UList<point>& l
456  )
457  {
459  (
460  mesh,
461  l,
462  eqOp<point>(),
464  );
465  }
466 
467  //- Swap coupled face values.
468  template<class T>
469  static void swapFaceList
470  (
471  const polyMesh& mesh,
472  UList<T>& l
473  )
474  {
475  SubList<T> bndValues
476  (
477  l,
478  mesh.nFaces()-mesh.nInternalFaces(),
479  mesh.nInternalFaces()
480  );
482  (
483  mesh,
484  bndValues,
485  eqOp<T>(),
487  );
488  }
489 
490  //- Swap to obtain neighbour cell values for all boundary faces
491  template<class T>
492  static void swapBoundaryCellList
493  (
494  const polyMesh& mesh,
495  const UList<T>& cellData,
496  List<T>& neighbourCellData
497  );
498 
499  //- Swap to obtain neighbour cell positions for all boundary faces
500  static void swapBoundaryCellPositions
501  (
502  const polyMesh& mesh,
503  const UList<point>& cellData,
504  List<point>& neighbourCellData
505  );
506 
507  // Sparse versions
508 
509  //- Synchronise values on selected points.
510  template<class T, class CombineOp>
511  static void syncPointMap
512  (
513  const polyMesh& mesh,
514  Map<T>& l,
515  const CombineOp& cop
516  )
517  {
518  syncPointMap(mesh, l, cop, distributionMap::transform());
519  }
520 
521  //- Synchronise locations on selected points.
522  template<class CombineOp>
523  static void syncPointPositions
524  (
525  const polyMesh& mesh,
526  Map<point>& l,
527  const CombineOp& cop
528  )
529  {
531  (
532  mesh,
533  l,
534  cop,
536  );
537  }
538 
539  //- Synchronise values on selected edges. Edges are represented
540  // by the two vertices that make it up so global edges never get
541  // constructed.
542  template<class T, class CombineOp>
543  static void syncEdgeMap
544  (
545  const polyMesh& mesh,
546  EdgeMap<T>& l,
547  const CombineOp& cop
548  )
549  {
550  syncEdgeMap(mesh, l, cop, distributionMap::transform());
551  }
552 
553  //- Synchronise locations on selected edges.
554  template<class CombineOp>
555  static void syncEdgePositions
556  (
557  const polyMesh& mesh,
558  EdgeMap<point>& l,
559  const CombineOp& cop
560  )
561  {
563  }
564 
565  // PackedList versions
566 
567  template<unsigned nBits, class CombineOp>
568  static void syncFaceList
569  (
570  const polyMesh& mesh,
571  PackedList<nBits>& faceValues,
572  const CombineOp& cop,
573  const bool parRun = Pstream::parRun()
574  );
575 
576  template<unsigned nBits>
577  static void swapFaceList
578  (
579  const polyMesh& mesh,
580  PackedList<nBits>& faceValues
581  );
582 
583  template<unsigned nBits, class CombineOp>
584  static void syncPointList
585  (
586  const polyMesh& mesh,
587  PackedList<nBits>& pointValues,
588  const CombineOp& cop,
589  const unsigned int nullValue
590  );
591 
592  template<unsigned nBits, class CombineOp>
593  static void syncEdgeList
594  (
595  const polyMesh& mesh,
596  PackedList<nBits>& edgeValues,
597  const CombineOp& cop,
598  const unsigned int nullValue
599  );
600 
601  // Other
602 
603  //- Get per point whether it is uncoupled or a master of a
604  // coupled set of points
605  static PackedBoolList getMasterPoints(const polyMesh&);
606 
607  //- Get per edge whether it is uncoupled or a master of a
608  // coupled set of edges
609  static PackedBoolList getMasterEdges(const polyMesh&);
610 
611  //- Get per face whether it is uncoupled or a master of a
612  // coupled set of faces
613  static PackedBoolList getMasterFaces(const polyMesh&);
614 
615  //- Get per face whether it is internal or a master of a
616  // coupled set of faces
618 
619  //- Get per face whether it is internal or coupled
621 
622 };
623 
624 
625 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
626 
627 } // End namespace Foam
628 
629 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
630 
631 #ifdef NoRepository
632  #include "syncToolsTemplates.C"
633 #endif
634 
635 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
636 
637 #endif
638 
639 // ************************************************************************* //
static void syncBoundaryFaceList(const polyMesh &, UList< T > &, const CombineOp &cop, const TransformOp &top, const bool parRun=Pstream::parRun())
Synchronise values on boundary faces only.
static void syncPointPositions(const polyMesh &mesh, List< point > &l, const CombineOp &cop, const point &nullValue)
Synchronise locations on all mesh points.
Definition: syncTools.H:196
label nInternalFaces() const
static void swapBoundaryFacePositions(const polyMesh &mesh, UList< point > &l)
Swap coupled positions.
Definition: syncTools.H:452
static PackedBoolList getInternalOrCoupledFaces(const polyMesh &)
Get per face whether it is internal or coupled.
Definition: syncTools.C:217
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
label nFaces() const
Default transformation behaviour.
Various tools to aid synchronising lists across coupled patches. WIP.
Definition: syncTools.H:62
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:31
static void syncEdgePositions(const polyMesh &mesh, List< point > &l, const CombineOp &cop, const point &nullValue)
Synchronise locations on all mesh edges.
Definition: syncTools.H:283
static PackedBoolList getMasterFaces(const polyMesh &)
Get per face whether it is uncoupled or a master of a.
Definition: syncTools.C:153
static PackedBoolList getInternalOrMasterFaces(const polyMesh &)
Get per face whether it is internal or a master of a.
Definition: syncTools.C:181
static PackedBoolList getMasterEdges(const polyMesh &)
Get per edge whether it is uncoupled or a master of a.
Definition: syncTools.C:109
A List obtained as a section of another List.
Definition: SubList.H:53
Definition: ops.H:70
A dynamically allocatable list of packed unsigned integers.
Definition: PackedList.H:116
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
static void syncEdgeList(const polyMesh &, List< T > &, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronise values on all mesh edges.
Default transformation behaviour for position.
static void swapFaceList(const polyMesh &mesh, UList< T > &l)
Swap coupled face values.
Definition: syncTools.H:469
static void syncPointMap(const polyMesh &, Map< T > &pointValues, const CombineOp &cop, const TransformOp &top)
Synchronise values on selected points.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
Map from edge (expressed as its endpoints) to value.
Definition: EdgeMap.H:47
static PackedBoolList getMasterPoints(const polyMesh &)
Get per point whether it is uncoupled or a master of a.
Definition: syncTools.C:65
static void syncEdgeMap(const polyMesh &, EdgeMap< T > &edgeValues, const CombineOp &cop, const TransformOp &top)
Synchronise values on selected edges.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
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 syncFaceList(const polyMesh &mesh, UList< T > &l, const CombineOp &cop)
Synchronise values on all mesh faces.
Definition: syncTools.H:387
A bit-packed bool list.
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:399
static void syncBoundaryFacePositions(const polyMesh &mesh, UList< point > &l, const CombineOp &cop)
Synchronise locations on boundary faces only.
Definition: syncTools.H:369
static void syncPointList(const polyMesh &, List< T > &, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronise values on all mesh points.
static void syncFacePositions(const polyMesh &mesh, UList< point > &l, const CombineOp &cop)
Synchronise locations on all mesh faces.
Definition: syncTools.H:412
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &l)
Swap coupled boundary face values.
Definition: syncTools.H:436
Namespace for OpenFOAM.
A HashTable to objects of type <T> with a label key.
Definition: Map.H:49