rheolef  7.0
branch_seq_visu_gnuplot.cc
Go to the documentation of this file.
1 #include "rheolef/branch.h"
2 #include "rheolef/pstream.h"
3 #include "rheolef/rheostream.h"
4 #include "rheolef/basis_on_pointset.h"
6 
7 namespace rheolef {
8 using namespace std;
9 
10 // yet hard-coded ! TODO: use a -select-contour option
11 template <class T>
12 void
14 {
15  ostream& out = ops.os();
18  string basename = iorheo::getbasename(out);
19  if (basename == "") basename = "output";
20  bool do_verbose = iorheo::getverbose(clog);
21  bool do_execute = iorheo::getexecute(clog);
22  bool do_clean = iorheo::getclean (clog);
23  string tmp = (do_clean ? get_tmpdir() + "/" : "");
24 
25  string plot_name = tmp+basename + ".plot";
26  string param_name = tmp+basename + "-visu-param.plot";
27  b._to_clean = plot_name;
28  b._p_ctrl_out = new_macro (ofstream(plot_name.c_str()));
29  do_verbose && clog << "! file `" << plot_name << "' created" << endl;
30  *(b._p_ctrl_out) << setbasename(basename)
31  << setprecision(numeric_limits<T>::digits10)
32  << "load \"" << param_name << "\"" << endl;
33  b._have_u_range.first = (b._u_range.first != std::numeric_limits<T>::max());
34  b._have_u_range.second = (b._u_range.second != -std::numeric_limits<T>::max());
35 }
36 template <class T>
37 void
39 {
41  bool do_verbose = iorheo::getverbose(clog);
42  size_t nfld = b.n_field();
43  if (nfld == 0) return;
44  const space_basic<T,sequential>& Xh = b[0].second.get_space();
45  const geo_basic<T,sequential>& omega = Xh.get_geo();
46  const disarray<point_basic<T>,sequential>& xdof = Xh.get_xdofs();
47 
48  bool do_clean = iorheo::getclean (clog);
49  string basename = iorheo::getbasename(ops.os());
50  if (basename == "") basename = "output";
51  string tmp = (do_clean ? get_tmpdir() + "/" : "");
52  if (b._count_value == 0) {
53  *(b._p_ctrl_out) << "set xrange [" << omega.xmin()[0] << ":" << omega.xmax()[0] << "]" << endl;
54  }
55  if (! b._have_u_range.first || ! b._have_u_range.second) {
56  for (size_t ifld = 0; ifld < nfld; ifld++) {
57  const field_basic<T,sequential>& u = b[ifld].second;
58  if (! b._have_u_range.first) {
59  b._u_range.first = std::min (b._u_range.first, u.min());
60  }
61  if (! b._have_u_range.second) {
62  b._u_range.second = std::max (b._u_range.second, u.max());
63  }
64  }
65  }
66  const string& pname = b.parameter_name() + " = " + ftos(b.parameter());
67  *(b._p_ctrl_out) << "set title \"i = " << b._count_value << ": " << pname << "\" font \"arial,20\"" << endl
68  << "plot \\" << endl;
69  for (size_t ifld = 0; ifld < nfld; ifld++) {
70  const string& uname = b[ifld].first;
71  string gdat_name = tmp + basename + "_" + uname + "_" + itos(b._count_value) + ".gdat";
72  *(b._p_ctrl_out) << (ifld == 0 ? " " : ",")
73  << " \"" << gdat_name << "\""
74  << " u 1:2"
75  << " t \"" << uname << "\""
76  << " w l"
77  << (ifld < nfld-1 ? " \\" : "")
78  << endl;
79  }
80  *(b._p_ctrl_out) << "pause dt_pause" << endl;
81  size_type subdivide = iorheo::getsubdivide(ops.os());
82  bool fill = iorheo::getfill(ops.os()); // show grid or fill elements
83  for (size_t ifld = 0; ifld < nfld; ifld++) {
84  const string& uname = b[ifld].first;
85  const field_basic<T,sequential>& uh = b[ifld].second;
86  string gdat_name = tmp + basename + "_" + uname + "_" + itos(b._count_value) + ".gdat";
87  ofstream gdat (gdat_name.c_str());
88  b._to_clean = b._to_clean + " " + gdat_name;
89  if (do_verbose) clog << "! file \"" << gdat_name << "\" created.\n";
90  gdat << setprecision(numeric_limits<T>::digits10);
91  const geo_basic<T,sequential>& omega = uh.get_geo();
92  const numbering<T,sequential>& fem = uh.get_space().get_numbering();
93  if (subdivide == 0) { // subdivide is unset: use default
94  subdivide = std::max(omega.order(), subdivide);
95  subdivide = std::max(fem.degree (), subdivide);
96  }
97  size_type map_dim = omega.map_dimension();
98  size_type used_dim = (fill ? map_dim : 1);
99  basis_basic<T> subdivide_pointset ("P"+itos(subdivide));
100  basis_on_pointset<T> geo_on_pointset (subdivide_pointset, omega.get_piola_basis());
101  basis_on_pointset<T> field_on_pointset (subdivide_pointset, fem.get_basis());
102  bound_type<T> bbox;
103  bbox.xmin = omega.xmin();
104  bbox.xmax = omega.xmax();
105  bbox.umin = uh.min();
106  bbox.umax = uh.max();
107  for (size_type ie = 0, ne = omega.size(used_dim); ie < ne; ie++) {
108  const geo_element& K = omega.get_geo_element(used_dim,ie);
109  put (gdat, K, omega, uh, geo_on_pointset, field_on_pointset, subdivide, bbox);
110  }
111  gdat.close();
112  }
113 }
114 template <class T>
115 void
117 {
118  string basename = iorheo::getbasename(ops.os());
119  if (basename == "") basename = "output";
120  bool do_verbose = iorheo::getverbose(clog);
121  bool do_execute = iorheo::getexecute(clog);
122  bool do_clean = iorheo::getclean(clog);
123  bool reader_on_stdin = iorheo::getreader_on_stdin(ops.os());
124  if (! reader_on_stdin) {
125  *(b._p_ctrl_out) << "pause -1 \"<end>\"" << endl;
126  }
127  string tmp = (do_clean ? get_tmpdir() + "/" : "");
128  string param_name = tmp+basename + "-visu-param.plot";
129  ofstream param (param_name.c_str());
130  if (do_verbose) clog << "! file \"" << param_name << "\" created.\n";
131  b._to_clean = b._to_clean + " " + param_name;
132  param << "duration = 30 # in seconds" << endl
133  << "n_step = " << b._count_value << endl
134  << "dt_pause = 1.0*duration/n_step" << endl;
135  if (b._u_range.second - b._u_range.first < 1e-7) {
136  b._u_range.second = b._u_range.first + 1;
137  }
138  param << "set yrange [" << b._u_range.first << ":" << b._u_range.second << "]" << endl;
139  param.close();
140  int status = 0;
141  string command;
142  if (do_execute) {
143  command = "gnuplot ";
144  if (reader_on_stdin) command += "-persist ";
145  command += tmp + basename + ".plot";
146  if (do_verbose) clog << "! " << command << endl;
147  cin.sync();
148  status = system (command.c_str());
149  }
150  if (do_clean) {
151  string tmp = get_tmpdir() + "/";
152  if (!do_clean) tmp = "";
153  string command = "/bin/rm -f " + b._to_clean;
154  // do_verbose && clog << "! " << command << endl;
155  do_verbose && clog << "! cleaning temporary .plot and .gdat files" << endl;
156  int status = system (command.c_str());
157  }
160  b._p_ctrl_out = 0;
161  b._p_data_out = 0;
162  b._to_clean = "";
163 }
167 
168 } // namespace rheolef
const disarray< point_basic< T >, sequential > & get_xdofs() const
Definition: space.h:550
#define new_macro(obj)
Definition: compiler.h:361
const basis_basic< T > & get_basis() const
Definition: numbering.h:77
field - piecewise polynomial finite element field
size_type degree() const
Definition: numbering.h:119
void put_finalize_gnuplot(odiststream &ops, const branch_basic< T, sequential > &b)
std::string get_tmpdir()
Definition: rheostream.cc:35
const_reference get_geo_element(size_type dim, size_type ige) const
Definition: geo.h:964
idiststream, odiststream - distributed interface for large data streams
Definition: diststream.h:68
void put(std::ostream &out, std::string name, const tiny_matrix< T > &a)
Definition: tiny_lu.h:106
#define delete_macro(ptr)
Definition: compiler.h:363
T max() const
Definition: field.h:592
const T & parameter() const
Definition: branch.h:309
STL namespace.
disarray - container in distributed environment
Definition: disarray.h:350
const node_type & xmin() const
Definition: geo.h:957
irheostream, orheostream - large data streams
Definition: compiler.h:7
string ftos(const Float &x)
Definition: rheostream.cc:40
branch - a parameter-dependent sequence of field
Definition: branch.h:46
const geo_type & get_geo() const
Definition: field.h:284
T min() const
Definition: field.h:576
void put_header_gnuplot(odiststream &ops, const branch_basic< T, sequential > &b)
std::string _to_clean
Definition: branch.h:166
const geo_basic< T, sequential > & get_geo() const
Definition: space.h:375
std::ostream * _p_data_out
Definition: branch.h:161
const node_type & xmax() const
Definition: geo.h:958
std::pair< bool, bool > _have_u_range
Definition: branch.h:168
void put_event_gnuplot(odiststream &ops, const branch_basic< T, sequential > &b)
Definition: rotating-hill.h:1
size_type map_dimension() const
Definition: geo.h:950
base::size_type size_type
Definition: branch.h:50
size_type n_field() const
Definition: branch.h:330
size_type _count_value
Definition: branch.h:160
const space_type & get_space() const
Definition: field.h:283
const basis_basic< T > & get_piola_basis() const
Definition: geo.h:955
std::pair< T, T > _u_range
Definition: branch.h:167
geo_element - element of a mesh
std::string itos(std::string::size_type i)
const std::string & parameter_name() const
Definition: branch.h:316
size_type order() const
Definition: geo.h:956
std::ostream & os()
Definition: diststream.h:166
size_type size(size_type dim) const
Definition: geo.h:1063
std::ostream * _p_ctrl_out
Definition: branch.h:162