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-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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#include "Time.H"
31#include "ListOps.H"
32#include "surfMesh.H"
33#include "OFstream.H"
34#include "faceTraits.H"
35
36// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
37
38template<class Face>
40{
41 return wordHashSet(*writefileExtensionMemberFunctionTablePtr_);
42}
43
44
45template<class Face>
47(
48 const word& fileType,
49 bool verbose
50)
51{
52 return fileFormats::surfaceFormatsCore::checkSupport
53 (
54 writeTypes(),
55 fileType,
56 verbose,
57 "writing"
58 );
59}
60
61
62template<class Face>
64(
65 const fileName& name,
66 const MeshedSurfaceProxy& surf,
67 IOstreamOption streamOpt,
68 const dictionary& options
69)
70{
71 write(name, name.ext(), surf, streamOpt, options);
72}
73
74
75template<class Face>
77(
78 const fileName& name,
79 const word& fileType,
80 const MeshedSurfaceProxy& surf,
81 IOstreamOption streamOpt,
82 const dictionary& options
83)
84{
85 if (fileType.empty())
86 {
87 // Handle empty/missing type
88
89 const word ext(name.ext());
90
91 if (ext.empty())
92 {
94 << "Cannot determine format from filename" << nl
95 << " " << name << nl
96 << exit(FatalError);
97 }
98
99 write(name, ext, surf, streamOpt, options);
100 return;
101 }
102
103
104 DebugInFunction << "Writing to " << name << nl;
105
106 auto* mfuncPtr = writefileExtensionMemberFunctionTable(fileType);
107
108 if (!mfuncPtr)
109 {
111 << "Unknown file type " << fileType << nl << nl
112 << "Valid types:" << nl
113 << flatOutput(writeTypes().sortedToc()) << nl
114 << exit(FatalError);
115 }
116
117 mfuncPtr(name, surf, streamOpt, options);
118}
119
120
121template<class Face>
123(
124 const Time& t,
125 const word& surfName
126) const
127{
128 // the surface name to be used
129 const word name(surfName.size() ? surfName : surfaceRegistry::defaultName);
130
131 DebugInFunction << "Writing to " << name << endl;
132
133
134 // The local location
135 const fileName objectDir
136 (
137 t.timePath()/surfaceRegistry::prefix/name/surfMesh::meshSubDir
138 );
139
140 if (!isDir(objectDir))
141 {
142 mkDir(objectDir);
143 }
144
145
146 // Write surfMesh/points
147 {
149 (
151 (
152 "points",
153 t.timeName(),
154 surfMesh::meshSubDir,
155 t,
156 IOobject::NO_READ,
157 IOobject::NO_WRITE,
158 false
159 )
160 );
161
162 OFstream os(objectDir/io.name(), t.writeStreamOption());
163
164 io.writeHeader(os);
165
166 os << this->points();
167
169 }
170
171
172 // Write surfMesh/faces
173 {
175 (
177 (
178 "faces",
179 t.timeName(),
180 surfMesh::meshSubDir,
181 t,
182 IOobject::NO_READ,
183 IOobject::NO_WRITE,
184 false
185 )
186 );
187
188 OFstream os(objectDir/io.name(), t.writeStreamOption());
189
190 io.writeHeader(os);
191
192 if (this->useFaceMap())
193 {
194 os << UIndirectList<Face>(this->surfFaces(), this->faceMap());
195 }
196 else
197 {
198 os << this->surfFaces();
199 }
200
201 io.writeEndDivider(os);
202 }
203
204
205 // Write surfMesh/surfZones
206 {
208 (
210 (
211 "surfZones",
212 t.timeName(),
213 surfMesh::meshSubDir,
214 t,
215 IOobject::NO_READ,
216 IOobject::NO_WRITE,
217 false
218 )
219 );
220
221 // Write as ASCII-only
222 OFstream os(objectDir/io.name());
223
224 io.writeHeader(os);
225
226 os << this->surfZones();
227
228 io.writeEndDivider(os);
229 }
230}
231
232
233// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
234
235template<class Face>
237(
238 const pointField& pointLst,
239 const UList<Face>& faceLst,
240 const UList<surfZone>& zoneLst,
241 const labelUList& faceMap,
242 const labelUList& faceIdsLst
243)
244:
245 points_(pointLst),
246 faces_(faceLst),
247 zones_(zoneLst),
248 faceMap_(faceMap),
249 faceIds_(faceIdsLst)
250{}
251
252
253// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
254
255template<class Face>
257{
259 {
260 return this->size();
261 }
262
263 label nTri = 0;
264 for (const auto& f : faces_)
265 {
266 nTri += f.nTriangles();
267 }
268
269 return nTri;
270}
271
272
273// ************************************************************************* //
Various functions to operate on Lists.
A primitive field of type <T> with automated input and output.
Definition: IOField.H:58
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
The IOstreamOption is a simple container for options an IOstream can normally have.
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats.
static bool canWriteType(const word &fileType, bool verbose=false)
Can this file format type be written via MeshedSurfaceProxy?
static wordHashSet writeTypes()
The file format types that can be written via MeshedSurfaceProxy.
label nTriangles() const
Count number of triangles.
Output to file stream, using an OSstream.
Definition: OFstream.H:57
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
IOstreamOption writeStreamOption() const
The write stream option (format, compression, version)
Definition: Time.H:381
fileName timePath() const
Return current time path.
Definition: Time.H:375
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Traits class for faces.
Definition: faceTraits.H:51
A class for handling file names.
Definition: fileName.H:76
virtual bool write()
Write the output fields.
IOobject for a surfZoneList.
A class for handling words, derived from Foam::string.
Definition: word.H:68
word ext() const
Return file name extension (part after last .)
Definition: word.C:126
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
OBJstream os(runTime.globalPath()/outputName)
const pointField & points
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
#define DebugInFunction
Report an information message using Foam::Info.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:215
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Definition: MSwindows.C:651
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
runTime write()
labelList f(nPoints)
mkDir(pdfPath)