FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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.
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  Can apply coordinate rotation/separation on cyclics but only for faces
37  or if there is a single rotation/separation tensor.
38 
39 SourceFiles
40  syncTools.C
41  syncToolsTemplates.C
42 
43 \*---------------------------------------------------------------------------*/
44 
45 #ifndef syncTools_H
46 #define syncTools_H
47 
48 #include <OpenFOAM/UList.H>
49 #include <OpenFOAM/Pstream.H>
50 #include <OpenFOAM/transformList.H>
51 #include <OpenFOAM/Map.H>
52 #include <OpenFOAM/EdgeMap.H>
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 
60 class polyBoundaryMesh;
61 class polyMesh;
62 class coupledPolyPatch;
63 
64 /*---------------------------------------------------------------------------*\
65  Class syncTools Declaration
66 \*---------------------------------------------------------------------------*/
67 
68 class syncTools
69 {
70  // Private Member Functions
71 
72  //- Check whether uses couples.
73  static bool hasCouples(const polyBoundaryMesh&);
74 
75  //- Check for single transformation tensor only.
76  static void checkTransform(const coupledPolyPatch&, const bool);
77 
78  //- Apply separation to list. Either single vector or one vector
79  // per element.
80  template <class T>
81  static void separateList(const vectorField&, UList<T>&);
82 
83  template <class T>
84  static void separateList(const vectorField&, Map<T>&);
85 
86  template <class T>
87  static void separateList(const vectorField&, EdgeMap<T>&);
88 
89  //- Combine value with existing value in map.
90  template <class T, class CombineOp>
91  static void combine
92  (
93  Map<T>& pointValues,
94  const CombineOp& cop,
95  const label index,
96  const T& val
97  );
98 
99  //- Combine val with existing value at (implicit index) e.
100  template <class T, class CombineOp>
101  static void combine
102  (
103  EdgeMap<T>& edgeValues,
104  const CombineOp& cop,
105  const edge& index,
106  const T& val
107  );
108 
109 
110 public:
111 
112  // Static data members
113 
114  //- Synchronize values on all mesh points.
115  // Applies rotation and optionally separation for parallel cyclics
116  template <class T, class CombineOp>
117  static void syncPointList
118  (
119  const polyMesh&,
120  UList<T>&,
121  const CombineOp& cop,
122  const T& nullValue,
123  const bool applySeparation
124  );
125 
126  //- Synchronize values on selected mesh points.
127  // Applies rotation and optionally separation for parallel cyclics
128  template <class T, class CombineOp>
129  static void syncPointList
130  (
131  const polyMesh&,
132  const labelList& meshPoints,
133  UList<T>&,
134  const CombineOp& bop,
135  const T& nullValue,
136  const bool applySeparation
137  );
138 
139  //- Synchronize values on all mesh edges.
140  // Applies rotation and optionally separation for parallel cyclics
141  template <class T, class CombineOp>
142  static void syncEdgeList
143  (
144  const polyMesh&,
145  UList<T>&,
146  const CombineOp& cop,
147  const T& nullValue,
148  const bool applySeparation
149  );
150 
151  //- Synchronize values on boundary faces only.
152  // Optionally applies rotation tensor for non-parallel cyclics
153  // (but not separation!)
154  template <class T, class CombineOp>
155  static void syncBoundaryFaceList
156  (
157  const polyMesh&,
158  UList<T>&,
159  const CombineOp& cop,
160  const bool applySeparation
161  );
162 
163  //- Synchronize values on all mesh faces.
164  // Optionally applies rotation tensor for non-parallel cyclics
165  // (but not separation!)
166  template <class T, class CombineOp>
167  static void syncFaceList
168  (
169  const polyMesh&,
170  UList<T>&,
171  const CombineOp& cop,
172  const bool applySeparation
173  );
174 
175  //- Swap coupled face values.
176  // Applies rotation and optionally separation for parallel cyclics
177  template <class T>
178  static void swapBoundaryFaceList
179  (
180  const polyMesh&,
181  UList<T>&,
182  const bool applySeparation
183  );
184 
185  //- Swap coupled face values.
186  // Applies rotation and optionally separation for parallel cyclics
187  template <class T>
188  static void swapFaceList
189  (
190  const polyMesh&,
191  UList<T>&,
192  const bool applySeparation
193  );
194 
195  // Sparse versions
196 
197  //- Synchronize values on selected points.
198  // Applies rotation and optionally separation for parallel
199  // cyclics.
200  template <class T, class CombineOp>
201  static void syncPointMap
202  (
203  const polyMesh&,
204  Map<T>& pointValues,
205  const CombineOp& cop,
206  const bool applySeparation
207  );
208 
209  //- Synchronize values on selected edges. Edges are represented
210  // by the two vertices that make it up so global edges never get
211  // constructed.
212  // Applies rotation and optionally separation for parallel
213  // cyclics.
214  template <class T, class CombineOp>
215  static void syncEdgeMap
216  (
217  const polyMesh&,
218  EdgeMap<T>& edgeValues,
219  const CombineOp& cop,
220  const bool applySeparation
221  );
222 
223  // PackedList versions
224 
225  template <unsigned nBits, class CombineOp>
226  static void syncFaceList
227  (
228  const polyMesh& mesh,
229  PackedList<nBits>& faceValues,
230  const CombineOp& cop
231  );
232 
233  template <unsigned nBits>
234  static void swapFaceList
235  (
236  const polyMesh& mesh,
237  PackedList<nBits>& faceValues
238  );
239 
240  template <unsigned nBits, class CombineOp>
241  static void syncPointList
242  (
243  const polyMesh& mesh,
244  PackedList<nBits>& pointValues,
245  const CombineOp& cop,
246  const unsigned int nullValue
247  );
248 
249  template <unsigned nBits, class CombineOp>
250  static void syncEdgeList
251  (
252  const polyMesh& mesh,
253  PackedList<nBits>& edgeValues,
254  const CombineOp& cop,
255  const unsigned int nullValue
256  );
257 
258  // Other
259 
260  //- Get per point whether is it master (of a coupled set of points)
261  static PackedBoolList getMasterPoints(const polyMesh&);
262 
263  //- Get per edge whether is it master (of a coupled set of edges)
264  static PackedBoolList getMasterEdges(const polyMesh&);
265 
266  //- Get per face whether is it master (of a coupled set of faces)
267  static PackedBoolList getMasterFaces(const polyMesh&);
268 
269 };
270 
271 
272 template<>
273 void syncTools::separateList(const vectorField&, UList<vector>&);
274 
275 template<>
276 void syncTools::separateList(const vectorField&, Map<vector>&);
277 
278 template<>
279 void syncTools::separateList(const vectorField&, EdgeMap<vector>&);
280 
281 
282 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283 
284 } // End namespace Foam
285 
286 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
287 
288 #ifdef NoRepository
289 # include "syncToolsTemplates.C"
290 #endif
291 
292 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
293 
294 #endif
295 
296 // ************************ vim: set sw=4 sts=4 et: ************************ //