~ubuntu-branches/ubuntu/trusty/rheolef/trusty

« back to all changes in this revision

Viewing changes to nfem/plib/branch_seq_visu_gnuplot.cc

  • Committer: Package Import Robot
  • Author(s): Pierre Saramito
  • Date: 2012-04-06 09:12:21 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20120406091221-m58me99p1nxqui49
Tags: 6.0-1
* New upstream release 6.0 (major changes):
  - massively distributed and parallel support
  - full FEM characteristic method (Lagrange-Gakerkin method) support
  - enhanced users documentation 
  - source code supports g++-4.7 (closes: #667356)
* debian/control: dependencies for MPI distributed solvers added
* debian/rules: build commands simplified
* debian/librheolef-dev.install: man1/* to man9/* added
* debian/changelog: package description rewritted (closes: #661689)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
///
 
2
/// This file is part of Rheolef.
 
3
///
 
4
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
 
5
///
 
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.
 
10
///
 
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.
 
15
///
 
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
 
19
///
 
20
/// =========================================================================
 
21
//
 
22
// animations using gnuplot
 
23
//
 
24
// author: Pierre.Saramito@imag.fr
 
25
//
 
26
// date: 17 november 2002
 
27
//
 
28
#include "rheolef/branch.h"
 
29
#include "rheolef/pstream.h"
 
30
#include "rheolef/rheostream.h"
 
31
namespace rheolef {
 
32
using namespace std;
 
33
 
 
34
// ====================================================
 
35
// yet hard-coded ! TODO: use a -select-contour option
 
36
// ====================================================
 
37
template <class T>
 
38
void
 
39
put_header_gnuplot (odiststream& ops, const branch_basic<T,sequential>& b)
 
40
{
 
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() + "/" : "");
 
50
 
 
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;
 
57
 
 
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);
 
63
}
 
64
template <class T>
 
65
void
 
66
put_event_gnuplot (odiststream& ops, const branch_basic<T,sequential>& b)
 
67
{
 
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();
 
74
 
 
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());
 
90
    }
 
91
    if (b._u_range.first != std::numeric_limits<T>::min()) {
 
92
      all_min = b._u_range.first;
 
93
    }
 
94
    if (b._u_range.second != std::numeric_limits<T>::max()) {
 
95
      all_max = b._u_range.second;
 
96
    }
 
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;
 
101
    }
 
102
    *(b._p_ctrl_out) << "set xrange [" << omega.xmin()[0] << ":" << omega.xmax()[0] << "]" << endl
 
103
                     << "set yrange [" << all_min << ":" << all_max << "]" << endl;
 
104
  }
 
105
  // -----------------------------------------------
 
106
  // 2) plot commands
 
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
 
116
                     << " u 1:" << ifld+2
 
117
                     << " t \"" << uname << "(" << pname << ")\""
 
118
                     << " w l"
 
119
                     << (ifld < nfld-1 ? " \\" : "")
 
120
                     << endl;
 
121
  }
 
122
  *(b._p_ctrl_out) << "pause dt_pause" << endl;
 
123
  // -----------------------------------------------
 
124
  // 3) data
 
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);
 
135
    }
 
136
    *(b._p_data_out) << endl;
 
137
  }
 
138
  *(b._p_data_out) << endl << endl;
 
139
}
 
140
template <class T>
 
141
void
 
142
put_finalize_gnuplot (odiststream& ops, const branch_basic<T,sequential>& b)
 
143
{
 
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;
 
153
  }
 
154
  string tmp = (do_clean ? get_tmpdir() + "/" : "");
 
155
  //
 
156
  // run gnuplot
 
157
  //
 
158
  int status = 0;
 
159
  string command;
 
160
  if (do_execute) {
 
161
      command = "gnuplot ";
 
162
      if (reader_on_stdin) command += "-persist ";
 
163
      command += tmp + basename + ".plot";
 
164
      if (do_verbose) clog << "! " << command << endl;
 
165
      cin.sync();
 
166
      status = system (command.c_str());
 
167
  }
 
168
  //
 
169
  // clear gnuplot data
 
170
  //
 
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());
 
178
  }
 
179
  delete_macro (b._p_ctrl_out);
 
180
  delete_macro (b._p_data_out);
 
181
  b._p_ctrl_out = 0;
 
182
  b._p_data_out = 0;
 
183
}
 
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>&);
 
190
 
 
191
} // namespace rheolef