OpenLB 1.7
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | List of all members
olb::Gnuplot< T > Class Template Reference

#include <gnuplotWriter.h>

+ Inheritance diagram for olb::Gnuplot< T >:
+ Collaboration diagram for olb::Gnuplot< T >:

Public Types

enum  AxisType { LINEAR , LOGLOG , LOGLOGINVERTED }
 
enum  Regression { OFF , LINREG }
 different types of data usage and axes scaling More...
 

Public Member Functions

 Gnuplot (std::string name, bool liveplot, std::string preCommand, AxisType axisType, Regression regressionType)
 type of Regression, off, LINear REGression, exponential Regression?,...
 
 Gnuplot (std::string name)
 overload the constructor using delegating constructors.
 
 Gnuplot (std::string name, bool liveplot)
 
 Gnuplot (std::string name, AxisType axisType)
 
 Gnuplot (std::string name, AxisType axisType, Regression regressionType)
 
void init ()
 initialises the data file
 
void setData (T xValue, T yValue, std::string name="", std::string key="", char plotType='l')
 sets the data and plot file for two doubles (x and y) the plotType indicates whether the user want to plot a line graph (default = 'l') or e.g.
 
void setData (bool noXvalue, T yValue, std::string name="", std::string key="", char plotType='l')
 if no x value is given, it is just an increasing integer
 
void setData (T xValue, std::vector< T > yValues, std::vector< std::string > names={""}, std::string key="right", std::vector< char > plotType={ 'l', 'l'})
 sets the data and plot file for a double and a vector of doubles (x and {y1,y2,...}) for each entry of the y-axis-list, a plot Type can be specified (default: line graph {'l', 'l'})
 
void setData (bool noXvalue, std::vector< T > yValues, std::vector< std::string > names={""}, std::string key="right", const std::vector< char > plotType={ 'l', 'l'})
 if no x value is given, it is just an increasing integer
 
void setLabel (std::string xLabel="", std::string yLabel="")
 set labels of the plot: xLabel and yLabel
 
void writePDF (std::string plotName="")
 writes an PDF
 
void writePNG (int iT=-1, double xRange=-1, std::string plotName="")
 writes PNGs usage: first argument: numbering of png file (optional), second argument: range for the x axis (optional) third argument: name the plot in order to specify a plotID in case the user want to create more than one plot with the simulation results no arguments: writes in one file with adaptive xrange and no specific name
 

Protected Member Functions

void startGnuplot (std::string plotFile, std::string plotName="")
 system command to start gnuplot (LINUX ONLY!)
 
void linRegression (std::ofstream &fout, std::string x_axisType, std::string y_axisType)
 creates the lin regression to the data
 
void scaleAxes (std::ofstream &fout)
 scales the axes if needed
 

Detailed Description

template<typename T>
class olb::Gnuplot< T >

Definition at line 36 of file gnuplotWriter.h.

Member Enumeration Documentation

◆ AxisType

template<typename T >
enum olb::Gnuplot::AxisType
Enumerator
LINEAR 
LOGLOG 
LOGLOGINVERTED 

Definition at line 39 of file gnuplotWriter.h.

◆ Regression

template<typename T >
enum olb::Gnuplot::Regression

different types of data usage and axes scaling

Enumerator
OFF 
LINREG 

Definition at line 40 of file gnuplotWriter.h.

Constructor & Destructor Documentation

◆ Gnuplot() [1/5]

template<typename T >
olb::Gnuplot< T >::Gnuplot ( std::string name,
bool liveplot,
std::string preCommand,
AxisType axisType,
Regression regressionType )

type of Regression, off, LINear REGression, exponential Regression?,...

Constructor with name of outputFiles boolean true for real-time plotting //WARNING: experimental!

Constructor with name for output files boolean true for real-time plotting //WARNING: experimental! Every set of paramters has its own constructor which is delegating the "large constructor"

Definition at line 39 of file gnuplotWriter.hh.

