Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
branch_seq_visu_gnuplot.cc
Go to the documentation of this file.
1
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/rheostream.h"
30#include "rheolef/basis_on_pointset.h"
32
33namespace rheolef {
34using namespace std;
35
36// ====================================================
37// yet hard-coded ! TODO: use a -select-contour option
38// ====================================================
39template <class T>
40void
42{
43 ostream& out = ops.os();
44 delete_macro (b._p_ctrl_out);
45 delete_macro (b._p_data_out);
46 string basename = iorheo::getbasename(out);
47 if (basename == "") basename = "output";
48 bool do_verbose = iorheo::getverbose(clog);
49 bool do_execute = iorheo::getexecute(clog);
50 bool do_clean = iorheo::getclean (clog);
51 string tmp = (do_clean ? get_tmpdir() + "/" : "");
52
53 string plot_name = tmp+basename + ".plot";
54 string param_name = tmp+basename + "-visu-param.plot";
55 b._to_clean = plot_name;
56 b._p_ctrl_out = new_macro (ofstream(plot_name.c_str()));
57 do_verbose && clog << "! file `" << plot_name << "' created" << endl;
58 *(b._p_ctrl_out) << setbasename(basename)
59 << setprecision(numeric_limits<T>::digits10)
60 << "load \"" << param_name << "\"" << endl;
61 b._have_u_range.first = (b._u_range.first != std::numeric_limits<T>::max());
62 b._have_u_range.second = (b._u_range.second != -std::numeric_limits<T>::max());
63}
64template <class T>
65void
67{
69 bool do_verbose = iorheo::getverbose(clog);
70 size_t nfld = b.n_field();
71 if (nfld == 0) return;
72 // TODO: assume all fields have the same mesh
73 const space_basic<T,sequential>& Xh = b[0].second.get_space();
74 const geo_basic<T,sequential>& omega = Xh.get_geo();
75 const disarray<point_basic<T>,sequential>& xdof = Xh.get_xdofs();
76
77 bool do_clean = iorheo::getclean (clog);
78 string basename = iorheo::getbasename(ops.os());
79 if (basename == "") basename = "output";
80 string tmp = (do_clean ? get_tmpdir() + "/" : "");
81 // ---------------------------------------------------------
82 // 1) range : as computed at the first occurrence
83 // -----------------------------------------------
84 if (b._count_value == 0) {
85 *(b._p_ctrl_out) << "set xrange [" << omega.xmin()[0] << ":" << omega.xmax()[0] << "]" << endl;
86 }
87 if (! b._have_u_range.first || ! b._have_u_range.second) {
88 for (size_t ifld = 0; ifld < nfld; ifld++) {
89 const field_basic<T,sequential>& u = b[ifld].second;
90 if (! b._have_u_range.first) {
91 b._u_range.first = std::min (b._u_range.first, u.min());
92 }
93 if (! b._have_u_range.second) {
94 b._u_range.second = std::max (b._u_range.second, u.max());
95 }
96 }
97 }
98 // -----------------------------------------------
99 // 2) plot commands
100 // -----------------------------------------------
101 const string& pname = b.parameter_name() + " = " + ftos(b.parameter());
102 *(b._p_ctrl_out) << "set title \"i = " << b._count_value << ": " << pname << "\" font \"arial,20\"" << endl
103 << "plot \\" << endl;
104 for (size_t ifld = 0; ifld < nfld; ifld++) {
105 const string& uname = b[ifld].first;
106 string gdat_name = tmp + basename + "_" + uname + "_" + std::to_string(b._count_value) + ".gdat";
107 *(b._p_ctrl_out) << (ifld == 0 ? " " : ",")
108 << " \"" << gdat_name << "\""
109 << " u 1:2"
110 << " t \"" << uname << "\""
111 << " w l"
112 << (ifld < nfld-1 ? " \\" : "")
113 << endl;
114 }
115 *(b._p_ctrl_out) << "pause dt_pause" << endl;
116 // -----------------------------------------------
117 // 3) data
118 // -----------------------------------------------
119 // TODO: subdivide option not set by the branch unix command
120 size_type subdivide = iorheo::getsubdivide(ops.os());
121 bool fill = iorheo::getfill(ops.os()); // show grid or fill elements
122 for (size_t ifld = 0; ifld < nfld; ifld++) {
123 const string& uname = b[ifld].first;
124 const field_basic<T,sequential>& uh = b[ifld].second;
125 string gdat_name = tmp + basename + "_" + uname + "_" + std::to_string(b._count_value) + ".gdat";
126 ofstream gdat (gdat_name.c_str());
127 b._to_clean = b._to_clean + " " + gdat_name;
128 if (do_verbose) clog << "! file \"" << gdat_name << "\" created.\n";
129 gdat << setprecision(numeric_limits<T>::digits10);
130 const geo_basic<T,sequential>& omega = uh.get_geo();
131 const basis_basic<T>& b_fem = uh.get_space().get_basis();
132 if (subdivide == 0) { // subdivide is unset: use default
133 subdivide = std::max(omega.order(), subdivide);
134 subdivide = std::max(b_fem.degree (), subdivide);
135 }
136 size_type map_dim = omega.map_dimension();
137 size_type used_dim = (fill ? map_dim : 1);
138 basis_basic<T> subdivide_pointset ("P"+std::to_string(subdivide));
139 piola_on_pointset<T> pops; pops.initialize (omega.get_piola_basis(), subdivide_pointset, integrate_option());
140 fem_on_pointset<T> fops; fops.initialize (b_fem, pops);
141 bound_type<T> bbox;
142 bbox.xmin = omega.xmin();
143 bbox.xmax = omega.xmax();
144 bbox.umin = uh.min();
145 bbox.umax = uh.max();
146 for (size_type ie = 0, ne = omega.size(used_dim); ie < ne; ie++) {
147 const geo_element& K = omega.get_geo_element(used_dim,ie);
148 put (gdat, omega, K, uh, fops, subdivide, bbox);
149 }
150 gdat.close();
151 }
152}
153template <class T>
154void
156{
157 // is the destructor virtual : ofstream::~ofstream() or opstream::~opstream() ?
158 string basename = iorheo::getbasename(ops.os());
159 if (basename == "") basename = "output";
160 bool do_verbose = iorheo::getverbose(clog);
161 bool do_execute = iorheo::getexecute(clog);
162 bool do_clean = iorheo::getclean(clog);
163 bool reader_on_stdin = iorheo::getreader_on_stdin(ops.os());
164 if (! reader_on_stdin) {
165 *(b._p_ctrl_out) << "pause -1 \"<end>\"" << endl;
166 }
167 string tmp = (do_clean ? get_tmpdir() + "/" : "");
168 //
169 // compute visu params: u_range, pause delay
170 //
171 string param_name = tmp+basename + "-visu-param.plot";
172 ofstream param (param_name.c_str());
173 if (do_verbose) clog << "! file \"" << param_name << "\" created.\n";
174 b._to_clean = b._to_clean + " " + param_name;
175 param << "duration = 30 # in seconds" << endl
176 << "n_step = " << b._count_value << endl
177 << "dt_pause = 1.0*duration/n_step" << endl;
178 if (b._u_range.second - b._u_range.first < 1e-7) {
179 // perhaps the solution is zero ? try to renormalize
180 b._u_range.second = b._u_range.first + 1;
181 }
182 param << "set yrange [" << b._u_range.first << ":" << b._u_range.second << "]" << endl;
183 param.close();
184 //
185 // run gnuplot
186 //
187 int status = 0;
188 string command;
189 if (do_execute) {
190 command = "gnuplot ";
191 if (reader_on_stdin) command += "-persist ";
192 command += tmp + basename + ".plot";
193 if (do_verbose) clog << "! " << command << endl;
194 cin.sync();
195 status = system (command.c_str());
196 }
197 //
198 // clear gnuplot data
199 //
200 if (do_clean) {
201 string tmp = get_tmpdir() + "/";
202 if (!do_clean) tmp = "";
203 string command = "/bin/rm -f " + b._to_clean;
204 // to much files to see:
205 // do_verbose && clog << "! " << command << endl;
206 do_verbose && clog << "! cleaning temporary .plot and .gdat files" << endl;
207 int status = system (command.c_str());
208 }
209 delete_macro (b._p_ctrl_out);
210 delete_macro (b._p_data_out);
211 b._p_ctrl_out = 0;
212 b._p_data_out = 0;
213 b._to_clean = "";
214}
215// ----------------------------------------------------------------------------
216// instanciation in library
217// ----------------------------------------------------------------------------
221
222} // namespace rheolef
field::size_type size_type
Definition branch.cc:430
size_type degree() const
Definition basis.h:728
base::size_type size_type
Definition branch.h:88
see the disarray page for the full documentation
Definition disarray.h:497
void initialize(const basis_basic< T > &fem_basis, const piola_on_pointset< T > &pops)
T min() const
Definition field.h:786
T max() const
Definition field.h:802
const geo_type & get_geo() const
Definition field.h:271
const space_type & get_space() const
Definition field.h:270
generic mesh with rerefence counting
Definition geo.h:1089
see the geo_element page for the full documentation
see the integrate_option page for the full documentation
odiststream: see the diststream page for the full documentation
Definition diststream.h:137
std::ostream & os()
Definition diststream.h:247
void initialize(const basis_basic< T > &piola_basis, const quadrature< T > &quad, const integrate_option &iopt)
the finite element space
Definition space.h:382
This file is part of Rheolef.
void put_event_gnuplot(odiststream &ops, const branch_basic< T, sequential > &b)
std::string get_tmpdir()
get_tmpdir: see the rheostream page for the full documentation
Definition rheostream.cc:54
void put_header_gnuplot(odiststream &ops, const branch_basic< T, sequential > &b)
void put(std::ostream &out, std::string name, const tiny_matrix< T > &a)
Definition tiny_lu.h:155
void put_finalize_gnuplot(odiststream &ops, const branch_basic< T, sequential > &b)
string ftos(const Float &x)
itof: see the rheostream page for the full documentation
Definition rheostream.cc:59
STL namespace.
Definition leveque.h:25