csvSetWriter.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "csvSetWriter.H"
30 #include "coordSet.H"
31 #include "fileName.H"
32 #include "OFstream.H"
33 
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 
36 template<class Type>
38 :
39  writer<Type>()
40 {}
41 
42 
43 template<class Type>
45 :
46  writer<Type>(dict)
47 {}
48 
49 
50 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
51 
52 template<class Type>
54 (
55  const coordSet& points,
56  const wordList& valueSetNames
57 ) const
58 {
59  return this->getBaseName(points, valueSetNames) + ".csv";
60 }
61 
62 
63 template<class Type>
65 (
66  const coordSet& points,
67  const wordList& valueSetNames,
68  const List<const Field<Type>*>& valueSets,
69  Ostream& os
70 ) const
71 {
72  writeHeader(points,valueSetNames,os);
73 
74  // Collect sets into columns
75  List<const List<Type>*> columns(valueSets.size());
76 
77  forAll(valueSets, i)
78  {
79  columns[i] = valueSets[i];
80  }
81 
82  this->writeTable(points, columns, os);
83 }
84 
85 
86 template<class Type>
88 (
89  const bool writeTracks,
90  const List<scalarField>& times,
91  const PtrList<coordSet>& tracks,
92  const wordList& valueSetNames,
93  const List<List<Field<Type>>>& valueSets,
94  Ostream& os
95 ) const
96 {
97  writeHeader(tracks[0],valueSetNames,os);
98 
99  if (valueSets.size() != valueSetNames.size())
100  {
102  << "Number of variables:" << valueSetNames.size() << endl
103  << "Number of valueSets:" << valueSets.size()
104  << exit(FatalError);
105  }
106 
107  List<const List<Type>*> columns(valueSets.size());
108 
109  forAll(tracks, trackI)
110  {
111  // Collect sets into columns
112  forAll(valueSets, i)
113  {
114  columns[i] = &valueSets[i][trackI];
115  }
116 
117  this->writeTable(tracks[trackI], columns, os);
118  os << nl << nl;
119  }
120 }
121 
122 
123 template<class Type>
125 {
126  os << token::COMMA;
127 }
128 
129 
130 namespace Foam
131 {
132  // otherwise compiler complains about specialization
133  template<>
135  (
136  const coordSet& points,
137  const wordList& valueSetNames,
138  Ostream& os
139  ) const
140  {
141  writeCoordHeader(points, os);
142 
143  forAll(valueSetNames, i)
144  {
145  if (i)
146  {
147  writeSeparator(os);
148  }
149  os << valueSetNames[i];
150  }
151 
152  os << nl;
153  }
154 }
155 
156 
157 template<class Type>
159 (
160  const coordSet& points,
161  const wordList& valueSetNames,
162  Ostream& os
163 ) const
164 {
165  writeCoordHeader(points, os);
166 
167  forAll(valueSetNames, i)
168  {
169  for (label j=0; j<Type::nComponents; j++)
170  {
171  if (i || j)
172  {
173  writeSeparator(os);
174  }
175  os << valueSetNames[i] << "_" << j;
176  }
177  }
178 
179  os << nl;
180 }
181 
182 
183 template<class Type>
185 (
186  const coordSet& points,
187  Ostream& os
188 ) const
189 {
190  const word axisName(points.axis());
191 
192  if (points.hasVectorAxis())
193  {
194  for (auto iter = axisName.cbegin(); iter != axisName.cend(); ++iter)
195  {
196  os << *iter;
197  writeSeparator(os);
198  }
199  }
200  else
201  {
202  os << axisName;
203  writeSeparator(os);
204  }
205 }
206 
207 
208 // ************************************************************************* //
Foam::csvSetWriter::write
virtual void write(const coordSet &, const wordList &, const List< const Field< Type > * > &, Ostream &) const
General entry point for writing.
Definition: csvSetWriter.C:65
Foam::token::COMMA
Comma [isseparator].
Definition: token.H:129
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::csvSetWriter::getFileName
virtual fileName getFileName(const coordSet &, const wordList &) const
Generate file name with correct extension.
Definition: csvSetWriter.C:54
coordSet.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::writeHeader
static void writeHeader(Ostream &os, const word &fieldName)
Definition: rawSurfaceWriterImpl.C:66
Foam::csvSetWriter
Write set in csv format.
Definition: csvSetWriter.H:52
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
OFstream.H
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
Foam::Field
Generic templated field type.
Definition: Field.H:63
fileName.H
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::writer
Base class for graphics format writing. Entry points are.
Definition: writer.H:81
Foam::coordSet
Holds list of sampling positions.
Definition: coordSet.H:53
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
csvSetWriter.H
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::List< word >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::csvSetWriter::csvSetWriter
csvSetWriter()
Default construct.
Definition: csvSetWriter.C:37
Foam::csvSetWriter::writeSeparator
virtual void writeSeparator(Ostream &) const
Writes a separator. Used by write functions.
Definition: csvSetWriter.C:124
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56