FreeFOAM The Cross-Platform CFD Toolkit
internalWriter.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 "internalWriter.H"
27 #include "writeFuns.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 // Construct from components
33 (
34  const vtkMesh& vMesh,
35  const bool binary,
36  const fileName& fName
37 )
38 :
39  vMesh_(vMesh),
40  binary_(binary),
41  fName_(fName),
42  os_(fName.c_str())
43 {
44  const fvMesh& mesh = vMesh_.mesh();
45  const vtkTopo& topo = vMesh_.topo();
46 
47  // Write header
48  writeFuns::writeHeader(os_, binary_, mesh.time().caseName());
49  os_ << "DATASET UNSTRUCTURED_GRID" << std::endl;
50 
51 
52  //------------------------------------------------------------------
53  //
54  // Write topology
55  //
56  //------------------------------------------------------------------
57 
58  const labelList& addPointCellLabels = topo.addPointCellLabels();
59  const label nTotPoints = mesh.nPoints() + addPointCellLabels.size();
60 
61  os_ << "POINTS " << nTotPoints
62  << " float" << std::endl;
63 
64  DynamicList<floatScalar> ptField(3*nTotPoints);
65 
66  writeFuns::insert(mesh.points(), ptField);
67 
68  const pointField& ctrs = mesh.cellCentres();
69  forAll(addPointCellLabels, api)
70  {
71  writeFuns::insert(ctrs[addPointCellLabels[api]], ptField);
72  }
73  writeFuns::write(os_, binary_, ptField);
74 
75 
76  //
77  // Write cells
78  //
79 
80  const labelListList& vtkVertLabels = topo.vertLabels();
81 
82  // Count total number of vertices referenced.
83  label nFaceVerts = 0;
84 
85  forAll(vtkVertLabels, cellI)
86  {
87  nFaceVerts += vtkVertLabels[cellI].size() + 1;
88  }
89 
90  os_ << "CELLS " << vtkVertLabels.size() << ' ' << nFaceVerts
91  << std::endl;
92 
93 
94  DynamicList<label> vertLabels(nFaceVerts);
95 
96  forAll(vtkVertLabels, cellI)
97  {
98  const labelList& vtkVerts = vtkVertLabels[cellI];
99 
100  vertLabels.append(vtkVerts.size());
101 
102  writeFuns::insert(vtkVerts, vertLabels);
103  }
104  writeFuns::write(os_, binary_, vertLabels);
105 
106 
107 
108  const labelList& vtkCellTypes = topo.cellTypes();
109 
110  os_ << "CELL_TYPES " << vtkCellTypes.size() << std::endl;
111 
112  // Make copy since writing might swap stuff.
113  DynamicList<label> cellTypes(vtkCellTypes.size());
114 
115  writeFuns::insert(vtkCellTypes, cellTypes);
116 
117  writeFuns::write(os_, binary_, cellTypes);
118 }
119 
120 
121 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
122 
124 {
125  const fvMesh& mesh = vMesh_.mesh();
126  const vtkTopo& topo = vMesh_.topo();
127  const labelList& vtkCellTypes = topo.cellTypes();
128  const labelList& superCells = topo.superCells();
129 
130  // Cell ids first
131  os_ << "cellID 1 " << vtkCellTypes.size() << " int"
132  << std::endl;
133 
134  labelList cellId(vtkCellTypes.size());
135  label labelI = 0;
136 
137 
138  if (vMesh_.useSubMesh())
139  {
140  const labelList& cMap = vMesh_.subsetter().cellMap();
141 
142  forAll(mesh.cells(), cellI)
143  {
144  cellId[labelI++] = cMap[cellI];
145  }
146  forAll(superCells, superCellI)
147  {
148  label origCellI = cMap[superCells[superCellI]];
149 
150  cellId[labelI++] = origCellI;
151  }
152  }
153  else
154  {
155  forAll(mesh.cells(), cellI)
156  {
157  cellId[labelI++] = cellI;
158  }
159  forAll(superCells, superCellI)
160  {
161  label origCellI = superCells[superCellI];
162 
163  cellId[labelI++] = origCellI;
164  }
165  }
166 
167  writeFuns::write(os_, binary_, cellId);
168 }
169 
170 
171 // ************************ vim: set sw=4 sts=4 et: ************************ //