initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / surfMesh / MeshedSurfaceProxy / MeshedSurfaceProxy.C
blob3eb0c9e40db3297535aad32091daac70ecfb9eba
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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 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
19     for more details.
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 "MeshedSurfaceProxy.H"
29 #include "Time.H"
30 #include "surfMesh.H"
31 #include "OFstream.H"
32 #include "ListOps.H"
34 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
36 template<class Face>
37 Foam::wordHashSet Foam::MeshedSurfaceProxy<Face>::writeTypes()
39     return wordHashSet(*writefileExtensionMemberFunctionTablePtr_);
43 template<class Face>
44 bool Foam::MeshedSurfaceProxy<Face>::canWriteType
46     const word& ext,
47     const bool verbose
50     return checkSupport(writeTypes(), ext, verbose, "writing");
54 template<class Face>
55 void Foam::MeshedSurfaceProxy<Face>::write
57     const fileName& name,
58     const MeshedSurfaceProxy& surf
61     if (debug)
62     {
63         Info<< "MeshedSurfaceProxy::write"
64             "(const fileName&, const MeshedSurfaceProxy&) : "
65             "writing to " << name
66             << endl;
67     }
69     word ext = name.ext();
71     typename writefileExtensionMemberFunctionTable::iterator mfIter =
72         writefileExtensionMemberFunctionTablePtr_->find(ext);
74     if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
75     {
76         FatalErrorIn
77         (
78             "MeshedSurfaceProxy::write(const fileName&)"
79         )   << "Unknown file extension " << ext << nl << nl
80             << "Valid types are :" << endl
81             << writeTypes()
82             << exit(FatalError);
83     }
85     mfIter()(name, surf);
89 template<class Face>
90 void Foam::MeshedSurfaceProxy<Face>::write
92     const Time& t,
93     const word& surfName
94 ) const
96     // the surface name to be used
97     word name(surfName.size() ? surfName : surfaceRegistry::defaultName);
99     if (debug)
100     {
101         Info<< "MeshedSurfaceProxy::write"
102             "(const Time&, const word&) : "
103             "writing to " << name
104             << endl;
105     }
108     // the local location
109     const fileName objectDir
110     (
111         t.timePath()/surfaceRegistry::prefix/name/surfMesh::meshSubDir
112     );
114     if (!isDir(objectDir))
115     {
116         mkDir(objectDir);
117     }
120     // write surfMesh/points
121     {
122         pointIOField io
123         (
124             IOobject
125             (
126                 "points",
127                 t.timeName(),
128                 surfMesh::meshSubDir,
129                 t,
130                 IOobject::NO_READ,
131                 IOobject::NO_WRITE,
132                 false
133             )
134         );
136         OFstream os
137         (
138             objectDir/io.name(),
139             t.writeFormat(),
140             IOstream::currentVersion,
141             t.writeCompression()
142         );
144         io.writeHeader(os);
146         os  << this->points();
148         io.writeEndDivider(os);
149     }
152     // write surfMesh/faces
153     {
154         faceIOList io
155         (
156             IOobject
157             (
158                 "faces",
159                 t.timeName(),
160                 surfMesh::meshSubDir,
161                 t,
162                 IOobject::NO_READ,
163                 IOobject::NO_WRITE,
164                 false
165             )
166         );
168         OFstream os
169         (
170             objectDir/io.name(),
171             t.writeFormat(),
172             IOstream::currentVersion,
173             t.writeCompression()
174         );
175         io.writeHeader(os);
177         if (this->useFaceMap())
178         {
179             // this is really a bit annoying (and wasteful) but no other way
180             os  << reorder(this->faceMap(), this->faces());
181         }
182         else
183         {
184             os  << this->faces();
185         }
187         io.writeEndDivider(os);
188     }
191     // write surfMesh/surfZones
192     {
193         surfZoneIOList io
194         (
195             IOobject
196             (
197                 "surfZones",
198                 t.timeName(),
199                 surfMesh::meshSubDir,
200                 t,
201                 IOobject::NO_READ,
202                 IOobject::NO_WRITE,
203                 false
204             )
205         );
207         // write as ascii
208         OFstream os(objectDir/io.name());
209         io.writeHeader(os);
211         os  << this->surfZones();
213         io.writeEndDivider(os);
214     }
219 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
221 template<class Face>
222 Foam::MeshedSurfaceProxy<Face>::MeshedSurfaceProxy
224     const pointField& pointLst,
225     const List<Face>& faceLst,
226     const List<surfZone>& zoneLst,
227     const List<label>& faceMap
230     points_(pointLst),
231     faces_(faceLst),
232     zones_(zoneLst),
233     faceMap_(faceMap)
237 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
239 template<class Face>
240 Foam::MeshedSurfaceProxy<Face>::~MeshedSurfaceProxy()
244 // ************************************************************************* //