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-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 "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 
45 template<class Type>
47 :
48  writer<Type>(dict)
49 {}
50 
51 
52 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
53 
54 template<class Type>
56 (
57  const coordSet& points,
58  const wordList& valueSetNames
59 ) const
60 {
61  return this->getBaseName(points, valueSetNames) + ".gplt";
62 }
63 
64 
65 template<class Type>
67 (
68  const coordSet& points,
69  const wordList& valueSetNames,
70  const List<const Field<Type>*>& valueSets,
71  Ostream& os
72 ) const
73 {
74  os << "set term postscript color" << nl
75  << "set output \"" << points.name() << ".ps\"" << nl;
76 
77  // Set secondary Y axis if using two columns. Falls back to same
78  // values if both on same scale. However, ignore if more columns.
79  if (valueSetNames.size() == 2)
80  {
81  os << "set ylabel \"" << valueSetNames[0] << "\"" << nl
82  << "set y2label \"" << valueSetNames[1] << "\"" << nl
83  << "set ytics nomirror" << nl << "set y2tics" << nl;
84  }
85 
86  os << "plot";
87 
88  forAll(valueSets, i)
89  {
90  if (i)
91  {
92  os << ',';
93  }
94 
95  os << " \"-\" title \"" << valueSetNames[i] << "\" with lines";
96 
97  if (valueSetNames.size() == 2)
98  {
99  os << " axes x1y" << (i+1) ;
100  }
101  }
102  os << nl;
103 
104  forAll(valueSets, i)
105  {
106  this->writeTable(points, *valueSets[i], os);
107  os << "e" << nl;
108  }
109 }
110 
111 
112 template<class Type>
114 (
115  const bool writeTracks,
116  const List<scalarField>& times,
117  const PtrList<coordSet>& tracks,
118  const wordList& valueSetNames,
119  const List<List<Field<Type>>>& valueSets,
120  Ostream& os
121 ) const
122 {
123  if (valueSets.size() != valueSetNames.size())
124  {
126  << "Number of variables:" << valueSetNames.size() << endl
127  << "Number of valueSets:" << valueSets.size()
128  << exit(FatalError);
129  }
130  if (tracks.size() > 0)
131  {
132  os << "set term postscript color" << nl
133  << "set output \"" << tracks[0].name() << ".ps\"" << nl;
134 
135  forAll(tracks, trackI)
136  {
137  os << "plot";
138 
139  forAll(valueSets, i)
140  {
141  if (i != 0)
142  {
143  os << ',';
144  }
145 
146  os << " \"-\" title \"" << valueSetNames[i] << "\" with lines";
147  }
148  os << nl;
149 
150  forAll(valueSets, i)
151  {
152  this->writeTable(tracks[trackI], valueSets[i][trackI], os);
153  os << "e" << nl;
154  }
155  }
156  }
157 }
158 
159 
160 // ************************************************************************* //
Foam::gnuplotSetWriter::getFileName
virtual fileName getFileName(const coordSet &, const wordList &) const
Generate file name with correct extension.
Definition: gnuplotSetWriter.C:56
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
coordSet.H
Foam::gnuplotSetWriter::gnuplotSetWriter
gnuplotSetWriter()
Default construct.
Definition: gnuplotSetWriter.C:39
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
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:59
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:67
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)
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:81
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:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
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