1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. 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 // STAR-CD index of points
90 // read points from .vrt file
93 IFstream(baseName + ".vrt")(),
98 // Build inverse mapping (STAR-CD pointId -> index)
99 Map<label> mapPointId(2*pointId.size());
102 mapPointId.insert(pointId[i], i);
109 IFstream is(baseName + ".cel");
114 "fileFormats::STARCDsurfaceFormat::read(const fileName&)"
116 << "Cannot read file " << is.name()
120 readHeader(is, "PROSTAR_CELL");
122 DynamicList<Face> dynFaces;
123 dynamicLabelList dynZones;
124 DynamicList<word> dynNames;
125 dynamicLabelList dynSizes;
128 // assume the cellTableIds are not intermixed
132 label lineLabel, shapeId, nLabels, cellTableId, typeId;
133 dynamicLabelList vertexLabels(64);
135 while ((is >> lineLabel).good())
137 is >> shapeId >> nLabels >> cellTableId >> typeId;
139 vertexLabels.clear();
140 vertexLabels.reserve(nLabels);
142 // read indices - max 8 per line
143 for (label i = 0; i < nLabels; ++i)
152 // convert original vertex id to point label
153 vertexLabels.append(mapPointId[vrtId]);
156 if (typeId == starcdShellType_)
158 // Convert groupID into zoneID
159 Map<label>::const_iterator fnd = lookup.find(cellTableId);
160 if (fnd != lookup.end())
164 // cellTableIds are intermixed
171 zoneI = dynSizes.size();
172 lookup.insert(cellTableId, zoneI);
173 dynNames.append(word("cellTable_") + ::Foam::name(zoneI));
177 SubList<label> vertices(vertexLabels, vertexLabels.size());
178 if (mustTriangulate && nLabels > 3)
182 faceList triFaces(f.nTriangles());
184 f.triangles(this->points(), nTri, triFaces);
186 forAll(triFaces, faceI)
188 // a triangular face, but not yet a triFace
193 static_cast<UList<label>&>(triFaces[faceI])
196 dynZones.append(zoneI);
202 dynFaces.append(Face(vertices));
203 dynZones.append(zoneI);
210 this->sortFacesAndStore(dynFaces.xfer(), dynZones.xfer(), sorted);
212 // add zones, culling empty ones
213 this->addZones(dynSizes, dynNames, true);
219 void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
221 const fileName& filename,
222 const MeshedSurfaceProxy<Face>& surf
225 const pointField& pointLst = surf.points();
226 const List<Face>& faceLst = surf.faces();
227 const List<label>& faceMap = surf.faceMap();
229 const List<surfZone>& zones =
231 surf.surfZones().size() > 1
233 : STARCDsurfaceFormat::oneZone(faceLst)
236 const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
239 fileName baseName = filename.lessExt();
241 writePoints(OFstream(baseName + ".vrt")(), pointLst);
242 OFstream os(baseName + ".cel");
243 writeHeader(os, "CELL");
248 const surfZone& zone = zones[zoneI];
252 forAll(zone, localFaceI)
254 const Face& f = faceLst[faceMap[faceIndex++]];
255 writeShell(os, f, faceIndex, zoneI + 1);
260 forAll(zone, localFaceI)
262 const Face& f = faceLst[faceIndex++];
263 writeShell(os, f, faceIndex, zoneI + 1);
268 // write simple .inp file
271 OFstream(baseName + ".inp")(),
279 // ************************************************************************* //