BUGFIX: Illegal use of uninitialised value (backport)
[foam-extend-3.2.git] / applications / utilities / postProcessing / dataConversion / foamToVTK / writeSurfFields.C
blob97ad781d1c2963e339e6b20f81fd8e92d92ac86e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "writeSurfFields.H"
28 #include "OFstream.H"
29 #include "floatScalar.H"
30 #include "writeFuns.H"
31 #include "emptyFvsPatchFields.H"
32 #include "fvsPatchFields.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 namespace Foam
39 // * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //
41 void writeSurfFields
43     const bool binary,
44     const vtkMesh& vMesh,
45     const fileName& fileName,
46     const PtrList<surfaceVectorField>& surfVectorFields
49     const fvMesh& mesh = vMesh.mesh();
51     std::ofstream str(fileName.c_str());
53     str << "# vtk DataFile Version 2.0" << std::endl
54         << "surfaceFields" << std::endl;
56     if (binary)
57     {
58         str << "BINARY" << std::endl;
59     }
60     else
61     {
62         str << "ASCII" << std::endl;
63     }
64     str << "DATASET POLYDATA" << std::endl;
66     const pointField& fc = mesh.faceCentres();
68     str << "POINTS " << mesh.nFaces() << " float" << std::endl;
70     DynamicList<floatScalar> pField(3*mesh.nFaces());
72     for (label faceI = 0; faceI < mesh.nFaces(); faceI++)
73     {
74         writeFuns::insert(fc[faceI], pField);
75     }
77     writeFuns::write(str, binary, pField);
79     str << "POINT_DATA " << mesh.nFaces() << std::endl
80         << "FIELD attributes " << surfVectorFields.size() << std::endl;
82     // surfVectorFields
83     forAll(surfVectorFields, fieldI)
84     {
85         const surfaceVectorField& svf = surfVectorFields[fieldI];
87         str << svf.name() << " 3 "
88             << mesh.nFaces() << " float" << std::endl;
90         DynamicList<floatScalar> fField(3*mesh.nFaces());
92         for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
93         {
94             writeFuns::insert(svf[faceI], fField);
95         }
97         forAll(svf.boundaryField(), patchI)
98         {
99             const fvsPatchVectorField& pf = svf.boundaryField()[patchI];
101             const fvPatch& pp = mesh.boundary()[patchI];
103             if (isA<emptyFvsPatchVectorField>(pf))
104             {
105                 // Note: loop over polypatch size, not fvpatch size.
106                 forAll(pp.patch(), i)
107                 {
108                     writeFuns::insert(vector::zero, fField);
109                 }
110             }
111             else
112             {
113                 forAll(pf, i)
114                 {
115                     writeFuns::insert(pf[i], fField);
116                 }
117             }
118         }
120         writeFuns::write(str, binary, fField);
121     }
125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
127 } // End namespace Foam
129 // ************************************************************************* //