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-2025 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  typedef typename pTraits<Type>::cmptType cmptType;
43 
44  static_assert
45  (
46  (
47  std::is_same_v<label, cmptType>
48  || std::is_floating_point_v<cmptType>
49  ),
50  "Label and Floating-point vector space only"
51  );
52 
53  // Other integral types (eg, bool etc) would need cast/convert to label.
54  // Similarly for labelVector etc.
55 
56 
57  // Fields are not always on all processors (eg, multi-component parcels).
58  // Thus need to resolve names between all processors.
59 
60  wordList fieldNames =
61  (
62  selectFields_.size()
63  ? obr.names<IOField<Type>>(selectFields_)
65  );
66 
68  Foam::sort(fieldNames); // Consistent order
69 
70  for (const word& fieldName : fieldNames)
71  {
72  const List<Type>* fldPtr = obr.findObject<IOField<Type>>(fieldName);
73  const List<Type>& values = (fldPtr ? *fldPtr : List<Type>::null());
74 
75  if (UPstream::master())
76  {
77  if constexpr (std::is_same_v<label, cmptType>)
78  {
79  const uint64_t payLoad =
80  vtk::sizeofData<label, nCmpt>(nTotParcels);
81 
82  format().beginDataArray<label, nCmpt>(fieldName);
83  format().writeSize(payLoad);
84  }
85  else
86  {
87  const uint64_t payLoad =
88  vtk::sizeofData<float, nCmpt>(nTotParcels);
89 
90  format().beginDataArray<float, nCmpt>(fieldName);
91  format().writeSize(payLoad);
92  }
93  }
94 
95  if (applyFilter_)
96  {
98  }
99  else
100  {
102  }
103 
104  if (UPstream::master())
105  {
106  // Non-legacy
107  format().flush();
108  format().endDataArray();
109  }
110  }
111 
112  return fieldNames;
113 }
114 
115 
116 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
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:61
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:295
List helper to append y unique elements onto the end of x.
Definition: ListOps.H:720
word format(conversionProperties.get< word >("format"))
static void combineReduce(T &value, CombineOp cop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) applying cop to inplace combine value from different processors...
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Definition: UPstream.H:1619
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:158