FreeFOAM The Cross-Platform CFD Toolkit
MeshedSurfaceProxy.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "MeshedSurfaceProxy.H"
27 
28 #include <OpenFOAM/Time.H>
29 #include <surfMesh/surfMesh.H>
30 #include <OpenFOAM/OFstream.H>
31 #include <OpenFOAM/ListOps.H>
32 
33 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
34 
35 template<class Face>
37 {
38  return wordHashSet(*writefileExtensionMemberFunctionTablePtr_);
39 }
40 
41 
42 template<class Face>
44 (
45  const word& ext,
46  const bool verbose
47 )
48 {
49  return checkSupport(writeTypes(), ext, verbose, "writing");
50 }
51 
52 
53 template<class Face>
55 (
56  const fileName& name,
57  const MeshedSurfaceProxy& surf
58 )
59 {
60  if (debug)
61  {
62  Info<< "MeshedSurfaceProxy::write"
63  "(const fileName&, const MeshedSurfaceProxy&) : "
64  "writing to " << name
65  << endl;
66  }
67 
68  word ext = name.ext();
69 
70  typename writefileExtensionMemberFunctionTable::iterator mfIter =
71  writefileExtensionMemberFunctionTablePtr_->find(ext);
72 
73  if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
74  {
76  (
77  "MeshedSurfaceProxy::write(const fileName&)"
78  ) << "Unknown file extension " << ext << nl << nl
79  << "Valid types are :" << endl
80  << writeTypes()
81  << exit(FatalError);
82  }
83 
84  mfIter()(name, surf);
85 }
86 
87 
88 template<class Face>
90 (
91  const Time& t,
92  const word& surfName
93 ) const
94 {
95  // the surface name to be used
96  word name(surfName.size() ? surfName : surfaceRegistry::defaultName);
97 
98  if (debug)
99  {
100  Info<< "MeshedSurfaceProxy::write"
101  "(const Time&, const word&) : "
102  "writing to " << name
103  << endl;
104  }
105 
106 
107  // the local location
108  const fileName objectDir
109  (
110  t.timePath()/surfaceRegistry::prefix/name/surfMesh::meshSubDir
111  );
112 
113  if (!isDir(objectDir))
114  {
115  mkDir(objectDir);
116  }
117 
118 
119  // write surfMesh/points
120  {
121  pointIOField io
122  (
123  IOobject
124  (
125  "points",
126  t.timeName(),
127  surfMesh::meshSubDir,
128  t,
129  IOobject::NO_READ,
130  IOobject::NO_WRITE,
131  false
132  )
133  );
134 
135  OFstream os
136  (
137  objectDir/io.name(),
138  t.writeFormat(),
139  IOstream::currentVersion,
140  t.writeCompression()
141  );
142 
143  io.writeHeader(os);
144 
145  os << this->points();
146 
147  io.writeEndDivider(os);
148  }
149 
150 
151  // write surfMesh/faces
152  {
153  faceIOList io
154  (
155  IOobject
156  (
157  "faces",
158  t.timeName(),
159  surfMesh::meshSubDir,
160  t,
161  IOobject::NO_READ,
162  IOobject::NO_WRITE,
163  false
164  )
165  );
166 
167  OFstream os
168  (
169  objectDir/io.name(),
170  t.writeFormat(),
171  IOstream::currentVersion,
172  t.writeCompression()
173  );
174  io.writeHeader(os);
175 
176  if (this->useFaceMap())
177  {
178  // this is really a bit annoying (and wasteful) but no other way
179  os << reorder(this->faceMap(), this->faces());
180  }
181  else
182  {
183  os << this->faces();
184  }
185 
186  io.writeEndDivider(os);
187  }
188 
189 
190  // write surfMesh/surfZones
191  {
192  surfZoneIOList io
193  (
194  IOobject
195  (
196  "surfZones",
197  t.timeName(),
198  surfMesh::meshSubDir,
199  t,
200  IOobject::NO_READ,
201  IOobject::NO_WRITE,
202  false
203  )
204  );
205 
206  // write as ascii
207  OFstream os(objectDir/io.name());
208  io.writeHeader(os);
209 
210  os << this->surfZones();
211 
212  io.writeEndDivider(os);
213  }
214 
215 }
216 
217 
218 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
219 
220 template<class Face>
222 (
223  const pointField& pointLst,
224  const List<Face>& faceLst,
225  const List<surfZone>& zoneLst,
226  const List<label>& faceMap
227 )
228 :
229  points_(pointLst),
230  faces_(faceLst),
231  zones_(zoneLst),
232  faceMap_(faceMap)
233 {}
234 
235 
236 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
237 
238 template<class Face>
240 {}
241 
242 
243 // ************************ vim: set sw=4 sts=4 et: ************************ //