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-2023 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 {
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 
75 :
76  setWriter(writer),
77  separateSegments_(true)
78 {}
79 
80 
81 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
82 
84 {}
85 
86 
87 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
88 
90 (
91  const fileName& outputDir,
92  const fileName& setName,
93  const coordSet& set,
94  const wordList& valueSetNames
95  #define TypeValueSetsConstArg(Type, nullArg) \
96  , const UPtrList<const Field<Type>>& Type##ValueSets
99 ) const
100 {
101  if (!isDir(outputDir))
102  {
103  mkDir(outputDir);
104  }
105 
106  OFstream os
107  (
108  outputDir/setName + ".xy",
111  writeCompression_
112  );
113 
114  separateSegments_ = set.segments() != identityMap(set.size());
115 
116  os << '#';
117 
118  OStringStream oss;
119  writeValueSeparator(oss);
120 
121  os << oss.str().c_str();
122 
123  writeTableHeader
124  (
125  set,
126  valueSetNames,
127  #define TypeValueSetsParameter(Type, nullArg) Type##ValueSets,
130  os,
131  true,
132  1 + oss.str().size()
133  );
134 
135  os << nl;
136 
137  writeTable
138  (
139  set,
140  #define TypeValueSetsParameter(Type, nullArg) Type##ValueSets,
143  os,
144  true
145  );
146 }
147 
148 
149 // ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Macros for easy insertion into run-time selection tables.
Pre-declare SubField and related Field type.
Definition: Field.H:82
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:194
Output to file stream.
Definition: OFstream.H:86
Output to memory buffer stream.
Definition: OStringStream.H:52
string str() const
Return the string.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: UPtrList.H:66
Holds list of sampling positions.
Definition: coordSet.H:51
label size() const
Return the size.
Definition: coordSet.H:135
const labelList & segments() const
Return the segments.
Definition: coordSet.H:141
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
A class for handling file names.
Definition: fileName.H:82
Write set in raw tabulated format.
Definition: rawSetWriter.H:51
virtual void writeSegmentSeparator(Ostream &os) const
Write a segment separator.
Definition: rawSetWriter.C:45
virtual ~rawSetWriter()
Destructor.
Definition: rawSetWriter.C:83
rawSetWriter(const IOstream::streamFormat writeFormat, const IOstream::compressionType writeCompression)
Construct given write options.
Definition: rawSetWriter.C:57
virtual void write(const fileName &outputDir, const fileName &setName, const coordSet &set, const wordList &valueSetNames #define TypeValueSetsConstArg(Type, nullArg)) const=0
Inherit base class write methods.
Base class for writing coordinate sets with data.
Definition: setWriter.H:64
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:290
FOR_ALL_FIELD_TYPES(DefineContiguousFvWallLocationDataType)
defineTypeNameAndDebug(combustionModel, 0)
bool isDir(const fileName &, const bool followLink=true)
Does the name exist as a directory in the file system?
Definition: POSIX.C:539
labelList identityMap(const label len)
Create identity map (map[i] == i) of given length.
Definition: ListOps.C:104
static const char nl
Definition: Ostream.H:260
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
#define TypeValueSetsParameter(Type, nullArg)
#define TypeValueSetsConstArg(Type, nullArg)
dictionary dict