1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "STARCDsurfaceFormat.H"
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 inline void Foam::fileFormats::STARCDsurfaceFormat<Face>::writeShell
37 const label cellTableId
40 os << cellId // includes 1 offset
41 << ' ' << starcdShellShape_ // 3(shell) shape
44 << ' ' << starcdShellType_; // 4(shell)
46 // primitives have <= 8 vertices, but prevent overrun anyhow
47 // indent following lines for ease of reading
53 os << nl << " " << cellId;
55 os << ' ' << f[fp] + 1;
62 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
65 Foam::fileFormats::STARCDsurfaceFormat<Face>::STARCDsurfaceFormat
67 const fileName& filename
74 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
77 bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
79 const fileName& filename
82 const bool mustTriangulate = this->isTri();
85 fileName baseName = filename.lessExt();
87 // read cellTable names (if possible)
88 Map<word> cellTableLookup;
91 IFstream is(baseName + ".inp");
94 cellTableLookup = readInpCellTable(is);
99 // STAR-CD index of points
102 // read points from .vrt file
105 IFstream(baseName + ".vrt")(),
106 this->storedPoints(),
110 // Build inverse mapping (STAR-CD pointId -> index)
111 Map<label> mapPointId(2*pointId.size());
114 mapPointId.insert(pointId[i], i);
121 IFstream is(baseName + ".cel");
126 "fileFormats::STARCDsurfaceFormat::read(const fileName&)"
128 << "Cannot read file " << is.name()
132 readHeader(is, "PROSTAR_CELL");
134 DynamicList<Face> dynFaces;
135 DynamicList<label> dynZones;
136 DynamicList<word> dynNames;
137 DynamicList<label> dynSizes;
140 // assume the cellTableIds are not intermixed
144 label lineLabel, shapeId, nLabels, cellTableId, typeId;
145 DynamicList<label> vertexLabels(64);
147 while ((is >> lineLabel).good())
149 is >> shapeId >> nLabels >> cellTableId >> typeId;
151 vertexLabels.clear();
152 vertexLabels.reserve(nLabels);
154 // read indices - max 8 per line
155 for (label i = 0; i < nLabels; ++i)
164 // convert original vertex id to point label
165 vertexLabels.append(mapPointId[vrtId]);
168 if (typeId == starcdShellType_)
170 // Convert groupID into zoneID
171 Map<label>::const_iterator fnd = lookup.find(cellTableId);
172 if (fnd != lookup.end())
176 // cellTableIds are intermixed
183 zoneI = dynSizes.size();
184 lookup.insert(cellTableId, zoneI);
186 Map<word>::const_iterator tableNameIter =
187 cellTableLookup.find(cellTableId);
189 if (tableNameIter == cellTableLookup.end())
193 word("cellTable_") + ::Foam::name(cellTableId)
198 dynNames.append(tableNameIter());
204 SubList<label> vertices(vertexLabels, vertexLabels.size());
205 if (mustTriangulate && nLabels > 3)
209 faceList triFaces(f.nTriangles());
211 f.triangles(this->points(), nTri, triFaces);
213 forAll(triFaces, faceI)
215 // a triangular face, but not yet a triFace
220 static_cast<labelUList&>(triFaces[faceI])
223 dynZones.append(zoneI);
229 dynFaces.append(Face(vertices));
230 dynZones.append(zoneI);
237 this->sortFacesAndStore(dynFaces.xfer(), dynZones.xfer(), sorted);
239 // add zones, culling empty ones
240 this->addZones(dynSizes, dynNames, true);
246 void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
248 const fileName& filename,
249 const MeshedSurfaceProxy<Face>& surf
252 const pointField& pointLst = surf.points();
253 const List<Face>& faceLst = surf.faces();
254 const List<label>& faceMap = surf.faceMap();
256 const List<surfZone>& zones =
258 surf.surfZones().empty()
259 ? surfaceFormatsCore::oneZone(faceLst)
263 const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
266 fileName baseName = filename.lessExt();
268 writePoints(OFstream(baseName + ".vrt")(), pointLst);
269 OFstream os(baseName + ".cel");
270 writeHeader(os, "CELL");
275 const surfZone& zone = zones[zoneI];
279 forAll(zone, localFaceI)
281 const Face& f = faceLst[faceMap[faceIndex++]];
282 writeShell(os, f, faceIndex, zoneI + 1);
287 forAll(zone, localFaceI)
289 const Face& f = faceLst[faceIndex++];
290 writeShell(os, f, faceIndex, zoneI + 1);
295 // write simple .inp file
298 OFstream(baseName + ".inp")(),
306 // ************************************************************************* //