vtkCloudTemplates.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) 2018-2022 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 "IOField.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 template<class Type>
33 Foam::wordList Foam::functionObjects::vtkCloud::writeFields
34 (
36  const objectRegistry& obrTmp,
37  const label nTotParcels
38 ) const
39 {
41 
42  static_assert
43  (
44  (
45  std::is_same<label, typename pTraits<Type>::cmptType>::value
46  || std::is_floating_point<typename pTraits<Type>::cmptType>::value
47  ),
48  "Label and Floating-point vector space only"
49  );
50 
51  // Other integral types (eg, bool etc) would need cast/convert to label.
52  // Similarly for labelVector etc.
53 
54 
55  // Fields are not always on all processors (eg, multi-component parcels).
56  // Thus need to resolve names between all processors.
57 
58  wordList fieldNames(obrTmp.names<IOField<Type>>());
60  Foam::sort(fieldNames); // Consistent order
61 
62  for (const word& fieldName : fieldNames)
63  {
64  const List<Type>* fldPtr = obrTmp.findObject<IOField<Type>>(fieldName);
65  const List<Type>& values = (fldPtr ? *fldPtr : List<Type>());
66 
67  if (Pstream::master())
68  {
69  if (std::is_same<label, typename pTraits<Type>::cmptType>::value)
70  {
71  const uint64_t payLoad =
72  vtk::sizeofData<label, nCmpt>(nTotParcels);
73 
74  format().beginDataArray<label, nCmpt>(fieldName);
75  format().writeSize(payLoad);
76  }
77  else
78  {
79  const uint64_t payLoad =
80  vtk::sizeofData<float, nCmpt>(nTotParcels);
81 
82  format().beginDataArray<float, nCmpt>(fieldName);
83  format().writeSize(payLoad);
84  }
85  }
86 
87  if (applyFilter_)
88  {
90  }
91  else
92  {
94  }
95 
96  if (Pstream::master())
97  {
98  // Non-legacy
99  format().flush();
100  format().endDataArray();
101  }
102  }
103 
104  return fieldNames;
105 }
106 
107 
108 // ************************************************************************* //
uint8_t direction
Definition: direction.H:46
wordList names() const
The unsorted names of all objects.
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:75
const Type * findObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
bitSet parcelAddr_
The filtered parcel addressing. Eg, for the current cloud.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
A class for handling words, derived from Foam::string.
Definition: word.H:63
void sort(UList< T > &list)
Sort the list.
Definition: UList.C:296
List helper to append y unique elements onto the end of x.
Definition: ListOps.H:689
static void combineReduce(const List< commsStruct > &comms, T &value, const CombineOp &cop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) applying cop to inplace combine value from different processors...
word format(conversionProperties.get< word >("format"))
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Definition: UPstream.H:1082
void writeListParallel(vtk::formatter &fmt, const UList< Type > &values)
Write a list of values.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Registry of regIOobjects.
A primitive field of type <T> with automated input and output.