dxSurfaceWriterTemplates.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 << "object 3 class array type float rank 0 items "
39  << values.size() << " data follows" << nl;
40 
41  forAll(values, elemI)
42  {
43  os << float(0.0) << nl;
44  }
45 }
46 
47 
48 template<class Type>
50 (
51  const fileName& outputDir,
52  const fileName& surfaceName,
53  const pointField& points,
54  const faceList& faces,
55  const word& fieldName,
56  const Field<Type>& values,
57  const bool isNodeValues,
58  const bool verbose
59 ) const
60 {
61  if (!isDir(outputDir))
62  {
63  mkDir(outputDir);
64  }
65 
66  OFstream os(outputDir/fieldName + '_' + surfaceName + ".dx");
67 
68  if (verbose)
69  {
70  Info<< "Writing field " << fieldName << " to " << os.name() << endl;
71  }
72 
73  writeGeometry(os, points, faces);
74  writeData(os, values);
75  writeTrailer(os, isNodeValues);
76 
77  return os.name();
78 }
79 
80 
81 // ************************************************************************* //
Foam::dxSurfaceWriter::writeData
static void writeData(Ostream &, const Field< Type > &)
Definition: dxSurfaceWriterTemplates.C:33
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::dxSurfaceWriter::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.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
OFstream.H
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