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