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 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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
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 
53  (
54  str,
55  binary,
56  "surfaceFields"
57  );
58 
59  str << "DATASET POLYDATA" << std::endl;
60 
61  const pointField& fc = mesh.faceCentres();
62 
63  str << "POINTS " << mesh.nFaces() << " float" << std::endl;
64 
65  DynamicList<floatScalar> pField(3*mesh.nFaces());
66 
67  for (label faceI = 0; faceI < mesh.nFaces(); faceI++)
68  {
69  writeFuns::insert(fc[faceI], pField);
70  }
71 
72  writeFuns::write(str, binary, pField);
73 
74  str << "POINT_DATA " << mesh.nFaces() << std::endl
75  << "FIELD attributes " << surfVectorFields.size() << std::endl;
76 
77  // surfVectorFields
78  forAll(surfVectorFields, fieldI)
79  {
80  const surfaceVectorField& svf = surfVectorFields[fieldI];
81 
82  str << svf.name() << " 3 "
83  << mesh.nFaces() << " float" << std::endl;
84 
85  DynamicList<floatScalar> fField(3*mesh.nFaces());
86 
87  for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
88  {
89  writeFuns::insert(svf[faceI], fField);
90  }
91 
92  forAll(svf.boundaryField(), patchI)
93  {
94  const fvsPatchVectorField& pf = svf.boundaryField()[patchI];
95 
96  const fvPatch& pp = mesh.boundary()[patchI];
97 
98  if (isA<emptyFvsPatchVectorField>(pf))
99  {
100  // Note: loop over polypatch size, not fvpatch size.
101  forAll(pp.patch(), i)
102  {
104  }
105  }
106  else
107  {
108  forAll(pf, i)
109  {
110  writeFuns::insert(pf[i], fField);
111  }
112  }
113  }
114 
115  writeFuns::write(str, binary, fField);
116  }
117 }
118 
119 
120 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
121 
122 } // End namespace Foam
123 
124 // ************************************************************************* //
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Foam::Vector< scalar >::zero
static const Vector zero
Definition: Vector.H:80
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
OFstream.H
Foam::writeFuns::writeHeader
static void writeHeader(std::ostream &, const bool isBinary, const std::string &title)
Definition: writeFuns.C:190
Foam::label
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
Foam::fvsPatchVectorField
fvsPatchField< vector > fvsPatchVectorField
Definition: fvsPatchFieldsFwd.H:46
Foam::writeFuns::write
static void write(std::ostream &, const bool, DynamicList< floatScalar > &)
Write floats ascii or binary.
Definition: writeFuns.C:107
emptyFvsPatchFields.H
Foam::primitiveMesh::nInternalFaces
label nInternalFaces() const
Definition: primitiveMeshI.H:52
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::writeSurfFields
void writeSurfFields(const bool binary, const vtkMesh &vMesh, const fileName &fileName, const PtrList< surfaceVectorField > &surfVectorFields)
Definition: writeSurfFields.C:41
fvsPatchFields.H
Foam::fvMesh::boundary
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:550
Foam::primitiveMesh::nFaces
label nFaces() const
Definition: primitiveMeshI.H:58
Foam::primitiveMesh::faceCentres
const vectorField & faceCentres() const
Definition: primitiveMeshFaceCentresAndAreas.C:130
floatScalar.H
Foam::surfaceVectorField
GeometricField< vector, fvsPatchField, surfaceMesh > surfaceVectorField
Definition: surfaceFieldsFwd.H:55
Foam::writeFuns::insert
static void insert(const point &, DynamicList< floatScalar > &dest)
Append point to given DynamicList.
Definition: writeFuns.C:170