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 | Copyright (C) 2011-2015 OpenFOAM Foundation
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 \*---------------------------------------------------------------------------*/
25 
26 #include "Pstream.H"
27 #include "PstreamBuffers.H"
30 #include "transformField.H"
31 #include "flipOp.H"
32 
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 
35 // In case of no transform: copy elements
36 template<class T>
38 {
39  forAll(transformElements_, trafoI)
40  {
41  const labelList& elems = transformElements_[trafoI];
42 
43  label n = transformStart_[trafoI];
44 
45  forAll(elems, i)
46  {
47  field[n++] = field[elems[i]];
48  }
49  }
50 }
51 
52 
53 // In case of no transform: copy elements
54 template<class T>
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 // Calculate transformed elements.
71 template<class T, class TransformOp> //, class CombineOp>
73 (
74  const globalIndexAndTransform& globalTransforms,
75  List<T>& field,
76  const TransformOp& top
77 ) const
78 {
79  const List<vectorTensorTransform>& totalTransform =
80  globalTransforms.transformPermutations();
81 
82  forAll(totalTransform, trafoI)
83  {
84  const vectorTensorTransform& vt = totalTransform[trafoI];
85  const labelList& elems = transformElements_[trafoI];
86  label n = transformStart_[trafoI];
87 
88  // Could be optimised to avoid memory allocations
89  List<T> transformFld(UIndirectList<T>(field, elems));
90  top(vt, true, transformFld);
91 
92  forAll(transformFld, i)
93  {
94  //cop(field[n++], transformFld[i]);
95  field[n++] = transformFld[i];
96  }
97  }
98 }
99 
100 
101 // Calculate transformed elements.
102 template<class T, class TransformOp> //, class CombineOp>
104 (
105  const globalIndexAndTransform& globalTransforms,
106  List<T>& field,
107  const TransformOp& top
108 ) const
109 {
110  const List<vectorTensorTransform>& totalTransform =
111  globalTransforms.transformPermutations();
112 
113  forAll(totalTransform, trafoI)
114  {
115  const vectorTensorTransform& vt = totalTransform[trafoI];
116  const labelList& elems = transformElements_[trafoI];
117  label n = transformStart_[trafoI];
118 
119  // Could be optimised to avoid memory allocations
120  List<T> transformFld(SubList<T>(field, elems.size(), n));
121  top(vt, false, transformFld);
122 
123  forAll(transformFld, i)
124  {
125  //cop(field[elems[i]], transformFld[i]);
126  field[elems[i]] = transformFld[i];
127  }
128  }
129 }
130 
131 
132 //- Distribute data using default commsType.
133 template<class T, class negateOp>
135 (
136  List<T>& fld,
137  const negateOp& negOp,
138  const bool dummyTransform,
139  const int tag
140 ) const
141 {
142  mapDistributeBase::distribute(fld, negOp, tag);
143 
144  //- Fill in transformed slots with copies
145  if (dummyTransform)
146  {
147  applyDummyTransforms(fld);
148  }
149 }
150 
151 
152 //- Distribute data using default commsType.
153 template<class T>
155 (
156  List<T>& fld,
157  const bool dummyTransform,
158  const int tag
159 ) const
160 {
161  distribute(fld, flipOp(), dummyTransform, tag);
162 }
163 
164 
165 //- Distribute data using default commsType.
166 template<class T>
168 (
170  const bool dummyTransform,
171  const int tag
172 ) const
173 {
174  fld.shrink();
175 
176  List<T>& fldList = static_cast<List<T>& >(fld);
177 
178  distribute(fldList, dummyTransform, tag);
179 
180  fld.setCapacity(fldList.size());
181 }
182 
183 
184 //- Reverse distribute data using default commsType.
185 template<class T>
187 (
188  const label constructSize,
189  List<T>& fld,
190  const bool dummyTransform,
191  const int tag
192 ) const
193 {
194  if (dummyTransform)
195  {
196  applyDummyInverseTransforms(fld);
197  }
198 
199  mapDistributeBase::reverseDistribute(constructSize, fld, tag);
200 }
201 
202 
203 //- Reverse distribute data using default commsType.
204 // Since constructSize might be larger than supplied size supply
205 // a nullValue
206 template<class T>
208 (
209  const label constructSize,
210  const T& nullValue,
211  List<T>& fld,
212  const bool dummyTransform,
213  const int tag
214 ) const
215 {
216  if (dummyTransform)
217  {
218  applyDummyInverseTransforms(fld);
219  }
220 
221  mapDistributeBase::reverseDistribute(constructSize, nullValue, fld, tag);
222 }
223 
224 
225 //- Distribute data using default commsType.
226 template<class T, class TransformOp>
228 (
229  const globalIndexAndTransform& git,
230  List<T>& fld,
231  const TransformOp& top,
232  const int tag
233 ) const
234 {
235  // Distribute. Leave out dummy transforms since we're doing them ourselves
236  distribute(fld, false, tag);
237  // Do transforms
238  applyTransforms(git, fld, top);
239 }
240 
241 
242 template<class T, class TransformOp>
244 (
245  const globalIndexAndTransform& git,
246  const label constructSize,
247  List<T>& fld,
248  const TransformOp& top,
249  const int tag
250 ) const
251 {
252  // Fill slots with reverse-transformed data. Note that it also copies
253  // back into the non-remote part of fld even though these values are not
254  // used.
255  applyInverseTransforms(git, fld, top);
256 
257  // And send back (the remote slots). Disable dummy transformations.
258  reverseDistribute(constructSize, fld, false, tag);
259 }
260 
261 
262 template<class T, class TransformOp>
264 (
265  const globalIndexAndTransform& git,
266  const label constructSize,
267  const T& nullValue,
268  List<T>& fld,
269  const TransformOp& top,
270  const int tag
271 ) const
272 {
273  // Fill slots with reverse-transformed data Note that it also copies
274  // back into the non-remote part of fld even though these values are not
275  // used.
276  applyInverseTransforms(git, fld, top); //, eqOp<T>());
277 
278  // And send back (the remote slots) Disable dummy transformations.
279  reverseDistribute(constructSize, nullValue, fld, false, tag);
280 }
281 
282 
283 // ************************************************************************* //
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:1242
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:56
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 Pstream::scheduled.
Definition: mapDistributeBaseTemplates.C:119
Foam::globalIndexAndTransform::transformPermutations
const List< vectorTensorTransform > & transformPermutations() const
Return access to the permuted transforms.
Definition: globalIndexAndTransformI.H:423
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:53
Foam::flipOp
Class containing functor to negate primitives. Dummy for all other types.
Definition: flipOp.H:50
Foam::mapDistribute::applyTransforms
void applyTransforms(const globalIndexAndTransform &globalTransforms, List< T > &field, const TransformOp &top) const
Definition: mapDistributeTemplates.C:73
Foam::mapDistribute::applyInverseTransforms
void applyInverseTransforms(const globalIndexAndTransform &globalTransforms, List< T > &field, const TransformOp &top) const
Definition: mapDistributeTemplates.C:104
Foam::dummyTransform
Definition: dummyTransform.H:44
transformField.H
Spatial transformation functions for primitive fields.
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
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
globalIndexAndTransform.H
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:55
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:155
Foam::mapDistribute::applyDummyTransforms
void applyDummyTransforms(List< T > &field) const
Helper function: copy transformElements without transformation.
Definition: mapDistributeTemplates.C:37
fld
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< ' ';}gmvFile<< nl;forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Pstream.H
flipOp.H
Foam::mapDistribute::transformElements_
labelListList transformElements_
For every globalIndexAndTransform::transformPermutations.
Definition: mapDistribute.H:160
Foam::List< T >
Foam::vectorTensorTransform
Vector-tensor class used to perform translations and rotations in 3D space.
Definition: vectorTensorTransform.H:61
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:187
Foam::UIndirectList< T >
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::globalIndexAndTransform
Determination and storage of the possible independent transforms introduced by coupledPolyPatches,...
Definition: globalIndexAndTransform.H:60
Foam::mapDistribute::applyDummyInverseTransforms
void applyDummyInverseTransforms(List< T > &field) const
Helper function: copy transformElements without transformation.
Definition: mapDistributeTemplates.C:55
Foam::mapDistribute::transformStart_
labelList transformStart_
Destination in constructMap for transformed elements.
Definition: mapDistribute.H:163