/
patchWriter.C
139 lines (107 loc) · 3.69 KB
/
patchWriter.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "patchWriter.H"
#include "writeFuns.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::patchWriter::patchWriter
(
const vtkMesh& vMesh,
const bool binary,
const bool nearCellValue,
const fileName& fName,
const labelList& patchIDs
)
:
vMesh_(vMesh),
binary_(binary),
nearCellValue_(nearCellValue),
fName_(fName),
patchIDs_(patchIDs),
os_(fName.c_str())
{
const fvMesh& mesh = vMesh_.mesh();
const polyBoundaryMesh& patches = mesh.boundaryMesh();
// Write header
if (patchIDs_.size() == 1)
{
writeFuns::writeHeader(os_, binary_, patches[patchIDs_[0]].name());
}
else
{
writeFuns::writeHeader(os_, binary_, "patches");
}
os_ << "DATASET POLYDATA" << std::endl;
// Write topology
nPoints_ = 0;
nFaces_ = 0;
label nFaceVerts = 0;
forAll(patchIDs_, i)
{
const polyPatch& pp = patches[patchIDs_[i]];
nPoints_ += pp.nPoints();
nFaces_ += pp.size();
forAll(pp, facei)
{
nFaceVerts += pp[facei].size() + 1;
}
}
os_ << "POINTS " << nPoints_ << " float" << std::endl;
DynamicList<floatScalar> ptField(3*nPoints_);
forAll(patchIDs_, i)
{
const polyPatch& pp = patches[patchIDs_[i]];
writeFuns::insert(pp.localPoints(), ptField);
}
writeFuns::write(os_, binary_, ptField);
os_ << "POLYGONS " << nFaces_ << ' ' << nFaceVerts << std::endl;
DynamicList<label> vertLabels(nFaceVerts);
label offset = 0;
forAll(patchIDs_, i)
{
const polyPatch& pp = patches[patchIDs_[i]];
forAll(pp, facei)
{
const face& f = pp.localFaces()[facei];
vertLabels.append(f.size());
writeFuns::insert(f + offset, vertLabels);
}
offset += pp.nPoints();
}
writeFuns::write(os_, binary_, vertLabels);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::patchWriter::writePatchIDs()
{
const fvMesh& mesh = vMesh_.mesh();
DynamicList<floatScalar> fField(nFaces_);
os_ << "patchID 1 " << nFaces_ << " float" << std::endl;
forAll(patchIDs_, i)
{
label patchi = patchIDs_[i];
const polyPatch& pp = mesh.boundaryMesh()[patchi];
if (!isA<emptyPolyPatch>(pp))
{
writeFuns::insert(scalarField(pp.size(), patchi), fField);
}
}
writeFuns::write(os_, binary_, fField);
}
// ************************************************************************* //