Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / surfMesh / MeshedSurfaceProxy / MeshedSurfaceProxy.C
blobe5d1f454b30becbe7eb396d17c0d172d22381c9e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2009-2010 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 "MeshedSurfaceProxy.H"
28 #include "Time.H"
29 #include "surfMesh.H"
30 #include "OFstream.H"
31 #include "ListOps.H"
33 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
35 template<class Face>
36 Foam::wordHashSet Foam::MeshedSurfaceProxy<Face>::writeTypes()
38     return wordHashSet(*writefileExtensionMemberFunctionTablePtr_);
42 template<class Face>
43 bool Foam::MeshedSurfaceProxy<Face>::canWriteType
45     const word& ext,
46     const bool verbose
49     return fileFormats::surfaceFormatsCore::checkSupport
50     (
51         writeTypes(), ext, verbose, "writing"
52     );
56 template<class Face>
57 void Foam::MeshedSurfaceProxy<Face>::write
59     const fileName& name,
60     const MeshedSurfaceProxy& surf
63     if (debug)
64     {
65         Info<< "MeshedSurfaceProxy::write"
66             "(const fileName&, const MeshedSurfaceProxy&) : "
67             "writing to " << name
68             << endl;
69     }
71     word ext = name.ext();
73     typename writefileExtensionMemberFunctionTable::iterator mfIter =
74         writefileExtensionMemberFunctionTablePtr_->find(ext);
76     if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
77     {
78         FatalErrorIn
79         (
80             "MeshedSurfaceProxy::write(const fileName&)"
81         )   << "Unknown file extension " << ext << nl << nl
82             << "Valid types are :" << endl
83             << writeTypes()
84             << exit(FatalError);
85     }
87     mfIter()(name, surf);
91 template<class Face>
92 void Foam::MeshedSurfaceProxy<Face>::write
94     const Time& t,
95     const word& surfName
96 ) const
98     // the surface name to be used
99     word name(surfName.size() ? surfName : surfaceRegistry::defaultName);
101     if (debug)
102     {
103         Info<< "MeshedSurfaceProxy::write"
104             "(const Time&, const word&) : "
105             "writing to " << name
106             << endl;
107     }
110     // the local location
111     const fileName objectDir
112     (
113         t.timePath()/surfaceRegistry::prefix/name/surfMesh::meshSubDir
114     );
116     if (!isDir(objectDir))
117     {
118         mkDir(objectDir);
119     }
122     // write surfMesh/points
123     {
124         pointIOField io
125         (
126             IOobject
127             (
128                 "points",
129                 t.timeName(),
130                 surfMesh::meshSubDir,
131                 t,
132                 IOobject::NO_READ,
133                 IOobject::NO_WRITE,
134                 false
135             )
136         );
138         OFstream os
139         (
140             objectDir/io.name(),
141             t.writeFormat(),
142             IOstream::currentVersion,
143             t.writeCompression()
144         );
146         io.writeHeader(os);
148         os  << this->points();
150         io.writeEndDivider(os);
151     }
154     // write surfMesh/faces
155     {
156         faceCompactIOList io
157         (
158             IOobject
159             (
160                 "faces",
161                 t.timeName(),
162                 surfMesh::meshSubDir,
163                 t,
164                 IOobject::NO_READ,
165                 IOobject::NO_WRITE,
166                 false
167             )
168         );
170         OFstream os
171         (
172             objectDir/io.name(),
173             t.writeFormat(),
174             IOstream::currentVersion,
175             t.writeCompression()
176         );
177         io.writeHeader(os);
179         if (this->useFaceMap())
180         {
181             // this is really a bit annoying (and wasteful) but no other way
182             os  << reorder(this->faceMap(), this->faces());
183         }
184         else
185         {
186             os  << this->faces();
187         }
189         io.writeEndDivider(os);
190     }
193     // write surfMesh/surfZones
194     {
195         surfZoneIOList io
196         (
197             IOobject
198             (
199                 "surfZones",
200                 t.timeName(),
201                 surfMesh::meshSubDir,
202                 t,
203                 IOobject::NO_READ,
204                 IOobject::NO_WRITE,
205                 false
206             )
207         );
209         // write as ascii
210         OFstream os(objectDir/io.name());
211         io.writeHeader(os);
213         os  << this->surfZones();
215         io.writeEndDivider(os);
216     }
221 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
223 template<class Face>
224 Foam::MeshedSurfaceProxy<Face>::MeshedSurfaceProxy
226     const pointField& pointLst,
227     const List<Face>& faceLst,
228     const List<surfZone>& zoneLst,
229     const List<label>& faceMap
232     points_(pointLst),
233     faces_(faceLst),
234     zones_(zoneLst),
235     faceMap_(faceMap)
239 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
241 template<class Face>
242 Foam::MeshedSurfaceProxy<Face>::~MeshedSurfaceProxy()
246 // ************************************************************************* //