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) 2011 OpenFOAM Foundation
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 "Time.H"
29 #include "surfMesh.H"
30 #include "OFstream.H"
31 #include "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 fileFormats::surfaceFormatsCore::checkSupport
50  (
51  writeTypes(), ext, verbose, "writing"
52  );
53 }
54 
55 
56 template<class Face>
58 (
59  const fileName& name,
60  const MeshedSurfaceProxy& surf
61 )
62 {
63  if (debug)
64  {
65  Info<< "MeshedSurfaceProxy::write"
66  "(const fileName&, const MeshedSurfaceProxy&) : "
67  "writing to " << name
68  << endl;
69  }
70 
71  word ext = name.ext();
72 
73  typename writefileExtensionMemberFunctionTable::iterator mfIter =
74  writefileExtensionMemberFunctionTablePtr_->find(ext);
75 
76  if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
77  {
79  (
80  "MeshedSurfaceProxy::write(const fileName&)"
81  ) << "Unknown file extension " << ext << nl << nl
82  << "Valid types are :" << endl
83  << writeTypes()
84  << exit(FatalError);
85  }
86 
87  mfIter()(name, surf);
88 }
89 
90 
91 template<class Face>
93 (
94  const Time& t,
95  const word& surfName
96 ) const
97 {
98  // the surface name to be used
99  word name(surfName.size() ? surfName : surfaceRegistry::defaultName);
100 
101  if (debug)
102  {
103  Info<< "MeshedSurfaceProxy::write"
104  "(const Time&, const word&) : "
105  "writing to " << name
106  << endl;
107  }
108 
109 
110  // the local location
111  const fileName objectDir
112  (
113  t.timePath()/surfaceRegistry::prefix/name/surfMesh::meshSubDir
114  );
115 
116  if (!isDir(objectDir))
117  {
118  mkDir(objectDir);
119  }
120 
121 
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  );
137 
138  OFstream os
139  (
140  objectDir/io.name(),
141  t.writeFormat(),
142  IOstream::currentVersion,
143  t.writeCompression()
144  );
145 
146  io.writeHeader(os);
147 
148  os << this->points();
149 
150  io.writeEndDivider(os);
151  }
152 
153 
154  // write surfMesh/faces
155  {
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  );
169 
170  OFstream os
171  (
172  objectDir/io.name(),
173  t.writeFormat(),
174  IOstream::currentVersion,
175  t.writeCompression()
176  );
177  io.writeHeader(os);
178 
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  }
188 
189  io.writeEndDivider(os);
190  }
191 
192 
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  );
208 
209  // write as ascii
210  OFstream os(objectDir/io.name());
211  io.writeHeader(os);
212 
213  os << this->surfZones();
214 
215  io.writeEndDivider(os);
216  }
217 
218 }
219 
220 
221 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
222 
223 template<class Face>
225 (
226  const pointField& pointLst,
227  const List<Face>& faceLst,
228  const List<surfZone>& zoneLst,
229  const List<label>& faceMap
230 )
231 :
232  points_(pointLst),
233  faces_(faceLst),
234  zones_(zoneLst),
235  faceMap_(faceMap)
236 {}
237 
238 
239 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
240 
241 template<class Face>
243 {}
244 
245 
246 // ************************************************************************* //
Output to file stream.
Definition: OFstream.H:81
const pointField & points
word ext() const
Return file name extension (part after last .)
Definition: fileName.C:323
HashSet wordHashSet
A HashSet with word keys.
Definition: HashSet.H:207
IOobject for a surfZoneList.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
static void write(const fileName &, const MeshedSurfaceProxy< Face > &)
Write to file.
static wordHashSet writeTypes()
The file format types that can be written via MeshedSurfaceProxy.
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats...
Definition: MeshedSurface.H:73
A class for handling words, derived from string.
Definition: word.H:59
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:741
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Various functions to operate on Lists.
messageStream Info
virtual ~MeshedSurfaceProxy()
Destructor.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
static bool canWriteType(const word &ext, const bool verbose=false)
Can this file format type be written via MeshedSurfaceProxy?
static Stream & writeEndDivider(Stream &os)
Write the standard end file divider.
Definition: IOobjectI.H:108
const word & name() const
Return name.
Definition: IOobject.H:260
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:616
fileName timePath() const
Return current time path.
Definition: Time.H:297
error FatalError
A class for handling file names.
Definition: fileName.H:69
A HashTable with keys but without contents.
Definition: HashSet.H:59
MeshedSurfaceProxy(const pointField &, const List< Face > &, const List< surfZone > &=List< surfZone >(), const List< label > &faceMap=List< label >())
Construct from component references.
bool writeHeader(Ostream &) const
Write header.
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:420
ListType reorder(const labelUList &oldToNew, const ListType &)
Reorder the elements (indices, not values) of a list.