Loading...
Searching...
No Matches
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-2025 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
12
13Description
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"
24#include "foamVtkPatchWriter.H"
25
26// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
27
28namespace Foam
29{
30
31template<class GeoField>
33(
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
56 {
57 internalWriter->write(tfield());
58 }
59
60 // Boundary
61 for (auto& writer : patchWriters)
62 {
63 writer.write(tfield());
64 }
65
66 tfield.clear();
67 ++count;
68 }
69 }
70
71 return count;
72}
73
74
75template<class GeoField>
77(
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 (
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;
117 for (auto& writer : patchWriters)
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
136(
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 label count = 0;
150 const label total = objects.size();
151 do
152 {
153 #undef doLocalWriteCode
154 #define doLocalWriteCode(Type) \
155 { \
156 typedef VolumeField<Type> FieldType; \
157 \
158 count += writeVolFields<FieldType> \
159 ( \
160 internalWriter, \
161 patchWriters, \
162 proxy, \
163 objects, \
164 syncPar, \
165 cache \
166 ); \
167 if (count >= total) break; /* early exit */ \
168 }
169
170 doLocalWriteCode(scalar);
175
176 #undef doLocalWriteCode
177 }
178 while (false);
179
180 return count;
181}
182
183
185(
188
191
192 const fvMeshSubsetProxy& proxy,
193 const IOobjectList& objects,
194 const bool syncPar,
195 objectRegistry* cache
196)
197{
198 label count = 0;
199 const label total = objects.size();
200 do
201 {
202 #undef doLocalWriteCode
203 #define doLocalWriteCode(Type) \
204 { \
205 typedef VolumeField<Type> FieldType; \
206 \
207 count += writeVolFields<FieldType> \
208 ( \
209 internalWriter, pInterp, \
210 patchWriters, patchInterps, \
211 proxy, \
212 objects, \
213 syncPar, \
214 cache \
215 ); \
216 if (count >= total) break; /* early exit */ \
217 }
218
219 doLocalWriteCode(scalar);
224
225 #undef doLocalWriteCode
226 }
227 while (false);
228
229 return count;
230}
231
232
233} // End namespace Foam
234
235// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236
237#endif
238
239// ************************************************************************* //
Helper routines for reading a field or fields, optionally with a mesh subset (using fvMeshSubsetProxy...
vtk::lineWriter writer(edgeCentres, edgeList::null(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edgesCentres")))
label size() const noexcept
The number of elements in table.
Definition HashTable.H:358
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable,...
wordList sortedNames() const
The sorted names of the IOobjects.
Interpolation class within a primitive patch. Allows interpolation from points to faces and vice vers...
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition UPtrList.H:101
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
Simple proxy for holding a mesh, or mesh-subset. The subMeshes are currently limited to cellSet or ce...
Registry of regIOobjects.
A class for managing temporary objects.
Definition tmp.H:75
void clear() const noexcept
If object pointer points to valid object: delete object and set pointer to nullptr.
Definition tmpI.H:289
A class for handling words, derived from Foam::string.
Definition word.H:66
autoPtr< vtk::internalWriter > internalWriter
PtrList< vtk::patchWriter > patchWriters
#define doLocalWriteCode(Type)
PtrList< PrimitivePatchInterpolation< primitivePatch > > patchInterps
autoPtr< volPointInterpolation > pInterp
Namespace for OpenFOAM.
label writeAllVolFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects, const bool nearCellValue=false)
label writeVolFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects, const bool nearCellValue=false)
Tensor< scalar > tensor
Definition symmTensor.H:57
Vector< scalar > vector
Definition vector.H:57
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars, i.e. SphericalTensor<scalar>.
tmp< GeoField > getField(const IOobject &io, const typename GeoField::Mesh &mesh)
Get the field or FatalError.
Definition readFields.H:51
SymmTensor< scalar > symmTensor
SymmTensor of scalars, i.e. SymmTensor<scalar>.
Definition symmTensor.H:55