1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "OFSsurfaceFormat.H"
29 #include "IStringStream.H"
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 Foam::fileFormats::OFSsurfaceFormat<Face>::OFSsurfaceFormat
37 const fileName& filename
44 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
47 bool Foam::fileFormats::OFSsurfaceFormat<Face>::read
49 const fileName& filename
54 IFstream is(filename);
59 "fileFormats::OFSsurfaceFormat::read(const fileName&)"
61 << "Cannot read file " << filename
66 is >> this->storedZones();
69 is >> this->storedPoints();
72 if (MeshedSurface<Face>::isTri())
74 // read faces as 'face' and transcribe to 'triFace'
75 List<face> faceLst(is);
77 MeshedSurface<face> surf
79 xferMove(this->storedPoints()),
81 xferMove(this->storedZones())
84 this->transcribe(surf);
88 // read faces directly
89 is >> this->storedFaces();
97 bool Foam::fileFormats::OFSsurfaceFormat<Face>::read
100 pointField& pointLst,
102 List<surfZone>& zoneLst
109 "fileFormats::OFSsurfaceFormat::read"
110 "(Istream&, pointField&, List<Face>&, List<surfZone>&)"
123 if (MeshedSurface<Face>::isTri())
125 // read faces as 'face' and transcribe to 'triFace'
126 List<face> origFaces(is);
128 MeshedSurface<face> origSurf
135 MeshedSurface<Face> surf;
136 surf.transcribe(origSurf);
140 // read faces directly
149 bool Foam::fileFormats::OFSsurfaceFormat<Face>::read
152 MeshedSurface<Face>& surf
161 "fileFormats::OFSsurfaceFormat::read"
162 "(Istream&, MeshedSurface<Face>&)"
170 List<surfZone> zoneLst;
172 read(is, pointLst, faceLst, zoneLst);
186 bool Foam::fileFormats::OFSsurfaceFormat<Face>::read
189 UnsortedMeshedSurface<Face>& surf
193 MeshedSurface<Face> origSurf(is);
194 surf.transfer(origSurf);
202 void Foam::fileFormats::OFSsurfaceFormat<Face>::write
204 const fileName& filename,
205 const MeshedSurfaceProxy<Face>& surf
208 const List<Face>& faceLst = surf.faces();
209 const List<label>& faceMap = surf.faceMap();
211 OFstream os(filename);
216 "fileFormats::OFSsurfaceFormat::write"
217 "(const fileName&, const MeshedSurfaceProxy<Face>&)"
219 << "Cannot open file for writing " << filename
224 OFSsurfaceFormatCore::writeHeader(os, surf.points(), surf.surfZones());
226 const List<surfZone>& zones = surf.surfZones();
227 const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
231 os << "\n// faces:" << nl
232 << faceLst.size() << token::BEGIN_LIST << nl;
237 // Print all faces belonging to this zone
238 const surfZone& zone = zones[zoneI];
240 forAll(zone, localFaceI)
242 os << faceLst[faceMap[faceI++]] << nl;
245 os << token::END_LIST << nl;
249 os << "\n// faces:" << nl << faceLst << nl;
252 IOobject::writeDivider(os);
254 // Check state of Ostream
255 os.check("OFSsurfaceFormat<Face>::write(Ostream&)");
259 // ************************************************************************* //