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-2020 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
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 anonymous namespace
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  streamOpt_(),
76  geometryScale_(1),
77  fieldScale_()
78 {}
79 
80 
82 (
83  const dictionary& options
84 )
85 :
86  surfaceWriter(options),
87  streamOpt_
88  (
90  IOstream::compressionEnum("compression", options)
91  ),
92  geometryScale_(options.getOrDefault<scalar>("scale", 1)),
93  fieldScale_(options.subOrEmptyDict("fieldScale"))
94 {}
95 
96 
98 (
99  const meshedSurf& surf,
100  const fileName& outputPath,
101  bool parallel,
102  const dictionary& options
103 )
104 :
105  rawWriter(options)
106 {
107  open(surf, outputPath, parallel);
108 }
109 
110 
112 (
113  const pointField& points,
114  const faceList& faces,
115  const fileName& outputPath,
116  bool parallel,
117  const dictionary& options
118 )
119 :
120  rawWriter(options)
121 {
122  open(points, faces, outputPath, parallel);
123 }
124 
125 
126 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
127 
129 {
130  checkOpen();
131 
132  // Geometry: rootdir/<TIME>/surfaceName.raw
133 
134  fileName outputFile = outputPath_;
135  if (useTimeDir() && !timeName().empty())
136  {
137  // Splice in time-directory
138  outputFile = outputPath_.path() / timeName() / outputPath_.name();
139  }
140  outputFile.ext("raw");
141 
142  if (verbose_)
143  {
144  Info<< "Writing geometry to " << outputFile << endl;
145  }
146 
147 
148  const meshedSurf& surf = surface();
149 
150  if (Pstream::master() || !parallel_)
151  {
152  const pointField& points = surf.points();
153  const faceList& faces = surf.faces();
154 
155  if (!isDir(outputFile.path()))
156  {
157  mkDir(outputFile.path());
158  }
159 
160  OFstream os(outputFile, streamOpt_);
161 
162  // Header
163  {
164  os << "# geometry NO_DATA " << faces.size() << nl
165  << "# x y z" << nl;
166  }
167 
168  // Write faces centres
169  for (const face& f : faces)
170  {
171  writePoint(os, f.centre(points)*geometryScale_);
172  os << nl;
173  }
174 
175  os << nl;
176  }
177 
178  wroteGeom_ = true;
179  return outputFile;
180 }
181 
182 
183 // ************************************************************************* //
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::surfaceWriter
Base class for surface writers.
Definition: surfaceWriter.H:111
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
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:186
rawSurfaceWriterImpl.C
Foam::meshedSurf::faces
virtual const faceList & faces() const =0
The faces used for the surface.
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:458
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
surfaceWriterMethods.H
Convenience macros for instantiating surfaceWriter methods.
OFstream.H
Foam::surfaceWriters::addToRunTimeSelectionTable
addToRunTimeSelectionTable(surfaceWriter, abaqusWriter, word)
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
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:118
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: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::dictionary::subOrEmptyDict
dictionary subOrEmptyDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX, const bool mandatory=false) const
Definition: dictionary.C:608
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:53
Foam::IOstreamOption::ASCII
"ascii" (normal default)
Definition: IOstreamOption.H:72
Foam::surfaceWriters::rawWriter::rawWriter
rawWriter()
Default construct.
Definition: rawSurfaceWriter.C:72
Foam::nl
constexpr char nl
Definition: Ostream.H:385
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:72
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:128
Foam::dictionary::getOrDefault
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:122
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