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-2024 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& obr,
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 =
59  (
60  selectFields_.size()
61  ? obr.names<IOField<Type>>(selectFields_)
63  );
64 
66  Foam::sort(fieldNames); // Consistent order
67 
68  for (const word& fieldName : fieldNames)
69  {
70  const List<Type>* fldPtr = obr.findObject<IOField<Type>>(fieldName);
71  const List<Type>& values = (fldPtr ? *fldPtr : List<Type>::null());
72 
73  if (UPstream::master())
74  {
75  if (std::is_same<label, typename pTraits<Type>::cmptType>::value)
76  {
77  const uint64_t payLoad =
78  vtk::sizeofData<label, nCmpt>(nTotParcels);
79 
80  format().beginDataArray<label, nCmpt>(fieldName);
81  format().writeSize(payLoad);
82  }
83  else
84  {
85  const uint64_t payLoad =
86  vtk::sizeofData<float, nCmpt>(nTotParcels);
87 
88  format().beginDataArray<float, nCmpt>(fieldName);
89  format().writeSize(payLoad);
90  }
91  }
92 
93  if (applyFilter_)
94  {
96  }
97  else
98  {
100  }
101 
102  if (UPstream::master())
103  {
104  // Non-legacy
105  format().flush();
106  format().endDataArray();
107  }
108  }
109 
110  return fieldNames;
111 }
112 
113 
114 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
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:721
static void combineReduce(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:1094
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.
virtual const objectRegistry & obr() const
The region or sub-region registry being used.
static const List< T > & null() noexcept
Return a null List (reference to a nullObject). Behaves like an empty List.
Definition: List.H:153