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-2015 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  << "Unknown file extension " << ext << nl << nl
80  << "Valid types are :" << endl
81  << writeTypes()
82  << exit(FatalError);
83  }
84 
85  mfIter()(name, surf);
86 }
87 
88 
89 template<class Face>
91 (
92  const Time& t,
93  const word& surfName
94 ) const
95 {
96  // the surface name to be used
97  word name(surfName.size() ? surfName : surfaceRegistry::defaultName);
98 
99  if (debug)
100  {
101  Info<< "MeshedSurfaceProxy::write"
102  "(const Time&, const word&) : "
103  "writing to " << name
104  << endl;
105  }
106 
107 
108  // the local location
109  const fileName objectDir
110  (
111  t.timePath()/surfaceRegistry::prefix/name/surfMesh::meshSubDir
112  );
113 
114  if (!isDir(objectDir))
115  {
116  mkDir(objectDir);
117  }
118 
119 
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  );
135 
136  OFstream os
137  (
138  objectDir/io.name(),
139  t.writeFormat(),
140  IOstream::currentVersion,
141  t.writeCompression()
142  );
143 
144  io.writeHeader(os);
145 
146  os << this->points();
147 
148  io.writeEndDivider(os);
149  }
150 
151 
152  // write surfMesh/faces
153  {
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  );
167 
168  OFstream os
169  (
170  objectDir/io.name(),
171  t.writeFormat(),
172  IOstream::currentVersion,
173  t.writeCompression()
174  );
175  io.writeHeader(os);
176 
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  }
186 
187  io.writeEndDivider(os);
188  }
189 
190 
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  );
206 
207  // write as ascii
208  OFstream os(objectDir/io.name());
209  io.writeHeader(os);
210 
211  os << this->surfZones();
212 
213  io.writeEndDivider(os);
214  }
215 
216 }
217 
218 
219 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
220 
221 template<class Face>
223 (
224  const pointField& pointLst,
225  const List<Face>& faceLst,
226  const List<surfZone>& zoneLst,
227  const List<label>& faceMap
228 )
229 :
230  points_(pointLst),
231  faces_(faceLst),
232  zones_(zoneLst),
233  faceMap_(faceMap)
234 {}
235 
236 
237 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
238 
239 template<class Face>
241 {}
242 
243 
244 // ************************************************************************* //
MeshedSurfaceProxy.H
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeFast.C:90
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::reorder
ListType reorder(const labelUList &oldToNew, const ListType &)
Reorder the elements (indices, not values) of a list.
Definition: ListOpsTemplates.C:74
Foam::MeshedSurfaceProxy::write
static void write(const fileName &, const MeshedSurfaceProxy< Face > &)
Write to file.
Foam::MeshedSurfaceProxy::canWriteType
static bool canWriteType(const word &ext, const bool verbose=false)
Can this file format type be written via MeshedSurfaceProxy?
Definition: MeshedSurfaceProxy.C:44
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::MeshedSurfaceProxy::~MeshedSurfaceProxy
virtual ~MeshedSurfaceProxy()
Destructor.
Definition: MeshedSurfaceProxy.C:240
Foam::HashSet
A HashTable with keys but without contents.
Definition: HashSet.H:59
Foam::MeshedSurfaceProxy
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats.
Definition: MeshedSurface.H:73
OFstream.H
Foam::pointIOField
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:42
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::FatalError
error FatalError
surfMesh.H
Foam::isDir
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:615
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::MeshedSurfaceProxy::writeTypes
static wordHashSet writeTypes()
The file format types that can be written via MeshedSurfaceProxy.
Definition: MeshedSurfaceProxy.C:36
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::List< Face >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::MeshedSurfaceProxy::MeshedSurfaceProxy
MeshedSurfaceProxy(const pointField &, const List< Face > &, const List< surfZone > &=List< surfZone >(), const List< label > &faceMap=List< label >())
Construct from component references.
Definition: MeshedSurfaceProxy.C:223
Foam::wordHashSet
HashSet wordHashSet
A HashSet with word keys.
Definition: HashSet.H:207
ListOps.H
Various functions to operate on Lists.
Foam::faceCompactIOList
CompactIOList< face, label > faceCompactIOList
Definition: faceIOList.H:43
Foam::mkDir
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:419
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47