writeDimFields.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 dimensioned fields from disk
31  and write with vtk::internalWriter
32 
33 SourceFiles
34  writeDimFields.H
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef writeDimFields_H
39 #define writeDimFields_H
40 
41 #include "readFields.H"
42 #include "foamVtkInternalWriter.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 template<class GeoField>
50 bool writeDimField
51 (
53  const tmp<GeoField>& tfield
54 )
55 {
56  if (!tfield.valid())
57  {
58  return false;
59  }
60 
61  const auto& field = tfield();
62 
63  if (internalWriter)
64  {
65  internalWriter->write(field);
66  }
67 
68  tfield.clear();
69  return true;
70 }
71 
72 
73 template<class GeoField>
74 bool writeDimField
75 (
78  const tmp<GeoField>& tfield
79 )
80 {
81  if (!tfield.valid())
82  {
83  return false;
84  }
85 
86  const auto& field = tfield();
87 
88  if (internalWriter && pInterp)
89  {
90  internalWriter->write(field, *pInterp);
91  }
92 
93  tfield.clear();
94  return true;
95 }
96 
97 
98 template<class GeoField>
99 label writeDimFields
100 (
102  const fvMeshSubsetProxy& proxy,
103  const IOobjectList& objects,
104  const bool syncPar
105 )
106 {
107  label count = 0;
108 
109  for (const word& fieldName : objects.sortedNames<GeoField>())
110  {
111  if
112  (
113  writeDimField<GeoField>
114  (
116  getField<GeoField>(proxy, objects, fieldName, syncPar)
117  )
118  )
119  {
120  ++count;
121  }
122  }
123 
124  return count;
125 }
126 
127 
128 template<class GeoField>
129 label writeDimFields
130 (
133 
134  const fvMeshSubsetProxy& proxy,
135  const IOobjectList& objects,
136  const bool syncPar
137 )
138 {
139  label count = 0;
140 
141  for (const word& fieldName : objects.sortedNames<GeoField>())
142  {
143  if
144  (
145  writeDimField<GeoField>
146  (
148  getField<GeoField>(proxy, objects, fieldName, syncPar)
149  )
150  )
151  {
152  ++count;
153  }
154  }
155 
156  return count;
157 }
158 
159 
160 label writeAllDimFields
161 (
163 
164  const fvMeshSubsetProxy& proxy,
165  const IOobjectList& objects,
166  const bool syncPar
167 )
168 {
169  #undef foamToVtk_WRITE_FIELD
170  #define foamToVtk_WRITE_FIELD(FieldType) \
171  writeDimFields<FieldType> \
172  ( \
173  internalWriter, \
174  proxy, \
175  objects, \
176  syncPar \
177  )
178 
179  label count = 0;
185 
186  #undef foamToVTK_WRITE_FIELD
187  return count;
188 }
189 
190 
191 label writeAllDimFields
192 (
195 
196  const fvMeshSubsetProxy& proxy,
197  const IOobjectList& objects,
198  const bool syncPar
199 )
200 {
201  #undef foamToVtk_WRITE_FIELD
202  #define foamToVtk_WRITE_FIELD(FieldType) \
203  writeDimFields<FieldType> \
204  ( \
205  internalWriter, pInterp, \
206  proxy, \
207  objects, \
208  syncPar \
209  )
210 
211  label count = 0;
217 
218  #undef foamToVTK_WRITE_FIELD
219  return count;
220 }
221 
222 
223 } // End namespace Foam
224 
225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 
227 #endif
228 
229 // ************************************************************************* //
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::IOobjectList::sortedNames
wordList sortedNames() const
The sorted names of the IOobjects.
Definition: IOobjectList.C:345
Foam::writeDimFields
label writeDimFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects)
Definition: writeDimFields.H:68
field
rDeltaTY field()
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::writeAllDimFields
label writeAllDimFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects)
Definition: writeDimFields.H:106
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:55
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
Foam::writeDimField
bool writeDimField(ensightCase &ensCase, const ensightMesh &ensMesh, const tmp< DimensionedField< Type, volMesh >> &tdf)
Definition: writeDimFields.H:41
foamToVtk_WRITE_FIELD
#define foamToVtk_WRITE_FIELD(FieldType)
foamVtkInternalWriter.H
Foam::tmp::valid
bool valid() const noexcept
Identical to good(), or bool operator.
Definition: tmp.H:292
pInterp
autoPtr< volPointInterpolation > pInterp
Definition: convertVolumeFields.H:81
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54