1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2009-2010 OpenCFD Ltd.
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 "NASedgeFormat.H"
28 #include "IStringStream.H"
29 #include "PackedBoolList.H"
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 Foam::fileFormats::NASedgeFormat::NASedgeFormat
35 const fileName& filename
42 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
44 bool Foam::fileFormats::NASedgeFormat::read
46 const fileName& filename
51 IFstream is(filename);
56 "fileFormats::NASedgeFormat::read(const fileName&)"
58 << "Cannot read file " << filename
62 DynamicList<point> dynPoints;
63 DynamicList<edge> dynEdges;
64 DynamicList<label> pointId; // Nastran index of points
71 // Skip empty or comment
72 if (line.empty() || line[0] == '$')
77 // Check if character 72 is continuation
78 if (line.size() > 72 && line[72] == '+')
80 line = line.substr(0, 72);
87 if (buf.size() > 72 && buf[72] == '+')
89 line += buf.substr(8, 64);
93 line += buf.substr(8, buf.size()-8);
101 IStringStream lineStream(line);
105 if (cmd == "CBEAM" || cmd == "CROD")
109 // label groupId = readLabel(IStringStream(line.substr(16,8))());
110 e[0] = readLabel(IStringStream(line.substr(24,8))());
111 e[1] = readLabel(IStringStream(line.substr(32,8))());
116 else if (cmd == "GRID")
118 label index = readLabel(IStringStream(line.substr(8,8))());
119 scalar x = parseNASCoord(line.substr(24, 8));
120 scalar y = parseNASCoord(line.substr(32, 8));
121 scalar z = parseNASCoord(line.substr(40, 8));
123 pointId.append(index);
124 dynPoints.append(point(x, y, z));
126 else if (cmd == "GRID*")
128 // Long format is on two lines with '*' continuation symbol
129 // on start of second line.
130 // Typical line (spaces compacted)
131 // GRID* 126 0 -5.55999875E+02 -5.68730474E+02
134 label index = readLabel(IStringStream(line.substr(8,16))());
135 scalar x = parseNASCoord(line.substr(40, 16));
136 scalar y = parseNASCoord(line.substr(56, 16));
143 "fileFormats::NASedgeFormat::read(const fileName&)"
145 << "Expected continuation symbol '*' when reading GRID*"
146 << " (double precision coordinate) format" << nl
147 << "Read:" << line << nl
148 << "File:" << is.name() << " line:" << is.lineNumber()
151 scalar z = parseNASCoord(line.substr(8, 16));
153 pointId.append(index);
154 dynPoints.append(point(x, y, z));
158 // transfer to normal lists
159 storedPoints().transfer(dynPoints);
164 // Build inverse mapping (NASTRAN pointId -> index)
165 Map<label> mapPointId(2*pointId.size());
168 mapPointId.insert(pointId[i], i);
171 // note which points were really used and which can be culled
172 PackedBoolList usedPoints(points().size());
175 // Pass1: relabel edges
176 // ~~~~~~~~~~~~~~~~~~~~
179 edge& e = dynEdges[i];
180 e[0] = mapPointId[e[0]];
181 e[1] = mapPointId[e[1]];
183 usedPoints.set(e[0]);
184 usedPoints.set(e[1]);
186 pointId.clearStorage();
189 // not all the points were used, cull them accordingly
190 if (unsigned(points().size()) != usedPoints.count())
194 pointField& pts = storedPoints();
197 if (usedPoints.get(pointI))
201 pts[nUsed] = pts[pointI];
204 // map prev -> new id
205 mapPointId[pointI] = nUsed;
213 // renumber edge vertices
214 forAll(dynEdges, edgeI)
216 edge& e = dynEdges[edgeI];
218 e[0] = mapPointId[e[0]];
219 e[1] = mapPointId[e[1]];
224 // transfer to normal lists
225 storedEdges().transfer(dynEdges);
231 // ************************************************************************* //