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 -------------------------------------------------------------------------------
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 // Field writing implementation
51 #include "rawSurfaceWriterImpl.C"
52 
53 // Field writing methods
55 
56 
57 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
58 
60 :
61  surfaceWriter(),
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 (UPstream::master() || !parallel_)
142  {
143  const pointField& points = surf.points();
144  const faceList& faces = surf.faces();
145  const bool withFaceNormal = (writeNormal_ && !this->isPointData());
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 // ************************************************************************* //
A class for handling file names.
Definition: fileName.H:72
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
A surfaceWriter for raw output.
A simple container for options an IOstream can normally have.
static std::string path(const std::string &str)
Return directory path name (part before last /)
Definition: fileNameI.H:169
word ext() const
Return file name extension (part after last .)
Definition: fileNameI.H:211
Macros for easy insertion into run-time selection tables.
Abstract definition of a meshed surface defined by faces and points.
Definition: meshedSurf.H:43
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:860
List< face > faceList
List of faces.
Definition: faceListFwd.H:39
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
word timeName
Definition: getTimeIndex.H:3
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:614
const pointField & points
defineSurfaceWriterWriteFields(Foam::surfaceWriters::rawWriter)
static void writePoint(Ostream &os, const point &p)
virtual fileName write()
Write surface geometry to file.
OBJstream os(runTime.globalPath()/outputName)
labelList f(nPoints)
Convenience macros for instantiating surfaceWriter methods.
defineTypeName(abaqusWriter)
An IOstream is an abstract base class for all input/output systems; be they streams, files, token lists etc.
Definition: IOstream.H:82
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Definition: UPstream.H:1082
static void writeHeaderArea(Ostream &os)
messageStream Info
Information stream (stdout output on master, null elsewhere)
Base class for surface writers.
rawWriter()
Default construct.
addToRunTimeSelectionTable(surfaceWriter, abaqusWriter, word)
Namespace for OpenFOAM.