writeVolFields.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-2023 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 volume fields from disk
15  and write with vtk::internalWriter and vtk::patchWriter
16 
17 \*---------------------------------------------------------------------------*/
18 
19 #ifndef FoamToVTK_writeVolFields_H
20 #define FoamToVTK_writeVolFields_H
21 
22 #include "readFields.H"
23 #include "foamVtkInternalWriter.H"
24 #include "foamVtkPatchWriter.H"
25 
26 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
27 
28 namespace Foam
29 {
30 
31 template<class GeoField>
32 label writeVolFields
33 (
34  autoPtr<vtk::internalWriter>& internalWriter,
36  const fvMeshSubsetProxy& proxy,
37  const IOobjectList& objects,
38  const bool syncPar,
39  objectRegistry* cache
40 )
41 {
42  // Sanity test
43  if (!internalWriter && patchWriters.empty()) return 0;
44 
45  label count = 0;
46 
47  for (const word& fieldName : objects.sortedNames<GeoField>())
48  {
49  tmp<GeoField> tfield =
50  getField<GeoField>(proxy, objects, fieldName, syncPar, cache);
51 
52  if (tfield)
53  {
54  // Internal
55  if (internalWriter)
56  {
57  internalWriter->write(tfield());
58  }
59 
60  // Boundary
62  {
63  writer.write(tfield());
64  }
65 
66  tfield.clear();
67  ++count;
68  }
69  }
70 
71  return count;
72 }
73 
74 
75 template<class GeoField>
76 label writeVolFields
77 (
78  autoPtr<vtk::internalWriter>& internalWriter,
80 
83 
84  const fvMeshSubsetProxy& proxy,
85  const IOobjectList& objects,
86  const bool syncPar,
87  objectRegistry* cache
88 )
89 {
90  // Sanity test
91  if
92  (
93  (!internalWriter || !pInterp)
94  && (patchWriters.empty() || patchInterps.empty())
95  )
96  {
97  return 0;
98  }
99 
100  label count = 0;
101 
102  for (const word& fieldName : objects.sortedNames<GeoField>())
103  {
104  tmp<GeoField> tfield =
105  getField<GeoField>(proxy, objects, fieldName, syncPar, cache);
106 
107  if (tfield)
108  {
109  // Internal
110  if (internalWriter && pInterp)
111  {
112  internalWriter->write(tfield(), *pInterp);
113  }
114 
115  // Boundary
116  label writeri = 0;
118  {
119  if (patchInterps.test(writeri))
120  {
121  writer.write(tfield(), patchInterps[writeri]);
122  }
123  ++writeri;
124  }
125 
126  tfield.clear();
127  ++count;
128  }
129  }
130 
131  return count;
132 }
133 
134 
135 label writeAllVolFields
136 (
137  autoPtr<vtk::internalWriter>& internalWriter,
139 
140  const fvMeshSubsetProxy& proxy,
141  const IOobjectList& objects,
142  const bool syncPar,
143  objectRegistry* cache
144 )
145 {
146  // Sanity test
147  if (!internalWriter && patchWriters.empty()) return 0;
148 
149  #undef foamToVtk_WRITE_FIELD
150  #define foamToVtk_WRITE_FIELD(FieldType) \
151  writeVolFields<FieldType> \
152  ( \
153  internalWriter, \
154  patchWriters, \
155  proxy, \
156  objects, \
157  syncPar, \
158  cache \
159  )
160 
161  label count = 0;
167 
168  #undef foamToVTK_WRITE_FIELD
169  return count;
170 }
171 
172 
173 label writeAllVolFields
174 (
175  autoPtr<vtk::internalWriter>& internalWriter,
177 
180 
181  const fvMeshSubsetProxy& proxy,
182  const IOobjectList& objects,
183  const bool syncPar,
184  objectRegistry* cache
185 )
186 {
187  #undef foamToVtk_WRITE_FIELD
188  #define foamToVtk_WRITE_FIELD(FieldType) \
189  writeVolFields<FieldType> \
190  ( \
191  internalWriter, pInterp, \
192  patchWriters, patchInterps, \
193  proxy, \
194  objects, \
195  syncPar, \
196  cache \
197  )
198 
199 
200  label count = 0;
206 
207  #undef foamToVtk_WRITE_FIELD
208  return count;
209 }
210 
211 
212 } // End namespace Foam
213 
214 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 
216 #endif
217 
218 // ************************************************************************* //
Interpolation class within a primitive patch. Allows interpolation from points to faces and vice vers...
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
vtk::lineWriter writer(edgeCentres, edgeList::null(), fileName(aMesh.time().globalPath()/"finiteArea-edgesCentres"))
label writeAllVolFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects, const bool nearCellValue=false)
wordList sortedNames() const
The sorted names of the IOobjects.
Definition: IOobjectList.C:250
Helper routines for reading a field or fields, optionally with a mesh subset (using fvMeshSubsetProxy...
void write(const word &fieldName, const UList< Type > &field)
Write primitive field of CellData (Poly or Line) or PointData values.
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
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: HashTable.H:106
Simple proxy for holding a mesh, or mesh-subset. The subMeshes are currently limited to cellSet or ce...
#define foamToVtk_WRITE_FIELD(FieldType)
PtrList< PrimitivePatchInterpolation< primitivePatch > > patchInterps
Write OpenFOAM patches and patch fields in VTP or legacy vtk format.
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.
PtrList< vtk::patchWriter > patchWriters
Namespace for OpenFOAM.
autoPtr< volPointInterpolation > pInterp
label writeVolFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects, const bool nearCellValue=false)