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-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 
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"
37 #include "surfaceWriterMethods.H"
39 
40 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
41 
42 namespace Foam
43 {
44 namespace surfaceWriters
45 {
48 }
49 }
50 
51 
52 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 
55 :
57 {}
58 
59 
61 (
62  const dictionary& options
63 )
64 :
65  surfaceWriter(options)
66 {}
67 
68 
70 (
71  const meshedSurf& surf,
72  const fileName& outputPath,
73  bool parallel,
74  const dictionary& options
75 )
76 :
77  boundaryDataWriter(options)
78 {
79  open(surf, outputPath, parallel);
80 }
81 
82 
84 (
85  const pointField& points,
86  const faceList& faces,
87  const fileName& outputPath,
88  bool parallel,
89  const dictionary& options
90 )
91 :
92  boundaryDataWriter(options)
93 {
94  open(points, faces, outputPath, parallel);
95 }
96 
97 
98 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
99 
101 {
102  checkOpen();
103 
104  // Geometry: rootdir/surfaceName/"points"
105  // Field: rootdir/surfaceName/<TIME>/field
106 
107  fileName surfaceDir = outputPath_;
108 
109  // Write points
110  if (verbose_)
111  {
112  Info<< "Writing points to " << surfaceDir/"points" << endl;
113  }
114 
115 
116  // Dummy Time to use as objectRegistry
118 
119 
120  const meshedSurf& surf = surface();
121 
122  if (Pstream::master() || !parallel_)
123  {
124  if (!isDir(surfaceDir))
125  {
126  mkDir(surfaceDir);
127  }
128 
129  pointIOField pts
130  (
131  IOobject
132  (
133  surfaceDir/"points",
134  *dummyTimePtr,
137  false
138  ),
139  surf.points()
140  );
141 
142  // Do like regIOobject::writeObject but don't do instance() adaptation
143  // since this would write to e.g. 0/ instead of postProcessing/
144 
145  // Try opening an OFstream for object
146  OFstream os(pts.objectPath());
147 
148  //pts.writeHeader(os);
149  pts.writeData(os);
150  //pts.writeEndDivider(os);
151  }
152 
153  wroteGeom_ = true;
154  return surfaceDir;
155 }
156 
157 
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 
160 template<class Type>
161 Foam::fileName Foam::surfaceWriters::boundaryDataWriter::writeTemplate
162 (
163  const word& fieldName,
164  const Field<Type>& localValues
165 )
166 {
167  checkOpen();
168 
169  // Geometry: rootdir/surfaceName/"points"
170  // Field: rootdir/surfaceName/<TIME>/field
171 
172  fileName surfaceDir = outputPath_;
173 
174  const fileName outputFile(surfaceDir/timeName()/fieldName);
175 
176 
177  // Dummy Time to use as objectRegistry
179 
180 
181  // Geometry merge() implicit
182  tmp<Field<Type>> tfield = mergeField(localValues);
183 
184  const meshedSurf& surf = surface();
185 
186  if (Pstream::master() || !parallel_)
187  {
188  const pointField& points = surf.points();
189  const faceList& faces = surf.faces();
190 
191  if (!isDir(outputFile.path()))
192  {
193  mkDir(outputFile.path());
194  }
195 
196  pointIOField pts
197  (
198  IOobject
199  (
200  surfaceDir/"points",
201  *dummyTimePtr,
204  false
205  ),
206  label(0)
207  );
208 
209  if (this->isPointData())
210  {
211  if (verbose_)
212  {
213  Info<< "Writing points to "
214  << surfaceDir/"points" << endl;
215  }
216  pts = points;
217  }
218  else
219  {
220  if (verbose_)
221  {
222  Info<< "Writing face centres to "
223  << surfaceDir/"points" << endl;
224  }
225 
226  primitivePatch pp(SubList<face>(faces, faces.size()), points);
227 
228  pts = pp.faceCentres();
229  }
230 
231  {
232  // Do like regIOobject::writeObject but don't do instance()
233  // adaptation
234  // since this would write to e.g. 0/ instead of postProcessing/
235 
236  // Try opening an OFstream for object
237  OFstream os(pts.objectPath());
238 
239  //pts.writeHeader(os);
240  pts.writeData(os);
241  //pts.writeEndDivider(os);
242  }
243 
244 
245  // Write field
246  OFstream(outputFile)() << tfield();
247  }
248 
249  wroteGeom_ = true;
250  return surfaceDir;
251 }
252 
253 
254 // Field writing methods
256 
257 
258 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
boundaryDataSurfaceWriter.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
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
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: foamVtkLagrangianWriter.H:61
Foam::argList::envGlobalPath
static fileName envGlobalPath()
Global case (directory) from environment variable.
Definition: argList.C:513
Foam::fileName::path
static std::string path(const std::string &str)
Return directory path name (part before last /)
Definition: fileNameI.H:186
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:53
Foam::surfaceWriters::boundaryDataWriter
A surfaceWriter for outputting to a form useable for the timeVaryingMapped boundary condition....
Definition: boundaryDataSurfaceWriter.H:111
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::defineTypeName
defineTypeName(boundaryDataWriter)
pointIOField.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
surfaceWriterMethods.H
Convenience macros for instantiating surfaceWriter methods.
Foam::surfaceWriters::boundaryDataWriter::boundaryDataWriter
boundaryDataWriter()
Construct null.
Definition: boundaryDataSurfaceWriter.C:54
OFstream.H
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
argList.H
IOmanip.H
Istream and Ostream manipulators taking arguments.
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
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
defineSurfaceWriterWriteFields
defineSurfaceWriterWriteFields(Foam::surfaceWriters::boundaryDataWriter)
Foam::Time::New
static autoPtr< Time > New()
Construct dummy time, without functionObjects or libraries.
Definition: Time.C:710
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:99
Foam::UPstream::master
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:438
Foam::surfaceWriters::boundaryDataWriter::write
virtual fileName write()
Write surface geometry to file.
Definition: boundaryDataSurfaceWriter.C:100
Time.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::surfaceWriters::addToRunTimeSelectionTable
addToRunTimeSelectionTable(surfaceWriter, boundaryDataWriter, word)
Foam::List< face >
Foam::PrimitivePatch::faceCentres
const Field< PointType > & faceCentres() const
Return face centres for patch.
Definition: PrimitivePatch.C:517
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::IOField::writeData
bool writeData(Ostream &os) const
Definition: IOField.C:208
Foam::IOobject::NO_READ
Definition: IOobject.H:123
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
primitivePatch.H
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
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:90