FreeFOAM The Cross-Platform CFD Toolkit
writeSurfFields.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 | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "writeSurfFields.H"
27 #include <OpenFOAM/OFstream.H>
28 #include <OpenFOAM/floatScalar.H>
29 #include "writeFuns.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 
38 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
39 
40 void writeSurfFields
41 (
42  const bool binary,
43  const vtkMesh& vMesh,
44  const fileName& fileName,
45  const PtrList<surfaceVectorField>& surfVectorFields
46 )
47 {
48  const fvMesh& mesh = vMesh.mesh();
49 
50  std::ofstream str(fileName.c_str());
51 
52  str << "# vtk DataFile Version 2.0" << std::endl
53  << "surfaceFields" << std::endl;
54 
55  if (binary)
56  {
57  str << "BINARY" << std::endl;
58  }
59  else
60  {
61  str << "ASCII" << std::endl;
62  }
63  str << "DATASET POLYDATA" << std::endl;
64 
65  const pointField& fc = mesh.faceCentres();
66 
67  str << "POINTS " << mesh.nFaces() << " float" << std::endl;
68 
69  DynamicList<floatScalar> pField(3*mesh.nFaces());
70 
71  for (label faceI = 0; faceI < mesh.nFaces(); faceI++)
72  {
73  writeFuns::insert(fc[faceI], pField);
74  }
75 
76  writeFuns::write(str, binary, pField);
77 
78  str << "POINT_DATA " << mesh.nFaces() << std::endl
79  << "FIELD attributes " << surfVectorFields.size() << std::endl;
80 
81  // surfVectorFields
82  forAll(surfVectorFields, fieldI)
83  {
84  const surfaceVectorField& svf = surfVectorFields[fieldI];
85 
86  str << svf.name() << " 3 "
87  << mesh.nFaces() << " float" << std::endl;
88 
89  DynamicList<floatScalar> fField(3*mesh.nFaces());
90 
91  for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
92  {
93  writeFuns::insert(svf[faceI], fField);
94  }
95 
96  forAll(svf.boundaryField(), patchI)
97  {
98  const fvsPatchVectorField& pf = svf.boundaryField()[patchI];
99 
100  const fvPatch& pp = mesh.boundary()[patchI];
101 
102  if (isA<emptyFvsPatchVectorField>(pf))
103  {
104  // Note: loop over polypatch size, not fvpatch size.
105  forAll(pp.patch(), i)
106  {
108  }
109  }
110  else
111  {
112  forAll(pf, i)
113  {
114  writeFuns::insert(pf[i], fField);
115  }
116  }
117  }
118 
119  writeFuns::write(str, binary, fField);
120  }
121 }
122 
123 
124 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
125 
126 } // End namespace Foam
127 
128 // ************************ vim: set sw=4 sts=4 et: ************************ //