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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2017 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "MeshedSurfaceProxy.H"
30 
31 #include "Time.H"
32 #include "ListOps.H"
33 #include "surfMesh.H"
34 #include "OFstream.H"
35 #include "faceTraits.H"
36 
37 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
38 
39 template<class Face>
41 {
42  return wordHashSet(*writefileExtensionMemberFunctionTablePtr_);
43 }
44 
45 
46 template<class Face>
48 (
49  const word& ext,
50  const bool verbose
51 )
52 {
53  return fileFormats::surfaceFormatsCore::checkSupport
54  (
55  writeTypes(), ext, verbose, "writing"
56  );
57 }
58 
59 
60 template<class Face>
62 (
63  const fileName& name,
64  const MeshedSurfaceProxy& surf,
65  const dictionary& options
66 )
67 {
68  write(name, name.ext(), surf, options);
69 }
70 
71 
72 template<class Face>
74 (
75  const fileName& name,
76  const word& ext,
77  const MeshedSurfaceProxy& surf,
78  const dictionary& options
79 )
80 {
81  if (debug)
82  {
83  InfoInFunction << "Writing to " << name << endl;
84  }
85 
86  auto mfIter = writefileExtensionMemberFunctionTablePtr_->cfind(ext);
87 
88  if (!mfIter.found())
89  {
91  << "Unknown file extension " << ext << nl << nl
92  << "Valid types:" << nl
93  << flatOutput(writeTypes().sortedToc()) << nl
94  << exit(FatalError);
95  }
96 
97  mfIter()(name, surf, options);
98 }
99 
100 
101 template<class Face>
103 (
104  const Time& t,
105  const word& surfName
106 ) const
107 {
108  // the surface name to be used
109  const word name(surfName.size() ? surfName : surfaceRegistry::defaultName);
110 
111  if (debug)
112  {
113  InfoInFunction << "Writing to " << name << endl;
114  }
115 
116 
117  // The local location
118  const fileName objectDir
119  (
120  t.timePath()/surfaceRegistry::prefix/name/surfMesh::meshSubDir
121  );
122 
123  if (!isDir(objectDir))
124  {
125  mkDir(objectDir);
126  }
127 
128 
129  // write surfMesh/points
130  {
131  pointIOField io
132  (
133  IOobject
134  (
135  "points",
136  t.timeName(),
137  surfMesh::meshSubDir,
138  t,
139  IOobject::NO_READ,
140  IOobject::NO_WRITE,
141  false
142  )
143  );
144 
145  OFstream os
146  (
147  objectDir/io.name(),
148  t.writeFormat(),
149  IOstream::currentVersion,
150  t.writeCompression()
151  );
152 
153  io.writeHeader(os);
154 
155  os << this->points();
156 
157  io.writeEndDivider(os);
158  }
159 
160 
161  // write surfMesh/faces
162  {
164  (
165  IOobject
166  (
167  "faces",
168  t.timeName(),
169  surfMesh::meshSubDir,
170  t,
171  IOobject::NO_READ,
172  IOobject::NO_WRITE,
173  false
174  )
175  );
176 
177  OFstream os
178  (
179  objectDir/io.name(),
180  t.writeFormat(),
181  IOstream::currentVersion,
182  t.writeCompression()
183  );
184  io.writeHeader(os);
185 
186  if (this->useFaceMap())
187  {
188  os << UIndirectList<Face>(this->surfFaces(), this->faceMap());
189  }
190  else
191  {
192  os << this->surfFaces();
193  }
194 
195  io.writeEndDivider(os);
196  }
197 
198 
199  // write surfMesh/surfZones
200  {
201  surfZoneIOList io
202  (
203  IOobject
204  (
205  "surfZones",
206  t.timeName(),
207  surfMesh::meshSubDir,
208  t,
209  IOobject::NO_READ,
210  IOobject::NO_WRITE,
211  false
212  )
213  );
214 
215  // write as ascii
216  OFstream os(objectDir/io.name());
217  io.writeHeader(os);
218 
219  os << this->surfZones();
220 
221  io.writeEndDivider(os);
222  }
223 
224 }
225 
226 
227 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
228 
229 template<class Face>
231 (
232  const pointField& pointLst,
233  const UList<Face>& faceLst,
234  const UList<surfZone>& zoneLst,
235  const labelUList& faceMap
236 )
237 :
238  points_(pointLst),
239  faces_(faceLst),
240  zones_(zoneLst),
241  faceMap_(faceMap)
242 {}
243 
244 
245 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
246 
247 template<class Face>
249 {
251  {
252  return this->size();
253  }
254 
255  label nTri = 0;
256  for (const Face& f : this->surfFaces())
257  {
258  nTri += f.nTriangles();
259  }
260 
261  return nTri;
262 }
263 
264 
265 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
InfoInFunction
#define InfoInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:316
MeshedSurfaceProxy.H
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeFast.C:94
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobjectI.H:46
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: foamVtkLagrangianWriter.H:61
Foam::MeshedSurfaceProxy::nTriangles
label nTriangles() const
Count number of triangles.
Definition: MeshedSurfaceProxy.C:248
Foam::IOobject::writeEndDivider
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
Definition: IOobjectWriteHeader.C:109
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:764
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:48
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::word::ext
word ext() const
Return file name extension (part after last .)
Definition: word.C:126
Foam::HashSet< word >
Foam::MeshedSurfaceProxy
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats.
Definition: MeshedSurface.H:78
OFstream.H
Foam::faceTraits
Traits class for faces.
Definition: faceTraits.H:50
Foam::surfZoneIOList
IOobject for a surfZoneList.
Definition: surfZoneIOList.H:61
Foam::MeshedSurfaceProxy::write
static void write(const fileName &name, const MeshedSurfaceProxy &surf, const dictionary &options)
Write to file, select based on its extension.
Definition: MeshedSurfaceProxy.C:62
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::Field< vector >
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::Time::timePath
fileName timePath() const
Return current time path.
Definition: Time.H:320
Foam::CompactIOList< face, label >
Foam::defaultName
static const word defaultName("coeffs")
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
surfMesh.H
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:99
Time.H
Foam::MeshedSurfaceProxy::writeTypes
static wordHashSet writeTypes()
The file format types that can be written via MeshedSurfaceProxy.
Definition: MeshedSurfaceProxy.C:40
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::flatOutput
FlatOutput< Container > flatOutput(const Container &obj, label len=0)
Global flatOutput function.
Definition: FlatOutput.H:85
f
labelList f(nPoints)
Foam::UList< Face >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:35
Foam::wordHashSet
HashSet< word > wordHashSet
A HashSet with word keys.
Definition: HashSet.H:412
Foam::IOobject::writeHeader
bool writeHeader(Ostream &os) const
Write header.
Definition: IOobjectWriteHeader.C:156
ListOps.H
Various functions to operate on Lists.
faceTraits.H
Foam::mkDir
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
Definition: MSwindows.C:507
Foam::MeshedSurfaceProxy::MeshedSurfaceProxy
MeshedSurfaceProxy(const pointField &pointLst, const UList< Face > &faceLst, const UList< surfZone > &zoneLst=List< surfZone >(), const labelUList &faceMap=labelUList::null())
Construct from component references.
Definition: MeshedSurfaceProxy.C:231
Foam::isDir
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Definition: MSwindows.C:643