rawSurfaceWriter.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) 2015-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 "rawSurfaceWriter.H"
30#include "OFstream.H"
31#include "OSspecific.H"
34
35// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36
37namespace Foam
38{
39namespace surfaceWriters
40{
44}
45}
46
47
48// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49
50// Field writing implementation
52
53// Field writing methods
55
56
57// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
58
60:
62 streamOpt_(),
63 precision_(IOstream::defaultPrecision()),
64 writeNormal_(false)
65{}
66
67
69(
70 const dictionary& options
71)
72:
73 surfaceWriter(options),
74 streamOpt_
75 (
76 IOstreamOption::ASCII,
77 IOstreamOption::compressionEnum("compression", options)
78 ),
79 precision_
80 (
81 options.getOrDefault("precision", IOstream::defaultPrecision())
82 ),
83 writeNormal_(options.getOrDefault("normal", false))
84{}
85
86
88(
89 const meshedSurf& surf,
90 const fileName& outputPath,
91 bool parallel,
92 const dictionary& options
93)
94:
95 rawWriter(options)
96{
97 open(surf, outputPath, parallel);
98}
99
100
102(
103 const pointField& points,
104 const faceList& faces,
105 const fileName& outputPath,
106 bool parallel,
107 const dictionary& options
108)
109:
110 rawWriter(options)
111{
112 open(points, faces, outputPath, parallel);
113}
114
115
116// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
117
119{
120 checkOpen();
121
122 // Geometry: rootdir/<TIME>/surfaceName.raw
123
124 fileName outputFile = outputPath_;
125 if (useTimeDir() && !timeName().empty())
126 {
127 // Splice in time-directory
128 outputFile = outputPath_.path() / timeName() / outputPath_.name();
129 }
130 outputFile.ext("raw");
131
132 if (verbose_)
133 {
134 Info<< "Writing geometry to " << outputFile << endl;
135 }
136
137
138 // const meshedSurf& surf = surface();
139 const meshedSurfRef& surf = adjustSurface();
140
141 if (Pstream::master() || !parallel_)
142 {
143 const pointField& points = surf.points();
144 const faceList& faces = surf.faces();
145 const bool withFaceNormal = writeNormal_; // Even for point data?
146
147 if (!isDir(outputFile.path()))
148 {
149 mkDir(outputFile.path());
150 }
151
152 OFstream os(outputFile, streamOpt_);
153 os.precision(precision_);
154
155 // Header
156 {
157 os << "# geometry NO_DATA " << faces.size() << nl;
158 os << "# x y z";
159 if (withFaceNormal)
160 {
162 }
163 os << nl;
164 }
165
166 // Write faces centres (optionally faceArea normals)
167 for (const face& f : faces)
168 {
169 writePoint(os, f.centre(points));
170 if (withFaceNormal)
171 {
172 os << ' ';
173 writePoint(os, f.areaNormal(points));
174 }
175 os << nl;
176 }
177
178 os << nl;
179 }
180
181 wroteGeom_ = true;
182 return outputFile;
183}
184
185
186// ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
The IOstreamOption is a simple container for options an IOstream can normally have.
An IOstream is an abstract base class for all input/output systems; be they streams,...
Definition: IOstream.H:82
Output to file stream, using an OSstream.
Definition: OFstream.H:57
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
A class for handling file names.
Definition: fileName.H:76
word ext() const
Return file name extension (part after last .)
Definition: fileNameI.H:218
static std::string path(const std::string &str)
Return directory path name (part before last /)
Definition: fileNameI.H:176
Implements a meshed surface by referencing another meshed surface or faces/points components.
Definition: meshedSurfRef.H:56
virtual const pointField & points() const
The points used for the surface.
virtual const faceList & faces() const
The faces used for the surface.
Abstract definition of a meshed surface defined by faces and points.
Definition: meshedSurf.H:50
splitCell * master() const
Definition: splitCell.H:113
Base class for surface writers.
virtual void open(const fileName &outputPath)
Open for output on specified path, using existing surface.
A surfaceWriter for raw output.
virtual fileName write()
Write surface geometry to file.
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeName(Type)
Define the typeName.
Definition: className.H:96
OBJstream os(runTime.globalPath()/outputName)
const pointField & points
word timeName
Definition: getTimeIndex.H:3
Namespace for OpenFOAM.
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:515
static void writePoint(Ostream &os, const point &p)
messageStream Info
Information stream (stdout output on master, null elsewhere)
static void writeHeaderArea(Ostream &os)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
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
labelList f(nPoints)
Convenience macros for instantiating surfaceWriter methods.
#define defineSurfaceWriterWriteFields(ThisClass)