OpenLB 1.7
Loading...
Searching...
No Matches
gnuplotWriter.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2016 Fabian Klemens
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#ifndef GNUPLOT_WRITER_H
25#define GNUPLOT_WRITER_H
26
27#include <iomanip>
28#include <iostream>
29#include <vector>
30#include "CSVWriter.h"
31#include "CSVWriter.hh"
32
33namespace olb {
34
35template< typename T >
36class Gnuplot {
37public:
38
41
45 Gnuplot(std::string name, bool liveplot, std::string preCommand, AxisType axisType, Regression regressionType);
46 explicit Gnuplot(std::string name);
47 Gnuplot(std::string name, bool liveplot);
48 Gnuplot(std::string name, AxisType axisType);
49 Gnuplot(std::string name, AxisType axisType, Regression regressionType);
50
52 void init();
53
57 void setData(T xValue, T yValue, std::string name = "", std::string key = "", char plotType = 'l');
59 void setData(bool noXvalue, T yValue, std::string name = "", std::string key = "", char plotType = 'l');
60
63 void setData(T xValue, std::vector<T> yValues, std::vector<std::string> names = {""}, std::string key = "right", std::vector<char> plotType = {'l','l'});
65 void setData(bool noXvalue, std::vector<T> yValues, std::vector<std::string> names = {""}, std::string key = "right", const std::vector<char> plotType = {'l','l'});
66
68 void setLabel(std::string xLabel = "", std::string yLabel = "");
69
71 void writePDF(std::string plotName = "");
72
79 void writePNG(int iT = -1, double xRange = -1, std::string plotName = "");
80
81
82private:
83 std::string _xLabel;
84 std::string _yLabel;
85 std::string _name;
86 bool _liveplot;
87 std::string _type;
88 std::string _dataFile;
89 std::string _dir;
90 std::vector<std::string> _names;
91 std::string _key;
92 std::string _preCommand;
93 AxisType _axisType;
94 Regression _regressionType;
95
98 CSV<T> csvWriter;
99
102 std::vector<char> _plotTypes;
103 bool _init = true;
104 unsigned int _dataSize = 0;
105 int _iT = -1;
106 double _xRange = -1;
107 T _time = 0.;
108
109 static constexpr int _rank {0}; // only process _rank will write output
110 bool _gnuplotInstalled {false};
111
113 void writePlotFile(std::string type, std::string plotName = "");
114
115protected:
117 void startGnuplot(std::string plotFile, std::string plotName = "");
118
120 void linRegression(std::ofstream& fout, std::string x_axisType, std::string y_axisType);
121
123 void scaleAxes(std::ofstream& fout);
124};
125
126} // namespace olb
127
128#endif
void init()
initialises the data file
void startGnuplot(std::string plotFile, std::string plotName="")
system command to start gnuplot (LINUX ONLY!)
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...
void scaleAxes(std::ofstream &fout)
scales the axes if needed
Gnuplot(std::string name, bool liveplot, std::string preCommand, AxisType axisType, Regression regressionType)
type of Regression, off, LINear REGression, exponential Regression?,...
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...
Regression
different types of data usage and axes scaling
void linRegression(std::ofstream &fout, std::string x_axisType, std::string y_axisType)
creates the lin regression to the data
void writePDF(std::string plotName="")
writes an PDF
void setLabel(std::string xLabel="", std::string yLabel="")
set labels of the plot: xLabel and yLabel
Top level namespace for all of OpenLB.