Loading...
Searching...
No Matches
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-2022 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{
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
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);
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 (
150 IOobject
151 (
152 "points",
153 t.timeName(),
154 surfMesh::meshSubDir,
155 t,
156 IOobjectOption::NO_READ,
157 IOobjectOption::NO_WRITE,
158 IOobjectOption::NO_REGISTER
159 )
160 );
161
162 OFstream os(objectDir/io.name(), t.writeStreamOption());
163
164 io.writeHeader(os);
165
166 os << this->points();
167
168 IOobject::writeEndDivider(os);
169 }
170
171
172 // Write surfMesh/faces
173 {
175 (
176 IOobject
177 (
178 "faces",
179 t.timeName(),
180 surfMesh::meshSubDir,
181 t,
182 IOobjectOption::NO_READ,
183 IOobjectOption::NO_WRITE,
184 IOobjectOption::NO_REGISTER
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 IOobject::writeEndDivider(os);
202 }
203
204
205 // Write surfMesh/surfZones
206 {
207 surfZoneIOList io
208 (
209 IOobject
210 (
211 "surfZones",
212 t.timeName(),
213 surfMesh::meshSubDir,
214 t,
215 IOobjectOption::NO_READ,
216 IOobjectOption::NO_WRITE,
217 IOobjectOption::NO_REGISTER
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 IOobject::writeEndDivider(os);
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>
256inline Foam::label Foam::MeshedSurfaceProxy<Face>::nTriangles() const
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.
@ NO_REGISTER
Do not request registration (bool: false).
@ NO_READ
Nothing to be read.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
A simple container for options an IOstream can normally have.
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats.
const UList< surfZone > & surfZones() const noexcept
Const access to the surface zones.
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.
const UList< Face > & surfFaces() const noexcept
Return const access to the faces.
const labelUList & faceMap() const noexcept
Const access to the faceMap, zero-sized when unused.
MeshedSurfaceProxy(const pointField &pointLst, const UList< Face > &faceLst, const UList< surfZone > &zoneLst=UList< surfZone >::null(), const labelUList &faceMap=labelUList::null(), const labelUList &faceIdLst=labelUList::null())
Construct from component references.
label nTriangles() const
Count number of triangles.
label size() const noexcept
The surface size is the number of faces.
static void write(const fileName &name, const MeshedSurfaceProxy &surf, IOstreamOption streamOpt=IOstreamOption(), const dictionary &options=dictionary::null)
Write to file, select based on its extension.
bool useFaceMap() const noexcept
Can/should use faceMap?
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
Definition OFstream.H:75
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
IOstreamOption writeStreamOption() const noexcept
Get write stream option (format, compression, version).
Definition TimeI.H:116
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
Definition Time.C:714
fileName timePath() const
Return current time path = path/timeName.
Definition Time.H:512
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:89
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
static bool isTri()
Face-type only handles triangles. Not true in general.
Definition faceTraits.H:51
static bool checkSupport(const wordHashSet &available, const word &fileType, const bool verbose=false, const char *functionName=nullptr)
Verbose checking of fileType in the list of available types.
A class for handling file names.
Definition fileName.H:75
static word meshSubDir
Return the mesh sub-directory name (normally "surfMesh").
Definition surfMesh.H:171
IOobject for a surfZoneList.
static const word prefix
The prefix to local: surfaces.
static word defaultName
The default surface name: default.
A class for handling words, derived from Foam::string.
Definition word.H:66
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
OBJstream os(runTime.globalPath()/outputName)
const auto & io
auto & name
const pointField & points
#define DebugInFunction
Report an information message using Foam::Info.
List< label > sortedToc(const UList< bool > &bools)
Return the (sorted) values corresponding to 'true' entries.
Definition BitOps.C:200
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
Definition HashSet.H:80
CompactIOList< face > faceCompactIOList
Compact IO for a List of face.
Definition faceIOList.H:35
vectorIOField pointIOField
pointIOField is a vectorIOField.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition FlatOutput.H:217
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
vectorField pointField
pointField is a vectorField.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
UList< label > labelUList
A UList of labels.
Definition UList.H:75
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Definition POSIX.C:862
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
runTime write()
labelList f(nPoints)
mkDir(pdfPath)