40 : _name(name),
41 _liveplot(liveplot),
42 _dataFile(singleton::directories().getGnuplotOutDir()+"data/"+_name+".dat"),
43 _dir(singleton::directories().getGnuplotOutDir()),
44 _preCommand(preCommand),
45 _axisType(axisType),
46 _regressionType(regressionType),
47 csvWriter(name)
48{
49#ifndef WIN32
50 _gnuplotInstalled = (! system("which gnuplot >/dev/null 2>/dev/null"));
51#endif
52 if ((! _gnuplotInstalled) && (singleton::mpi().getRank() == _rank )) {
53 std::cout << "We could not find a gnuplot distribution at your system." << std::endl;
54 std::cout << "We still write the data files s.t. you can plot the data yourself." << std::endl;
55 }
56}
int getRank() const
Returns the process ID.
MpiManager & mpi()
Directories & directories()
Definition singleton.h:150

◆ Gnuplot() [2/5]

template<typename T >
olb::Gnuplot< T >::Gnuplot ( std::string name)
explicit

overload the constructor using delegating constructors.

This has the advantage that there is no necessity for default values which might cause some trouble

Definition at line 61 of file gnuplotWriter.hh.

61: Gnuplot(name, false, "", LINEAR, OFF) {}
Gnuplot(std::string name, bool liveplot, std::string preCommand, AxisType axisType, Regression regressionType)
type of Regression, off, LINear REGression, exponential Regression?,...

◆ Gnuplot() [3/5]

template<typename T >
olb::Gnuplot< T >::Gnuplot ( std::string name,
bool liveplot )

Definition at line 64 of file gnuplotWriter.hh.

64: Gnuplot(name, liveplot,"", LINEAR, OFF) {}

◆ Gnuplot() [4/5]

template<typename T >
olb::Gnuplot< T >::Gnuplot ( std::string name,
AxisType axisType )

Definition at line 67 of file gnuplotWriter.hh.

67: Gnuplot(name, false, "", axisType, OFF) {}

◆ Gnuplot() [5/5]

template<typename T >
olb::Gnuplot< T >::Gnuplot ( std::string name,
AxisType axisType,
Regression regressionType )

Definition at line 70 of file gnuplotWriter.hh.

70: Gnuplot(name, false,"", axisType, regressionType) {}

Member Function Documentation

◆ init()

template<typename T >
void olb::Gnuplot< T >::init ( )

initialises the data file

◆ linRegression()

template<typename T >
void olb::Gnuplot< T >::linRegression ( std::ofstream & fout,
std::string xAxisType,
std::string yAxisType )
protected

creates the lin regression to the data

create lin Regression to the given Datasets in the given scaling, e.g.

loglog, logloginverted, linear,.... The kind of scaling is provided by the parameters xAxisType and yAxisType

plotting the data and for each set 1:2 / 1:3,... the lin regression is plotted IMPORTANT the word "plot" must be included in every kind of regression used in the context auf the plotting

Definition at line 129 of file gnuplotWriter.hh.

130{
131 fout << "set fit quiet\n";
132
133 for (unsigned int i = 0; i < _dataSize; ++i) {
134 fout << "f" << i+1 << "(x) = m" << i+1 << " * x + b"<< i+1 << "\n"; //Match f2 to the dataset 1:3 with f2(x) = m2 * x + b2 and so on
135 fout << "fit f" << i+1 << "(x) path using ("<< xAxisType << "$1)):(" << yAxisType << "$" << i+2 << ")) via m" << i+1 << ", b" << i+1 <<"\n";
136 }
137 fout << "\n";
138
141 fout << "plot ";
142 for (unsigned int i = 0; i < _dataSize; ++i) {
143 fout << "f"<< i+1 <<"(x) title sprintf('regr " << _names[i] << ", gradient = %.3f', m" << i+1 << ") lc " << i+1 << " axis x1y1,";
144 }
145
146 return;
147}

◆ scaleAxes()

