vtkSurfaceWriterTemplates.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 | Copyright (C) 2011-2014 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "OFstream.H"
27 #include "OSspecific.H"
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 template<class Type>
33 (
34  Ostream& os,
35  const Field<Type>& values
36 )
37 {
38  os << "1 " << values.size() << " float" << nl;
39 
40  forAll(values, elemI)
41  {
42  os << float(0) << nl;
43  }
44 }
45 
46 
47 template<class Type>
49 (
50  const fileName& outputDir,
51  const fileName& surfaceName,
52  const pointField& points,
53  const faceList& faces,
54  const word& fieldName,
55  const Field<Type>& values,
56  const bool isNodeValues,
57  const bool verbose
58 ) const
59 {
60  if (!isDir(outputDir))
61  {
62  mkDir(outputDir);
63  }
64 
65  OFstream os(outputDir/fieldName + '_' + surfaceName + ".vtk");
66 
67  if (verbose)
68  {
69  Info<< "Writing field " << fieldName << " to " << os.name() << endl;
70  }
71 
72  writeGeometry(os, points, faces);
73 
74  // start writing data
75  if (isNodeValues)
76  {
77  os << "POINT_DATA ";
78  }
79  else
80  {
81  os << "CELL_DATA ";
82  }
83 
84  os << values.size() << nl
85  << "FIELD attributes 1" << nl
86  << fieldName << " ";
87 
88  // Write data
89  writeData(os, values);
90 
91  return os.name();
92 }
93 
94 
95 // ************************************************************************* //
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 string.
Definition: word.H:59
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
OFstream.H
Foam::vtkSurfaceWriter::writeData
static void writeData(Ostream &, const Field< Type > &)
Definition: vtkSurfaceWriterTemplates.C:33
Foam::Field< Type >
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
writeData
const bool writeData(readBool(pdfDictionary.lookup("writeData")))
Foam::isDir
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:615
Foam::OFstream
Output to file stream.
Definition: OFstream.H:81
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::OFstream::name
const fileName & name() const
Return the name of the stream.
Definition: OFstream.H:118
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::mkDir
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:419
Foam::vtkSurfaceWriter::writeTemplate
fileName writeTemplate(const fileName &outputDir, const fileName &surfaceName, const pointField &points, const faceList &faces, const word &fieldName, const Field< Type > &values, const bool isNodeValues, const bool verbose) const
Templated write operation.