1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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 "OFSsurfaceFormat.H"
28 #include "IStringStream.H"
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 Foam::fileFormats::OFSsurfaceFormat<Face>::OFSsurfaceFormat
36 const fileName& filename
43 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
46 bool Foam::fileFormats::OFSsurfaceFormat<Face>::read
48 const fileName& filename
53 IFstream is(filename);
58 "fileFormats::OFSsurfaceFormat::read(const fileName&)"
60 << "Cannot read file " << filename
65 is >> this->storedZones();
68 is >> this->storedPoints();
71 if (MeshedSurface<Face>::isTri())
73 // read faces as 'face' and transcribe to 'triFace'
74 List<face> faceLst(is);
76 MeshedSurface<face> surf
78 xferMove(this->storedPoints()),
80 xferMove(this->storedZones())
83 this->transcribe(surf);
87 // read faces directly
88 is >> this->storedFaces();
96 bool Foam::fileFormats::OFSsurfaceFormat<Face>::read
101 List<surfZone>& zoneLst
108 "fileFormats::OFSsurfaceFormat::read"
109 "(Istream&, pointField&, List<Face>&, List<surfZone>&)"
122 if (MeshedSurface<Face>::isTri())
124 // read faces as 'face' and transcribe to 'triFace'
125 List<face> origFaces(is);
127 MeshedSurface<face> origSurf
134 MeshedSurface<Face> surf;
135 surf.transcribe(origSurf);
139 // read faces directly
148 bool Foam::fileFormats::OFSsurfaceFormat<Face>::read
151 MeshedSurface<Face>& surf
160 "fileFormats::OFSsurfaceFormat::read"
161 "(Istream&, MeshedSurface<Face>&)"
169 List<surfZone> zoneLst;
171 read(is, pointLst, faceLst, zoneLst);
185 bool Foam::fileFormats::OFSsurfaceFormat<Face>::read
188 UnsortedMeshedSurface<Face>& surf
192 MeshedSurface<Face> origSurf(is);
193 surf.transfer(origSurf);
201 void Foam::fileFormats::OFSsurfaceFormat<Face>::write
203 const fileName& filename,
204 const MeshedSurfaceProxy<Face>& surf
207 const List<Face>& faceLst = surf.faces();
208 const List<label>& faceMap = surf.faceMap();
210 OFstream os(filename);
215 "fileFormats::OFSsurfaceFormat::write"
216 "(const fileName&, const MeshedSurfaceProxy<Face>&)"
218 << "Cannot open file for writing " << filename
223 OFSsurfaceFormatCore::writeHeader(os, surf.points(), surf.surfZones());
225 const List<surfZone>& zones = surf.surfZones();
226 const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
230 os << "\n// faces:" << nl
231 << faceLst.size() << token::BEGIN_LIST << nl;
236 // Print all faces belonging to this zone
237 const surfZone& zone = zones[zoneI];
239 forAll(zone, localFaceI)
241 os << faceLst[faceMap[faceI++]] << nl;
244 os << token::END_LIST << nl;
248 os << "\n// faces:" << nl << faceLst << nl;
251 IOobject::writeDivider(os);
253 // Check state of Ostream
254 os.check("OFSsurfaceFormat<Face>::write(Ostream&)");
258 // ************************************************************************* //