1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "STARCDsurfaceFormat.H"
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 inline void Foam::fileFormats::STARCDsurfaceFormat<Face>::writeShell
38 const label cellTableId
41 os << cellId // includes 1 offset
42 << ' ' << starcdShellShape_ // 3(shell) shape
45 << ' ' << starcdShellType_; // 4(shell)
47 // primitives have <= 8 vertices, but prevent overrun anyhow
48 // indent following lines for ease of reading
54 os << nl << " " << cellId;
56 os << ' ' << f[fp] + 1;
63 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
66 Foam::fileFormats::STARCDsurfaceFormat<Face>::STARCDsurfaceFormat
68 const fileName& filename
75 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
78 bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
80 const fileName& filename
83 const bool mustTriangulate = this->isTri();
86 fileName baseName = filename.lessExt();
88 // STAR-CD index of points
91 // read points from .vrt file
94 IFstream(baseName + ".vrt")(),
99 // Build inverse mapping (STAR-CD pointId -> index)
100 Map<label> mapPointId(2*pointId.size());
103 mapPointId.insert(pointId[i], i);
110 IFstream is(baseName + ".cel");
115 "fileFormats::STARCDsurfaceFormat::read(const fileName&)"
117 << "Cannot read file " << is.name()
121 readHeader(is, "PROSTAR_CELL");
123 DynamicList<Face> dynFaces;
124 DynamicList<label> dynZones;
125 DynamicList<word> dynNames;
126 DynamicList<label> dynSizes;
129 // assume the cellTableIds are not intermixed
133 label lineLabel, shapeId, nLabels, cellTableId, typeId;
134 DynamicList<label> vertexLabels(64);
136 while ((is >> lineLabel).good())
138 is >> shapeId >> nLabels >> cellTableId >> typeId;
140 vertexLabels.clear();
141 vertexLabels.reserve(nLabels);
143 // read indices - max 8 per line
144 for (label i = 0; i < nLabels; ++i)
153 // convert original vertex id to point label
154 vertexLabels.append(mapPointId[vrtId]);
157 if (typeId == starcdShellType_)
159 // Convert groupID into zoneID
160 Map<label>::const_iterator fnd = lookup.find(cellTableId);
161 if (fnd != lookup.end())
165 // cellTableIds are intermixed
172 zoneI = dynSizes.size();
173 lookup.insert(cellTableId, zoneI);
174 dynNames.append(word("cellTable_") + ::Foam::name(zoneI));
178 SubList<label> vertices(vertexLabels, vertexLabels.size());
179 if (mustTriangulate && nLabels > 3)
183 faceList triFaces(f.nTriangles());
185 f.triangles(this->points(), nTri, triFaces);
187 forAll(triFaces, faceI)
189 // a triangular face, but not yet a triFace
194 static_cast<UList<label>&>(triFaces[faceI])
197 dynZones.append(zoneI);
203 dynFaces.append(Face(vertices));
204 dynZones.append(zoneI);
211 sortFacesAndStore(dynFaces.xfer(), dynZones.xfer(), sorted);
213 // add zones, culling empty ones
214 this->addZones(dynSizes, dynNames, true);
220 void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
222 const fileName& filename,
223 const MeshedSurfaceProxy<Face>& surf
226 const pointField& pointLst = surf.points();
227 const List<Face>& faceLst = surf.faces();
228 const List<label>& faceMap = surf.faceMap();
230 const List<surfZone>& zones =
232 surf.surfZones().size() > 1
237 const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
240 fileName baseName = filename.lessExt();
242 writePoints(OFstream(baseName + ".vrt")(), pointLst);
243 OFstream os(baseName + ".cel");
244 writeHeader(os, "CELL");
249 const surfZone& zone = zones[zoneI];
253 forAll(zone, localFaceI)
255 const Face& f = faceLst[faceMap[faceIndex++]];
256 writeShell(os, f, faceIndex, zoneI + 1);
261 forAll(zone, localFaceI)
263 const Face& f = faceLst[faceIndex++];
264 writeShell(os, f, faceIndex, zoneI + 1);
269 // write simple .inp file
272 OFstream(baseName + ".inp")(),
280 // ************************************************************************* //