foamVtkOutputTemplates.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) 2016-2019 OpenCFD Ltd.
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 "ListOps.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 template<class Type>
34 inline void Foam::vtk::write
35 (
36  vtk::formatter& fmt,
37  const Type& val,
38  const label n
39 )
40 {
42 
43  for (label i=0; i < n; ++i)
44  {
45  for (direction cmpt=0; cmpt < nCmpt; ++cmpt)
46  {
47  fmt.write(component(val, cmpt));
48  }
49  }
50 }
51 
52 
53 template<class Type>
55 (
56  vtk::formatter& fmt,
57  const UList<Type>& values
58 )
59 {
60  for (const Type& val : values)
61  {
62  vtk::write(fmt, val);
63  }
64 }
65 
66 
67 template<class Type, unsigned N>
69 (
70  vtk::formatter& fmt,
72 )
73 {
74  for (const Type& val : values)
75  {
76  vtk::write(fmt, val);
77  }
78 }
79 
80 
81 template<class Type>
83 (
84  vtk::formatter& fmt,
85  const UList<Type>& values,
86  const labelUList& addressing
87 )
88 {
89  for (const label idx : addressing)
90  {
91  vtk::write(fmt, values[idx]);
92  }
93 }
94 
95 
96 template<class Type>
98 (
99  vtk::formatter& fmt,
100  const UList<Type>& values,
101  const bitSet& selected
102 )
103 {
104  for (const label idx : selected)
105  {
106  vtk::write(fmt, values[idx]);
107  }
108 }
109 
110 
111 template<class Type>
113 (
114  vtk::formatter& fmt,
115  const UList<Type>& values,
116  const UList<Type>& indirect,
117  const labelUList& addressing
118 )
119 {
120  vtk::writeList(fmt, values);
121  vtk::writeList(fmt, indirect, addressing);
122 }
123 
124 
125 template<class Type>
127 (
128  vtk::formatter& fmt,
129  const UList<Type>& values
130 )
131 {
132  if (Pstream::master())
133  {
134  vtk::writeList(fmt, values);
135 
136  List<Type> recv;
137 
138  // Receive and write
139  for
140  (
141  int slave=Pstream::firstSlave();
142  slave<=Pstream::lastSlave();
143  ++slave
144  )
145  {
146  IPstream fromSlave(Pstream::commsTypes::blocking, slave);
147 
148  fromSlave >> recv;
149 
150  vtk::writeList(fmt, recv);
151  }
152  }
153  else
154  {
155  // Send to master
156  OPstream toMaster
157  (
158  Pstream::commsTypes::blocking,
159  Pstream::masterNo()
160  );
161 
162  toMaster << values;
163  }
164 }
165 
166 
167 template<class Type>
169 (
170  vtk::formatter& fmt,
171  const UList<Type>& values,
172  const labelUList& addressing
173 )
174 {
175  if (Pstream::master())
176  {
177  vtk::writeList(fmt, values, addressing);
178 
179  List<Type> recv;
180 
181  // Receive and write
182  for
183  (
184  int slave=Pstream::firstSlave();
185  slave<=Pstream::lastSlave();
186  ++slave
187  )
188  {
189  IPstream fromSlave(Pstream::commsTypes::blocking, slave);
190 
191  fromSlave >> recv;
192 
193  vtk::writeList(fmt, recv);
194  }
195  }
196  else
197  {
198  // Send to master
199  OPstream toMaster
200  (
201  Pstream::commsTypes::blocking,
202  Pstream::masterNo()
203  );
204 
205  toMaster << List<Type>(values, addressing);
206  }
207 }
208 
209 
210 template<class Type>
212 (
213  vtk::formatter& fmt,
214  const UList<Type>& values,
215  const bitSet& selected
216 )
217 {
218  if (Pstream::master())
219  {
220  vtk::writeList(fmt, values, selected);
221 
222  List<Type> recv;
223 
224  // Receive and write
225  for
226  (
227  int slave=Pstream::firstSlave();
228  slave<=Pstream::lastSlave();
229  ++slave
230  )
231  {
232  IPstream fromSlave(Pstream::commsTypes::blocking, slave);
233 
234  fromSlave >> recv;
235 
236  vtk::writeList(fmt, recv);
237  }
238  }
239  else
240  {
241  // Send to master
242  OPstream toMaster
243  (
244  Pstream::commsTypes::blocking,
245  Pstream::masterNo()
246  );
247 
248  toMaster << subset(selected, values);
249  }
250 }
251 
252 
253 template<class Type>
255 (
256  vtk::formatter& fmt,
257  const UList<Type>& values1,
258  const UList<Type>& values2
259 )
260 {
261  if (Pstream::master())
262  {
263  vtk::writeList(fmt, values1);
264  vtk::writeList(fmt, values2);
265 
266  List<Type> recv1, recv2;
267 
268  // Receive and write
269  for
270  (
271  int slave=Pstream::firstSlave();
272  slave<=Pstream::lastSlave();
273  ++slave
274  )
275  {
276  IPstream fromSlave(Pstream::commsTypes::blocking, slave);
277 
278  fromSlave >> recv1 >> recv2;
279 
280  vtk::writeList(fmt, recv1);
281  vtk::writeList(fmt, recv2);
282  }
283  }
284  else
285  {
286  // Send to master
287  OPstream toMaster
288  (
289  Pstream::commsTypes::blocking,
290  Pstream::masterNo()
291  );
292 
293  toMaster << values1 << values2;
294  }
295 }
296 
297 
298 template<class Type>
300 (
301  vtk::formatter& fmt,
302  const UList<Type>& values1,
303  const UList<Type>& values2,
304  const labelUList& addressing
305 )
306 {
307  if (Pstream::master())
308  {
309  vtk::writeList(fmt, values1);
310  vtk::writeList(fmt, values2, addressing);
311 
312  List<Type> recv1, recv2;
313 ;
314  // Receive and write
315  for
316  (
317  int slave=Pstream::firstSlave();
318  slave<=Pstream::lastSlave();
319  ++slave
320  )
321  {
322  IPstream fromSlave(Pstream::commsTypes::blocking, slave);
323 
324  fromSlave >> recv1 >> recv2;
325 
326  vtk::writeList(fmt, recv1);
327  vtk::writeList(fmt, recv2);
328  }
329  }
330  else
331  {
332  // Send to master
333  OPstream toMaster
334  (
335  Pstream::commsTypes::blocking,
336  Pstream::masterNo()
337  );
338 
339  toMaster << values1 << List<Type>(values2, addressing);
340  }
341 }
342 
343 
344 // ************************************************************************* //
Foam::vtk::writeListParallel
void writeListParallel(vtk::formatter &fmt, const UList< uint8_t > &values)
Write a list of uint8_t values.
Definition: foamVtkOutput.C:126
Foam::val
label ListType::const_reference val
Definition: ListOps.H:407
Foam::component
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Definition: FieldFieldFunctions.C:44
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:64
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
Foam::OPstream
Output inter-processor communications stream.
Definition: OPstream.H:52
Foam::subset
List< T > subset(const BoolListType &select, const UList< T > &input, const bool invert=false)
Extract elements of the input list when select is true.
Foam::vtk::writeListsParallel
void writeListsParallel(vtk::formatter &fmt, const UList< Type > &values1, const UList< Type > &values2)
Write a list of values and another list of values.
Definition: foamVtkOutputTemplates.C:255
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:62
Foam::vtk::writeList
void writeList(vtk::formatter &fmt, const UList< uint8_t > &values)
Write a list of uint8_t values.
Definition: foamVtkOutput.C:112
Foam::vtk::writeLists
void writeLists(vtk::formatter &fmt, const UList< Type > &values1, const UList< Type > &values2, const labelUList &addressing)
Write a list of values and a list of values via indirect addressing.
Definition: foamVtkOutputTemplates.C:113
Pstream.H
Foam::List< Type >
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:52
Foam::FixedList
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: HashTable.H:104
Foam::UList< Type >
Foam::direction
uint8_t direction
Definition: direction.H:47
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:35
Foam::IPstream
Input inter-processor communications stream.
Definition: IPstream.H:52
ListOps.H
Various functions to operate on Lists.
Foam::vtk::formatter::write
virtual void write(const uint8_t val)=0
Foam::vtk::formatter
Abstract class for a VTK output stream formatter.
Definition: foamVtkFormatter.H:68