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-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 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  #undef foamToVtk_WRITE_FIELD
112  #define foamToVtk_WRITE_FIELD(FieldType) \
113  writeDimFields<FieldType> \
114  ( \
115  internalWriter, \
116  proxy, \
117  objects, \
118  syncPar, \
119  cache \
120  )
121 
122  label count = 0;
128 
129  #undef foamToVTK_WRITE_FIELD
130  return count;
131 }
132 
133 
134 label writeAllDimFields
135 (
136  autoPtr<vtk::internalWriter>& internalWriter,
138 
139  const fvMeshSubsetProxy& proxy,
140  const IOobjectList& objects,
141  const bool syncPar,
142  objectRegistry* cache
143 )
144 {
145  // Sanity test
146  if (!internalWriter || !pInterp) return 0;
147 
148  #undef foamToVtk_WRITE_FIELD
149  #define foamToVtk_WRITE_FIELD(FieldType) \
150  writeDimFields<FieldType> \
151  ( \
152  internalWriter, pInterp, \
153  proxy, \
154  objects, \
155  syncPar, \
156  cache \
157  )
158 
159  label count = 0;
165 
166  #undef foamToVTK_WRITE_FIELD
167  return count;
168 }
169 
170 
171 } // End namespace Foam
172 
173 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
174 
175 #endif
176 
177 // ************************************************************************* //
#define foamToVtk_WRITE_FIELD(FieldType)
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:250
Helper routines for reading a field or fields, optionally with a mesh subset (using fvMeshSubsetProxy...
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...
label writeDimFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects)
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
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.
label writeAllDimFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects)
Namespace for OpenFOAM.
autoPtr< volPointInterpolation > pInterp