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 "doubleScalar.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  // Use binary mode in case we write binary.
51  // Causes windows reading to fail if we don't
52  std::ofstream str(fileName.c_str(),
53  ios_base::out|ios_base::binary);
54 
56  (
57  str,
58  binary,
59  "surfaceFields"
60  );
61 
62  str << "DATASET POLYDATA" << std::endl;
63 
64  const pointField& fc = mesh.faceCentres();
65 
66  str << "POINTS " << mesh.nFaces() << " double" << std::endl;
67 
69 
70  for (label faceI = 0; faceI < mesh.nFaces(); faceI++)
71  {
72  writeFuns::insert(fc[faceI], pField);
73  }
74 
75  writeFuns::write(str, binary, pField);
76 
77  str << "POINT_DATA " << mesh.nFaces() << std::endl
78  << "FIELD attributes " << surfVectorFields.size() << std::endl;
79 
80  // surfVectorFields
81  forAll(surfVectorFields, fieldI)
82  {
83  const surfaceVectorField& svf = surfVectorFields[fieldI];
84 
85  str << svf.name() << " 3 "
86  << mesh.nFaces() << " double" << std::endl;
87 
89 
90  for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
91  {
92  writeFuns::insert(svf[faceI], fField);
93  }
94 
95  forAll(svf.boundaryField(), patchI)
96  {
97  const fvsPatchVectorField& pf = svf.boundaryField()[patchI];
98 
99  const fvPatch& pp = mesh.boundary()[patchI];
100 
101  if (isA<emptyFvsPatchVectorField>(pf))
102  {
103  // Note: loop over polypatch size, not fvpatch size.
104  forAll(pp.patch(), i)
105  {
107  }
108  }
109  else
110  {
111  forAll(pf, i)
112  {
113  writeFuns::insert(pf[i], fField);
114  }
115  }
116  }
117 
118  writeFuns::write(str, binary, fField);
119  }
120 }
121 
122 
123 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
124 
125 } // End namespace Foam
126 
127 // ************************************************************************* //
writeFuns.H
Foam::Vector< scalar >::zero
static const Vector zero
Definition: Vector.H:80
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:56
Foam::fvsPatchField
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
Definition: fvsPatchField.H:65
Foam::GeometricField::boundaryField
GeometricBoundaryField & boundaryField()
Return reference to GeometricBoundaryField.
Definition: GeometricField.C:735
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::vtkMesh
Encapsulation of VTK mesh data. Holds mesh or meshsubset and polyhedral-cell decomposition on it.
Definition: vtkMesh.H:52
writeSurfFields.H
Write a patch with its data.
OFstream.H
Foam::writeFuns::writeHeader
static void writeHeader(std::ostream &, const bool isBinary, const std::string &title)
Definition: writeFuns.C:190
doubleScalar.H
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::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:61
Foam::writeFuns::write
static void write(std::ostream &, const bool, DynamicList< floatScalar > &)
Write floats ascii or binary.
Definition: writeFuns.C:107
emptyFvsPatchFields.H
Foam::PtrList
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
Foam::primitiveMesh::nInternalFaces
label nInternalFaces() const
Definition: primitiveMeshI.H:52
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
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
Foam::vtkMesh::mesh
const fvMesh & mesh() const
Access either mesh or submesh.
Definition: vtkMesh.H:119
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
Foam::PtrList::size
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
Foam::fvPatch::patch
const polyPatch & patch() const
Return the polyPatch.
Definition: fvPatch.H:143
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::writeFuns::insert
static void insert(const point &, DynamicList< floatScalar > &dest)
Append point to given DynamicList.
Definition: writeFuns.C:170