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-2020 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 (const int slave : Pstream::subProcs())
140  {
141  IPstream fromSlave(Pstream::commsTypes::blocking, slave);
142 
143  fromSlave >> recv;
144 
145  vtk::writeList(fmt, recv);
146  }
147  }
148  else
149  {
150  // Send to master
151  OPstream toMaster
152  (
153  Pstream::commsTypes::blocking,
154  Pstream::masterNo()
155  );
156 
157  toMaster << values;
158  }
159 }
160 
161 
162 template<class Type>
164 (
165  vtk::formatter& fmt,
166  const UList<Type>& values,
167  const labelUList& addressing
168 )
169 {
170  if (Pstream::master())
171  {
172  vtk::writeList(fmt, values, addressing);
173 
174  List<Type> recv;
175 
176  // Receive and write
177  for (const int slave : Pstream::subProcs())
178  {
179  IPstream fromSlave(Pstream::commsTypes::blocking, slave);
180 
181  fromSlave >> recv;
182 
183  vtk::writeList(fmt, recv);
184  }
185  }
186  else
187  {
188  // Send to master
189  OPstream toMaster
190  (
191  Pstream::commsTypes::blocking,
192  Pstream::masterNo()
193  );
194 
195  toMaster << List<Type>(values, addressing);
196  }
197 }
198 
199 
200 template<class Type>
202 (
203  vtk::formatter& fmt,
204  const UList<Type>& values,
205  const bitSet& selected
206 )
207 {
208  if (Pstream::master())
209  {
210  vtk::writeList(fmt, values, selected);
211 
212  List<Type> recv;
213 
214  // Receive and write
215  for (const int slave : Pstream::subProcs())
216  {
217  IPstream fromSlave(Pstream::commsTypes::blocking, slave);
218 
219  fromSlave >> recv;
220 
221  vtk::writeList(fmt, recv);
222  }
223  }
224  else
225  {
226  // Send to master
227  OPstream toMaster
228  (
229  Pstream::commsTypes::blocking,
230  Pstream::masterNo()
231  );
232 
233  toMaster << subset(selected, values);
234  }
235 }
236 
237 
238 template<class Type>
240 (
241  vtk::formatter& fmt,
242  const UList<Type>& values1,
243  const UList<Type>& values2
244 )
245 {
246  if (Pstream::master())
247  {
248  vtk::writeList(fmt, values1);
249  vtk::writeList(fmt, values2);
250 
251  List<Type> recv1, recv2;
252 
253  // Receive and write
254  for (const int slave : Pstream::subProcs())
255  {
256  IPstream fromSlave(Pstream::commsTypes::blocking, slave);
257 
258  fromSlave >> recv1 >> recv2;
259 
260  vtk::writeList(fmt, recv1);
261  vtk::writeList(fmt, recv2);
262  }
263  }
264  else
265  {
266  // Send to master
267  OPstream toMaster
268  (
269  Pstream::commsTypes::blocking,
270  Pstream::masterNo()
271  );
272 
273  toMaster << values1 << values2;
274  }
275 }
276 
277 
278 template<class Type>
280 (
281  vtk::formatter& fmt,
282  const UList<Type>& values1,
283  const UList<Type>& values2,
284  const labelUList& addressing
285 )
286 {
287  if (Pstream::master())
288  {
289  vtk::writeList(fmt, values1);
290  vtk::writeList(fmt, values2, addressing);
291 
292  List<Type> recv1, recv2;
293 
294  // Receive and write
295  for (const int slave : Pstream::subProcs())
296  {
297  IPstream fromSlave(Pstream::commsTypes::blocking, slave);
298 
299  fromSlave >> recv1 >> recv2;
300 
301  vtk::writeList(fmt, recv1);
302  vtk::writeList(fmt, recv2);
303  }
304  }
305  else
306  {
307  // Send to master
308  OPstream toMaster
309  (
310  Pstream::commsTypes::blocking,
311  Pstream::masterNo()
312  );
313 
314  toMaster << values1 << List<Type>(values2, addressing);
315  }
316 }
317 
318 
319 // ************************************************************************* //
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::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:63
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:240
n
label n
Definition: TABSMDCalcMethod2.H:31
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:54
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:52
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