proxySurfaceWriter.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 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 "proxySurfaceWriter.H"
30 #include "MeshedSurfaceProxy.H"
31 #include "OSspecific.H"
32 #include "surfaceWriterMethods.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace surfaceWriters
39 {
40  defineTypeName(proxyWriter);
41 }
42 }
43 
44 
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 
48 :
49  surfaceWriter(),
50  fileExtension_(fileExt)
51 {}
52 
53 
55 (
56  const word& fileExt,
57  const dictionary& options
58 )
59 :
60  surfaceWriter(options),
61  fileExtension_(fileExt),
62  options_(options)
63 {}
64 
65 
67 (
68  const meshedSurf& surf,
69  const fileName& outputPath,
70  bool parallel,
71  const dictionary& options
72 )
73 :
74  proxyWriter(outputPath.ext(), options)
75 {
76  surfaceWriter::open(surf, outputPath, parallel);
77 }
78 
79 
81 (
82  const pointField& points,
83  const faceList& faces,
84  const fileName& outputPath,
85  bool parallel,
86  const dictionary& options
87 )
88 :
89  proxyWriter(outputPath.ext(), options)
90 {
91  surfaceWriter::open(points, faces, outputPath, parallel);
92 }
93 
94 
95 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
96 
98 {
99  checkOpen();
100 
101  // Avoid bad values
102  if (fileExtension_.empty())
103  {
104  return fileName::null;
105  }
106 
107  // Geometry: rootdir/<TIME>/surfaceName.{extension}
108 
109  fileName outputFile = outputPath_;
110  if (useTimeDir() && !timeName().empty())
111  {
112  // Splice in time-directory
113  outputFile = outputPath_.path() / timeName() / outputPath_.name();
114  }
115  outputFile.ext(fileExtension_);
116 
117  if (verbose_)
118  {
119  Info<< "Writing geometry to " << outputFile << endl;
120  }
121 
122  const meshedSurf& surf = surface();
123 
124  if (Pstream::master() || !parallel_)
125  {
126  if (!isDir(outputFile.path()))
127  {
128  mkDir(outputFile.path());
129  }
130 
132  (
133  outputFile,
134  fileExtension_,
135  options_
136  );
137  }
138 
139  wroteGeom_ = true;
140  return outputFile;
141 }
142 
143 
144 // Field writing methods
146 
147 
148 // ************************************************************************* //
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
MeshedSurfaceProxy.H
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
proxySurfaceWriter.H
Foam::fileName::path
static std::string path(const std::string &str)
Return directory path name (part before last /)
Definition: fileNameI.H:186
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::surfaceWriters::proxyWriter::write
virtual fileName write()
Write surface geometry to file.
Definition: proxySurfaceWriter.C:97
Foam::surfaceWriters::defineTypeName
defineTypeName(boundaryDataWriter)
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
surfaceWriterMethods.H
Convenience macros for instantiating surfaceWriter methods.
Foam::MeshedSurfaceProxy
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats.
Definition: MeshedSurface.H:78
defineSurfaceWriterWriteFields
defineSurfaceWriterWriteFields(Foam::surfaceWriters::proxyWriter)
Foam::surfaceWriters::proxyWriter
A surfaceWriter that writes the geometry via the MeshedSurfaceProxy, but which does not support any f...
Definition: proxySurfaceWriter.H:69
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.
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
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::fileName::null
static const fileName null
An empty fileName.
Definition: fileName.H:97
Foam::UPstream::master
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:438
Foam::surfaceWriters::proxyWriter::proxyWriter
proxyWriter(const word &fileExt)
Construct for a given extension.
Definition: proxySurfaceWriter.C:47
Foam::List< face >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:35
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::surfaceWriter::open
virtual void open(const fileName &outputPath)
Open for output on specified path, using existing surface.
Definition: surfaceWriter.C:247
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