vtkWriteTemplates.C
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 \*---------------------------------------------------------------------------*/
27 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 template<class GeoField>
31 Foam::label Foam::functionObjects::vtkWrite::writeVolFields
32 (
35  const fvMeshSubset& proxy,
36  const wordHashSet& acceptField
37 ) const
38 {
39  const fvMesh& baseMesh = proxy.baseMesh();
40 
41  label count = 0;
42 
43  for (const word& fieldName : baseMesh.sortedNames<GeoField>(acceptField))
44  {
45  bool ok = false;
46  const auto* fieldptr = baseMesh.findObject<GeoField>(fieldName);
47 
48  if (!fieldptr)
49  {
50  continue;
51  }
52 
53  auto tfield = fvMeshSubsetProxy::interpolate(proxy, *fieldptr);
54  const auto& field = tfield();
55 
56  // Internal
57  if (internalWriter)
58  {
59  ok = true;
60  internalWriter->write(field);
61  }
62 
63  // Boundary
64  label writeri = 0;
66  {
67  ok = true;
69  ++writeri;
70  }
71 
72  if (ok)
73  {
74  ++count;
75 
76  if (verbose_)
77  {
78  if (count == 1)
79  {
80  Log << " " << GeoField::typeName << '(';
81  }
82  else
83  {
84  Log << ' ';
85  }
86  Log << fieldName;
87  }
88  }
89  }
90 
91  if (verbose_ && count)
92  {
93  Log << ')' << endl;
94  }
95 
96  return count;
97 }
98 
99 
100 template<class GeoField>
101 Foam::label Foam::functionObjects::vtkWrite::writeVolFields
102 (
107  const fvMeshSubset& proxy,
108  const wordHashSet& acceptField
109 ) const
110 {
111  const fvMesh& baseMesh = proxy.baseMesh();
112 
113  label count = 0;
114 
115  for (const word& fieldName : baseMesh.sortedNames<GeoField>(acceptField))
116  {
117  bool ok = false;
118  const auto* fieldptr = baseMesh.findObject<GeoField>(fieldName);
119 
120  if (!fieldptr)
121  {
122  continue;
123  }
124 
125  auto tfield = fvMeshSubsetProxy::interpolate(proxy, *fieldptr);
126  const auto& field = tfield();
127 
128  // Internal
129  if (internalWriter && pInterp)
130  {
131  ok = true;
132  internalWriter->write(field, *pInterp);
133  }
134 
135  // Boundary
136  label writeri = 0;
138  {
139  if (writeri < patchInterps.size() && patchInterps.set(writeri))
140  {
141  ok = true;
142  writer.write(field, patchInterps[writeri]);
143  }
144  ++writeri;
145  }
146 
147  if (ok)
148  {
149  ++count;
150 
151  if (verbose_)
152  {
153  if (count == 1)
154  {
155  Log << " " << GeoField::typeName << "->point(";
156  }
157  else
158  {
159  Log << ' ';
160  }
161  Log << fieldName;
162  }
163  }
164  }
165 
166  if (verbose_ && count)
167  {
168  Log << ')' << endl;
169  }
170 
171  return count;
172 }
173 
174 
175 // ************************************************************************* //
Foam::objectRegistry::sortedNames
wordList sortedNames() const
The sorted names of all objects.
Definition: objectRegistry.C:153
Log
#define Log
Definition: PDRblock.C:35
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fvMeshSubset
Given the original mesh and the list of selected cells, it creates the mesh consisting only of the de...
Definition: fvMeshSubset.H:73
internalWriter
autoPtr< vtk::internalWriter > internalWriter
Definition: convertProcessorPatches.H:60
Foam::writer::write
virtual void write(const coordSet &, const wordList &, const List< const Field< Type > * > &, Ostream &) const =0
General entry point for writing.
patchWriters
PtrList< vtk::patchWriter > patchWriters
Definition: convertProcessorPatches.H:63
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::HashSet< word, Hash< word > >
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::writer
Base class for graphics format writing. Entry points are.
Definition: writer.H:81
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam::fvMeshSubset::baseMesh
const fvMesh & baseMesh() const noexcept
Original mesh.
Definition: fvMeshSubsetI.H:30
Foam::vtk::patchWriter
Write OpenFOAM patches and patch fields in VTP or legacy vtk format.
Definition: foamVtkPatchWriter.H:68
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::objectRegistry::findObject
const Type * findObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
Definition: objectRegistryTemplates.C:401
Foam::PrimitivePatchInterpolation
Interpolation class within a primitive patch. Allows interpolation from points to faces and vice vers...
Definition: PrimitivePatchInterpolation.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
patchInterps
PtrList< PrimitivePatchInterpolation< primitivePatch > > patchInterps
Definition: convertVolumeFields.H:130
Foam::fac::interpolate
static tmp< GeometricField< Type, faePatchField, edgeMesh > > interpolate(const GeometricField< Type, faPatchField, areaMesh > &tvf, const edgeScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
pInterp
autoPtr< volPointInterpolation > pInterp
Definition: convertVolumeFields.H:81