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-2019 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 "rawSurfaceWriter.H"
30 #include "OFstream.H"
31 #include "OSspecific.H"
32 #include "surfaceWriterMethods.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 namespace surfaceWriters
40 {
41  defineTypeName(rawWriter);
42  addToRunTimeSelectionTable(surfaceWriter, rawWriter, word);
43  addToRunTimeSelectionTable(surfaceWriter, rawWriter, wordDict);
44 }
45 }
46 
47 
48 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52  // Emit x,y,z
53  static inline void writePoint(Foam::Ostream& os, const Foam::point& p)
54  {
55  os << p.x() << ' ' << p.y() << ' ' << p.z();
56  }
57 
58 } // End namespace Foam
59 
60 
61 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
62 
63 // Field writing implementation
64 #include "rawSurfaceWriterImpl.C"
65 
66 // Field writing methods
68 
69 
70 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
71 
73 :
74  surfaceWriter(),
75  writeCompression_(IOstream::UNCOMPRESSED)
76 {}
77 
78 
80 (
81  const dictionary& options
82 )
83 :
84  surfaceWriter(options),
85  writeCompression_
86  (
88  (
89  options.lookupOrDefault<word>("compression", "false")
90  )
91  )
92 {}
93 
94 
96 (
97  const meshedSurf& surf,
98  const fileName& outputPath,
99  bool parallel,
100  const dictionary& options
101 )
102 :
103  rawWriter(options)
104 {
105  open(surf, outputPath, parallel);
106 }
107 
108 
110 (
111  const pointField& points,
112  const faceList& faces,
113  const fileName& outputPath,
114  bool parallel,
115  const dictionary& options
116 )
117 :
118  rawWriter(options)
119 {
120  open(points, faces, outputPath, parallel);
121 }
122 
123 
124 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
125 
127 {
128  checkOpen();
129 
130  // Geometry: rootdir/<TIME>/surfaceName.raw
131 
132  fileName outputFile = outputPath_;
133  if (useTimeDir() && !timeName().empty())
134  {
135  // Splice in time-directory
136  outputFile = outputPath_.path() / timeName() / outputPath_.name();
137  }
138  outputFile.ext("raw");
139 
140  if (verbose_)
141  {
142  Info<< "Writing geometry to " << outputFile << endl;
143  }
144 
145 
146  const meshedSurf& surf = surface();
147 
148  if (Pstream::master() || !parallel_)
149  {
150  const pointField& points = surf.points();
151  const faceList& faces = surf.faces();
152 
153  if (!isDir(outputFile.path()))
154  {
155  mkDir(outputFile.path());
156  }
157 
158  OFstream os
159  (
160  outputFile,
163  writeCompression_
164  );
165 
166  // Header
167  {
168  os << "# geometry NO_DATA " << faces.size() << nl
169  << "# x y z" << nl;
170  }
171 
172  // Write faces centres
173  for (const face& f : faces)
174  {
175  writePoint(os, f.centre(points));
176  os << nl;
177  }
178 
179  os << nl;
180  }
181 
182  wroteGeom_ = true;
183  return outputFile;
184 }
185 
186 
187 // ************************************************************************* //
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::surfaceWriter
Base class for surface writers.
Definition: surfaceWriter.H:111
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
rawSurfaceWriter.H
Foam::fileName::path
static std::string path(const std::string &str)
Return directory path name (part before last /)
Definition: fileNameI.H:186
rawSurfaceWriterImpl.C
Foam::meshedSurf::faces
virtual const faceList & faces() const =0
The faces used for the surface.
Foam::IOstream
An IOstream is an abstract base class for all input/output systems; be they streams,...
Definition: IOstream.H:75
Foam::IOstreamOption::currentVersion
static const versionNumber currentVersion
The current version number.
Definition: IOstreamOption.H:193
Foam::meshedSurf
Abstract definition of a meshed surface defined by faces and points.
Definition: meshedSurf.H:49
Foam::surfaceWriters::defineTypeName
defineTypeName(boundaryDataWriter)
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::dictionary::lookupOrDefault
T lookupOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionary.H:1241
surfaceWriterMethods.H
Convenience macros for instantiating surfaceWriter methods.
Foam::writePoint
static void writePoint(Foam::Ostream &os, const Foam::point &p)
Definition: rawSurfaceWriter.C:53
OFstream.H
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::IOstreamOption::compressionEnum
static compressionType compressionEnum(const word &compName)
The compression enum corresponding to the string.
Definition: IOstreamOption.C:73
Foam::meshedSurf::points
virtual const pointField & points() const =0
The points used for the surface.
Foam::surfaceWriters::rawWriter
A surfaceWriter for raw output.
Definition: rawSurfaceWriter.H:100
timeName
word timeName
Definition: getTimeIndex.H:3
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::fileName::ext
word ext() const
Return file name extension (part after last .)
Definition: fileNameI.H:228
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:99
Foam::UPstream::master
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:438
Foam::surfaceWriters::addToRunTimeSelectionTable
addToRunTimeSelectionTable(surfaceWriter, boundaryDataWriter, word)
Foam::IOstreamOption::ASCII
"ascii"
Definition: IOstreamOption.H:66
Foam::surfaceWriters::rawWriter::rawWriter
rawWriter()
Construct null.
Definition: rawSurfaceWriter.C:72
Foam::nl
constexpr char nl
Definition: Ostream.H:372
f
labelList f(nPoints)
Foam::Vector< scalar >
Foam::List< face >
defineSurfaceWriterWriteFields
defineSurfaceWriterWriteFields(Foam::surfaceWriters::rawWriter)
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:74
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::surfaceWriters::rawWriter::write
virtual fileName write()
Write surface geometry to file.
Definition: rawSurfaceWriter.C:126
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::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