csvSetWriter.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
6  \\/ M anipulation |
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 "csvSetWriter.H"
27 #include "coordSet.H"
28 #include "fileName.H"
29 #include "OFstream.H"
30 #include "OSspecific.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(csvSetWriter, 0);
38  addToRunTimeSelectionTable(setWriter, csvSetWriter, word);
39  addToRunTimeSelectionTable(setWriter, csvSetWriter, dict);
40 }
41 
42 
43 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
44 
46 {
47  os << separator_;
48 }
49 
50 
52 {}
53 
54 
55 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56 
58 (
59  const IOstream::streamFormat writeFormat,
60  const IOstream::compressionType writeCompression
61 )
62 :
63  setWriter(writeFormat, writeCompression),
64  separator_(',')
65 {}
66 
67 
69 :
70  setWriter(dict),
71  separator_(dict.lookupOrDefault<string>("separator", string(","))[0])
72 {}
73 
74 
75 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
76 
78 {}
79 
80 
81 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
82 
84 (
85  const fileName& outputDir,
86  const fileName& setName,
87  const coordSet& set,
88  const wordList& valueSetNames
89  #define TypeValueSetsConstArg(Type, nullArg) \
90  , const UPtrList<const Field<Type>>& Type##ValueSets
91  FOR_ALL_FIELD_TYPES(TypeValueSetsConstArg)
92  #undef TypeValueSetsConstArg
93 ) const
94 {
95  if (!isDir(outputDir))
96  {
97  mkDir(outputDir);
98  }
99 
100  OFstream os
101  (
102  outputDir/setName + ".csv",
106  );
107 
109  (
110  set,
111  valueSetNames,
112  #define TypeValueSetsParameter(Type, nullArg) Type##ValueSets,
115  os
116  );
117 
118  os << nl;
119 
120  writeTable
121  (
122  set,
123  #define TypeValueSetsParameter(Type, nullArg) Type##ValueSets,
126  os
127  );
128 }
129 
130 
131 // ************************************************************************* //
virtual ~csvSetWriter()
Destructor.
Definition: csvSetWriter.C:77
dictionary dict
A class for handling file names.
Definition: fileName.H:79
#define TypeValueSetsParameter(Type, nullArg)
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
void writeTableHeader(const coordSet &set, const wordList &valueSetNames, #define TypeValueSetsConstArg(Type, nullArg) Ostream &os, const bool align=false, const unsigned long alignPad=0) const
Write multi-column table header.
Definition: setWriter.C:119
IOstream::compressionType writeCompression_
Write compression.
Definition: setWriter.H:206
Base class for writing coordinate sets with data.
Definition: setWriter.H:63
Output to file stream.
Definition: OFstream.H:82
virtual void write(const fileName &outputDir, const fileName &setName, const coordSet &set, const wordList &valueSetNames #define TypeValueSetsConstArg(Type, nullArg)) const
Write a coordSet and associated data.
Definition: csvSetWriter.C:84
virtual void writeSegmentSeparator(Ostream &os) const
Write a segment separator.
Definition: csvSetWriter.C:51
Macros for easy insertion into run-time selection tables.
#define TypeValueSetsConstArg(Type, nullArg)
void writeTable(const coordSet &set, #define TypeValueSetsConstArg(Type, nullArg) Ostream &os, const bool align=false) const
Write multi-column table of data.
Definition: setWriter.C:193
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Holds list of sampling positions.
Definition: coordSet.H:50
Pre-declare SubField and related Field type.
Definition: Field.H:56
bool isDir(const fileName &, const bool followLink=true)
Does the name exist as a directory in the file system?
Definition: POSIX.C:539
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: UPtrList.H:54
virtual void writeValueSeparator(Ostream &os) const
Write a value separator.
Definition: csvSetWriter.C:45
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
static const char nl
Definition: Ostream.H:260
defineTypeNameAndDebug(combustionModel, 0)
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:290
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
csvSetWriter(const IOstream::streamFormat writeFormat, const IOstream::compressionType writeCompression)
Construct given write options.
Definition: csvSetWriter.C:58
FOR_ALL_FIELD_TYPES(DefineFvWallInfoType)
A class for handling character strings derived from std::string.
Definition: string.H:76
Namespace for OpenFOAM.