rawSetWriter.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-2021 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 "rawSetWriter.H"
27 #include "coordSet.H"
28 #include "OFstream.H"
29 #include "OSspecific.H"
30 #include "SubList.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(rawSetWriter, 0);
38  addToRunTimeSelectionTable(setWriter, rawSetWriter, word);
39  addToRunTimeSelectionTable(setWriter, rawSetWriter, dict);
40 }
41 
42 
43 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
44 
46 {
47  if (separateSegments_)
48  {
49  os << nl << nl;
50  }
51 }
52 
53 
54 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55 
57 (
58  const IOstream::streamFormat writeFormat,
59  const IOstream::compressionType writeCompression
60 )
61 :
62  setWriter(writeFormat, writeCompression),
63  separateSegments_(true)
64 {}
65 
66 
68 :
69  setWriter(dict),
70  separateSegments_(true)
71 {}
72 
73 
74 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
75 
77 {}
78 
79 
80 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
81 
83 (
84  const fileName& outputDir,
85  const fileName& setName,
86  const coordSet& set,
87  const wordList& valueSetNames
88  #define TypeValueSetsConstArg(Type, nullArg) \
89  , const UPtrList<const Field<Type>>& Type##ValueSets
90  FOR_ALL_FIELD_TYPES(TypeValueSetsConstArg)
91  #undef TypeValueSetsConstArg
92 ) const
93 {
94  if (!isDir(outputDir))
95  {
96  mkDir(outputDir);
97  }
98 
99  OFstream os
100  (
101  outputDir/setName + ".xy",
105  );
106 
107  separateSegments_ = set.segments() != identity(set.size());
108 
109  os << '#';
110 
111  OStringStream oss;
112  writeValueSeparator(oss);
113 
114  os << oss.str().c_str();
115 
117  (
118  set,
119  valueSetNames,
120  #define TypeValueSetsParameter(Type, nullArg) Type##ValueSets,
123  os,
124  true,
125  1 + oss.str().size()
126  );
127 
128  os << nl;
129 
130  writeTable
131  (
132  set,
133  #define TypeValueSetsParameter(Type, nullArg) Type##ValueSets,
136  os,
137  true
138  );
139 }
140 
141 
142 // ************************************************************************* //
rawSetWriter(const IOstream::streamFormat writeFormat, const IOstream::compressionType writeCompression)
Construct given write options.
Definition: rawSetWriter.C:57
dictionary dict
A class for handling file names.
Definition: fileName.H:79
#define TypeValueSetsConstArg(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 writeSegmentSeparator(Ostream &os) const
Write a segment separator.
Definition: rawSetWriter.C:45
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
Definition: ListOps.C:104
virtual void writeValueSeparator(Ostream &os) const
Write a value separator.
Definition: setWriter.C:43
Macros for easy insertion into run-time selection tables.
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
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: rawSetWriter.C:83
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
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
string str() const
Return the string.
FOR_ALL_FIELD_TYPES(DefineFvWallInfoType)
Output to memory buffer stream.
Definition: OStringStream.H:49
#define TypeValueSetsParameter(Type, nullArg)
virtual ~rawSetWriter()
Destructor.
Definition: rawSetWriter.C:76
Namespace for OpenFOAM.