writeDimFields.H
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, distributed under GPL-3.0-or-later.
12 
13 Description
14  Code chunk for reading dimensioned fields from disk
15  and write with vtk::internalWriter
16 
17 \*---------------------------------------------------------------------------*/
18 
19 #ifndef FoamToVTK_writeDimFields_H
20 #define FoamToVTK_writeDimFields_H
21 
22 #include "readFields.H"
23 #include "foamVtkInternalWriter.H"
24 
25 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
26 
27 namespace Foam
28 {
29 
30 template<class GeoField>
31 label writeDimFields
32 (
33  autoPtr<vtk::internalWriter>& internalWriter,
34  const fvMeshSubsetProxy& proxy,
35  const IOobjectList& objects,
36  const bool syncPar,
37  objectRegistry* cache
38 )
39 {
40  // Sanity test
41  if (!internalWriter) return 0;
42 
43  label count = 0;
44 
45  for (const word& fieldName : objects.sortedNames<GeoField>())
46  {
47  tmp<GeoField> tfield =
48  getField<GeoField>(proxy, objects, fieldName, syncPar, cache);
49 
50  if (tfield)
51  {
52  internalWriter->write(tfield());
53 
54  tfield.clear();
55  ++count;
56  }
57  }
58 
59  return count;
60 }
61 
62 
63 template<class GeoField>
64 label writeDimFields
65 (
66  autoPtr<vtk::internalWriter>& internalWriter,
68 
69  const fvMeshSubsetProxy& proxy,
70  const IOobjectList& objects,
71  const bool syncPar,
72  objectRegistry* cache
73 )
74 {
75  // Sanity test
76  if (!internalWriter || !pInterp) return 0;
77 
78  label count = 0;
79 
80  for (const word& fieldName : objects.sortedNames<GeoField>())
81  {
82  tmp<GeoField> tfield =
83  getField<GeoField>(proxy, objects, fieldName, syncPar, cache);
84 
85  if (tfield)
86  {
87  internalWriter->write(tfield(), *pInterp);
88 
89  tfield.clear();
90  ++count;
91  }
92  }
93 
94  return count;
95 }
96 
97 
99 (
100  autoPtr<vtk::internalWriter>& internalWriter,
102  const fvMeshSubsetProxy& proxy,
103  const IOobjectList& objects,
104  const bool syncPar,
105  objectRegistry* cache
106 )
107 {
108  // Sanity test
109  if (!internalWriter) return 0;
110 
111  label count = 0;
112  const label total = objects.size();
113  do
114  {
115  #undef doLocalWriteCode
116  #define doLocalWriteCode(Type) \
117  { \
118  typedef VolumeInternalField<Type> FieldType; \
119  \
120  count += writeDimFields<FieldType> \
121  ( \
122  internalWriter, \
123  proxy, \
124  objects, \
125  syncPar, \
126  cache \
127  ); \
128  if (count >= total) break; /* early exit */ \
129  }
130 
131  doLocalWriteCode(scalar);
136 
137  #undef doLocalWriteField
138  }
139  while (false);
140 
141  return count;
142 }
143 
144 
145 label writeAllDimFields
146 (
147  autoPtr<vtk::internalWriter>& internalWriter,
149 
150  const fvMeshSubsetProxy& proxy,
151  const IOobjectList& objects,
152  const bool syncPar,
153  objectRegistry* cache
154 )
155 {
156  // Sanity test
157  if (!internalWriter || !pInterp) return 0;
158 
159  label count = 0;
160  const label total = objects.size();
161  do
162  {
163  #undef doLocalWriteCode
164  #define doLocalWriteCode(Type) \
165  { \
166  typedef VolumeInternalField<Type> FieldType; \
167  \
168  count += writeDimFields<FieldType> \
169  ( \
170  internalWriter, pInterp, \
171  proxy, \
172  objects, \
173  syncPar, \
174  cache \
175  ); \
176  if (count >= total) break; /* early exit */ \
177  }
178 
179  doLocalWriteCode(scalar);
184 
185  #undef doLocalWriteCode
186  }
187  while (false);
188 
189  return count;
190 }
191 
192 
193 } // End namespace Foam
194 
195 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196 
197 #endif
198 
199 // ************************************************************************* //
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable, so the various sorted methods should be used if traversing in parallel.
Definition: IOobjectList.H:55
wordList sortedNames() const
The sorted names of the IOobjects.
Definition: IOobjectList.C:253
Helper routines for reading a field or fields, optionally with a mesh subset (using fvMeshSubsetProxy...
#define doLocalWriteCode(Type)
label size() const noexcept
The number of elements in table.
Definition: HashTable.H:358
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of &#39;true&#39; entries.
Definition: BitOps.H:73
A class for handling words, derived from Foam::string.
Definition: word.H:63
autoPtr< vtk::internalWriter > internalWriter
Simple proxy for holding a mesh, or mesh-subset. The subMeshes are currently limited to cellSet or ce...
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
label writeDimFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects)
void clear() const noexcept
If object pointer points to valid object: delete object and set pointer to nullptr.
Definition: tmpI.H:289
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Registry of regIOobjects.
Tensor of scalars, i.e. Tensor<scalar>.
label writeAllDimFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects)
Namespace for OpenFOAM.
autoPtr< volPointInterpolation > pInterp