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-2020 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 #include "OSspecific.H"
33 
34 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
35 
36 template<class Face>
38 {
39  return wordHashSet(*writefileExtensionMemberFunctionTablePtr_);
40 }
41 
42 
43 template<class Face>
45 (
46  const word& ext,
47  const bool verbose
48 )
49 {
50  return fileFormats::surfaceFormatsCore::checkSupport
51  (
52  writeTypes(), ext, verbose, "writing"
53  );
54 }
55 
56 
57 template<class Face>
59 (
60  const fileName& name,
61  const MeshedSurfaceProxy& surf
62 )
63 {
64  if (debug)
65  {
66  InfoInFunction << "Writing to " << name << endl;
67  }
68 
69  word ext = name.ext();
70 
71  typename writefileExtensionMemberFunctionTable::iterator mfIter =
72  writefileExtensionMemberFunctionTablePtr_->find(ext);
73 
74  if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
75  {
77  << "Unknown file extension " << ext << nl << nl
78  << "Valid types are :" << endl
79  << writeTypes()
80  << exit(FatalError);
81  }
82 
83  mfIter()(name, surf);
84 }
85 
86 
87 template<class Face>
89 (
90  const Time& t,
91  const word& surfName
92 ) const
93 {
94  // the surface name to be used
95  word name(surfName.size() ? surfName : surfaceRegistry::defaultName);
96 
97  if (debug)
98  {
99  InfoInFunction << "Writing to " << name << endl;
100  }
101 
102 
103  // The local location
104  const fileName objectDir
105  (
106  t.timePath()/surfaceRegistry::prefix/name/surfMesh::meshSubDir
107  );
108 
109  if (!isDir(objectDir))
110  {
111  mkDir(objectDir);
112  }
113 
114 
115  // write surfMesh/points
116  {
117  pointIOField io
118  (
119  IOobject
120  (
121  "points",
122  t.timeName(),
123  surfMesh::meshSubDir,
124  t,
125  IOobject::NO_READ,
126  IOobject::NO_WRITE,
127  false
128  )
129  );
130 
131  OFstream os
132  (
133  objectDir/io.name(),
134  t.writeFormat(),
135  IOstream::currentVersion,
136  t.writeCompression()
137  );
138 
139  io.writeHeader(os);
140 
141  os << this->points();
142 
143  io.writeEndDivider(os);
144  }
145 
146 
147  // write surfMesh/faces
148  {
150  (
151  IOobject
152  (
153  "faces",
154  t.timeName(),
155  surfMesh::meshSubDir,
156  t,
157  IOobject::NO_READ,
158  IOobject::NO_WRITE,
159  false
160  )
161  );
162 
163  OFstream os
164  (
165  objectDir/io.name(),
166  t.writeFormat(),
167  IOstream::currentVersion,
168  t.writeCompression()
169  );
170  io.writeHeader(os);
171 
172  if (this->useFaceMap())
173  {
174  // this is really a bit annoying (and wasteful) but no other way
175  os << reorder(this->faceMap(), this->faces());
176  }
177  else
178  {
179  os << this->faces();
180  }
181 
182  io.writeEndDivider(os);
183  }
184 
185 
186  // write surfMesh/surfZones
187  {
188  surfZoneIOList io
189  (
190  IOobject
191  (
192  "surfZones",
193  t.timeName(),
194  surfMesh::meshSubDir,
195  t,
196  IOobject::NO_READ,
197  IOobject::NO_WRITE,
198  false
199  )
200  );
201 
202  // write as ascii
203  OFstream os(objectDir/io.name());
204  io.writeHeader(os);
205 
206  os << this->surfZones();
207 
208  io.writeEndDivider(os);
209  }
210 
211 }
212 
213 
214 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
215 
216 template<class Face>
218 (
219  const pointField& pointLst,
220  const List<Face>& faceLst,
221  const List<surfZone>& zoneLst,
222  const List<label>& faceMap
223 )
224 :
225  points_(pointLst),
226  faces_(faceLst),
227  zones_(zoneLst),
228  faceMap_(faceMap)
229 {}
230 
231 
232 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
233 
234 template<class Face>
236 {}
237 
238 
239 // ************************************************************************* //
A HashTable with keys but without contents.
Definition: HashSet.H:59
const word & name() const
Return name.
Definition: IOobject.H:303
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:323
fileName timePath() const
Return current time path.
Definition: Time.H:279
Output to file stream.
Definition: OFstream.H:82
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:636
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:299
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Various functions to operate on Lists.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
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:208
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:260
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:123
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.