STARCDsurfaceFormat.C
Go to the documentation of this file.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 "STARCDsurfaceFormat.H"
00028 #include "ListOps.H"
00029
00030
00031
00032 template<class Face>
00033 inline void Foam::fileFormats::STARCDsurfaceFormat<Face>::writeShell
00034 (
00035 Ostream& os,
00036 const Face& f,
00037 const label cellId,
00038 const label cellTableId
00039 )
00040 {
00041 os << cellId
00042 << ' ' << starcdShellShape_
00043 << ' ' << f.size()
00044 << ' ' << cellTableId
00045 << ' ' << starcdShellType_;
00046
00047
00048
00049 label count = 0;
00050 forAll(f, fp)
00051 {
00052 if ((count % 8) == 0)
00053 {
00054 os << nl << " " << cellId;
00055 }
00056 os << ' ' << f[fp] + 1;
00057 count++;
00058 }
00059 os << endl;
00060 }
00061
00062
00063
00064
00065 template<class Face>
00066 Foam::fileFormats::STARCDsurfaceFormat<Face>::STARCDsurfaceFormat
00067 (
00068 const fileName& filename
00069 )
00070 {
00071 read(filename);
00072 }
00073
00074
00075
00076
00077 template<class Face>
00078 bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
00079 (
00080 const fileName& filename
00081 )
00082 {
00083 const bool mustTriangulate = this->isTri();
00084 this->clear();
00085
00086 fileName baseName = filename.lessExt();
00087
00088
00089 List<label> pointId;
00090
00091
00092 readPoints
00093 (
00094 IFstream(baseName + ".vrt")(),
00095 this->storedPoints(),
00096 pointId
00097 );
00098
00099
00100 Map<label> mapPointId(2*pointId.size());
00101 forAll(pointId, i)
00102 {
00103 mapPointId.insert(pointId[i], i);
00104 }
00105 pointId.clear();
00106
00107
00108
00109
00110 IFstream is(baseName + ".cel");
00111 if (!is.good())
00112 {
00113 FatalErrorIn
00114 (
00115 "fileFormats::STARCDsurfaceFormat::read(const fileName&)"
00116 )
00117 << "Cannot read file " << is.name()
00118 << exit(FatalError);
00119 }
00120
00121 readHeader(is, "PROSTAR_CELL");
00122
00123 DynamicList<Face> dynFaces;
00124 DynamicList<label> dynZones;
00125 DynamicList<word> dynNames;
00126 DynamicList<label> dynSizes;
00127 Map<label> lookup;
00128
00129
00130 bool sorted = true;
00131 label zoneI = 0;
00132
00133 label lineLabel, shapeId, nLabels, cellTableId, typeId;
00134 DynamicList<label> vertexLabels(64);
00135
00136 while ((is >> lineLabel).good())
00137 {
00138 is >> shapeId >> nLabels >> cellTableId >> typeId;
00139
00140 vertexLabels.clear();
00141 vertexLabels.reserve(nLabels);
00142
00143
00144 for (label i = 0; i < nLabels; ++i)
00145 {
00146 label vrtId;
00147 if ((i % 8) == 0)
00148 {
00149 is >> lineLabel;
00150 }
00151 is >> vrtId;
00152
00153
00154 vertexLabels.append(mapPointId[vrtId]);
00155 }
00156
00157 if (typeId == starcdShellType_)
00158 {
00159
00160 Map<label>::const_iterator fnd = lookup.find(cellTableId);
00161 if (fnd != lookup.end())
00162 {
00163 if (zoneI != fnd())
00164 {
00165
00166 sorted = false;
00167 }
00168 zoneI = fnd();
00169 }
00170 else
00171 {
00172 zoneI = dynSizes.size();
00173 lookup.insert(cellTableId, zoneI);
00174 dynNames.append(word("cellTable_") + ::Foam::name(zoneI));
00175 dynSizes.append(0);
00176 }
00177
00178 SubList<label> vertices(vertexLabels, vertexLabels.size());
00179 if (mustTriangulate && nLabels > 3)
00180 {
00181 face f(vertices);
00182
00183 faceList triFaces(f.nTriangles());
00184 label nTri = 0;
00185 f.triangles(this->points(), nTri, triFaces);
00186
00187 forAll(triFaces, faceI)
00188 {
00189
00190 dynFaces.append
00191 (
00192 triFace
00193 (
00194 static_cast<UList<label>&>(triFaces[faceI])
00195 )
00196 );
00197 dynZones.append(zoneI);
00198 dynSizes[zoneI]++;
00199 }
00200 }
00201 else
00202 {
00203 dynFaces.append(Face(vertices));
00204 dynZones.append(zoneI);
00205 dynSizes[zoneI]++;
00206 }
00207 }
00208 }
00209 mapPointId.clear();
00210
00211 sortFacesAndStore(dynFaces.xfer(), dynZones.xfer(), sorted);
00212
00213
00214 this->addZones(dynSizes, dynNames, true);
00215 return true;
00216 }
00217
00218
00219 template<class Face>
00220 void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
00221 (
00222 const fileName& filename,
00223 const MeshedSurfaceProxy<Face>& surf
00224 )
00225 {
00226 const pointField& pointLst = surf.points();
00227 const List<Face>& faceLst = surf.faces();
00228 const List<label>& faceMap = surf.faceMap();
00229
00230 const List<surfZone>& zones =
00231 (
00232 surf.surfZones().size() > 1
00233 ? surf.surfZones()
00234 : oneZone(faceLst)
00235 );
00236
00237 const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
00238
00239
00240 fileName baseName = filename.lessExt();
00241
00242 writePoints(OFstream(baseName + ".vrt")(), pointLst);
00243 OFstream os(baseName + ".cel");
00244 writeHeader(os, "CELL");
00245
00246 label faceIndex = 0;
00247 forAll(zones, zoneI)
00248 {
00249 const surfZone& zone = zones[zoneI];
00250
00251 if (useFaceMap)
00252 {
00253 forAll(zone, localFaceI)
00254 {
00255 const Face& f = faceLst[faceMap[faceIndex++]];
00256 writeShell(os, f, faceIndex, zoneI + 1);
00257 }
00258 }
00259 else
00260 {
00261 forAll(zone, localFaceI)
00262 {
00263 const Face& f = faceLst[faceIndex++];
00264 writeShell(os, f, faceIndex, zoneI + 1);
00265 }
00266 }
00267 }
00268
00269
00270 writeCase
00271 (
00272 OFstream(baseName + ".inp")(),
00273 pointLst,
00274 faceLst.size(),
00275 zones
00276 );
00277 }
00278
00279
00280
Copyright © 2000-2009 OpenCFD Ltd