2
/// This file is part of Rheolef.
4
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
6
/// Rheolef is free software; you can redistribute it and/or modify
7
/// it under the terms of the GNU General Public License as published by
8
/// the Free Software Foundation; either version 2 of the License, or
9
/// (at your option) any later version.
11
/// Rheolef is distributed in the hope that it will be useful,
12
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
/// GNU General Public License for more details.
16
/// You should have received a copy of the GNU General Public License
17
/// along with Rheolef; if not, write to the Free Software
18
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
/// =========================================================================
22
// animations using gnuplot
24
// author: Pierre.Saramito@imag.fr
26
// date: 17 november 2002
28
#include "rheolef/branch.h"
29
#include "rheolef/pstream.h"
30
#include "rheolef/rheostream.h"
34
// ====================================================
35
// yet hard-coded ! TODO: use a -select-contour option
36
// ====================================================
39
put_header_gnuplot (odiststream& ops, const branch_basic<T,sequential>& b)
41
ostream& out = ops.os();
42
delete_macro (b._p_ctrl_out);
43
delete_macro (b._p_data_out);
44
string basename = iorheo::getbasename(out);
45
if (basename == "") basename = "output";
46
bool do_verbose = iorheo::getverbose(clog);
47
bool do_execute = iorheo::getexecute(clog);
48
bool do_clean = iorheo::getclean (clog);
49
string tmp = (do_clean ? get_tmpdir() + "/" : "");
51
string plot_name = tmp+basename + ".plot";
52
b._p_ctrl_out = new_macro (ofstream(plot_name.c_str()));
53
do_verbose && clog << "! file `" << plot_name << "' created" << endl;
54
*(b._p_ctrl_out) << setbasename(basename)
55
<< setprecision(numeric_limits<Float>::digits10)
56
<< "dt_pause = 0.25 # in seconds" << endl;
58
string gdat_name = tmp+basename + ".gdat";
59
b._p_data_out = new_macro (ofstream(gdat_name.c_str()));
60
do_verbose && clog << "! file `" << gdat_name << "' created" << endl;
61
*(b._p_data_out) << setbasename(basename)
62
<< setprecision(numeric_limits<Float>::digits10);
66
put_event_gnuplot (odiststream& ops, const branch_basic<T,sequential>& b)
68
typedef typename branch_basic<T,sequential>::size_type size_type;
69
if (b.n_field() == 0) return;
70
// TODO: assume all fields have the same mesh
71
const space_basic<T,sequential>& Xh = b[0].second.get_space();
72
const geo_basic<T,sequential>& omega = Xh.get_geo();
73
const array<point_basic<T>,sequential>& xdof = Xh.get_xdofs();
75
bool do_clean = iorheo::getclean (clog);
76
string basename = iorheo::getbasename(ops.os());
77
if (basename == "") basename = "output";
78
string tmp = (do_clean ? get_tmpdir() + "/" : "");
79
string gdat_name = tmp+basename + ".gdat";
80
// -----------------------------------------------
81
// 1) range, as computed at the first occurence
82
// -----------------------------------------------
83
if (b._count_value == 0) {
84
T all_min = std::numeric_limits<T>::max();
85
T all_max = std::numeric_limits<T>::min();
86
for (size_t ifld = 0, nfld = b.n_field(); ifld < nfld; ifld++) {
87
const field_basic<T,sequential>& u = b[ifld].second;
88
all_min = std::min (all_min, u.min());
89
all_max = std::max (all_max, u.max());
91
if (b._u_range.first != std::numeric_limits<T>::min()) {
92
all_min = b._u_range.first;
94
if (b._u_range.second != std::numeric_limits<T>::max()) {
95
all_max = b._u_range.second;
97
if (fabs(all_max) - fabs(all_min) < 1e-7) {
98
// perhaps the solution is zero ? try to renormalize
99
// TODO: add command-line options for the range
100
all_max = all_min + 1;
102
*(b._p_ctrl_out) << "set xrange [" << omega.xmin()[0] << ":" << omega.xmax()[0] << "]" << endl
103
<< "set yrange [" << all_min << ":" << all_max << "]" << endl;
105
// -----------------------------------------------
107
// -----------------------------------------------
108
*(b._p_ctrl_out) << "plot \\" << endl;
109
const string& pname = b.parameter_name() + itos(b._count_value)
110
+ "=" + ftos(b.parameter());
111
for (size_t ifld = 0, nfld = b.n_field(); ifld < nfld; ifld++) {
112
const string& uname = b[ifld].first;
113
*(b._p_ctrl_out) << (ifld == 0 ? " " : ",")
114
<< " \"" << gdat_name << "\""
115
<< " i " << b._count_value
117
<< " t \"" << uname << "(" << pname << ")\""
119
<< (ifld < nfld-1 ? " \\" : "")
122
*(b._p_ctrl_out) << "pause dt_pause" << endl;
123
// -----------------------------------------------
125
// -----------------------------------------------
126
// TODO: Pk is buggy if edges are not ordered from left to right... to fix !
127
// TODO: P0, P1d, ... recycler field::gnuplot() dans "field-mtv.cc"
128
// mais avec un multi-field
129
size_type ndof_P1 = omega.n_vertex();
130
for (size_type idof = 0, ndof = ndof_P1; idof < ndof; idof++) {
131
*(b._p_data_out) << xdof[idof][0];
132
for (size_t ifld = 0, nfld = b.n_field(); ifld < nfld; ifld++) {
133
const field_basic<T,sequential>& u = b[ifld].second;
134
*(b._p_data_out) << " " << u.dof(idof);
136
*(b._p_data_out) << endl;
138
*(b._p_data_out) << endl << endl;
142
put_finalize_gnuplot (odiststream& ops, const branch_basic<T,sequential>& b)
144
// is the destructor virtual : ofstream::~ofstream() or opstream::~opstream() ?
145
string basename = iorheo::getbasename(ops.os());
146
if (basename == "") basename = "output";
147
bool do_verbose = iorheo::getverbose(clog);
148
bool do_execute = iorheo::getexecute(clog);
149
bool do_clean = iorheo::getclean(clog);
150
bool reader_on_stdin = iorheo::getreader_on_stdin(ops.os());
151
if (! reader_on_stdin) {
152
*(b._p_ctrl_out) << "pause -1 \"<end>\"" << endl;
154
string tmp = (do_clean ? get_tmpdir() + "/" : "");
161
command = "gnuplot ";
162
if (reader_on_stdin) command += "-persist ";
163
command += tmp + basename + ".plot";
164
if (do_verbose) clog << "! " << command << endl;
166
status = system (command.c_str());
169
// clear gnuplot data
171
if (!do_execute && do_clean) {
172
string tmp = get_tmpdir() + "/";
173
if (!do_clean) tmp = "";
174
string command = "/bin/rm -f " + tmp+basename + ".plot "
175
+ tmp+basename + ".gdat";
176
do_verbose && clog << "! " << command << endl;
177
int status = system (command.c_str());
179
delete_macro (b._p_ctrl_out);
180
delete_macro (b._p_data_out);
184
// ----------------------------------------------------------------------------
185
// instanciation in library
186
// ----------------------------------------------------------------------------
187
template void put_header_gnuplot (odiststream&, const branch_basic<Float,sequential>&);
188
template void put_event_gnuplot (odiststream&, const branch_basic<Float,sequential>&);
189
template void put_finalize_gnuplot (odiststream&, const branch_basic<Float,sequential>&);
191
} // namespace rheolef