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-2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 InNamespace
27  Foam
28 
29 Description
30  Read point fields from disk
31  and write with vtk::internalWriter and vtk::patchWriter
32 
33 SourceFiles
34  writePointFields.H
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef writePointFields_H
39 #define writePointFields_H
40 
41 #include "readFields.H"
42 #include "foamVtkInternalWriter.H"
43 #include "foamVtkPatchWriter.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 template<class GeoField>
51 bool writePointField
52 (
55 
56  const tmp<GeoField>& tfield,
57  const fvMeshSubsetProxy& proxy
58 )
59 {
60  if (!tfield.valid())
61  {
62  return false;
63  }
64 
65  tmp<GeoField> tproxied;
66  if (proxy.useSubMesh())
67  {
68  tproxied = proxy.interpolate(tfield());
69  tfield.clear();
70  }
71  else
72  {
73  tproxied = tfield;
74  }
75 
76  if (!tproxied.valid())
77  {
78  // Or Error?
79  return false;
80  }
81 
82 
83  const auto& field = tproxied();
84 
85  // Internal
86  if (internalWriter)
87  {
88  internalWriter->write(field);
89  }
90 
91  // Boundary
93  {
95  }
96 
97 
98  tproxied.clear();
99 
100  return true;
101 }
102 
103 
104 template<class GeoField>
105 label writePointFields
106 (
109 
110  const fvMeshSubsetProxy& proxy,
111  const typename GeoField::Mesh& ptMesh,
112  const IOobjectList& objects,
113  const bool syncPar
114 )
115 {
116  label count = 0;
117 
118  for (const word& fieldName : objects.sortedNames<GeoField>())
119  {
120  if
121  (
122  writePointField<GeoField>
123  (
125  patchWriters,
126  getField<GeoField>(ptMesh, objects, fieldName, syncPar),
127  proxy
128  )
129  )
130  {
131  ++count;
132  }
133  }
134 
135  return count;
136 }
137 
138 
140 (
143 
144  const fvMeshSubsetProxy& proxy,
145  const IOobjectList& objects,
146  const bool syncPar
147 )
148 {
149  const pointMesh& ptMesh = pointMesh::New(proxy.baseMesh());
150 
151  #undef foamToVtk_WRITE_FIELD
152  #define foamToVtk_WRITE_FIELD(FieldType) \
153  writePointFields<FieldType> \
154  ( \
155  internalWriter, \
156  patchWriters, \
157  proxy, ptMesh, \
158  objects, \
159  syncPar \
160  )
161 
162  label count = 0;
168 
169  #undef foamToVTK_WRITE_FIELD
170  return count;
171 }
172 
173 
174 } // End namespace Foam
175 
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
177 
178 #endif
179 
180 // ************************************************************************* //
Foam::writePointFields
label writePointFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects)
Definition: writePointFields.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::tmp::clear
void clear() const noexcept
Definition: tmpI.H:287
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
internalWriter
autoPtr< vtk::internalWriter > internalWriter
Definition: convertProcessorPatches.H:60
Foam::MeshObject< polyMesh, UpdateableMeshObject, pointMesh >::New
static const pointMesh & New(const polyMesh &mesh, Args &&... args)
Get existing or create a new MeshObject.
Definition: MeshObject.C:48
Foam::writer::write
virtual void write(const coordSet &, const wordList &, const List< const Field< Type > * > &, Ostream &) const =0
General entry point for writing.
Foam::IOobjectList::sortedNames
wordList sortedNames() const
The sorted names of the IOobjects.
Definition: IOobjectList.C:345
patchWriters
PtrList< vtk::patchWriter > patchWriters
Definition: convertProcessorPatches.H:63
Foam::fvMeshSubsetProxy::interpolate
static tmp< GeoField > interpolate(const fvMeshSubset &subsetter, const GeoField &fld)
Wrapper for field or the subsetted field.
Foam::UPtrList
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: UPtrList.H:62
field
rDeltaTY field()
Foam::writePointField
bool writePointField(ensightCase &ensCase, const ensightMesh &ensMesh, const tmp< GeometricField< Type, pointPatchField, pointMesh >> &tfield)
Definition: writePointFields.H:43
Foam::fvMeshSubsetProxy::useSubMesh
bool useSubMesh() const noexcept
True if sub-mesh should be used.
Definition: fvMeshSubsetProxy.H:165
Foam::writer
Base class for graphics format writing. Entry points are.
Definition: writer.H:81
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::pointMesh
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:51
foamToVtk_WRITE_FIELD
#define foamToVtk_WRITE_FIELD(FieldType)
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:55
foamVtkPatchWriter.H
Foam::vtk::patchWriter
Write OpenFOAM patches and patch fields in VTP or legacy vtk format.
Definition: foamVtkPatchWriter.H:68
readFields.H
Helper routines for reading a field or fields, optionally with a mesh subset (using fvMeshSubsetProxy...
Foam::fvMeshSubsetProxy
Simple proxy for holding a mesh, or mesh-subset. The subMeshes are currently limited to cellSet or ce...
Definition: fvMeshSubsetProxy.H:55
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
foamVtkInternalWriter.H
Foam::tmp::valid
bool valid() const noexcept
Identical to good(), or bool operator.
Definition: tmp.H:292
Foam::GeometricField< scalar, pointPatchField, pointMesh >
Foam::writeAllPointFields
label writeAllPointFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects)
Definition: writePointFields.H:107
Foam::fvMeshSubsetProxy::baseMesh
const fvMesh & baseMesh() const noexcept
The entire base mesh.
Definition: fvMeshSubsetProxy.H:147