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) 2011-2016 OpenFOAM Foundation
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 "OFstream.H"
28 #include "floatScalar.H"
29 #include "writeFuns.H"
30 #include "emptyFvsPatchFields.H"
31 #include "fvsPatchFields.H"
32 
33 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
34 
36 (
37  const bool binary,
38  const vtkMesh& vMesh,
39  const fileName& fileName,
40  const UPtrList<const surfaceVectorField>& surfVectorFields
41 )
42 {
43  const fvMesh& mesh = vMesh.mesh();
44 
45  std::ofstream str(fileName.c_str());
46 
47  writeFuns::writeHeader
48  (
49  str,
50  binary,
51  "surfaceFields"
52  );
53 
54  str << "DATASET POLYDATA" << std::endl;
55 
56  const pointField& fc = mesh.faceCentres();
57 
58  str << "POINTS " << mesh.nFaces() << " float" << std::endl;
59 
60  DynamicList<floatScalar> pField(3*mesh.nFaces());
61 
62  for (label facei = 0; facei < mesh.nFaces(); facei++)
63  {
64  writeFuns::insert(fc[facei], pField);
65  }
66 
67  writeFuns::write(str, binary, pField);
68 
69  str << "POINT_DATA " << mesh.nFaces() << std::endl
70  << "FIELD attributes " << surfVectorFields.size() << std::endl;
71 
72  // surfVectorFields
73  forAll(surfVectorFields, fieldi)
74  {
75  const surfaceVectorField& svf = surfVectorFields[fieldi];
76 
77  str << svf.name() << " 3 "
78  << mesh.nFaces() << " float" << std::endl;
79 
80  DynamicList<floatScalar> fField(3*mesh.nFaces());
81 
82  for (label facei = 0; facei < mesh.nInternalFaces(); facei++)
83  {
84  writeFuns::insert(svf[facei], fField);
85  }
86 
87  forAll(svf.boundaryField(), patchi)
88  {
89  const fvsPatchVectorField& pf = svf.boundaryField()[patchi];
90 
91  const fvPatch& pp = mesh.boundary()[patchi];
92 
93  if (isA<emptyFvsPatchVectorField>(pf))
94  {
95  // Note: loop over polypatch size, not fvpatch size.
96  forAll(pp.patch(), i)
97  {
98  writeFuns::insert(vector::zero, fField);
99  }
100  }
101  else
102  {
103  forAll(pf, i)
104  {
105  writeFuns::insert(pf[i], fField);
106  }
107  }
108  }
109 
110  writeFuns::write(str, binary, fField);
111  }
112 }
113 
114 
115 // ************************************************************************* //
fvsPatchField< vector > fvsPatchVectorField
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
const word & name() const
Return name.
Definition: IOobject.H:291
GeometricField< vector, fvsPatchField, surfaceMesh > surfaceVectorField
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
void write(Ostream &, const label, const dictionary &)
Write with dictionary lookup.
void writeSurfFields(const bool binary, const vtkMesh &vMesh, const fileName &fileName, const UPtrList< const surfaceVectorField > &surfVectorFields)
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
timeIndices insert(timeIndex, timeDirs[timeI].value())
Write a patch with its data.
label patchi