Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
37template<class T>
38void 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
53template<class T>
54void 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
69template<class T, class TransformOp> //, class CombineOp>
70void Foam::mapDistribute::applyTransforms
71(
72 const globalIndexAndTransform& globalTransforms,
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
99template<class T, class TransformOp> //, class CombineOp>
100void Foam::mapDistribute::applyInverseTransforms
101(
102 const globalIndexAndTransform& globalTransforms,
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
129template<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);
146}
147
148
149template<class T, class NegateOp>
151(
152 List<T>& fld,
153 const NegateOp& negOp,
154 const bool dummyTransform,
155 const int tag
156) const
157{
159}
160
161
162template<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
175template<class T>
177(
178 List<T>& fld,
179 const bool dummyTransform,
180 const int tag
181) const
182{
184}
185
186
187template<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
204template<class T>
206(
208 const bool dummyTransform,
209 const int tag
210) const
211{
213}
214
215
216template<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
232}
233
234
235template<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
255template<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
282template<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
304template<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
322template<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
333}
334
335
336template<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
357template<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.
374}
375
376
377template<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
407template<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// ************************************************************************* //
label n
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
A non-owning sub-view of a List (allocated or unallocated storage).
Definition SubList.H:61
A List with indirect addressing. Like IndirectList but does not store addressing.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
commsTypes
Communications types.
Definition UPstream.H:81
static commsTypes defaultCommsType
Default commsType.
Definition UPstream.H:1045
Determination and storage of the possible independent transforms introduced by coupledPolyPatches,...
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.
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).
label constructSize() const noexcept
Constructed data size.
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 distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute List data using default commsType, default flip/negate operator.
Vector-tensor class used to perform translations and rotations in 3D space.
rDeltaTY field()
List< label > labelList
A List of labels.
Definition List.H:62
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299
Functor to negate primitives. Dummy for most other types.
Definition flipOp.H:67
Spatial transformation functions for primitive fields.