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-------------------------------------------------------------------------------
10License
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"
31#include "transformField.H"
32#include "flipOp.H"
33
34// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35
36template<class T>
37void Foam::mapDistribute::applyDummyTransforms(List<T>& field) const
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
53template<class T>
54void Foam::mapDistribute::applyDummyInverseTransforms(List<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,
73 List<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
99template<class T, class TransformOp> //, class CombineOp>
100void Foam::mapDistribute::applyInverseTransforms
101(
102 const globalIndexAndTransform& globalTransforms,
103 List<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
129template<class T, class NegateOp>
131(
132 List<T>& fld,
133 const NegateOp& negOp,
134 const bool dummyTransform,
135 const int tag
136) const
137{
138 mapDistributeBase::distribute(fld, negOp, tag);
139
140 //- Fill in transformed slots with copies
141 if (dummyTransform)
142 {
143 applyDummyTransforms(fld);
144 }
145}
146
147
148template<class T>
150(
151 List<T>& fld,
152 const bool dummyTransform,
153 const int tag
154) const
155{
156 distribute(fld, flipOp(), dummyTransform, tag);
157}
158
159
160template<class T>
162(
164 const bool dummyTransform,
165 const int tag
166) const
167{
168 fld.shrink();
169
170 List<T>& list = static_cast<List<T>&>(fld);
171
172 distribute(list, dummyTransform, tag);
173
174 fld.setCapacity(list.size());
175}
176
177
178template<class T>
180(
181 const label constructSize,
182 List<T>& fld,
183 const bool dummyTransform,
184 const int tag
185) const
186{
187 if (dummyTransform)
188 {
189 applyDummyInverseTransforms(fld);
190 }
191
192 mapDistributeBase::reverseDistribute(constructSize, fld, tag);
193}
194
195
196template<class T>
198(
199 const label constructSize,
200 const T& nullValue,
201 List<T>& fld,
202 const bool dummyTransform,
203 const int tag
204) const
205{
206 if (dummyTransform)
207 {
208 applyDummyInverseTransforms(fld);
209 }
210
211 mapDistributeBase::reverseDistribute(constructSize, nullValue, fld, tag);
212}
213
214
215template<class T, class TransformOp>
217(
218 const globalIndexAndTransform& git,
219 List<T>& fld,
220 const TransformOp& top,
221 const int tag
222) const
223{
224 // Distribute. Leave out dummy transforms since we're doing them ourselves
225 distribute(fld, false, tag);
226
227 // Do transforms
228 applyTransforms(git, fld, top);
229}
230
231
232template<class T, class TransformOp>
234(
235 const globalIndexAndTransform& git,
236 const label constructSize,
237 List<T>& fld,
238 const TransformOp& top,
239 const int tag
240) const
241{
242 // Fill slots with reverse-transformed data. Note that it also copies
243 // back into the non-remote part of fld even though these values are not
244 // used.
245 applyInverseTransforms(git, fld, top);
246
247 // And send back (the remote slots). Disable dummy transformations.
248 reverseDistribute(constructSize, fld, false, tag);
249}
250
251
252template<class T, class TransformOp>
254(
255 const globalIndexAndTransform& git,
256 const label constructSize,
257 const T& nullValue,
258 List<T>& fld,
259 const TransformOp& top,
260 const int tag
261) const
262{
263 // Fill slots with reverse-transformed data Note that it also copies
264 // back into the non-remote part of fld even though these values are not
265 // used.
266 applyInverseTransforms(git, fld, top); //, eqOp<T>());
267
268 // And send back (the remote slots) Disable dummy transformations.
269 reverseDistribute(constructSize, nullValue, fld, false, tag);
270}
271
272
273// ************************************************************************* //
label n
Info<< nl<< "Wrote faMesh in vtk format: "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.mesh().time().globalPath()/"finiteArea-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:72
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
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
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 data using default commsType.
const volScalarField & T
rDeltaTY field()
List< label > labelList
A List of labels.
Definition: List.H:66
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
Functor to negate primitives. Dummy for most other types.
Definition: flipOp.H:69
Spatial transformation functions for primitive fields.