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-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 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
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  #undef foamToVtk_WRITE_FIELD
142  #define foamToVtk_WRITE_FIELD(FieldType) \
143  writePointFields<FieldType> \
144  ( \
145  internalWriter, \
146  patchWriters, \
147  proxy, ptMesh, \
148  objects, \
149  syncPar \
150  )
151 
152  label count = 0;
158 
159  #undef foamToVTK_WRITE_FIELD
160  return count;
161 }
162 
163 
164 } // End namespace Foam
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
168 #endif
169 
170 // ************************************************************************* //
label writePointFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects)
#define foamToVtk_WRITE_FIELD(FieldType)
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
vtk::lineWriter writer(edgeCentres, edgeList::null(), fileName(aMesh.time().globalPath()/"finiteArea-edgesCentres"))
static const pointMesh & New(const polyMesh &mesh, Args &&... args)
Get existing or create a new MeshObject. Registered with typeName.
Definition: MeshObject.C:53
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...
label writeAllPointFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects)
void write(const word &fieldName, const UList< Type > &field)
Write primitive field of CellData (Poly or Line) or PointData values.
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
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.
bool useSubMesh() const noexcept
True if sub-mesh should be used.
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
A class for managing temporary objects.
Definition: HashPtrTable.H:50
PtrList< vtk::patchWriter > patchWriters
Namespace for OpenFOAM.