00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "NASsurfaceFormat.H"
00028 #include "IFstream.H"
00029 #include "IStringStream.H"
00030
00031
00032
00033 template<class Face>
00034 Foam::fileFormats::NASsurfaceFormat<Face>::NASsurfaceFormat
00035 (
00036 const fileName& filename
00037 )
00038 {
00039 read(filename);
00040 }
00041
00042
00043
00044
00045 template<class Face>
00046 bool Foam::fileFormats::NASsurfaceFormat<Face>::read
00047 (
00048 const fileName& filename
00049 )
00050 {
00051 const bool mustTriangulate = this->isTri();
00052 this->clear();
00053
00054 IFstream is(filename);
00055 if (!is.good())
00056 {
00057 FatalErrorIn
00058 (
00059 "fileFormats::NASsurfaceFormat::read(const fileName&)"
00060 )
00061 << "Cannot read file " << filename
00062 << exit(FatalError);
00063 }
00064
00065
00066 DynamicList<label> pointId;
00067 DynamicList<point> dynPoints;
00068 DynamicList<Face> dynFaces;
00069 DynamicList<label> dynZones;
00070 DynamicList<label> dynSizes;
00071 Map<label> lookup;
00072
00073
00074
00075 bool sorted = true;
00076 label zoneI = 0;
00077
00078
00079 Map<word> nameLookup;
00080
00081
00082
00083
00084
00085 label ansaId = -1;
00086 word ansaType, ansaName;
00087
00088
00089 HashSet<word> unhandledCmd;
00090
00091 while (is.good())
00092 {
00093 string line;
00094 is.getLine(line);
00095
00096
00097 if (line.substr(0, 10) == "$ANSA_NAME")
00098 {
00099 string::size_type sem0 = line.find (';', 0);
00100 string::size_type sem1 = line.find (';', sem0+1);
00101 string::size_type sem2 = line.find (';', sem1+1);
00102
00103 if
00104 (
00105 sem0 != string::npos
00106 && sem1 != string::npos
00107 && sem2 != string::npos
00108 )
00109 {
00110 ansaId = readLabel
00111 (
00112 IStringStream(line.substr(sem0+1, sem1-sem0-1))()
00113 );
00114 ansaType = line.substr(sem1+1, sem2-sem1-1);
00115
00116 string rawName;
00117 is.getLine(rawName);
00118 if (rawName[rawName.size()-1] == '\r')
00119 {
00120 rawName = rawName.substr(1, rawName.size()-2);
00121 }
00122 else
00123 {
00124 rawName = rawName.substr(1, rawName.size()-1);
00125 }
00126
00127 string::stripInvalid<word>(rawName);
00128 ansaName = rawName;
00129
00130
00131
00132
00133 }
00134 }
00135
00136
00137
00138
00139 if
00140 (
00141 line.substr(0, 12) == "$HMNAME COMP"
00142 && line.find ('"') != string::npos
00143 )
00144 {
00145 label groupId = readLabel
00146 (
00147 IStringStream(line.substr(16, 16))()
00148 );
00149
00150 IStringStream lineStream(line.substr(32));
00151
00152 string rawName;
00153 lineStream >> rawName;
00154 string::stripInvalid<word>(rawName);
00155
00156 word groupName(rawName);
00157 nameLookup.insert(groupId, groupName);
00158
00159
00160 }
00161
00162
00163
00164 if (line.empty() || line[0] == '$')
00165 {
00166 continue;
00167 }
00168
00169
00170 if (line.size() > 72 && line[72] == '+')
00171 {
00172 line = line.substr(0, 72);
00173
00174 while (true)
00175 {
00176 string buf;
00177 is.getLine(buf);
00178
00179 if (buf.size() > 72 && buf[72] == '+')
00180 {
00181 line += buf.substr(8, 64);
00182 }
00183 else
00184 {
00185 line += buf.substr(8, buf.size()-8);
00186 break;
00187 }
00188 }
00189 }
00190
00191
00192
00193 IStringStream lineStream(line);
00194 word cmd;
00195 lineStream >> cmd;
00196
00197 if (cmd == "CTRIA3")
00198 {
00199 triFace fTri;
00200
00201 label groupId = readLabel(IStringStream(line.substr(16,8))());
00202 fTri[0] = readLabel(IStringStream(line.substr(24,8))());
00203 fTri[1] = readLabel(IStringStream(line.substr(32,8))());
00204 fTri[2] = readLabel(IStringStream(line.substr(40,8))());
00205
00206
00207 Map<label>::const_iterator fnd = lookup.find(groupId);
00208 if (fnd != lookup.end())
00209 {
00210 if (zoneI != fnd())
00211 {
00212
00213 sorted = false;
00214 }
00215 zoneI = fnd();
00216 }
00217 else
00218 {
00219 zoneI = dynSizes.size();
00220 lookup.insert(groupId, zoneI);
00221 dynSizes.append(0);
00222
00223 }
00224
00225 dynFaces.append(fTri);
00226 dynZones.append(zoneI);
00227 dynSizes[zoneI]++;
00228 }
00229 else if (cmd == "CQUAD4")
00230 {
00231 face fQuad(4);
00232 UList<label>& f = static_cast<UList<label>&>(fQuad);
00233
00234 label groupId = readLabel(IStringStream(line.substr(16,8))());
00235 fQuad[0] = readLabel(IStringStream(line.substr(24,8))());
00236 fQuad[1] = readLabel(IStringStream(line.substr(32,8))());
00237 fQuad[2] = readLabel(IStringStream(line.substr(40,8))());
00238 fQuad[3] = readLabel(IStringStream(line.substr(48,8))());
00239
00240
00241 Map<label>::const_iterator fnd = lookup.find(groupId);
00242 if (fnd != lookup.end())
00243 {
00244 if (zoneI != fnd())
00245 {
00246
00247 sorted = false;
00248 }
00249 zoneI = fnd();
00250 }
00251 else
00252 {
00253 zoneI = dynSizes.size();
00254 lookup.insert(groupId, zoneI);
00255 dynSizes.append(0);
00256
00257 }
00258
00259
00260 if (mustTriangulate)
00261 {
00262 dynFaces.append(triFace(f[0], f[1], f[2]));
00263 dynFaces.append(triFace(f[0], f[2], f[3]));
00264 dynZones.append(zoneI);
00265 dynZones.append(zoneI);
00266 dynSizes[zoneI] += 2;
00267 }
00268 else
00269 {
00270 dynFaces.append(Face(f));
00271 dynZones.append(zoneI);
00272 dynSizes[zoneI]++;
00273 }
00274 }
00275 else if (cmd == "GRID")
00276 {
00277 label index = readLabel(IStringStream(line.substr(8,8))());
00278 scalar x = parseNASCoord(line.substr(24, 8));
00279 scalar y = parseNASCoord(line.substr(32, 8));
00280 scalar z = parseNASCoord(line.substr(40, 8));
00281
00282 pointId.append(index);
00283 dynPoints.append(point(x, y, z));
00284 }
00285 else if (cmd == "GRID*")
00286 {
00287
00288
00289
00290
00291
00292
00293 label index = readLabel(IStringStream(line.substr(8,16))());
00294 scalar x = parseNASCoord(line.substr(40, 16));
00295 scalar y = parseNASCoord(line.substr(56, 16));
00296
00297 is.getLine(line);
00298 if (line[0] != '*')
00299 {
00300 FatalErrorIn
00301 (
00302 "fileFormats::NASsurfaceFormat::read(const fileName&)"
00303 )
00304 << "Expected continuation symbol '*' when reading GRID*"
00305 << " (double precision coordinate) format" << nl
00306 << "Read:" << line << nl
00307 << "File:" << is.name() << " line:" << is.lineNumber()
00308 << exit(FatalError);
00309 }
00310 scalar z = parseNASCoord(line.substr(8, 16));
00311
00312 pointId.append(index);
00313 dynPoints.append(point(x, y, z));
00314 }
00315 else if (cmd == "PSHELL")
00316 {
00317
00318 label groupId = readLabel(IStringStream(line.substr(8,8))());
00319
00320 if (groupId == ansaId && ansaType == "PSHELL")
00321 {
00322 nameLookup.insert(ansaId, ansaName);
00323
00324 }
00325 }
00326 else if (unhandledCmd.insert(cmd))
00327 {
00328 Info<< "Unhandled Nastran command " << line << nl
00329 << "File:" << is.name() << " line:" << is.lineNumber()
00330 << endl;
00331 }
00332 }
00333
00334
00335
00336
00337
00338
00339 this->storedPoints().transfer(dynPoints);
00340
00341 pointId.shrink();
00342 dynFaces.shrink();
00343
00344
00345 Map<label> mapPointId(2*pointId.size());
00346 forAll(pointId, i)
00347 {
00348 mapPointId.insert(pointId[i], i);
00349 }
00350
00351
00352
00353 forAll(dynFaces, i)
00354 {
00355 Face& f = dynFaces[i];
00356 forAll(f, fp)
00357 {
00358 f[fp] = mapPointId[f[fp]];
00359 }
00360 }
00361 pointId.clearStorage();
00362 mapPointId.clear();
00363
00364
00365
00366 List<word> names(dynSizes.size());
00367 forAllConstIter(Map<label>, lookup, iter)
00368 {
00369 const label zoneI = iter();
00370 const label groupI = iter.key();
00371
00372 Map<word>::const_iterator fnd = nameLookup.find(groupI);
00373 if (fnd != nameLookup.end())
00374 {
00375 names[zoneI] = fnd();
00376 }
00377 else
00378 {
00379 names[zoneI] = word("zone") + ::Foam::name(zoneI);
00380 }
00381 }
00382
00383 sortFacesAndStore(dynFaces.xfer(), dynZones.xfer(), sorted);
00384
00385
00386 this->addZones(dynSizes, names, true);
00387
00388 return true;
00389 }
00390
00391
00392