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(UList<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(UList<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  UList<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  UList<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  List<T> work(std::move(fld));
197 
198  distribute(commsType, work, dummyTransform, tag);
199 
200  fld = std::move(work);
201 }
202 
203 
204 template<class T>
206 (
208  const bool dummyTransform,
209  const int tag
210 ) const
211 {
212  distribute(UPstream::defaultCommsType, fld, dummyTransform, tag);
213 }
214 
215 
216 template<class T>
218 (
219  const UPstream::commsTypes commsType,
220  const label constructSize,
221  List<T>& fld,
222  const bool dummyTransform,
223  const int tag
224 ) const
225 {
226  if (dummyTransform)
227  {
228  applyDummyInverseTransforms(fld);
229  }
230 
231  mapDistributeBase::reverseDistribute(commsType, constructSize, fld, tag);
232 }
233 
234 
235 template<class T>
237 (
238  const label constructSize,
239  List<T>& fld,
240  const bool dummyTransform,
241  const int tag
242 ) const
243 {
244  reverseDistribute
245  (
247  constructSize,
248  fld,
250  tag
251  );
252 }
253 
254 
255 template<class T>
257 (
258  const UPstream::commsTypes commsType,
259  const label constructSize,
260  const T& nullValue,
261  List<T>& fld,
262  const bool dummyTransform,
263  const int tag
264 ) const
265 {
266  if (dummyTransform)
267  {
268  applyDummyInverseTransforms(fld);
269  }
270 
272  (
273  commsType,
274  constructSize,
275  nullValue,
276  fld,
277  tag
278  );
279 }
280 
281 
282 template<class T>
284 (
285  const label constructSize,
286  const T& nullValue,
287  List<T>& fld,
288  const bool dummyTransform,
289  const int tag
290 ) const
291 {
292  reverseDistribute
293  (
295  constructSize,
296  nullValue,
297  fld,
299  tag
300  );
301 }
302 
303 
304 template<class T, class TransformOp>
306 (
307  const UPstream::commsTypes commsType,
308  const globalIndexAndTransform& git,
309  List<T>& fld,
310  const TransformOp& top,
311  const int tag
312 ) const
313 {
314  // Distribute. Leave out dummy transforms since we're doing them ourselves
315  distribute(commsType, fld, false, tag);
316 
317  // Do transforms
318  applyTransforms(git, fld, top);
319 }
320 
321 
322 template<class T, class TransformOp>
324 (
325  const globalIndexAndTransform& git,
326  List<T>& fld,
327  const TransformOp& top,
328  const int tag
329 ) const
330 {
331  // Distribute. Leave out dummy transforms since we're doing them ourselves
332  distribute(UPstream::defaultCommsType, git, fld, top, tag);
333 }
334 
335 
336 template<class T, class TransformOp>
338 (
339  const UPstream::commsTypes commsType,
340  const globalIndexAndTransform& git,
341  const label constructSize,
342  List<T>& fld,
343  const TransformOp& top,
344  const int tag
345 ) const
346 {
347  // Fill slots with reverse-transformed data. Note that it also copies
348  // back into the non-remote part of fld even though these values are not
349  // used.
350  applyInverseTransforms(git, fld, top);
351 
352  // And send back (the remote slots). Disable dummy transformations.
353  reverseDistribute(commsType, constructSize, fld, false, tag);
354 }
355 
356 
357 template<class T, class TransformOp>
359 (
360  const globalIndexAndTransform& git,
361  const label constructSize,
362  List<T>& fld,
363  const TransformOp& top,
364  const int tag
365 ) const
366 {
367  // Fill slots with reverse-transformed data. Note that it also copies
368  // back into the non-remote part of fld even though these values are not
369  // used.
370  applyInverseTransforms(git, fld, top);
371 
372  // And send back (the remote slots). Disable dummy transformations.
373  reverseDistribute(constructSize, fld, false, tag);
374 }
375 
376 
377 template<class T, class TransformOp>
379 (
380  const UPstream::commsTypes commsType,
381  const globalIndexAndTransform& git,
382  const label constructSize,
383  const T& nullValue,
384  List<T>& fld,
385  const TransformOp& top,
386  const int tag
387 ) const
388 {
389  // Fill slots with reverse-transformed data Note that it also copies
390  // back into the non-remote part of fld even though these values are not
391  // used.
392  applyInverseTransforms(git, fld, top); //, eqOp<T>());
393 
394  // And send back (the remote slots) Disable dummy transformations.
395  reverseDistribute
396  (
397  commsType,
398  constructSize,
399  nullValue,
400  fld,
401  false,
402  tag
403  );
404 }
405 
406 
407 template<class T, class TransformOp>
409 (
410  const globalIndexAndTransform& git,
411  const label constructSize,
412  const T& nullValue,
413  List<T>& fld,
414  const TransformOp& top,
415  const int tag
416 ) const
417 {
418  reverseDistribute
419  (
421  git,
422  constructSize,
423  nullValue,
424  fld,
425  top,
426  tag
427  );
428 }
429 
430 
431 // ************************************************************************* //
rDeltaTY field()
commsTypes
Communications types.
Definition: UPstream.H:77
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:286
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:963
label n
List< label > labelList
A List of labels.
Definition: List.H:61
Functor to negate primitives. Dummy for most other types.
Definition: flipOp.H:66
static void distribute(const UPstream::commsTypes commsType, const UList< 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)