MeshedSurfaceProxy.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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  InfoInFunction << "Writing to " << name << 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  << "Unknown file extension " << ext << nl << nl
77  << "Valid types are :" << endl
78  << writeTypes()
79  << exit(FatalError);
80  }
81 
82  mfIter()(name, surf);
83 }
84 
85 
86 template<class Face>
88 (
89  const Time& t,
90  const word& surfName
91 ) const
92 {
93  // the surface name to be used
94  word name(surfName.size() ? surfName : surfaceRegistry::defaultName);
95 
96  if (debug)
97  {
98  InfoInFunction << "Writing to " << name << endl;
99  }
100 
101 
102  // The local location
103  const fileName objectDir
104  (
105  t.timePath()/surfaceRegistry::prefix/name/surfMesh::meshSubDir
106  );
107 
108  if (!isDir(objectDir))
109  {
110  mkDir(objectDir);
111  }
112 
113 
114  // write surfMesh/points
115  {
116  pointIOField io
117  (
118  IOobject
119  (
120  "points",
121  t.timeName(),
122  surfMesh::meshSubDir,
123  t,
124  IOobject::NO_READ,
125  IOobject::NO_WRITE,
126  false
127  )
128  );
129 
130  OFstream os
131  (
132  objectDir/io.name(),
133  t.writeFormat(),
134  IOstream::currentVersion,
135  t.writeCompression()
136  );
137 
138  io.writeHeader(os);
139 
140  os << this->points();
141 
142  io.writeEndDivider(os);
143  }
144 
145 
146  // write surfMesh/faces
147  {
149  (
150  IOobject
151  (
152  "faces",
153  t.timeName(),
154  surfMesh::meshSubDir,
155  t,
156  IOobject::NO_READ,
157  IOobject::NO_WRITE,
158  false
159  )
160  );
161 
162  OFstream os
163  (
164  objectDir/io.name(),
165  t.writeFormat(),
166  IOstream::currentVersion,
167  t.writeCompression()
168  );
169  io.writeHeader(os);
170 
171  if (this->useFaceMap())
172  {
173  // this is really a bit annoying (and wasteful) but no other way
174  os << reorder(this->faceMap(), this->faces());
175  }
176  else
177  {
178  os << this->faces();
179  }
180 
181  io.writeEndDivider(os);
182  }
183 
184 
185  // write surfMesh/surfZones
186  {
187  surfZoneIOList io
188  (
189  IOobject
190  (
191  "surfZones",
192  t.timeName(),
193  surfMesh::meshSubDir,
194  t,
195  IOobject::NO_READ,
196  IOobject::NO_WRITE,
197  false
198  )
199  );
200 
201  // write as ascii
202  OFstream os(objectDir/io.name());
203  io.writeHeader(os);
204 
205  os << this->surfZones();
206 
207  io.writeEndDivider(os);
208  }
209 
210 }
211 
212 
213 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
214 
215 template<class Face>
217 (
218  const pointField& pointLst,
219  const List<Face>& faceLst,
220  const List<surfZone>& zoneLst,
221  const List<label>& faceMap
222 )
223 :
224  points_(pointLst),
225  faces_(faceLst),
226  zones_(zoneLst),
227  faceMap_(faceMap)
228 {}
229 
230 
231 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
232 
233 template<class Face>
235 {}
236 
237 
238 // ************************************************************************* //
A HashTable with keys but without contents.
Definition: HashSet.H:59
const word & name() const
Return name.
Definition: IOobject.H:295
A class for handling file names.
Definition: fileName.H:79
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
fileName timePath() const
Return current time path.
Definition: Time.H:282
Output to file stream.
Definition: OFstream.H:82
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:626
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
word ext() const
Return file name extension (part after last .)
Definition: fileName.C:287
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Various functions to operate on Lists.
const pointField & points
bool isDir(const fileName &, const bool followLink=true)
Does the name exist as a directory in the file system?
Definition: POSIX.C:539
A class for handling words, derived from string.
Definition: word.H:59
MeshedSurfaceProxy(const pointField &, const List< Face > &, const List< surfZone > &=List< surfZone >(), const List< label > &faceMap=List< label >())
Construct from component references.
IOobject for a surfZoneList.
HashSet wordHashSet
A HashSet with word keys.
Definition: HashSet.H:205
static bool canWriteType(const word &ext, const bool verbose=false)
Can this file format type be written via MeshedSurfaceProxy?
ListType reorder(const labelUList &oldToNew, const ListType &)
Reorder the elements (indices, not values) of a list.
static const char nl
Definition: Ostream.H:265
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats...
Definition: MeshedSurface.H:73
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:290
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
static Stream & writeEndDivider(Stream &os)
Write the standard end file divider.
Definition: IOobjectI.H:103
static void write(const fileName &, const MeshedSurfaceProxy< Face > &)
Write to file.
bool writeHeader(Ostream &) const
Write header.
virtual ~MeshedSurfaceProxy()
Destructor.
static wordHashSet writeTypes()
The file format types that can be written via MeshedSurfaceProxy.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
A primitive field of type <T> with automated input and output.
Definition: IOField.H:50
#define InfoInFunction
Report an information message using Foam::Info.