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 | Copyright (C) 2011-2013 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 synchronizing 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 "mapDistribute.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  //- Synchronize 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  //- Synchronize 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  //- Synchronize 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  //- Synchronize 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  //- Synchronize 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  //- Synchronize 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  //- Synchronize 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  );
169 
170 
171  // Synchronise point-wise data
172 
173  //- Synchronize values on all mesh points.
174  template<class T, class CombineOp>
175  static void syncPointList
176  (
177  const polyMesh& mesh,
178  List<T>& l,
179  const CombineOp& cop,
180  const T& nullValue
181  )
182  {
184  (
185  mesh,
186  l,
187  cop,
188  nullValue,
190  );
191  }
192 
193  //- Synchronize locations on all mesh points.
194  template<class CombineOp>
195  static void syncPointPositions
196  (
197  const polyMesh& mesh,
198  List<point>& l,
199  const CombineOp& cop,
200  const point& nullValue
201  )
202  {
204  (
205  mesh,
206  l,
207  cop,
208  nullValue,
210  );
211  }
212 
213  //- Synchronize values on selected mesh points.
214  template<class T, class CombineOp>
215  static void syncPointList
216  (
217  const polyMesh& mesh,
218  const labelList& meshPoints,
219  List<T>& l,
220  const CombineOp& cop,
221  const T& nullValue
222  )
223  {
225  (
226  mesh,
227  meshPoints,
228  l,
229  cop,
230  nullValue,
232  );
233  }
234 
235  //- Synchronize locations on selected mesh points.
236  template<class CombineOp>
237  static void syncPointPositions
238  (
239  const polyMesh& mesh,
240  const labelList& meshPoints,
241  List<point>& l,
242  const CombineOp& cop,
243  const point& nullValue
244  )
245  {
247  (
248  mesh,
249  meshPoints,
250  l,
251  cop,
252  nullValue,
254  );
255  }
256 
257 
258  // Synchronise edge-wise data
259 
260  //- Synchronize values on all mesh edges.
261  template<class T, class CombineOp>
262  static void syncEdgeList
263  (
264  const polyMesh& mesh,
265  List<T>& l,
266  const CombineOp& cop,
267  const T& nullValue
268  )
269  {
271  (
272  mesh,
273  l,
274  cop,
275  nullValue,
277  );
278  }
279 
280  //- Synchronize locations on all mesh edges.
281  template<class CombineOp>
282  static void syncEdgePositions
283  (
284  const polyMesh& mesh,
285  List<point>& l,
286  const CombineOp& cop,
287  const point& nullValue
288  )
289  {
291  (
292  mesh,
293  l,
294  cop,
295  nullValue,
297  );
298  }
299 
300  //- Synchronize values on selected mesh edges.
301  template<class T, class CombineOp>
302  static void syncEdgeList
303  (
304  const polyMesh& mesh,
305  const labelList& meshEdges,
306  List<T>& l,
307  const CombineOp& cop,
308  const T& nullValue
309  )
310  {
312  (
313  mesh,
314  meshEdges,
315  l,
316  cop,
317  nullValue,
319  );
320  }
321 
322  //- Synchronize locations on selected mesh edges.
323  template<class CombineOp>
324  static void syncEdgePositions
325  (
326  const polyMesh& mesh,
327  const labelList& meshEdges,
328  List<point>& l,
329  const CombineOp& cop,
330  const point& nullValue
331  )
332  {
334  (
335  mesh,
336  meshEdges,
337  l,
338  cop,
339  nullValue,
341  );
342  }
343 
344 
345 
346  // Synchronise face-wise data
347 
348  //- Synchronize values on boundary faces only.
349  template<class T, class CombineOp>
351  (
352  const polyMesh& mesh,
353  UList<T>& l,
354  const CombineOp& cop
355  )
356  {
358  }
359 
360  //- Synchronize locations on boundary faces only.
361  template<class CombineOp>
363  (
364  const polyMesh& mesh,
365  UList<point>& l,
366  const CombineOp& cop
367  )
368  {
370  (
371  mesh,
372  l,
373  cop,
375  );
376  }
377 
378  //- Synchronize values on all mesh faces.
379  template<class T, class CombineOp>
380  static void syncFaceList
381  (
382  const polyMesh& mesh,
383  UList<T>& l,
384  const CombineOp& cop
385  )
386  {
387  SubList<T> bndValues
388  (
389  l,
390  mesh.nFaces()-mesh.nInternalFaces(),
391  mesh.nInternalFaces()
392  );
393 
395  (
396  mesh,
397  bndValues,
398  cop,
400  );
401  }
402 
403  //- Synchronize locations on all mesh faces.
404  template<class CombineOp>
405  static void syncFacePositions
406  (
407  const polyMesh& mesh,
408  UList<point>& l,
409  const CombineOp& cop
410  )
411  {
412  SubList<point> bndValues
413  (
414  l,
415  mesh.nFaces()-mesh.nInternalFaces(),
416  mesh.nInternalFaces()
417  );
419  (
420  mesh,
421  bndValues,
422  cop,
424  );
425  }
426 
427  //- Swap coupled boundary face values.
428  template<class T>
430  (
431  const polyMesh& mesh,
432  UList<T>& l
433  )
434  {
436  (
437  mesh,
438  l,
439  eqOp<T>(),
441  );
442  }
443 
444  //- Swap coupled positions.
446  (
447  const polyMesh& mesh,
448  UList<point>& l
449  )
450  {
452  (
453  mesh,
454  l,
455  eqOp<point>(),
457  );
458  }
459 
460  //- Swap coupled face values.
461  template<class T>
462  static void swapFaceList
463  (
464  const polyMesh& mesh,
465  UList<T>& l
466  )
467  {
468  SubList<T> bndValues
469  (
470  l,
471  mesh.nFaces()-mesh.nInternalFaces(),
472  mesh.nInternalFaces()
473  );
475  (
476  mesh,
477  bndValues,
478  eqOp<T>(),
480  );
481  }
482 
483  //- Swap to obtain neighbour cell values for all boundary faces
484  template<class T>
485  static void swapBoundaryCellList
486  (
487  const polyMesh& mesh,
488  const UList<T>& cellData,
489  List<T>& neighbourCellData
490  );
491 
492  //- Swap to obtain neighbour cell positions for all boundary faces
493  static void swapBoundaryCellPositions
494  (
495  const polyMesh& mesh,
496  const UList<point>& cellData,
497  List<point>& neighbourCellData
498  );
499 
500  // Sparse versions
501 
502  //- Synchronize values on selected points.
503  template<class T, class CombineOp>
504  static void syncPointMap
505  (
506  const polyMesh& mesh,
507  Map<T>& l,
508  const CombineOp& cop
509  )
510  {
511  syncPointMap(mesh, l, cop, mapDistribute::transform());
512  }
513 
514  //- Synchronize locations on selected points.
515  template<class CombineOp>
516  static void syncPointPositions
517  (
518  const polyMesh& mesh,
519  Map<point>& l,
520  const CombineOp& cop
521  )
522  {
524  }
525 
526  //- Synchronize values on selected edges. Edges are represented
527  // by the two vertices that make it up so global edges never get
528  // constructed.
529  template<class T, class CombineOp>
530  static void syncEdgeMap
531  (
532  const polyMesh& mesh,
533  EdgeMap<T>& l,
534  const CombineOp& cop
535  )
536  {
537  syncEdgeMap(mesh, l, cop, mapDistribute::transform());
538  }
539 
540  //- Synchronize locations on selected edges.
541  template<class CombineOp>
542  static void syncEdgePositions
543  (
544  const polyMesh& mesh,
545  EdgeMap<point>& l,
546  const CombineOp& cop
547  )
548  {
550  }
551 
552  // PackedList versions
553 
554  template<unsigned nBits, class CombineOp>
555  static void syncFaceList
556  (
557  const polyMesh& mesh,
558  PackedList<nBits>& faceValues,
559  const CombineOp& cop
560  );
561 
562  template<unsigned nBits>
563  static void swapFaceList
564  (
565  const polyMesh& mesh,
566  PackedList<nBits>& faceValues
567  );
568 
569  template<unsigned nBits, class CombineOp>
570  static void syncPointList
571  (
572  const polyMesh& mesh,
573  PackedList<nBits>& pointValues,
574  const CombineOp& cop,
575  const unsigned int nullValue
576  );
577 
578  template<unsigned nBits, class CombineOp>
579  static void syncEdgeList
580  (
581  const polyMesh& mesh,
582  PackedList<nBits>& edgeValues,
583  const CombineOp& cop,
584  const unsigned int nullValue
585  );
586 
587  // Other
588 
589  //- Get per point whether it is uncoupled or a master of a
590  // coupled set of points
591  static PackedBoolList getMasterPoints(const polyMesh&);
592 
593  //- Get per edge whether it is uncoupled or a master of a
594  // coupled set of edges
595  static PackedBoolList getMasterEdges(const polyMesh&);
596 
597  //- Get per face whether it is uncoupled or a master of a
598  // coupled set of faces
599  static PackedBoolList getMasterFaces(const polyMesh&);
600 
601  //- Get per face whether it is internal or a master of a
602  // coupled set of faces
604 
605  //- Get per face whether it is internal or coupled
607 
608 };
609 
610 
611 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
612 
613 } // End namespace Foam
614 
615 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
616 
617 #ifdef NoRepository
618 # include "syncToolsTemplates.C"
619 #endif
620 
621 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
622 
623 #endif
624 
625 // ************************************************************************* //
Default transformation behaviour for position.
static PackedBoolList getMasterFaces(const polyMesh &)
Get per face whether it is uncoupled or a master of a.
Definition: syncTools.C:156
Map from edge (expressed as its endpoints) to value.
Definition: EdgeMap.H:47
label nFaces() const
Default transformation behaviour.
static void syncFacePositions(const polyMesh &mesh, UList< point > &l, const CombineOp &cop)
Synchronize locations on all mesh faces.
Definition: syncTools.H:405
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
static PackedBoolList getInternalOrMasterFaces(const polyMesh &)
Get per face whether it is internal or a master of a.
Definition: syncTools.C:184
static void syncEdgeMap(const polyMesh &, EdgeMap< T > &edgeValues, const CombineOp &cop, const TransformOp &top)
Synchronize values on selected edges.
Definition: ops.H:70
A HashTable to objects of type <T> with a label key.
Definition: Map.H:49
A bit-packed bool list.
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
static PackedBoolList getMasterEdges(const polyMesh &)
Get per edge whether it is uncoupled or a master of a.
Definition: syncTools.C:112
static void syncPointMap(const polyMesh &, Map< T > &pointValues, const CombineOp &cop, const TransformOp &top)
Synchronize values on selected points.
static void syncEdgeList(const polyMesh &, List< T > &, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh edges.
static PackedBoolList getMasterPoints(const polyMesh &)
Get per point whether it is uncoupled or a master of a.
Definition: syncTools.C:68
static void syncBoundaryFaceList(const polyMesh &, UList< T > &, const CombineOp &cop, const TransformOp &top)
Synchronize values on boundary faces only.
static void syncFaceList(const polyMesh &mesh, UList< T > &l, const CombineOp &cop)
Synchronize values on all mesh faces.
Definition: syncTools.H:380
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
static PackedBoolList getInternalOrCoupledFaces(const polyMesh &)
Get per face whether it is internal or coupled.
Definition: syncTools.C:220
Namespace for OpenFOAM.
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
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)
Synchronize locations on all mesh edges.
Definition: syncTools.H:282
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &l)
Swap coupled boundary face values.
Definition: syncTools.H:429
static void syncPointList(const polyMesh &, List< T > &, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh points.
static void syncPointPositions(const polyMesh &mesh, List< point > &l, const CombineOp &cop, const point &nullValue)
Synchronize locations on all mesh points.
Definition: syncTools.H:195
label nInternalFaces() const
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
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
A List obtained as a section of another List.
Definition: SubList.H:53
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 swapBoundaryFacePositions(const polyMesh &mesh, UList< point > &l)
Swap coupled positions.
Definition: syncTools.H:445
static void syncBoundaryFacePositions(const polyMesh &mesh, UList< point > &l, const CombineOp &cop)
Synchronize locations on boundary faces only.
Definition: syncTools.H:362
A dynamically allocatable list of packed unsigned integers.
Definition: PackedList.H:117
static void swapFaceList(const polyMesh &mesh, UList< T > &l)
Swap coupled face values.
Definition: syncTools.H:462
Various tools to aid synchronizing lists across coupled patches. WIP.
Definition: syncTools.H:62