OFSsurfaceFormat.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 "OFSsurfaceFormat.H"
00028 #include "IFstream.H"
00029 #include "IStringStream.H"
00030 #include "ListOps.H"
00031
00032
00033
00034 template<class Face>
00035 Foam::fileFormats::OFSsurfaceFormat<Face>::OFSsurfaceFormat
00036 (
00037 const fileName& filename
00038 )
00039 {
00040 read(filename);
00041 }
00042
00043
00044
00045
00046 template<class Face>
00047 bool Foam::fileFormats::OFSsurfaceFormat<Face>::read
00048 (
00049 const fileName& filename
00050 )
00051 {
00052 this->clear();
00053
00054 IFstream is(filename);
00055 if (!is.good())
00056 {
00057 FatalErrorIn
00058 (
00059 "fileFormats::OFSsurfaceFormat::read(const fileName&)"
00060 )
00061 << "Cannot read file " << filename
00062 << exit(FatalError);
00063 }
00064
00065
00066 is >> this->storedZones();
00067
00068
00069 is >> this->storedPoints();
00070
00071
00072 if (MeshedSurface<Face>::isTri())
00073 {
00074
00075 List<face> faceLst(is);
00076
00077 MeshedSurface<face> surf
00078 (
00079 xferMove(this->storedPoints()),
00080 xferMove(faceLst),
00081 xferMove(this->storedZones())
00082 );
00083
00084 this->transcribe(surf);
00085 }
00086 else
00087 {
00088
00089 is >> this->storedFaces();
00090 }
00091
00092 return true;
00093 }
00094
00095
00096 template<class Face>
00097 bool Foam::fileFormats::OFSsurfaceFormat<Face>::read
00098 (
00099 Istream& is,
00100 pointField& pointLst,
00101 List<Face>& faceLst,
00102 List<surfZone>& zoneLst
00103 )
00104 {
00105 if (!is.good())
00106 {
00107 FatalErrorIn
00108 (
00109 "fileFormats::OFSsurfaceFormat::read"
00110 "(Istream&, pointField&, List<Face>&, List<surfZone>&)"
00111 )
00112 << "read error "
00113 << exit(FatalError);
00114 }
00115
00116
00117 is >> zoneLst;
00118
00119
00120 is >> pointLst;
00121
00122
00123 if (MeshedSurface<Face>::isTri())
00124 {
00125
00126 List<face> origFaces(is);
00127
00128 MeshedSurface<face> origSurf
00129 (
00130 xferMove(pointLst),
00131 xferMove(origFaces),
00132 xferMove(zoneLst)
00133 );
00134
00135 MeshedSurface<Face> surf;
00136 surf.transcribe(origSurf);
00137 }
00138 else
00139 {
00140
00141 is >> faceLst;
00142 }
00143
00144 return true;
00145 }
00146
00147
00148 template<class Face>
00149 bool Foam::fileFormats::OFSsurfaceFormat<Face>::read
00150 (
00151 Istream& is,
00152 MeshedSurface<Face>& surf
00153 )
00154 {
00155 surf.clear();
00156
00157 if (!is.good())
00158 {
00159 FatalErrorIn
00160 (
00161 "fileFormats::OFSsurfaceFormat::read"
00162 "(Istream&, MeshedSurface<Face>&)"
00163 )
00164 << "read error "
00165 << exit(FatalError);
00166 }
00167
00168 pointField pointLst;
00169 List<Face> faceLst;
00170 List<surfZone> zoneLst;
00171
00172 read(is, pointLst, faceLst, zoneLst);
00173
00174 surf.reset
00175 (
00176 xferMove(pointLst),
00177 xferMove(faceLst),
00178 xferMove(zoneLst)
00179 );
00180
00181 return true;
00182 }
00183
00184
00185 template<class Face>
00186 bool Foam::fileFormats::OFSsurfaceFormat<Face>::read
00187 (
00188 Istream& is,
00189 UnsortedMeshedSurface<Face>& surf
00190 )
00191 {
00192 surf.clear();
00193 MeshedSurface<Face> origSurf(is);
00194 surf.transfer(origSurf);
00195
00196 return true;
00197 }
00198
00199
00200
00201 template<class Face>
00202 void Foam::fileFormats::OFSsurfaceFormat<Face>::write
00203 (
00204 const fileName& filename,
00205 const MeshedSurfaceProxy<Face>& surf
00206 )
00207 {
00208 const List<Face>& faceLst = surf.faces();
00209 const List<label>& faceMap = surf.faceMap();
00210
00211 OFstream os(filename);
00212 if (!os.good())
00213 {
00214 FatalErrorIn
00215 (
00216 "fileFormats::OFSsurfaceFormat::write"
00217 "(const fileName&, const MeshedSurfaceProxy<Face>&)"
00218 )
00219 << "Cannot open file for writing " << filename
00220 << exit(FatalError);
00221 }
00222
00223
00224 OFSsurfaceFormatCore::writeHeader(os, surf.points(), surf.surfZones());
00225
00226 const List<surfZone>& zones = surf.surfZones();
00227 const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
00228
00229 if (useFaceMap)
00230 {
00231 os << "\n// faces:" << nl
00232 << faceLst.size() << token::BEGIN_LIST << nl;
00233
00234 label faceI = 0;
00235 forAll(zones, zoneI)
00236 {
00237
00238 const surfZone& zone = zones[zoneI];
00239
00240 forAll(zone, localFaceI)
00241 {
00242 os << faceLst[faceMap[faceI++]] << nl;
00243 }
00244 }
00245 os << token::END_LIST << nl;
00246 }
00247 else
00248 {
00249 os << "\n// faces:" << nl << faceLst << nl;
00250 }
00251
00252 IOobject::writeDivider(os);
00253
00254
00255 os.check("OFSsurfaceFormat<Face>::write(Ostream&)");
00256 }
00257
00258
00259
Copyright © 2000-2009 OpenCFD Ltd