Loading...
Searching...
No Matches
writePointFields.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 point fields from disk
15 and write with vtk::internalWriter and vtk::patchWriter
16
17\*---------------------------------------------------------------------------*/
18
19#ifndef FoamToVTK_writePointFields_H
20#define FoamToVTK_writePointFields_H
21
22#include "readFields.H"
24#include "foamVtkPatchWriter.H"
25
26// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
27
28namespace Foam
29{
30
31template<class GeoField>
33(
36
37 const tmp<GeoField>& tfield,
38 const fvMeshSubsetProxy& proxy
39)
40{
41 // Sanity test
42 if (!internalWriter && patchWriters.empty()) return false;
43
44 if (!tfield)
45 {
46 return false;
47 }
48
49 tmp<GeoField> tproxied;
50 if (proxy.useSubMesh())
51 {
52 tproxied = proxy.interpolate(tfield());
53 tfield.clear();
54 }
55 else
56 {
57 tproxied = tfield;
58 }
59
60 if (!tproxied)
61 {
62 // Or Error?
63 return false;
64 }
65
66
67 const auto& field = tproxied();
68
69 // Internal
71 {
72 internalWriter->write(field);
73 }
74
75 // Boundary
76 for (auto& writer : patchWriters)
77 {
78 writer.write(field);
79 }
80
81
82 tproxied.clear();
83
84 return true;
85}
86
87
88template<class GeoField>
90(
93
94 const fvMeshSubsetProxy& proxy,
95 const typename GeoField::Mesh& ptMesh,
96 const IOobjectList& objects,
97 const bool syncPar
98)
99{
100 // Sanity test
101 if (!internalWriter && patchWriters.empty()) return 0;
102
103 label count = 0;
104
105 for (const word& fieldName : objects.sortedNames<GeoField>())
106 {
107 if
108 (
110 (
113 getField<GeoField>(ptMesh, objects, fieldName, syncPar),
114 proxy
115 )
116 )
117 {
118 ++count;
119 }
120 }
121
122 return count;
123}
124
125
127(
130
131 const fvMeshSubsetProxy& proxy,
132 const IOobjectList& objects,
133 const bool syncPar
134)
135{
136 // Sanity test
137 if (!internalWriter && patchWriters.empty()) return 0;
138
139 const pointMesh& ptMesh = pointMesh::New(proxy.baseMesh());
140
141 label count = 0;
142 const label total = objects.size();
143 do
144 {
145 #undef doLocalWriteCode
146 #define doLocalWriteCode(Type) \
147 { \
148 typedef PointField<Type> FieldType; \
149 \
150 count += writePointFields<FieldType> \
151 ( \
152 internalWriter, \
153 patchWriters, \
154 proxy, ptMesh, \
155 objects, \
156 syncPar \
157 ); \
158 if (count >= total) break; /* early exit */ \
159 }
160
161 doLocalWriteCode(scalar);
166
167 #undef doLocalWriteCode
168 }
169 while (false);
170
171 return count;
172}
173
174
175} // End namespace Foam
176
177// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178
179#endif
180
181// ************************************************************************* //
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.
static FOAM_NO_DANGLING_REFERENCE const pointMesh & New(const polyMesh &mesh, Args &&... args)
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...
static tmp< GeoField > interpolate(const fvMeshSubset &subsetter, const GeoField &fld)
Wrapper for field or the subsetted field.
const fvMesh & baseMesh() const noexcept
The entire base mesh.
bool useSubMesh() const noexcept
True if sub-mesh should be used.
Mesh representing a set of points created from polyMesh.
Definition pointMesh.H:49
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
rDeltaTY field()
autoPtr< vtk::internalWriter > internalWriter
PtrList< vtk::patchWriter > patchWriters
#define doLocalWriteCode(Type)
Namespace for OpenFOAM.
label writeAllPointFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects)
Tensor< scalar > tensor
Definition symmTensor.H:57
bool writePointField(ensightCase &ensCase, const ensightMesh &ensMesh, const tmp< PointField< Type > > &tfield)
label writePointFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects)
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