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 "STARCDedgeFormat.H"
29 #include "PackedBoolList.H"
30 #include "IStringStream.H"
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 inline void Foam::fileFormats::STARCDedgeFormat::writeLines
40 writeHeader(os, "CELL");
44 const edge& e = edges[edgeI];
45 const label cellId = edgeI + 1;
47 os << cellId // includes 1 offset
48 << ' ' << starcdLineShape_ // 2(line) shape
50 << ' ' << 401 // arbitrary value
51 << ' ' << starcdLineType_; // 5(line)
53 os << nl << " " << cellId << " "
54 << (e[0]+1) << " " << (e[1]+1) << nl;
59 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
61 void Foam::fileFormats::STARCDedgeFormat::writeCase
64 const pointField& pointLst,
68 word caseName = os.name().lessExt().name();
70 os << "! STAR-CD file written " << clock::dateTime().c_str() << nl
71 << "! " << pointLst.size() << " points, " << nEdges << " lines" << nl
72 << "! case " << caseName << nl
73 << "! ------------------------------" << nl;
75 // forAll(zoneLst, zoneI)
77 // os << "ctable " << zoneI + 1 << " line" << nl
78 // << "ctname " << zoneI + 1 << " "
79 // << zoneLst[zoneI].name() << nl;
82 os << "! ------------------------------" << nl
83 << "*set icvo mxv - 1" << nl
84 << "vread " << caseName << ".vrt icvo,,,coded" << nl
85 << "cread " << caseName << ".cel icvo,,,add,coded" << nl
93 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
95 Foam::fileFormats::STARCDedgeFormat::STARCDedgeFormat
97 const fileName& filename
104 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
106 bool Foam::fileFormats::STARCDedgeFormat::read
108 const fileName& filename
113 fileName baseName = filename.lessExt();
115 // STAR-CD index of points
118 // read points from .vrt file
121 IFstream(baseName + ".vrt")(),
126 // Build inverse mapping (STAR-CD pointId -> index)
127 Map<label> mapPointId(2*pointId.size());
130 mapPointId.insert(pointId[i], i);
134 // note which points were really used and which can be culled
135 PackedBoolList usedPoints(points().size());
140 IFstream is(baseName + ".cel");
145 "fileFormats::STARCDedgeFormat::read(const fileName&)"
147 << "Cannot read file " << is.name()
151 readHeader(is, "PROSTAR_CELL");
153 DynamicList<edge> dynEdges;
155 label lineLabel, shapeId, nLabels, cellTableId, typeId;
156 DynamicList<label> vertexLabels(64);
158 while ((is >> lineLabel).good())
160 is >> shapeId >> nLabels >> cellTableId >> typeId;
162 vertexLabels.clear();
163 vertexLabels.reserve(nLabels);
165 // read indices - max 8 per line
166 for (label i = 0; i < nLabels; ++i)
175 // convert original vertex id to point label
176 vertexLabels.append(mapPointId[vrtId]);
179 if (typeId == starcdLineType_)
181 if (vertexLabels.size() >= 2)
183 dynEdges.append(edge(vertexLabels[0], vertexLabels[1]));
185 usedPoints.set(vertexLabels[0]);
186 usedPoints.set(vertexLabels[1]);
193 // not all the points were used, cull them accordingly
194 if (unsigned(points().size()) != usedPoints.count())
198 pointField& pts = storedPoints();
201 if (usedPoints.get(pointI))
205 pts[nUsed] = pts[pointI];
208 // map prev -> new id
209 mapPointId.set(pointI, nUsed);
217 // renumber edge vertices
218 forAll(dynEdges, edgeI)
220 edge& e = dynEdges[edgeI];
222 e[0] = mapPointId[e[0]];
223 e[1] = mapPointId[e[1]];
228 storedEdges().transfer(dynEdges);
234 void Foam::fileFormats::STARCDedgeFormat::write
236 const fileName& filename,
240 const pointField& pointLst = mesh.points();
241 const edgeList& edgeLst = mesh.edges();
243 fileName baseName = filename.lessExt();
245 writePoints(OFstream(baseName + ".vrt")(), pointLst);
246 writeLines(OFstream(baseName + ".cel")(), edgeLst);
248 // write a simple .inp file
251 OFstream(baseName + ".inp")(),
258 // ************************************************************************* //