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-2021 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  geometryScale_(1),
66  fieldScale_()
67 {}
68 
69 
71 (
72  const dictionary& options
73 )
74 :
75  surfaceWriter(options),
76  streamOpt_
77  (
79  IOstream::compressionEnum("compression", options)
80  ),
81  precision_
82  (
83  options.getOrDefault("precision", IOstream::defaultPrecision())
84  ),
85  writeNormal_(options.getOrDefault("normal", false)),
86  geometryScale_(options.getOrDefault<scalar>("scale", 1)),
87  fieldScale_(options.subOrEmptyDict("fieldScale"))
88 {}
89 
90 
92 (
93  const meshedSurf& surf,
94  const fileName& outputPath,
95  bool parallel,
96  const dictionary& options
97 )
98 :
99  rawWriter(options)
100 {
101  open(surf, outputPath, parallel);
102 }
103 
104 
106 (
107  const pointField& points,
108  const faceList& faces,
109  const fileName& outputPath,
110  bool parallel,
111  const dictionary& options
112 )
113 :
114  rawWriter(options)
115 {
116  open(points, faces, outputPath, parallel);
117 }
118 
119 
120 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
121 
123 {
124  checkOpen();
125 
126  // Geometry: rootdir/<TIME>/surfaceName.raw
127 
128  fileName outputFile = outputPath_;
129  if (useTimeDir() && !timeName().empty())
130  {
131  // Splice in time-directory
132  outputFile = outputPath_.path() / timeName() / outputPath_.name();
133  }
134  outputFile.ext("raw");
135 
136  if (verbose_)
137  {
138  Info<< "Writing geometry to " << outputFile << endl;
139  }
140 
141 
142  const meshedSurf& surf = surface();
143 
144  if (Pstream::master() || !parallel_)
145  {
146  const pointField& points = surf.points();
147  const faceList& faces = surf.faces();
148  const bool withFaceNormal = writeNormal_; // Even for point data?
149 
150  if (!isDir(outputFile.path()))
151  {
152  mkDir(outputFile.path());
153  }
154 
155  OFstream os(outputFile, streamOpt_);
156  os.precision(precision_);
157 
158  // Header
159  {
160  os << "# geometry NO_DATA " << faces.size() << nl;
162  if (withFaceNormal)
163  {
165  }
166  os << nl;
167  }
168 
169  // Write faces centres (optionally faceArea normals)
170  for (const face& f : faces)
171  {
172  writePoint(os, f.centre(points)*geometryScale_);
173  if (withFaceNormal)
174  {
175  os << ' ';
176  writePoint(os, f.areaNormal(points)*geometryScale_);
177  }
178  os << nl;
179  }
180 
181  os << nl;
182  }
183 
184  wroteGeom_ = true;
185  return outputFile;
186 }
187 
188 
189 // ************************************************************************* //
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Foam::surfaceWriter
Base class for surface writers.
Definition: surfaceWriter.H:114
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::surfaceWriters::defineTypeName
defineTypeName(abaqusWriter)
rawSurfaceWriter.H
Foam::fileName::path
static std::string path(const std::string &str)
Return directory path name (part before last /)
Definition: fileNameI.H:176
rawSurfaceWriterImpl.C
Foam::writeHeaderArea
static void writeHeaderArea(Ostream &os)
Definition: rawSurfaceWriterImpl.C:60
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:79
Foam::meshedSurf
Abstract definition of a meshed surface defined by faces and points.
Definition: meshedSurf.H:49
Foam::UPstream::master
static bool master(const label communicator=worldComm)
Am I the master process.
Definition: UPstream.H:457
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::writeHeaderXYZ
static void writeHeaderXYZ(Ostream &os)
Definition: rawSurfaceWriterImpl.C:54
surfaceWriterMethods.H
Convenience macros for instantiating surfaceWriter methods.
OFstream.H
Foam::writePoint
static void writePoint(Ostream &os, const point &p)
Definition: rawSurfaceWriterImpl.C:38
Foam::surfaceWriters::addToRunTimeSelectionTable
addToRunTimeSelectionTable(surfaceWriter, abaqusWriter, word)
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
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:132
timeName
word timeName
Definition: getTimeIndex.H:3
Foam::IOstreamOption::compressionEnum
static compressionType compressionEnum(const word &compName, const compressionType deflt=compressionType::UNCOMPRESSED)
The compression enum corresponding to the string.
Definition: IOstreamOption.C:92
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
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:218
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::dictionary::subOrEmptyDict
dictionary subOrEmptyDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX, const bool mandatory=false) const
Definition: dictionary.C:540
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:53
Foam::IOstream::defaultPrecision
static unsigned int defaultPrecision() noexcept
Return the default precision.
Definition: IOstream.H:342
Foam::IOstreamOption::ASCII
"ascii" (normal default)
Definition: IOstreamOption.H:72
Foam::surfaceWriters::rawWriter::rawWriter
rawWriter()
Default construct.
Definition: rawSurfaceWriter.C:59
Foam::nl
constexpr char nl
Definition: Ostream.H:404
f
labelList f(nPoints)
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:72
Foam::surfaceWriters::rawWriter::write
virtual fileName write()
Write surface geometry to file.
Definition: rawSurfaceWriter.C:122
Foam::dictionary::getOrDefault
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:148
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