boundaryDataSurfaceWriter.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) 2015 OpenFOAM Foundation
9 Copyright (C) 2015-2022 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
30#include "argList.H"
31#include "OFstream.H"
32#include "OSspecific.H"
33#include "IOmanip.H"
34#include "Time.H"
35#include "pointIOField.H"
36#include "primitivePatch.H"
39
40// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
41
42namespace Foam
43{
44namespace surfaceWriters
45{
49}
50}
51
52
53// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
54
56:
58 header_(true),
59 streamOpt_()
60{}
61
62
64(
65 const dictionary& options
66)
67:
68 surfaceWriter(options),
69 header_(options.getOrDefault("header", true)),
70 streamOpt_
71 (
72 IOstreamOption::formatEnum("format", options, IOstreamOption::ASCII),
73 IOstreamOption::compressionEnum("compression", options)
74 )
75{}
76
77
79(
80 const meshedSurf& surf,
81 const fileName& outputPath,
82 bool parallel,
83 const dictionary& options
84)
85:
86 boundaryDataWriter(options)
87{
88 open(surf, outputPath, parallel);
89}
90
91
93(
94 const pointField& points,
95 const faceList& faces,
96 const fileName& outputPath,
97 bool parallel,
98 const dictionary& options
99)
100:
101 boundaryDataWriter(options)
102{
103 open(points, faces, outputPath, parallel);
104}
105
106
107// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
108
109void Foam::surfaceWriters::boundaryDataWriter::serialWriteGeometry
110(
111 const regIOobject& iopts,
112 const meshedSurf& surf
113)
114{
115 const pointField& points = surf.points();
116 const faceList& faces = surf.faces();
117
118 if (verbose_)
119 {
120 if (this->isPointData())
121 {
122 Info<< "Writing points: " << iopts.objectPath() << endl;
123 }
124 else
125 {
126 Info<< "Writing face centres: " << iopts.objectPath() << endl;
127 }
128 }
129
130 // Like regIOobject::writeObject without instance() adaptation
131 // since this would write to e.g. 0/ instead of postProcessing/
132
133 OFstream osGeom(iopts.objectPath(), streamOpt_);
134
135 if (header_)
136 {
137 iopts.writeHeader(osGeom);
138 }
139
140 if (this->isPointData())
141 {
142 // Just like writeData, but without copying beforehand
143 osGeom << points;
144 }
145 else
146 {
147 primitivePatch pp(SubList<face>(faces), points);
148
149 // Just like writeData, but without copying beforehand
150 osGeom << pp.faceCentres();
151 }
152
153 if (header_)
154 {
155 iopts.writeEndDivider(osGeom);
156 }
157}
158
159
161{
162 checkOpen();
163
164 // Geometry: rootdir/surfaceName/"points"
165 // Field: rootdir/surfaceName/<TIME>/field
166
167 fileName surfaceDir = outputPath_;
168
169 // Dummy Time to use as objectRegistry
171
172 // const meshedSurf& surf = surface();
173 const meshedSurfRef& surf = adjustSurface();
174
175 if (Pstream::master() || !parallel_)
176 {
177 if (!isDir(surfaceDir))
178 {
179 mkDir(surfaceDir);
180 }
181
182 // Write sample locations
183 pointIOField iopts
184 (
186 (
187 surfaceDir/"points",
188 *dummyTimePtr,
191 false
192 )
193 );
194 iopts.note() = (this->isPointData() ? "point data" : "face data");
195
196 serialWriteGeometry(iopts, surf);
197 }
198
199 wroteGeom_ = true;
200 return surfaceDir;
201}
202
203
204// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205
206template<class Type>
207Foam::fileName Foam::surfaceWriters::boundaryDataWriter::writeTemplate
208(
209 const word& fieldName,
210 const Field<Type>& localValues
211)
212{
213 checkOpen();
214
215 // Geometry: rootdir/surfaceName/"points"
216 // Field: rootdir/surfaceName/<TIME>/field
217
218 fileName surfaceDir = outputPath_;
219
220 const fileName outputFile(surfaceDir/timeName()/fieldName);
221
222 // Implicit geometry merge()
223 tmp<Field<Type>> tfield = adjustField(fieldName, mergeField(localValues));
224
225 if (verbose_)
226 {
227 Info<< " to " << outputFile << endl;
228 }
229
230
231 // Dummy Time to use as objectRegistry
233
234 // const meshedSurf& surf = surface();
235 const meshedSurfRef& surf = adjustSurface();
236
237 if (Pstream::master() || !parallel_)
238 {
239 if (!isDir(outputFile.path()))
240 {
241 mkDir(outputFile.path());
242 }
243
244 // Write sample locations
245 {
246 pointIOField iopts
247 (
249 (
250 surfaceDir/"points",
251 *dummyTimePtr,
254 false
255 )
256 );
257 iopts.note() = (this->isPointData() ? "point data" : "face data");
258
259 serialWriteGeometry(iopts, surf);
260 }
261
262 // Write field
263 {
264 IOField<Type> iofld
265 (
267 (
268 outputFile,
269 *dummyTimePtr,
272 false
273 )
274 );
275 iofld.note() = (this->isPointData() ? "point data" : "face data");
276
277 OFstream osField(iofld.objectPath(), streamOpt_);
278
279 if (header_)
280 {
281 iofld.writeHeader(osField);
282 }
283
284 // Just like writeData, but without copying beforehand
285 osField << tfield();
286
287 if (header_)
288 {
289 iofld.writeEndDivider(osField);
290 }
291 }
292 }
293
294 wroteGeom_ = true;
295 return surfaceDir;
296}
297
298
299// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
300
301// Field writing methods
303
304
305// ************************************************************************* //
Istream and Ostream manipulators taking arguments.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A primitive field of type <T> with automated input and output.
Definition: IOField.H:58
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
const string & note() const noexcept
Return the optional note.
Definition: IOobjectI.H:95
fileName objectPath() const
The complete path + object name.
Definition: IOobjectI.H:214
bool writeHeader(Ostream &os) const
Write header with current type()
The IOstreamOption is a simple container for options an IOstream can normally have.
Output to file stream, using an OSstream.
Definition: OFstream.H:57
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
static fileName envGlobalPath()
Global case (directory) from environment variable.
Definition: argList.C:549
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A class for handling file names.
Definition: fileName.H:76
static std::string path(const std::string &str)
Return directory path name (part before last /)
Definition: fileNameI.H:176
Implements a meshed surface by referencing another meshed surface or faces/points components.
Definition: meshedSurfRef.H:56
Abstract definition of a meshed surface defined by faces and points.
Definition: meshedSurf.H:50
virtual const faceList & faces() const =0
The faces used for the surface.
virtual const pointField & points() const =0
The points used for the surface.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:76
splitCell * master() const
Definition: splitCell.H:113
Base class for surface writers.
virtual void open(const fileName &outputPath)
Open for output on specified path, using existing surface.
A surfaceWriter for outputting to a form usable for the timeVaryingMapped boundary condition....
virtual fileName write()
Write surface geometry to file.
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeName(Type)
Define the typeName.
Definition: className.H:96
const pointField & points
word timeName
Definition: getTimeIndex.H:3
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: MSwindows.C:515
messageStream Info
Information stream (stdout output on master, null elsewhere)
PrimitivePatch< SubList< face >, const pointField & > primitivePatch
A PrimitivePatch with a SubList addressing for the faces, const reference for the point field.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Definition: MSwindows.C:651
Convenience macros for instantiating surfaceWriter methods.
#define defineSurfaceWriterWriteFields(ThisClass)