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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "Pstream.H"
29 #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 
44  label n = transformStart_[trafoI];
45 
46  forAll(elems, i)
47  {
48  field[n++] = field[elems[i]];
49  }
50  }
51 }
52 
53 
54 template<class T>
55 void Foam::mapDistribute::applyDummyInverseTransforms(List<T>& field) const
56 {
57  forAll(transformElements_, trafoI)
58  {
59  const labelList& elems = transformElements_[trafoI];
60  label n = transformStart_[trafoI];
61 
62  forAll(elems, i)
63  {
64  field[elems[i]] = field[n++];
65  }
66  }
67 }
68 
69 
70 template<class T, class TransformOp> //, class CombineOp>
71 void Foam::mapDistribute::applyTransforms
72 (
73  const globalIndexAndTransform& globalTransforms,
74  List<T>& field,
75  const TransformOp& top
76 ) const
77 {
78  const List<vectorTensorTransform>& totalTransform =
79  globalTransforms.transformPermutations();
80 
81  forAll(totalTransform, trafoI)
82  {
83  const vectorTensorTransform& vt = totalTransform[trafoI];
84  const labelList& elems = transformElements_[trafoI];
85  label n = transformStart_[trafoI];
86 
87  // Could be optimised to avoid memory allocations
88  List<T> transformFld(UIndirectList<T>(field, elems));
89  top(vt, true, transformFld);
90 
91  forAll(transformFld, i)
92  {
93  //cop(field[n++], transformFld[i]);
94  field[n++] = transformFld[i];
95  }
96  }
97 }
98 
99 
100 template<class T, class TransformOp> //, class CombineOp>
101 void Foam::mapDistribute::applyInverseTransforms
102 (
103  const globalIndexAndTransform& globalTransforms,
104  List<T>& field,
105  const TransformOp& top
106 ) const
107 {
108  const List<vectorTensorTransform>& totalTransform =
109  globalTransforms.transformPermutations();
110 
111  forAll(totalTransform, trafoI)
112  {
113  const vectorTensorTransform& vt = totalTransform[trafoI];
114  const labelList& elems = transformElements_[trafoI];
115  label n = transformStart_[trafoI];
116 
117  // Could be optimised to avoid memory allocations
118  List<T> transformFld(SubList<T>(field, elems.size(), n));
119  top(vt, false, transformFld);
120 
121  forAll(transformFld, i)
122  {
123  //cop(field[elems[i]], transformFld[i]);
124  field[elems[i]] = transformFld[i];
125  }
126  }
127 }
128 
129 
130 template<class T, class negateOp>
132 (
133  List<T>& fld,
134  const negateOp& negOp,
135  const bool dummyTransform,
136  const int tag
137 ) const
138 {
139  mapDistributeBase::distribute(fld, negOp, tag);
140 
141  //- Fill in transformed slots with copies
142  if (dummyTransform)
143  {
144  applyDummyTransforms(fld);
145  }
146 }
147 
148 
149 //- Distribute data using default commsType.
150 template<class T>
152 (
153  List<T>& fld,
154  const bool dummyTransform,
155  const int tag
156 ) const
157 {
158  distribute(fld, flipOp(), dummyTransform, tag);
159 }
160 
161 
162 template<class T>
164 (
166  const bool dummyTransform,
167  const int tag
168 ) const
169 {
170  fld.shrink();
171 
172  List<T>& fldList = static_cast<List<T>&>(fld);
173 
174  distribute(fldList, dummyTransform, tag);
175 
176  fld.setCapacity(fldList.size());
177 }
178 
179 
180 template<class T>
182 (
183  const label constructSize,
184  List<T>& fld,
185  const bool dummyTransform,
186  const int tag
187 ) const
188 {
189  if (dummyTransform)
190  {
191  applyDummyInverseTransforms(fld);
192  }
193 
194  mapDistributeBase::reverseDistribute(constructSize, fld, tag);
195 }
196 
197 
198 template<class T>
200 (
201  const label constructSize,
202  const T& nullValue,
203  List<T>& fld,
204  const bool dummyTransform,
205  const int tag
206 ) const
207 {
208  if (dummyTransform)
209  {
210  applyDummyInverseTransforms(fld);
211  }
212 
213  mapDistributeBase::reverseDistribute(constructSize, nullValue, fld, tag);
214 }
215 
216 
217 template<class T, class TransformOp>
219 (
220  const globalIndexAndTransform& git,
221  List<T>& fld,
222  const TransformOp& top,
223  const int tag
224 ) const
225 {
226  // Distribute. Leave out dummy transforms since we're doing them ourselves
227  distribute(fld, false, tag);
228  // Do transforms
229  applyTransforms(git, fld, top);
230 }
231 
232 
233 template<class T, class TransformOp>
235 (
236  const globalIndexAndTransform& git,
237  const label constructSize,
238  List<T>& fld,
239  const TransformOp& top,
240  const int tag
241 ) const
242 {
243  // Fill slots with reverse-transformed data. Note that it also copies
244  // back into the non-remote part of fld even though these values are not
245  // used.
246  applyInverseTransforms(git, fld, top);
247 
248  // And send back (the remote slots). Disable dummy transformations.
249  reverseDistribute(constructSize, fld, false, tag);
250 }
251 
252 
253 template<class T, class TransformOp>
255 (
256  const globalIndexAndTransform& git,
257  const label constructSize,
258  const T& nullValue,
259  List<T>& fld,
260  const TransformOp& top,
261  const int tag
262 ) const
263 {
264  // Fill slots with reverse-transformed data Note that it also copies
265  // back into the non-remote part of fld even though these values are not
266  // used.
267  applyInverseTransforms(git, fld, top); //, eqOp<T>());
268 
269  // And send back (the remote slots) Disable dummy transformations.
270  reverseDistribute(constructSize, nullValue, fld, false, tag);
271 }
272 
273 
274 // ************************************************************************* //
Foam::mapDistributeBase::reverseDistribute
void reverseDistribute(const label constructSize, List< T > &, const int tag=UPstream::msgType()) const
Reverse distribute data using default commsType.
Definition: mapDistributeBaseTemplates.C:1293
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:55
Foam::mapDistributeBase::distribute
static void distribute(const Pstream::commsTypes commsType, const List< labelPair > &schedule, const label constructSize, const labelListList &subMap, const bool subHasFlip, const labelListList &constructMap, const bool constructHasFlip, List< T > &, const negateOp &negOp, const int tag=UPstream::msgType())
Distribute data. Note:schedule only used for.
Definition: mapDistributeBaseTemplates.C:122
Foam::dummyTransform
Definition: dummyTransform.H:47
transformField.H
Spatial transformation functions for primitive fields.
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
PstreamCombineReduceOps.H
Combination-Reduction operation for a parallel run. The information from all nodes is collected on th...
n
label n
Definition: TABSMDCalcMethod2.H:31
globalIndexAndTransform.H
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
field
rDeltaTY field()
fld
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))
Definition: gmvOutputLagrangian.H:23
Foam::mapDistribute::distribute
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute data using default commsType.
Definition: mapDistributeTemplates.C:152
Pstream.H
flipOp.H
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:102
PstreamBuffers.H
Foam::mapDistribute::reverseDistribute
void reverseDistribute(const label constructSize, List< T > &, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Reverse distribute data using default commsType.
Definition: mapDistributeTemplates.C:182
Foam::globalIndexAndTransform
Determination and storage of the possible independent transforms introduced by coupledPolyPatches,...
Definition: globalIndexAndTransform.H:64
Foam::flipOp
Functor to negate primitives. Dummy for most other types.
Definition: flipOp.H:53