rheolef  6.6
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  b._to_clean = plot_name;
27  b._p_ctrl_out = new_macro (ofstream(plot_name.c_str()));
28  do_verbose && clog << "! file `" << plot_name << "' created" << endl;
29  *(b._p_ctrl_out) << setbasename(basename)
30  << setprecision(numeric_limits<T>::digits10)
31  << "dt_pause = 0.25 # in seconds" << endl;
32 }
33 template <class T>
34 void
36 {
38  bool do_verbose = iorheo::getverbose(clog);
39  if (b.n_field() == 0) return;
40  const space_basic<T,sequential>& Xh = b[0].second.get_space();
41  const geo_basic<T,sequential>& omega = Xh.get_geo();
42  const array<point_basic<T>,sequential>& xdof = Xh.get_xdofs();
43 
44  bool do_clean = iorheo::getclean (clog);
45  string basename = iorheo::getbasename(ops.os());
46  if (basename == "") basename = "output";
47  string tmp = (do_clean ? get_tmpdir() + "/" : "");
48  size_t nfld = b.n_field();
49  if (b._count_value == 0) {
50  T all_min = std::numeric_limits<T>::max();
51  T all_max = std::numeric_limits<T>::min();
52  for (size_t ifld = 0; ifld < nfld; ifld++) {
53  const field_basic<T,sequential>& u = b[ifld].second;
54  all_min = std::min (all_min, u.min());
55  all_max = std::max (all_max, u.max());
56  }
57  if (b._u_range.first != std::numeric_limits<T>::min()) {
58  all_min = b._u_range.first;
59  }
60  if (b._u_range.second != std::numeric_limits<T>::max()) {
61  all_max = b._u_range.second;
62  }
63  if (fabs(all_max - all_min) < 1e-7) {
64  all_max = all_min + 1;
65  }
66  *(b._p_ctrl_out) << "set xrange [" << omega.xmin()[0] << ":" << omega.xmax()[0] << "]" << endl
67  << "set yrange [" << all_min << ":" << all_max << "]" << endl;
68  }
69  const string& pname = b.parameter_name() + " = " + ftos(b.parameter());
70  *(b._p_ctrl_out) << "set title \"i = " << b._count_value << ": " << pname << "\" font \"arial,20\"" << endl
71  << "plot \\" << endl;
72  for (size_t ifld = 0; ifld < nfld; ifld++) {
73  const string& uname = b[ifld].first;
74  string gdat_name = tmp + basename + "_" + uname + "_" + itos(b._count_value) + ".gdat";
75  *(b._p_ctrl_out) << (ifld == 0 ? " " : ",")
76  << " \"" << gdat_name << "\""
77  << " u 1:2"
78  << " t \"" << uname << "\""
79  << " w l"
80  << (ifld < nfld-1 ? " \\" : "")
81  << endl;
82  }
83  *(b._p_ctrl_out) << "pause dt_pause" << endl;
84  size_type subdivide = iorheo::getsubdivide(ops.os());
85  bool fill = iorheo::getfill(ops.os()); // show grid or fill elements
86  for (size_t ifld = 0; ifld < nfld; ifld++) {
87  const string& uname = b[ifld].first;
88  const field_basic<T,sequential>& uh = b[ifld].second;
89  string gdat_name = tmp + basename + "_" + uname + "_" + itos(b._count_value) + ".gdat";
90  ofstream gdat (gdat_name.c_str());
91  b._to_clean = b._to_clean + " " + gdat_name;
92  if (do_verbose) clog << "! file \"" << gdat_name << "\" created.\n";
93  gdat << setprecision(numeric_limits<T>::digits10);
94  const geo_basic<T,sequential>& omega = uh.get_geo();
95  const numbering<T,sequential>& fem = uh.get_space().get_numbering();
96  if (subdivide == 0) { // subdivide is unset: use default
97  subdivide = std::max(omega.order(), subdivide);
98  subdivide = std::max(fem.degree (), subdivide);
99  }
100  size_type map_dim = omega.map_dimension();
101  size_type used_dim = (fill ? map_dim : 1);
102  basis_basic<T> subdivide_pointset ("P"+itos(subdivide));
103  basis_on_pointset<T> geo_on_pointset (subdivide_pointset, omega.get_piola_basis());
104  basis_on_pointset<T> field_on_pointset (subdivide_pointset, fem.get_basis());
105  bound_type<T> bbox;
106  bbox.xmin = omega.xmin();
107  bbox.xmax = omega.xmax();
108  bbox.umin = uh.min();
109  bbox.umax = uh.max();
110  for (size_type ie = 0, ne = omega.size(used_dim); ie < ne; ie++) {
111  const geo_element& K = omega.get_geo_element(used_dim,ie);
112  put (gdat, K, omega, uh, geo_on_pointset, field_on_pointset, subdivide, bbox);
113  }
114  gdat.close();
115  }
116 }
117 template <class T>
118 void
120 {
121  string basename = iorheo::getbasename(ops.os());
122  if (basename == "") basename = "output";
123  bool do_verbose = iorheo::getverbose(clog);
124  bool do_execute = iorheo::getexecute(clog);
125  bool do_clean = iorheo::getclean(clog);
126  bool reader_on_stdin = iorheo::getreader_on_stdin(ops.os());
127  if (! reader_on_stdin) {
128  *(b._p_ctrl_out) << "pause -1 \"<end>\"" << endl;
129  }
130  string tmp = (do_clean ? get_tmpdir() + "/" : "");
131  int status = 0;
132  string command;
133  if (do_execute) {
134  command = "gnuplot ";
135  if (reader_on_stdin) command += "-persist ";
136  command += tmp + basename + ".plot";
137  if (do_verbose) clog << "! " << command << endl;
138  cin.sync();
139  status = system (command.c_str());
140  }
141  if (do_clean) {
142  string tmp = get_tmpdir() + "/";
143  if (!do_clean) tmp = "";
144  string command = "/bin/rm -f " + b._to_clean;
145  // do_verbose && clog << "! " << command << endl;
146  do_verbose && clog << "! cleaning temporary .plot and .gdat files" << endl;
147  int status = system (command.c_str());
148  }
151  b._p_ctrl_out = 0;
152  b._p_data_out = 0;
153  b._to_clean = "";
154 }
155 template void put_header_gnuplot (odiststream&, const branch_basic<Float,sequential>&);
156 template void put_event_gnuplot (odiststream&, const branch_basic<Float,sequential>&);
157 template void put_finalize_gnuplot (odiststream&, const branch_basic<Float,sequential>&);
158 
159 } // namespace rheolef
const basis_basic< T > & get_basis() const
Definition: numbering.h:76
#define new_macro(obj)
Definition: compiler.h:364
const node_type & xmin() const
Definition: geo.h:919
field - piecewise polynomial finite element field
Definition: field.h:225
const geo_type & get_geo() const
Definition: field.h:272
void put_finalize_gnuplot(odiststream &ops, const branch_basic< T, sequential > &b)
const basis_basic< T > & get_piola_basis() const
Definition: geo.h:917
std::string get_tmpdir()
Definition: rheostream.cc:33
size_type size(size_type dim) const
Definition: geo.h:1025
idiststream, odiststream - distributed interface for large data streams
Definition: diststream.h:68
boost::proto::result_of::make_expr< boost::proto::tag::function, vec_domain, const vec_detail::fabs_, const vec< T, M > & >::type fabs(const vec< T, M > &x)
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:366
STL namespace.
irheostream, orheostream - large data streams
Definition: compiler.h:7
string itos(string::size_type i)
Definition: rheostream.cc:38
const std::string & parameter_name() const
Definition: branch.h:310
string ftos(const Float &x)
Definition: rheostream.cc:45
branch - a parameter-dependent sequence of field
Definition: branch.h:46
const T & parameter() const
Definition: branch.h:303
const node_type & xmax() const
Definition: geo.h:920
void put_header_gnuplot(odiststream &ops, const branch_basic< T, sequential > &b)
const_reference get_geo_element(size_type dim, size_type ige) const
Definition: geo.h:926
std::string _to_clean
Definition: branch.h:166
size_type map_dimension() const
Definition: geo.h:912
std::ostream * _p_data_out
Definition: branch.h:161
void put_event_gnuplot(odiststream &ops, const branch_basic< T, sequential > &b)
Definition: rotating-hill.h:1
size_type n_field() const
Definition: branch.h:324
T min() const
Definition: field.h:550
base::size_type size_type
Definition: branch.h:50
size_type _count_value
Definition: branch.h:160
basis - polynomial basis
Definition: basis.h:77
std::pair< T, T > _u_range
Definition: branch.h:167
boost::proto::result_of::make_expr< boost::proto::tag::function, vec_domain, const vec_detail::max_, const int &, const vec< T, M > & >::type max(const int &x, const vec< T, M > &y)
geo_element - element of a mesh
const space_type & get_space() const
Definition: field.h:271
size_type order() const
Definition: geo.h:918
T max() const
Definition: field.h:566
boost::proto::result_of::make_expr< boost::proto::tag::function, vec_domain, const vec_detail::min_, const int &, const vec< T, M > & >::type min(const int &x, const vec< T, M > &y)
reference_element_H::size_type size_type
const array< point_basic< T >, sequential > & get_xdofs() const
Definition: space.h:549
std::ostream & os()
Definition: diststream.h:166
const geo_basic< T, sequential > & get_geo() const
Definition: space.h:374
std::ostream * _p_ctrl_out
Definition: branch.h:162
size_type degree() const
Definition: numbering.h:118