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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
12 
13 Description
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"
23 #include "foamVtkInternalWriter.H"
24 #include "foamVtkPatchWriter.H"
25 
26 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
27 
28 namespace Foam
29 {
30 
31 template<class GeoField>
32 bool writePointField
33 (
34  autoPtr<vtk::internalWriter>& internalWriter,
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
70  if (internalWriter)
71  {
72  internalWriter->write(field);
73  }
74 
75  // Boundary
76  for (auto& writer : patchWriters)
77  {
79  }
80 
81 
82  tproxied.clear();
83 
84  return true;
85 }
86 
87 
88 template<class GeoField>
89 label writePointFields
90 (
91  autoPtr<vtk::internalWriter>& internalWriter,
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  (
109  writePointField<GeoField>
110  (
112  patchWriters,
113  getField<GeoField>(ptMesh, objects, fieldName, syncPar),
114  proxy
115  )
116  )
117  {
118  ++count;
119  }
120  }
121 
122  return count;
123 }
124 
125 
127 (
128  autoPtr<vtk::internalWriter>& internalWriter,
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 // ************************************************************************* //
label writePointFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects)
rDeltaTY field()
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
static FOAM_NO_DANGLING_REFERENCE const pointMesh & New(const polyMesh &mesh, Args &&... args)
Get existing or create MeshObject registered with typeName.
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 writeAllPointFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects)
void write(const word &fieldName, const UList< Type > &field)
Write primitive field of CellData or PointData values (size depending on the current context)...
bool writePointField(ensightCase &ensCase, const ensightMesh &ensMesh, const tmp< PointField< Type >> &tfield)
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:45
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
const fvMesh & baseMesh() const noexcept
The entire base mesh.
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...
static tmp< GeoField > interpolate(const fvMeshSubset &subsetter, const GeoField &fld)
Wrapper for field or the subsetted field.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
bool useSubMesh() const noexcept
True if sub-mesh should be used.
void clear() const noexcept
If object pointer points to valid object: delete object and set pointer to nullptr.
Definition: tmpI.H:289
vtk::vertexWriter writer(edgeCentres, outputOpts,(aMesh.time().globalPath()/outputName), UPstream::parRun())
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Tensor of scalars, i.e. Tensor<scalar>.
PtrList< vtk::patchWriter > patchWriters
Namespace for OpenFOAM.