mapDistributeTemplates.C
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) 2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "Pstream.H"
30 #include "PstreamBuffers.H"
32 #include "transformField.H"
33 #include "flipOp.H"
34 
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36 
37 template<class T>
38 void Foam::mapDistribute::applyDummyTransforms(List<T>& field) const
39 {
40  forAll(transformElements_, trafoI)
41  {
42  const labelList& elems = transformElements_[trafoI];
43  label n = transformStart_[trafoI];
44 
45  forAll(elems, i)
46  {
47  field[n++] = field[elems[i]];
48  }
49  }
50 }
51 
52 
53 template<class T>
54 void Foam::mapDistribute::applyDummyInverseTransforms(List<T>& field) const
55 {
56  forAll(transformElements_, trafoI)
57  {
58  const labelList& elems = transformElements_[trafoI];
59  label n = transformStart_[trafoI];
60 
61  forAll(elems, i)
62  {
63  field[elems[i]] = field[n++];
64  }
65  }
66 }
67 
68 
69 template<class T, class TransformOp> //, class CombineOp>
70 void Foam::mapDistribute::applyTransforms
71 (
72  const globalIndexAndTransform& globalTransforms,
73  List<T>& field,
74  const TransformOp& top
75 ) const
76 {
77  const List<vectorTensorTransform>& totalTransform =
78  globalTransforms.transformPermutations();
79 
80  forAll(totalTransform, trafoI)
81  {
82  const vectorTensorTransform& vt = totalTransform[trafoI];
83  const labelList& elems = transformElements_[trafoI];
84  label n = transformStart_[trafoI];
85 
86  // Could be optimised to avoid memory allocations
87  List<T> transformFld(UIndirectList<T>(field, elems));
88  top(vt, true, transformFld);
89 
90  forAll(transformFld, i)
91  {
92  //cop(field[n++], transformFld[i]);
93  field[n++] = transformFld[i];
94  }
95  }
96 }
97 
98 
99 template<class T, class TransformOp> //, class CombineOp>
100 void Foam::mapDistribute::applyInverseTransforms
101 (
102  const globalIndexAndTransform& globalTransforms,
103  List<T>& field,
104  const TransformOp& top
105 ) const
106 {
107  const List<vectorTensorTransform>& totalTransform =
108  globalTransforms.transformPermutations();
109 
110  forAll(totalTransform, trafoI)
111  {
112  const vectorTensorTransform& vt = totalTransform[trafoI];
113  const labelList& elems = transformElements_[trafoI];
114  label n = transformStart_[trafoI];
115 
116  // Could be optimised to avoid memory allocations
117  List<T> transformFld(SubList<T>(field, elems.size(), n));
118  top(vt, false, transformFld);
119 
120  forAll(transformFld, i)
121  {
122  //cop(field[elems[i]], transformFld[i]);
123  field[elems[i]] = transformFld[i];
124  }
125  }
126 }
127 
128 
129 template<class T, class NegateOp>
131 (
132  const UPstream::commsTypes commsType,
133  List<T>& fld,
134  const NegateOp& negOp,
135  const bool dummyTransform,
136  const int tag
137 ) const
138 {
139  mapDistributeBase::distribute(commsType, fld, negOp, tag);
140 
141  //- Fill in transformed slots with copies
142  if (dummyTransform)
143  {
144  applyDummyTransforms(fld);
145  }
146 }
147 
148 
149 template<class T, class NegateOp>
151 (
152  List<T>& fld,
153  const NegateOp& negOp,
154  const bool dummyTransform,
155  const int tag
156 ) const
157 {
158  distribute(UPstream::defaultCommsType, fld, negOp, dummyTransform, tag);
159 }
160 
161 
162 template<class T>
164 (
165  const UPstream::commsTypes commsType,
166  List<T>& fld,
167  const bool dummyTransform,
168  const int tag
169 ) const
170 {
171  distribute(commsType, fld, flipOp(), dummyTransform, tag);
172 }
173 
174 
175 template<class T>
177 (
178  List<T>& fld,
179  const bool dummyTransform,
180  const int tag
181 ) const
182 {
183  distribute(UPstream::defaultCommsType, fld, dummyTransform, tag);
184 }
185 
186 
187 template<class T>
189 (
190  const UPstream::commsTypes commsType,
192  const bool dummyTransform,
193  const int tag
194 ) const
195 {
196  fld.shrink();
197 
198  List<T>& list = static_cast<List<T>&>(fld);
199 
200  distribute(commsType, list, dummyTransform, tag);
201 
202  fld.setCapacity(list.size());
203 }
204 
205 
206 template<class T>
208 (
210  const bool dummyTransform,
211  const int tag
212 ) const
213 {
214  distribute(UPstream::defaultCommsType, fld, dummyTransform, tag);
215 }
216 
217 
218 template<class T>
220 (
221  const UPstream::commsTypes commsType,
222  const label constructSize,
223  List<T>& fld,
224  const bool dummyTransform,
225  const int tag
226 ) const
227 {
228  if (dummyTransform)
229  {
230  applyDummyInverseTransforms(fld);
231  }
232 
233  mapDistributeBase::reverseDistribute(commsType, constructSize, fld, tag);
234 }
235 
236 
237 template<class T>
239 (
240  const label constructSize,
241  List<T>& fld,
242  const bool dummyTransform,
243  const int tag
244 ) const
245 {
246  reverseDistribute
247  (
249  constructSize,
250  fld,
252  tag
253  );
254 }
255 
256 
257 template<class T>
259 (
260  const UPstream::commsTypes commsType,
261  const label constructSize,
262  const T& nullValue,
263  List<T>& fld,
264  const bool dummyTransform,
265  const int tag
266 ) const
267 {
268  if (dummyTransform)
269  {
270  applyDummyInverseTransforms(fld);
271  }
272 
274  (
275  commsType,
276  constructSize,
277  nullValue,
278  fld,
279  tag
280  );
281 }
282 
283 
284 template<class T>
286 (
287  const label constructSize,
288  const T& nullValue,
289  List<T>& fld,
290  const bool dummyTransform,
291  const int tag
292 ) const
293 {
294  reverseDistribute
295  (
297  constructSize,
298  nullValue,
299  fld,
301  tag
302  );
303 }
304 
305 
306 template<class T, class TransformOp>
308 (
309  const UPstream::commsTypes commsType,
310  const globalIndexAndTransform& git,
311  List<T>& fld,
312  const TransformOp& top,
313  const int tag
314 ) const
315 {
316  // Distribute. Leave out dummy transforms since we're doing them ourselves
317  distribute(commsType, fld, false, tag);
318 
319  // Do transforms
320  applyTransforms(git, fld, top);
321 }
322 
323 
324 template<class T, class TransformOp>
326 (
327  const globalIndexAndTransform& git,
328  List<T>& fld,
329  const TransformOp& top,
330  const int tag
331 ) const
332 {
333  // Distribute. Leave out dummy transforms since we're doing them ourselves
334  distribute(UPstream::defaultCommsType, git, fld, top, tag);
335 }
336 
337 
338 template<class T, class TransformOp>
340 (
341  const UPstream::commsTypes commsType,
342  const globalIndexAndTransform& git,
343  const label constructSize,
344  List<T>& fld,
345  const TransformOp& top,
346  const int tag
347 ) const
348 {
349  // Fill slots with reverse-transformed data. Note that it also copies
350  // back into the non-remote part of fld even though these values are not
351  // used.
352  applyInverseTransforms(git, fld, top);
353 
354  // And send back (the remote slots). Disable dummy transformations.
355  reverseDistribute(commsType, constructSize, fld, false, tag);
356 }
357 
358 
359 template<class T, class TransformOp>
361 (
362  const globalIndexAndTransform& git,
363  const label constructSize,
364  List<T>& fld,
365  const TransformOp& top,
366  const int tag
367 ) const
368 {
369  // Fill slots with reverse-transformed data. Note that it also copies
370  // back into the non-remote part of fld even though these values are not
371  // used.
372  applyInverseTransforms(git, fld, top);
373 
374  // And send back (the remote slots). Disable dummy transformations.
375  reverseDistribute(constructSize, fld, false, tag);
376 }
377 
378 
379 template<class T, class TransformOp>
381 (
382  const UPstream::commsTypes commsType,
383  const globalIndexAndTransform& git,
384  const label constructSize,
385  const T& nullValue,
386  List<T>& fld,
387  const TransformOp& top,
388  const int tag
389 ) const
390 {
391  // Fill slots with reverse-transformed data Note that it also copies
392  // back into the non-remote part of fld even though these values are not
393  // used.
394  applyInverseTransforms(git, fld, top); //, eqOp<T>());
395 
396  // And send back (the remote slots) Disable dummy transformations.
397  reverseDistribute
398  (
399  commsType,
400  constructSize,
401  nullValue,
402  fld,
403  false,
404  tag
405  );
406 }
407 
408 
409 template<class T, class TransformOp>
411 (
412  const globalIndexAndTransform& git,
413  const label constructSize,
414  const T& nullValue,
415  List<T>& fld,
416  const TransformOp& top,
417  const int tag
418 ) const
419 {
420  reverseDistribute
421  (
423  git,
424  constructSize,
425  nullValue,
426  fld,
427  top,
428  tag
429  );
430 }
431 
432 
433 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
rDeltaTY field()
commsTypes
Communications types.
Definition: UPstream.H:72
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute List data using default commsType, default flip/negate operator.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
Spatial transformation functions for primitive fields.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:51
void reverseDistribute(const label constructSize, List< T > &values, const int tag=UPstream::msgType()) const
Reverse distribute data using default commsType and the default flip/negate operator.
void reverseDistribute(const label constructSize, List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Reverse distribute data using default commsType.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
static commsTypes defaultCommsType
Default commsType.
Definition: UPstream.H:385
label n
List< label > labelList
A List of labels.
Definition: List.H:62
Functor to negate primitives. Dummy for most other types.
Definition: flipOp.H:66
static void distribute(const UPstream::commsTypes commsType, const List< labelPair > &schedule, const label constructSize, const labelListList &subMap, const bool subHasFlip, const labelListList &constructMap, const bool constructHasFlip, List< T > &field, const T &nullValue, const CombineOp &cop, const NegateOp &negOp, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Distribute combine data with specified combine operation and negate operator (for flips)...
Determination and storage of the possible independent transforms introduced by coupledPolyPatches, as well as all of the possible permutations of these transforms generated by the presence of multiple coupledPolyPatches, i.e. more than one cyclic boundary. Note that any given point can be on maximum 3 transforms only (and these transforms have to be perpendicular)