mapDistributeTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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 template<class T>
36 void Foam::mapDistribute::applyDummyTransforms(List<T>& field) const
37 {
38  forAll(transformElements_, trafoI)
39  {
40  const labelList& elems = transformElements_[trafoI];
41 
42  label n = transformStart_[trafoI];
43 
44  forAll(elems, i)
45  {
46  field[n++] = field[elems[i]];
47  }
48  }
49 }
50 
51 
52 template<class T>
53 void Foam::mapDistribute::applyDummyInverseTransforms(List<T>& field) const
54 {
55  forAll(transformElements_, trafoI)
56  {
57  const labelList& elems = transformElements_[trafoI];
58  label n = transformStart_[trafoI];
59 
60  forAll(elems, i)
61  {
62  field[elems[i]] = field[n++];
63  }
64  }
65 }
66 
67 
68 template<class T, class TransformOp> //, class CombineOp>
69 void Foam::mapDistribute::applyTransforms
70 (
71  const globalIndexAndTransform& globalTransforms,
72  List<T>& field,
73  const TransformOp& top
74 ) const
75 {
76  const List<vectorTensorTransform>& totalTransform =
77  globalTransforms.transformPermutations();
78 
79  forAll(totalTransform, trafoI)
80  {
81  const vectorTensorTransform& vt = totalTransform[trafoI];
82  const labelList& elems = transformElements_[trafoI];
83  label n = transformStart_[trafoI];
84 
85  // Could be optimised to avoid memory allocations
86  List<T> transformFld(UIndirectList<T>(field, elems));
87  top(vt, true, transformFld);
88 
89  forAll(transformFld, i)
90  {
91  // cop(field[n++], transformFld[i]);
92  field[n++] = transformFld[i];
93  }
94  }
95 }
96 
97 
98 template<class T, class TransformOp> //, class CombineOp>
99 void Foam::mapDistribute::applyInverseTransforms
100 (
101  const globalIndexAndTransform& globalTransforms,
102  List<T>& field,
103  const TransformOp& top
104 ) const
105 {
106  const List<vectorTensorTransform>& totalTransform =
107  globalTransforms.transformPermutations();
108 
109  forAll(totalTransform, trafoI)
110  {
111  const vectorTensorTransform& vt = totalTransform[trafoI];
112  const labelList& elems = transformElements_[trafoI];
113  label n = transformStart_[trafoI];
114 
115  // Could be optimised to avoid memory allocations
116  List<T> transformFld(SubList<T>(field, elems.size(), n));
117  top(vt, false, transformFld);
118 
119  forAll(transformFld, i)
120  {
121  // cop(field[elems[i]], transformFld[i]);
122  field[elems[i]] = transformFld[i];
123  }
124  }
125 }
126 
127 
128 template<class T, class negateOp>
130 (
131  List<T>& fld,
132  const negateOp& negOp,
133  const bool dummyTransform,
134  const int tag
135 ) const
136 {
137  mapDistributeBase::distribute(fld, negOp, tag);
138 
139  //- Fill in transformed slots with copies
140  if (dummyTransform)
141  {
142  applyDummyTransforms(fld);
143  }
144 }
145 
146 
147 template<class T>
149 (
150  List<T>& fld,
151  const bool dummyTransform,
152  const int tag
153 ) const
154 {
155  distribute(fld, flipOp(), dummyTransform, tag);
156 }
157 
158 
159 template<class T>
161 (
162  DynamicList<T>& fld,
163  const bool dummyTransform,
164  const int tag
165 ) const
166 {
167  fld.shrink();
168 
169  List<T>& fldList = static_cast<List<T>& >(fld);
170 
171  distribute(fldList, dummyTransform, tag);
172 
173  fld.setCapacity(fldList.size());
174 }
175 
176 
177 template<class T>
179 (
180  const label constructSize,
181  List<T>& fld,
182  const bool dummyTransform,
183  const int tag
184 ) const
185 {
186  if (dummyTransform)
187  {
188  applyDummyInverseTransforms(fld);
189  }
190 
191  mapDistributeBase::reverseDistribute(constructSize, fld, tag);
192 }
193 
194 
195 template<class T>
197 (
198  const label constructSize,
199  const T& nullValue,
200  List<T>& fld,
201  const bool dummyTransform,
202  const int tag
203 ) const
204 {
205  if (dummyTransform)
206  {
207  applyDummyInverseTransforms(fld);
208  }
209 
210  mapDistributeBase::reverseDistribute(constructSize, nullValue, fld, tag);
211 }
212 
213 
214 template<class T, class TransformOp>
216 (
217  const globalIndexAndTransform& git,
218  List<T>& fld,
219  const TransformOp& top,
220  const int tag
221 ) const
222 {
223  // Distribute. Leave out dummy transforms since we're doing them ourselves
224  distribute(fld, false, tag);
225  // Do transforms
226  applyTransforms(git, fld, top);
227 }
228 
229 
230 template<class T, class TransformOp>
232 (
233  const globalIndexAndTransform& git,
234  const label constructSize,
235  List<T>& fld,
236  const TransformOp& top,
237  const int tag
238 ) const
239 {
240  // Fill slots with reverse-transformed data. Note that it also copies
241  // back into the non-remote part of fld even though these values are not
242  // used.
243  applyInverseTransforms(git, fld, top);
244 
245  // And send back (the remote slots). Disable dummy transformations.
246  reverseDistribute(constructSize, fld, false, tag);
247 }
248 
249 
250 template<class T, class TransformOp>
252 (
253  const globalIndexAndTransform& git,
254  const label constructSize,
255  const T& nullValue,
256  List<T>& fld,
257  const TransformOp& top,
258  const int tag
259 ) const
260 {
261  // Fill slots with reverse-transformed data Note that it also copies
262  // back into the non-remote part of fld even though these values are not
263  // used.
264  applyInverseTransforms(git, fld, top); //, eqOp<T>());
265 
266  // And send back (the remote slots) Disable dummy transformations.
267  reverseDistribute(constructSize, nullValue, fld, false, tag);
268 }
269 
270 
271 // ************************************************************************* //
Class containing functor to negate primitives. Dummy for all other types.
Definition: flipOp.H:50
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute data using default commsType.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
Combination-Reduction operation for a parallel run. The information from all nodes is collected on th...
void reverseDistribute(const label constructSize, List< T > &, const int tag=UPstream::msgType()) const
Reverse distribute data using default commsType.
Spatial transformation functions for primitive fields.
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))
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
void setCapacity(const label)
Alter the size of the underlying storage.
Definition: DynamicListI.H:130
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.
List< label > labelList
A List of labels.
Definition: labelList.H:56
DynamicList< T, SizeInc, SizeMult, SizeDiv > & shrink()
Shrink the allocated space to the number of elements used.
Definition: DynamicListI.H:252
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
void reverseDistribute(const label constructSize, List< T > &, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Reverse distribute data using default commsType.
label n
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)