FreeFOAM The Cross-Platform CFD Toolkit
patchWriter.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 "patchWriter.H"
27 #include "writeFuns.H"
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 // Construct from components
35 (
36  const vtkMesh& vMesh,
37  const bool binary,
38  const bool nearCellValue,
39  const fileName& fName,
40  const labelList& patchIDs
41 )
42 :
43  vMesh_(vMesh),
44  binary_(binary),
45  nearCellValue_(nearCellValue),
46  fName_(fName),
47  patchIDs_(patchIDs),
48  os_(fName.c_str())
49 {
50  const fvMesh& mesh = vMesh_.mesh();
51  const polyBoundaryMesh& patches = mesh.boundaryMesh();
52 
53  // Write header
54  if (patchIDs_.size() == 1)
55  {
56  writeFuns::writeHeader(os_, binary_, patches[patchIDs_[0]].name());
57  }
58  else
59  {
60  writeFuns::writeHeader(os_, binary_, "patches");
61  }
62  os_ << "DATASET UNSTRUCTURED_GRID" << std::endl;
63 
64  // Write topology
65  nPoints_ = 0;
66  nFaces_ = 0;
67  label nFaceVerts = 0;
68 
69  forAll(patchIDs_, i)
70  {
71  const polyPatch& pp = patches[patchIDs_[i]];
72 
73  nPoints_ += pp.nPoints();
74  nFaces_ += pp.size();
75 
76  forAll(pp, faceI)
77  {
78  nFaceVerts += pp[faceI].size() + 1;
79  }
80  }
81 
82  os_ << "POINTS " << nPoints_ << " float" << std::endl;
83 
84  DynamicList<floatScalar> ptField(3*nPoints_);
85 
86  forAll(patchIDs_, i)
87  {
88  const polyPatch& pp = patches[patchIDs_[i]];
89 
90  writeFuns::insert(pp.localPoints(), ptField);
91  }
92  writeFuns::write(os_, binary_, ptField);
93 
94  os_ << "CELLS " << nFaces_ << ' ' << nFaceVerts
95  << std::endl;
96 
97  DynamicList<label> vertLabels(nFaceVerts);
98  DynamicList<label> faceTypes(nFaceVerts);
99 
100  label offset = 0;
101 
102  forAll(patchIDs_, i)
103  {
104  const polyPatch& pp = patches[patchIDs_[i]];
105 
106  forAll(pp, faceI)
107  {
108  const face& f = pp.localFaces()[faceI];
109 
110  const label fSize = f.size();
111  vertLabels.append(fSize);
112 
113  writeFuns::insert(f + offset, vertLabels);
114 
115  if (fSize == 3)
116  {
117  faceTypes.append(vtkTopo::VTK_TRIANGLE);
118  }
119  else if (fSize == 4)
120  {
121  faceTypes.append(vtkTopo::VTK_QUAD);
122  }
123  else
124  {
125  faceTypes.append(vtkTopo::VTK_POLYGON);
126  }
127  }
128  offset += pp.nPoints();
129  }
130  writeFuns::write(os_, binary_, vertLabels);
131 
132  os_ << "CELL_TYPES " << nFaces_ << std::endl;
133 
134  writeFuns::write(os_, binary_, faceTypes);
135 }
136 
137 
138 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
139 
141 {
142  const fvMesh& mesh = vMesh_.mesh();
143 
144  DynamicList<floatScalar> fField(nFaces_);
145 
146  os_ << "patchID 1 " << nFaces_ << " float" << std::endl;
147 
148  forAll(patchIDs_, i)
149  {
150  label patchI = patchIDs_[i];
151 
152  const polyPatch& pp = mesh.boundaryMesh()[patchI];
153 
154  if (!isA<emptyPolyPatch>(pp))
155  {
156  writeFuns::insert(scalarField(pp.size(), patchI), fField);
157  }
158  }
159  writeFuns::write(os_, binary_, fField);
160 }
161 
162 
163 // ************************ vim: set sw=4 sts=4 et: ************************ //