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