gnuplotSetWriter.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-2016 OpenFOAM Foundation
9  Copyright (C) 2017 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 "gnuplotSetWriter.H"
30 #include "coordSet.H"
31 #include "fileName.H"
32 #include "OFstream.H"
34 
35 
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 
38 template<class Type>
40 :
41  writer<Type>()
42 {}
43 
44 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
45 
46 template<class Type>
48 {}
49 
50 
51 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52 
53 template<class Type>
55 (
56  const coordSet& points,
57  const wordList& valueSetNames
58 ) const
59 {
60  return this->getBaseName(points, valueSetNames) + ".gplt";
61 }
62 
63 
64 template<class Type>
66 (
67  const coordSet& points,
68  const wordList& valueSetNames,
69  const List<const Field<Type>*>& valueSets,
70  Ostream& os
71 ) const
72 {
73  os << "set term postscript color" << nl
74  << "set output \"" << points.name() << ".ps\"" << nl;
75 
76  // Set secondary Y axis if using two columns. Falls back to same
77  // values if both on same scale. However, ignore if more columns.
78  if (valueSetNames.size() == 2)
79  {
80  os << "set ylabel \"" << valueSetNames[0] << "\"" << nl
81  << "set y2label \"" << valueSetNames[1] << "\"" << nl
82  << "set ytics nomirror" << nl << "set y2tics" << nl;
83  }
84 
85  os << "plot";
86 
87  forAll(valueSets, i)
88  {
89  if (i)
90  {
91  os << ',';
92  }
93 
94  os << " \"-\" title \"" << valueSetNames[i] << "\" with lines";
95 
96  if (valueSetNames.size() == 2)
97  {
98  os << " axes x1y" << (i+1) ;
99  }
100  }
101  os << nl;
102 
103  forAll(valueSets, i)
104  {
105  this->writeTable(points, *valueSets[i], os);
106  os << "e" << nl;
107  }
108 }
109 
110 
111 template<class Type>
113 (
114  const bool writeTracks,
115  const PtrList<coordSet>& trackPoints,
116  const wordList& valueSetNames,
117  const List<List<Field<Type>>>& valueSets,
118  Ostream& os
119 ) const
120 {
121  if (valueSets.size() != valueSetNames.size())
122  {
124  << "Number of variables:" << valueSetNames.size() << endl
125  << "Number of valueSets:" << valueSets.size()
126  << exit(FatalError);
127  }
128  if (trackPoints.size() > 0)
129  {
130  os << "set term postscript color" << nl
131  << "set output \"" << trackPoints[0].name() << ".ps\"" << nl;
132 
133  forAll(trackPoints, trackI)
134  {
135  os << "plot";
136 
137  forAll(valueSets, i)
138  {
139  if (i != 0)
140  {
141  os << ',';
142  }
143 
144  os << " \"-\" title \"" << valueSetNames[i] << "\" with lines";
145  }
146  os << nl;
147 
148  forAll(valueSets, i)
149  {
150  this->writeTable(trackPoints[trackI], valueSets[i][trackI], os);
151  os << "e" << nl;
152  }
153  }
154  }
155 }
156 
157 
158 // ************************************************************************* //
Foam::gnuplotSetWriter::getFileName
virtual fileName getFileName(const coordSet &, const wordList &) const
Generate file name with correct extension.
Definition: gnuplotSetWriter.C:55
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
coordSet.H
Foam::gnuplotSetWriter::gnuplotSetWriter
gnuplotSetWriter()
Construct null.
Definition: gnuplotSetWriter.C:39
Foam::gnuplotSetWriter::~gnuplotSetWriter
virtual ~gnuplotSetWriter()
Destructor.
Definition: gnuplotSetWriter.C:47
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
OFstream.H
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::gnuplotSetWriter::write
virtual void write(const coordSet &, const wordList &, const List< const Field< Type > * > &, Ostream &) const
General entry point for writing.
Definition: gnuplotSetWriter.C:66
Foam::FatalError
error FatalError
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
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::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
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::List< word >
points
const pointField & points
Definition: gmvOutputHeader.H:1
gnuplotSetWriter.H
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56