template<typename T >
void olb::Gnuplot< T >::scaleAxes ( std::ofstream & fout)
protected

scales the axes if needed

scales the axes if necessary to add new kinds of scaling, just add another case, the labels for the x and y axes will be expanded by the kind of scaling (if it's other than linear) this labeling provides a labeling of the axes even if the function setLabel isn't specifically called

Difference between LOGLOG and LOGLOGINVERTED is just 1/N in the x-axes

this command will change the tics-labels, the {%.2f} is replaced by the original tic-label using two

digits after the comma

Definition at line 153 of file gnuplotWriter.hh.

154{
155 switch (_axisType)
156 {
157 case (LOGLOG):
158 case(LOGLOGINVERTED):
159 {
160 fout << "set xtics nomirror" << "\n";
161 fout << "set ytics nomirror" << "\n";
162
163 fout << "set format y '10^{%.2f}'" << "\n";
164 fout << "set format x '10^{%.2f}'" << "\n";
165 } break;
166
167 case LINEAR:
168 default:
169 {} break;
170 }
171
172 fout << "\n";
173 return;
174}

◆ setData() [1/4]

template<typename T >
void olb::Gnuplot< T >::setData ( bool noXvalue,
std::vector< T > yValues,
std::vector< std::string > names = {""},
std::string key = "right",
const std::vector< char > plotType = {'l','l'} )

if no x value is given, it is just an increasing integer

writes the data and plot file for a double and a vector of doubles (x and y1,y2,...), where x is increasing integer

Definition at line 179 of file gnuplotWriter.hh.

180{
181 T xValue = _time;
182 setData(xValue, yValues, names, key, plotType);
183 _time++;
184}
void setData(T xValue, T yValue, std::string name="", std::string key="", char plotType='l')
sets the data and plot file for two doubles (x and y) the plotType indicates whether the user want to...

◆ setData() [2/4]

template<typename T >
void olb::Gnuplot< T >::setData ( bool noXvalue,
T yValue,
std::string name = "",
std::string key = "",
char plotType = 'l' )

if no x value is given, it is just an increasing integer

writes the data and plot file for two doubles (x and y), where x is increasing integer

Definition at line 83 of file gnuplotWriter.hh.

84{
85 T xValue = _time;
86 setData(xValue, yValue, name, key, std::vector<char>{plotType});
87 _time++;
88}

◆ setData() [3/4]

template<typename T >
void olb::Gnuplot< T >::setData ( T xValue,
std::vector< T > yValues,
std::vector< std::string > names = {""},
std::string key = "right",
std::vector< char > plotType = {'l','l'} )

sets the data and plot file for a double and a vector of doubles (x and {y1,y2,...}) for each entry of the y-axis-list, a plot Type can be specified (default: line graph {'l', 'l'})

writes the data and plot file for a double and a vector of doubles (x and y1,y2,...) plotType indicates whether you want a linegraph 'l' (default) or a scatterplot 'p': (default: {'l','l'}) The position in the vector 'plotType'{'l', 'p'} is linked to the rank of the y-axis (y1, y2) : y1 is plotted in form of a line plot & y2 is plotted in form of a scatterplot

Definition at line 95 of file gnuplotWriter.hh.

96{
97 if (_init) {
98 _dataSize = yValues.size();
99 _key = key;
100 _names = names;
101 _plotTypes = plotType;
102 if (_names.size() < _dataSize) {
103 for (unsigned int i = _names.size(); i < _dataSize; i++) {
104 _names.push_back("");
105 }
106 }
107 if (_plotTypes.size() < _dataSize) {
108 for (unsigned int i = _plotTypes.size(); i < _dataSize; i++) {
109 _plotTypes.push_back('l');
110 }
111 }
112 if (_gnuplotInstalled && _liveplot) {
113 writePlotFile("plot");
114 }
115 }
116 csvWriter.writeDataFile(xValue,yValues);
117
118 if (_gnuplotInstalled && _liveplot && _init) {
119 startGnuplot("plot");
120 }
121
122 _init = false;
123 return;
124}
void startGnuplot(std::string plotFile, std::string plotName="")
system command to start gnuplot (LINUX ONLY!)

◆ setData() [4/4]

template<typename T >
void olb::Gnuplot< T >::setData ( T xValue,
T yValue,
std::string name = "",
std::string key = "",
char plotType = 'l' )

sets the data and plot file for two doubles (x and y) the plotType indicates whether the user want to plot a line graph (default = 'l') or e.g.

writes the data and plot file for two doubles (x and y) plotType indicates whether you want a linegraph 'l' (default) or a scatterplot 'p' (default: 'l')

a scatter plot ('p')

Definition at line 76 of file gnuplotWriter.hh.

77{
78 setData(xValue, std::vector<T>{yValue}, std::vector<std::string>{name}, key, std::vector<char>{plotType});
79}
std::string name()
Returns distinct name on GCC, Clang and ICC but may return arbitrary garbage as per the standard.
Definition meta.h:100

◆ setLabel()

template<typename T >
void olb::Gnuplot< T >::setLabel ( std::string xLabel = "",
std::string yLabel = "" )

set labels of the plot: xLabel and yLabel

set Label of the gnuplotPlot; xLabel and yLabel

Definition at line 352 of file gnuplotWriter.hh.

353{
354 _xLabel = xLabel;
355 _yLabel = yLabel;
356}

◆ startGnuplot()

template<typename T >
void olb::Gnuplot< T >::startGnuplot ( std::string plotFile,
std::string plotName = "" )
protected

system command to start gnuplot (LINUX ONLY!)

system command to start gnuplot (LINUX ONLY!) plotName indicates the name of the plot in case the user wants to create more than one plot with the simulation results (default: plotName = "")

Definition at line 363 of file gnuplotWriter.hh.

364{
365#ifndef WIN32
366 if (singleton::mpi().getRank() == _rank) {
367 if (!system(nullptr)) {
368 exit (EXIT_FAILURE);
369 }
370 const std::string command = "gnuplot -persistent "+_dir+"data/"+plotFile+plotName+".p > /dev/null &";
371 if ( system(command.c_str()) ) {
372 std::cout << "Error at GnuplotWriter" << std::endl;
373 }
374 }
375 return;
376#endif
377}
void exit(int exitcode)
Definition singleton.h:165

References olb::singleton::mpi().

+ Here is the call graph for this function:

◆ writePDF()

template<typename T >
void olb::Gnuplot< T >::writePDF ( std::string plotName = "")

writes an PDF

Definition at line 189 of file gnuplotWriter.hh.

190{
191 if (_gnuplotInstalled && (!_init)) {
192 writePlotFile("pdf", plotName);
193 startGnuplot("plotPDF", plotName);
194 }
195 return;
196}

◆ writePNG()

template<typename T >
void olb::Gnuplot< T >::writePNG ( int iT = -1,
double xRange = -1,
std::string plotName = "" )

writes PNGs usage: first argument: numbering of png file (optional), second argument: range for the x axis (optional) third argument: name the plot in order to specify a plotID in case the user want to create more than one plot with the simulation results no arguments: writes in one file with adaptive xrange and no specific name

writes PNGs usage: first argument: numbering of png file second argument: range for the x axis thrid argument: specifies the name of the plot in case the user wants to create more than one plot with the simulation results (default: plotName = "") no arguments: writes consecutive numbers with adaptive xrange

initialize the writePlotFile for Gnuplot with the type and the name of the output data

Definition at line 206 of file gnuplotWriter.hh.

207{
208 if (_gnuplotInstalled && (!_init)) {
209 _iT = iT;
210 _xRange = xRange;
211
213 writePlotFile("png", plotName);
214 startGnuplot("plotPNG", plotName);
215 }
216 return;
217}

The documentation for this class was generated from the following files: