Loading...
Searching...
No Matches
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-2024 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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"
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36namespace Foam
37{
38namespace surfaceWriters
39{
41}
42}
43
44
45// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46
50 fileExtension_(fileExt),
51 streamOpt_()
52{}
53
54
56(
57 const word& fileExt,
58 const dictionary& options
59)
60:
61 surfaceWriter(options),
62 fileExtension_(fileExt),
63 streamOpt_
64 (
65 IOstreamOption::formatEnum("format", options, IOstreamOption::ASCII),
66 IOstreamOption::compressionEnum("compression", options)
67 ),
68 options_(options)
69{}
70
71
73(
74 const meshedSurf& surf,
75 const fileName& outputPath,
76 bool parallel,
77 const dictionary& options
78)
80 proxyWriter(outputPath.ext(), options)
81{
82 surfaceWriter::open(surf, outputPath, parallel);
83}
84
85
87(
88 const pointField& points,
89 const faceList& faces,
90 const fileName& outputPath,
91 bool parallel,
92 const dictionary& options
93)
94:
95 proxyWriter(outputPath.ext(), options)
96{
97 surfaceWriter::open(points, faces, outputPath, parallel);
98}
99
100
101// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
102
105{
107 {
108 return autoPtr<surfaceWriter>(new proxyWriter(writeType));
110
111 return nullptr;
112}
113
114
117(
118 const word& writeType,
119 const dictionary& writeOpts
120)
121{
123 {
124 return autoPtr<surfaceWriter>(new proxyWriter(writeType, writeOpts));
125 }
127 return nullptr;
128}
129
130
131// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
132
134{
135 checkOpen();
136
137 // Avoid bad values
138 if (fileExtension_.empty())
139 {
140 return fileName::null;
141 }
142
143 // Geometry: rootdir/<TIME>/surfaceName.{extension}
144
145 fileName outputFile = outputPath_;
146 if (useTimeDir() && !timeName().empty())
147 {
148 // Splice in time-directory
149 outputFile = outputPath_.path() / timeName() / outputPath_.name();
150 }
151 outputFile.ext(fileExtension_);
152
153 if (verbose_)
154 {
155 Info<< "Writing geometry to " << outputFile << endl;
156 }
157
158 // const meshedSurf& surf = surface();
159 const meshedSurfRef& surf = adjustSurface();
160
161 if (UPstream::master() || !parallel_)
162 {
163 if (!isDir(outputFile.path()))
164 {
165 mkDir(outputFile.path());
166 }
167
168 MeshedSurfaceProxy<face>(surf.points(), surf.faces()).write
169 (
170 outputFile,
171 fileExtension_,
172 streamOpt_,
173 options_
174 );
175 }
176
177 wroteGeom_ = true;
178 return outputFile;
179}
180
181
182// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183
184// Field writing methods
185defineSurfaceWriterWriteFields(Foam::surfaceWriters::proxyWriter);
186
187
188// ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
A simple container for options an IOstream can normally have.
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats.
static bool canWriteType(const word &fileType, bool verbose=false)
Can this file format type be written via MeshedSurfaceProxy?
static void write(const fileName &name, const MeshedSurfaceProxy &surf, IOstreamOption streamOpt=IOstreamOption(), const dictionary &options=dictionary::null)
Write to file, select based on its extension.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Definition UPstream.H:1714
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A class for handling file names.
Definition fileName.H:75
static const fileName null
An empty fileName.
Definition fileName.H:111
word ext() const
Return file name extension (part after last .).
Definition fileNameI.H:211
static std::string path(const std::string &str)
Return directory path name (part before last /).
Definition fileNameI.H:169
Implements a meshed surface by referencing another meshed surface or faces/points components.
virtual const pointField & points() const
The points used for the surface.
virtual const faceList & faces() const
The faces used for the surface.
Abstract definition of a meshed surface defined by faces and points.
Definition meshedSurf.H:44
Base class for surface writers.
surfaceWriter()
Default construct.
virtual void open(const fileName &outputPath)
Open for output on specified path, using existing surface.
bool wroteGeom_
Track if geometry has been written since the last open.
bool useTimeDir() const noexcept
Should a time directory be spliced into the output path?
void checkOpen() const
Verify that the outputPath_ has been set or FatalError.
bool parallel_
Writing in parallel (via master).
bool empty() const
The surface to write is empty if the global number of faces is zero.
bool verbose_
Additional output verbosity.
const meshedSurfRef & adjustSurface() const
Merge surfaces (if not upToDate) and return merged (parallel) or regular surface (non-parallel) and a...
fileName outputPath_
The full output directory and file (surface) name.
A surfaceWriter that writes the geometry via the MeshedSurfaceProxy, but which does not support any f...
static autoPtr< surfaceWriter > TryNew(const word &writeType)
Optional select construct proxy writer.
proxyWriter(const word &fileExt)
Construct for a given extension.
virtual fileName write()
Write surface geometry to file.
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeName(Type)
Define the typeName.
Definition className.H:113
const pointField & points
word timeName
Definition getTimeIndex.H:3
Namespace for surface writers.
Namespace for OpenFOAM.
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:616
messageStream Info
Information stream (stdout output on master, null elsewhere).
List< face > faceList
List of faces.
Definition faceListFwd.H:41
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
vectorField pointField
pointField is a vectorField.
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Definition POSIX.C:862
Convenience macros for instantiating surfaceWriter methods.
#define defineSurfaceWriterWriteFields(ThisClass)