branch_seq_visu_gnuplot.cc
Go to the documentation of this file.
//
// animations using gnuplot
//
// author: Pierre.Saramito@imag.fr
//
// date: 17 november 2002
//
#include "rheolef/branch.h"
#include "rheolef/rheostream.h"
#include "rheolef/basis_on_pointset.h"
#include "field_seq_visu_gnuplot_internal.h"
namespace rheolef {
using namespace std;
// ====================================================
// yet hard-coded ! TODO: use a -select-contour option
// ====================================================
template <class T>
void
put_header_gnuplot (odiststream& ops, const branch_basic<T,sequential>& b)
{
ostream& out = ops.os();
delete_macro (b._p_ctrl_out);
delete_macro (b._p_data_out);
string basename = iorheo::getbasename(out);
if (basename == "") basename = "output";
bool do_verbose = iorheo::getverbose(clog);
bool do_execute = iorheo::getexecute(clog);
bool do_clean = iorheo::getclean (clog);
string tmp = (do_clean ? get_tmpdir() + "/" : "");
string plot_name = tmp+basename + ".plot";
string param_name = tmp+basename + "-visu-param.plot";
b._to_clean = plot_name;
b._p_ctrl_out = new_macro (ofstream(plot_name.c_str()));
do_verbose && clog << "! file `" << plot_name << "' created" << endl;
*(b._p_ctrl_out) << setbasename(basename)
<< setprecision(numeric_limits<T>::digits10)
<< "load \"" << param_name << "\"" << endl;
b._have_u_range.first = (b._u_range.first != std::numeric_limits<T>::max());
b._have_u_range.second = (b._u_range.second != -std::numeric_limits<T>::max());
}
template <class T>
void
put_event_gnuplot (odiststream& ops, const branch_basic<T,sequential>& b)
{
typedef typename branch_basic<T,sequential>::size_type size_type;
bool do_verbose = iorheo::getverbose(clog);
size_t nfld = b.n_field();
if (nfld == 0) return;
// TODO: assume all fields have the same mesh
const space_basic<T,sequential>& Xh = b[0].second.get_space();
const geo_basic<T,sequential>& omega = Xh.get_geo();
const disarray<point_basic<T>,sequential>& xdof = Xh.get_xdofs();
bool do_clean = iorheo::getclean (clog);
string basename = iorheo::getbasename(ops.os());
if (basename == "") basename = "output";
string tmp = (do_clean ? get_tmpdir() + "/" : "");
// ---------------------------------------------------------
// 1) range : as computed at the first occurrence
// -----------------------------------------------
if (b._count_value == 0) {
*(b._p_ctrl_out) << "set xrange [" << omega.xmin()[0] << ":" << omega.xmax()[0] << "]" << endl;
}
if (! b._have_u_range.first || ! b._have_u_range.second) {
for (size_t ifld = 0; ifld < nfld; ifld++) {
const field_basic<T,sequential>& u = b[ifld].second;
if (! b._have_u_range.first) {
b._u_range.first = std::min (b._u_range.first, u.min());
}
if (! b._have_u_range.second) {
b._u_range.second = std::max (b._u_range.second, u.max());
}
}
}
// -----------------------------------------------
// 2) plot commands
// -----------------------------------------------
const string& pname = b.parameter_name() + " = " + ftos(b.parameter());
*(b._p_ctrl_out) << "set title \"i = " << b._count_value << ": " << pname << "\" font \"arial,20\"" << endl
<< "plot \\" << endl;
for (size_t ifld = 0; ifld < nfld; ifld++) {
const string& uname = b[ifld].first;
string gdat_name = tmp + basename + "_" + uname + "_" + itos(b._count_value) + ".gdat";
*(b._p_ctrl_out) << (ifld == 0 ? " " : ",")
<< " \"" << gdat_name << "\""
<< " u 1:2"
<< " t \"" << uname << "\""
<< " w l"
<< (ifld < nfld-1 ? " \\" : "")
<< endl;
}
*(b._p_ctrl_out) << "pause dt_pause" << endl;
// -----------------------------------------------
// 3) data
// -----------------------------------------------
// TODO: subdivide option not set by the branch unix command
size_type subdivide = iorheo::getsubdivide(ops.os());
bool fill = iorheo::getfill(ops.os()); // show grid or fill elements
for (size_t ifld = 0; ifld < nfld; ifld++) {
const string& uname = b[ifld].first;
const field_basic<T,sequential>& uh = b[ifld].second;
string gdat_name = tmp + basename + "_" + uname + "_" + itos(b._count_value) + ".gdat";
ofstream gdat (gdat_name.c_str());
b._to_clean = b._to_clean + " " + gdat_name;
if (do_verbose) clog << "! file \"" << gdat_name << "\" created.\n";
gdat << setprecision(numeric_limits<T>::digits10);
const geo_basic<T,sequential>& omega = uh.get_geo();
const basis_basic<T>& b_fem = uh.get_space().get_basis();
if (subdivide == 0) { // subdivide is unset: use default
subdivide = std::max(omega.order(), subdivide);
subdivide = std::max(b_fem.degree (), subdivide);
}
size_type map_dim = omega.map_dimension();
size_type used_dim = (fill ? map_dim : 1);
basis_basic<T> subdivide_pointset ("P"+itos(subdivide));
piola_on_pointset<T> pops; pops.initialize (omega.get_piola_basis(), subdivide_pointset, integrate_option());
fem_on_pointset<T> fops; fops.initialize (b_fem, pops);
bound_type<T> bbox;
bbox.xmin = omega.xmin();
bbox.xmax = omega.xmax();
bbox.umin = uh.min();
bbox.umax = uh.max();
for (size_type ie = 0, ne = omega.size(used_dim); ie < ne; ie++) {
const geo_element& K = omega.get_geo_element(used_dim,ie);
put (gdat, omega, K, uh, fops, subdivide, bbox);
}
gdat.close();
}
}
template <class T>
void
put_finalize_gnuplot (odiststream& ops, const branch_basic<T,sequential>& b)
{
// is the destructor virtual : ofstream::~ofstream() or opstream::~opstream() ?
string basename = iorheo::getbasename(ops.os());
if (basename == "") basename = "output";
bool do_verbose = iorheo::getverbose(clog);
bool do_execute = iorheo::getexecute(clog);
bool do_clean = iorheo::getclean(clog);
bool reader_on_stdin = iorheo::getreader_on_stdin(ops.os());
if (! reader_on_stdin) {
*(b._p_ctrl_out) << "pause -1 \"<end>\"" << endl;
}
string tmp = (do_clean ? get_tmpdir() + "/" : "");
//
// compute visu params: u_range, pause delay
//
string param_name = tmp+basename + "-visu-param.plot";
ofstream param (param_name.c_str());
if (do_verbose) clog << "! file \"" << param_name << "\" created.\n";
b._to_clean = b._to_clean + " " + param_name;
param << "duration = 30 # in seconds" << endl
<< "n_step = " << b._count_value << endl
<< "dt_pause = 1.0*duration/n_step" << endl;
if (b._u_range.second - b._u_range.first < 1e-7) {
// perhaps the solution is zero ? try to renormalize
b._u_range.second = b._u_range.first + 1;
}
param << "set yrange [" << b._u_range.first << ":" << b._u_range.second << "]" << endl;
param.close();
//
// run gnuplot
//
int status = 0;
string command;
if (do_execute) {
command = "gnuplot ";
if (reader_on_stdin) command += "-persist ";
command += tmp + basename + ".plot";
if (do_verbose) clog << "! " << command << endl;
cin.sync();
status = system (command.c_str());
}
//
// clear gnuplot data
//
if (do_clean) {
string tmp = get_tmpdir() + "/";
if (!do_clean) tmp = "";
string command = "/bin/rm -f " + b._to_clean;
// to much files to see:
// do_verbose && clog << "! " << command << endl;
do_verbose && clog << "! cleaning temporary .plot and .gdat files" << endl;
int status = system (command.c_str());
}
delete_macro (b._p_ctrl_out);
delete_macro (b._p_data_out);
b._p_ctrl_out = 0;
b._p_data_out = 0;
b._to_clean = "";
}
// ----------------------------------------------------------------------------
// instanciation in library
// ----------------------------------------------------------------------------
template void put_header_gnuplot (odiststream&, const branch_basic<Float,sequential>&);
template void put_event_gnuplot (odiststream&, const branch_basic<Float,sequential>&);
template void put_finalize_gnuplot (odiststream&, const branch_basic<Float,sequential>&);
} // namespace rheolef
size_type
field::size_type size_type
Definition: branch.cc:425
rheolef::basis_basic
Definition: basis.h:532
rheolef::basis_basic::degree
size_type degree() const
Definition: basis.h:689
rheolef::branch_basic
Definition: branch.h:83
rheolef::branch_basic::size_type
base::size_type size_type
Definition: branch.h:88
rheolef::disarray
see the disarray page for the full documentation
Definition: disarray.h:459
rheolef::fem_on_pointset
Definition: fem_on_pointset.h:117
rheolef::fem_on_pointset::initialize
void initialize(const basis_basic< T > &fem_basis, const piola_on_pointset< T > &pops)
Definition: fem_on_pointset.h:130
rheolef::field_basic
Definition: field.h:235
rheolef::field_basic::get_space
const space_type & get_space() const
Definition: field.h:300
rheolef::field_basic::get_geo
const geo_type & get_geo() const
Definition: field.h:301
rheolef::field_basic::min
T min() const
Definition: field.h:683
rheolef::field_basic::max
T max() const
Definition: field.h:699
rheolef::geo_basic< T, sequential >
Definition: geo.h:1108
rheolef::geo_basic< T, sequential >::get_piola_basis
const basis_basic< T > & get_piola_basis() const
Definition: geo.h:1155
rheolef::geo_basic< T, sequential >::xmin
const node_type & xmin() const
Definition: geo.h:1157
rheolef::geo_basic< T, sequential >::size
size_type size(size_type dim) const
Definition: geo.h:1209
rheolef::geo_basic< T, sequential >::map_dimension
size_type map_dimension() const
Definition: geo.h:1149
rheolef::geo_basic< T, sequential >::xmax
const node_type & xmax() const
Definition: geo.h:1158
rheolef::geo_basic< T, sequential >::get_geo_element
const_reference get_geo_element(size_type dim, size_type ige) const
Definition: geo.h:1164
rheolef::geo_basic< T, sequential >::order
size_type order() const
Definition: geo.h:1156
rheolef::geo_element
see the geo_element page for the full documentation
Definition: geo_element.h:102
rheolef::integrate_option
see the integrate_option page for the full documentation
Definition: integrate_option.h:125
rheolef::odiststream
odiststream: see the diststream page for the full documentation
Definition: diststream.h:126
rheolef::odiststream::os
std::ostream & os()
Definition: diststream.h:236
rheolef::piola_on_pointset
Definition: piola_on_pointset.h:142
rheolef::piola_on_pointset::initialize
void initialize(const basis_basic< T > &piola_basis, const quadrature< T > &quad, const integrate_option &iopt)
Definition: piola_on_pointset.h:190
rheolef::space_basic< T, sequential >
Definition: space.h:361
rheolef::space_basic< T, sequential >::get_geo
const geo_basic< T, sequential > & get_geo() const
Definition: space.h:522
rheolef::space_basic< T, sequential >::get_xdofs
const disarray< point_basic< T >, sequential > & get_xdofs() const
Definition: space.h:725
rheolef::size_type
size_t size_type
Definition: basis_get.cc:76
field_seq_visu_gnuplot_internal.h
mkgeo_ball.b
int b
Definition: mkgeo_ball.sh:152
mkgeo_ball.command
string command
Definition: mkgeo_ball.sh:136
mkgeo_ball.map_dim
map_dim
Definition: mkgeo_ball.sh:337
mkgeo_ball.tmp
tmp
Definition: mkgeo_ball.sh:380
mkgeo_contraction.status
status
Definition: mkgeo_contraction.sh:290
mkgeo_couette.basename
string basename
Definition: mkgeo_couette.sh:73
rheolef::io::out
@ out
Definition: rheostream.h:167
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
rheolef::put
void put(std::ostream &out, std::string name, const tiny_matrix< T > &a)
Definition: tiny_lu.h:155
rheolef::put_header_gnuplot
void put_header_gnuplot(odiststream &ops, const branch_basic< T, sequential > &b)
Definition: branch_seq_visu_gnuplot.cc:41
rheolef::put_finalize_gnuplot
void put_finalize_gnuplot(odiststream &ops, const branch_basic< T, sequential > &b)
Definition: branch_seq_visu_gnuplot.cc:155
rheolef::itos
std::string itos(std::string::size_type i)
itos: see the rheostream page for the full documentation
rheolef::ftos
string ftos(const Float &x)
itof: see the rheostream page for the full documentation
Definition: rheostream.cc:55
rheolef::get_tmpdir
std::string get_tmpdir()
get_tmpdir: see the rheostream page for the full documentation
Definition: rheostream.cc:50
rheolef::put_event_gnuplot
void put_event_gnuplot(odiststream &ops, const branch_basic< T, sequential > &b)
Definition: branch_seq_visu_gnuplot.cc:66
rheolef::bound_type
Definition: field_seq_visu_gnuplot_internal.h:42
rheolef::bound_type::xmax
point_basic< T > xmax
Definition: field_seq_visu_gnuplot_internal.h:44
rheolef::bound_type::umax
T umax
Definition: field_seq_visu_gnuplot_internal.h:45
rheolef::bound_type::xmin
point_basic< T > xmin
Definition: field_seq_visu_gnuplot_internal.h:44
rheolef::bound_type::umin
T umin
Definition: field_seq_visu_gnuplot_internal.h:45
rheolef::sequential
Definition: distributed.h:28
u
Definition: leveque.h:25