rawSurfaceWriterTemplates.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 #include "IOmanip.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 template<class Type>
34 (
35  const fileName& outputDir,
36  const fileName& surfaceName,
37  const pointField& points,
38  const faceList& faces,
39  const word& fieldName,
40  const Field<Type>& values,
41  const bool isNodeValues,
42  const bool verbose
43 ) const
44 {
45  if (!isDir(outputDir))
46  {
47  mkDir(outputDir);
48  }
49 
50  OFstream os(outputDir/fieldName + '_' + surfaceName + ".raw");
51 
52  if (verbose)
53  {
54  Info<< "Writing field " << fieldName << " to " << os.name() << endl;
55  }
56 
57  // header
58  os << "# " << fieldName;
59  if (isNodeValues)
60  {
61  os << " POINT_DATA ";
62  }
63  else
64  {
65  os << " FACE_DATA ";
66  }
67 
68  // header
69  writeHeader(os, fieldName, values);
70 
71  // values
72  if (isNodeValues)
73  {
74  forAll(values, elemI)
75  {
76  writeLocation(os, points, elemI);
77  writeData(os, values[elemI]);
78  }
79  }
80  else
81  {
82  forAll(values, elemI)
83  {
84  writeLocation(os, points, faces, elemI);
85  writeData(os, values[elemI]);
86  }
87  }
88 
89  return os.name();
90 }
91 
92 
93 // ************************************************************************* //
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
Foam::rawSurfaceWriter::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.
OFstream.H
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Info
messageStream Info
IOmanip.H
Istream and Ostream manipulators taking arguments.
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::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