2
/// This file is part of Rheolef.
4
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
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.
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.
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
20
/// =========================================================================
25
// Nicolas.Roquet@imag.fr
26
// Pierre.Saramito@imag.fr
28
// date: 12 may 1997 update: 6 may 2001
30
#include "rheolef/field.h"
31
#include "rheolef/iorheo.h"
32
#include "rheolef/rheostream.h"
33
#include "rheolef/tiny_matvec.h"
38
mtv_point (ostream& s, const point& p, Float value)
40
s << p[0] << " " << p[1] << " " << value << endl;
43
//======================================================
47
void mtv_segment (ostream& s, const point& p, const point& q, Float z)
49
p.put(s, 2); s << '\t' << z << endl;
50
q.put(s, 2); s << '\t' << z << endl;
54
void mtv_element (ostream& s, const geo_element& g, geo::const_iterator_node x, Float z, Float value)
56
// cas d'un element 't'
57
s << "% fillcolor = " << value << endl;
60
mtv_segment (s, x[g[0]], x[g[1]], z);
61
mtv_segment (s, x[g[2]], x[g[0]], z);
64
x[g[0]].put(s, 2); s << '\t' << z << endl;
65
x[g[1]].put(s, 2); s << '\t' << z << endl;
66
x[g[2]].put(s, 2); s << '\t' << z << endl;
67
x[g[3]].put(s, 2); s << '\t' << z << endl;
68
x[g[0]].put(s, 2); s << '\t' << z << endl;
71
error_macro ("mtv_element: unexpected element `" << g.type() << "'");
76
// ============================================================================
81
const string basename,
82
const field& x, ostream& mtv, int digits10,
83
bool grid, bool put_domains, bool fill, bool label, size_t isovalue_table_zero_index)
85
const size_t niso = 50;
86
const size_t default_isovalue_table_zero_index = 10;
87
mtv << setprecision(digits10)
89
<< "$ DATA = CONTCURVE\n"
90
<< "% comment = \"rheolef\"\n"
91
<< "% toplabel = \"" << basename << "\"\n"
92
<< "% subtitle = \"\"\n"
94
<< "# scale and window\n"
97
const point xmin = x.get_geo().xmin();
98
const point xmax = x.get_geo().xmax();
100
Float umax = x.max();
101
mtv << "% xmin= " << xmin[0] << " xmax= " << xmax[0]
102
<< " ymin= " << xmin[1] << " ymax= " << xmax[1]
103
<< " zmin= " << umin << " zmax= " << umax << "\n"
105
if (fill) mtv << "#";
106
mtv << "%contstyle=1 # line style color drawing, with label values\n";
107
if (!fill) mtv << "#";
108
mtv << "%contstyle=2 # fill color painting\n"
109
<< "%contlabel=" << (label ? "true" : "false") << " # write labels when using line style contours\n"
111
<< "%nsteps=" << niso << " # set constant value step\n";
112
if (isovalue_table_zero_index == 0 || isovalue_table_zero_index == numeric_limits<size_t>::max()) {
113
mtv << "#%contours=() # specify also values associated to lines\n";
115
size_t nneg = isovalue_table_zero_index;
116
size_t npos = niso - nneg;
117
mtv << "%contours=( \\\n";
118
for (size_t i = 0; i < nneg; i++)
119
mtv << "\t" << umin - Float(i)*umin/Float(nneg) << " \\\n";
121
for (size_t i = 1; i <= npos; i++)
122
mtv << "\t" << Float(i)*umax/Float(npos) << "\\\n";
126
if (!grid) mtv << "#";
127
mtv << "%meshplot # show also grid mesh\n"
129
<< "# for Postscript output: rectangle with background color (white) and solid fill\n"
130
<< "#@rectangle x1=1 y1=0 z1=0.0 x2=4 y2=5 z2=0.0\n"
131
<< "#@fillcolor=-1 \n"
135
// ============================================================================
137
field::plotmtv2d_P0 (
138
const string& basename, bool execute, bool clean, bool verbose,
139
bool grid, bool put_domains, bool fill, bool elevation) const
141
char filename [1000];
142
sprintf (filename, "%s.mtv", basename.c_str());
143
ofstream mtv (filename);
144
if (verbose) clog << "! file \"" << filename << "\" created.\n";
145
int dim = dimension();
146
int digits10 = numeric_limits<Float>::digits10;
147
mtv << setprecision(digits10);
151
mtv << "#!plotmtv\n";
152
mtv << "$ DATA = CURVE3D\n";
153
mtv << "% comment = \"rheolef\"\n";
154
mtv << "% toplabel = \"" << basename << "\"\n";
155
mtv << "% subtitle = \"\"\n";
156
mtv << "% equalscale\n";
157
mtv << "% linecolor = 1\n";
158
mtv << "% dfilltype = 1\n";
161
const point p1 = get_geo().xmin();
162
const point p2 = get_geo().xmax();
164
mtv << "% xmin= " << p1[0] << " xmax= " << p2[0]
165
<< " ymin= " << p1[1] << " ymax= " << p2[1]
166
<< " zmin= " << min() << " zmax= " << max() << "\n";
168
// if (fill) mtv << "#";
169
mtv << "%contstyle=1 # line style color drawing, with label values\n";
170
if (!fill) mtv << "#";
171
mtv << "%contstyle=2 # fill color painting\n";
173
mtv << "%nsteps=50 # set constant value step\n";
174
mtv << "#%contours=() # specify also values associated to lines\n";
176
if (!grid) mtv << "#";
177
mtv << "%meshplot # show also grid mesh\n";
179
mtv << "# for Postscript output: rectangle with background color (white) and solid fill\n";
180
mtv << "#@ rectangle x1=1 y1=0 z1=0.0 x2=4 y2=5 z2=0.0 fillcolor=-1 filltype=1\n";
185
const geo& m = get_geo();
186
Float MAX = max(), MIN = min();
187
Float ratio = 10./(MIN-MAX);
189
geo::const_iterator iter_K = m.begin();
190
geo::const_iterator last_K = m.end();
191
vec<Float>::const_iterator iter_u = u.begin();
192
while (iter_K != last_K)
194
mtv_element (mtv, *iter_K++, m.begin_node(), *iter_u++, ratio*(MIN-(*iter_u)));
199
mtv << "$ DATA = CURVE2D" << endl;
200
m.put_mtv_domains(mtv,1);
207
string option = (elevation ? "-3d " : "");
208
option += (put_domains ? "-plotall " : "");
209
string command = "plotmtv " + option + basename + ".mtv";
212
clog << "! " << command << endl;
214
command += " >/dev/null";
216
status = system (command.c_str());
219
// clear plotmtv data
222
string command = "/bin/rm -f " + basename + ".mtv";
223
if (verbose) clog << "! " << command << endl;
224
status |= system (command.c_str());
229
//======================================================
232
field::plotmtv2d_P1 (
233
const string& basename, bool execute, bool clean, bool verbose,
234
bool grid, bool put_domains, bool fill, bool elevation,
235
bool label, size_type isovalue_table_zero_index) const
237
const geo& m = get_geo();
239
char filename [1000];
240
sprintf (filename, "%s.mtv", basename.c_str());
241
ofstream mtv (filename);
242
if (verbose) clog << "! file \"" << filename << "\" created.\n";
243
int digits10 = numeric_limits<Float>::digits10;
244
mtv << setprecision(digits10);
248
plotmtv_2d_header (basename, *this, mtv, digits10, grid, put_domains, fill, label,
249
isovalue_table_zero_index);
253
geo::const_iterator_node p = m.begin_node(); // random access
254
for (geo::const_iterator iter_K = m.begin(); iter_K != m.end(); iter_K++) {
256
const geo_element& K = *iter_K;
257
for (size_type i = 0; i < K.size(); i++)
258
mtv_point (mtv, p[K[i]], at(K[i]));
263
mtv << "$ DATA = CURVE2D" << endl;
264
m.put_mtv_domains(mtv,1);
272
string option = (elevation ? "-3d " : "");
273
option += (put_domains ? "-plotall " : "");
274
string command = "plotmtv " + option + basename + ".mtv";
277
clog << "! " << command << endl;
279
command += " >/dev/null";
281
status = system (command.c_str());
284
// clear plotmtv data
287
string command = "/bin/rm -f " + basename + ".mtv";
288
if (verbose) clog << "! " << command << endl;
289
status |= system (command.c_str());
295
field::plotmtv2d_P1d (
296
const string& basename, bool execute, bool clean, bool verbose,
297
bool grid, bool put_domains, bool fill, bool elevation,
298
bool label, size_type isovalue_table_zero_index) const
300
char filename [1000];
301
sprintf (filename, "%s.mtv", basename.c_str());
302
ofstream mtv (filename);
303
if (verbose) clog << "! file \"" << filename << "\" created.\n";
304
int digits10 = numeric_limits<Float>::digits10;
305
mtv << setprecision(digits10);
309
plotmtv_2d_header (basename, *this, mtv, digits10, grid, put_domains, fill, label,
310
isovalue_table_zero_index);
311
const geo& m = get_geo();
312
geo::const_iterator iter_K = m.begin();
313
geo::const_iterator last_K = m.end();
314
geo::const_iterator_node p = m.begin_node(); // random access
315
size_type K_idx = 0 ;
316
while (iter_K != last_K)
318
const geo_element& K = *iter_K++;
324
size_type n_dof = _V.get_basis().size(K.type()) ;
325
tiny_vector<size_type> dof(n_dof) ;
327
for (size_type i_loc_dof = 0; i_loc_dof < n_dof; i_loc_dof++)
328
mtv_point( mtv, _V.x_dof(K, i_loc_dof), at(dof(i_loc_dof)) ) ;
339
mtv << "$ DATA = CURVE2D" << endl;
340
m.put_mtv_domains(mtv,1);
348
string option = (elevation ? "-3d " : "");
349
option += (put_domains ? "-plotall " : "");
350
string command = "plotmtv " + option + basename + ".mtv";
353
clog << "! " << command << endl;
355
command += " >/dev/null";
357
status = system (command.c_str());
360
// clear plotmtv data
363
string command = "/bin/rm -f " + basename + ".mtv";
364
if (verbose) clog << "! " << command << endl;
365
status |= system (command.c_str());
370
field::plotmtv2d_P2 (
371
const string& basename, bool execute, bool clean, bool verbose,
372
bool grid, bool put_domains, bool fill, bool elevation,
373
bool label, size_type isovalue_table_zero_index) const
375
string filename = basename + ".mtv";
376
ofstream mtv (filename.c_str());
377
if (verbose) clog << "! file \"" << filename << "\" created.\n";
378
int digits10 = numeric_limits<Float>::digits10;
382
plotmtv_2d_header (basename, *this, mtv, digits10, grid, put_domains, fill, label,
383
isovalue_table_zero_index);
387
const geo& m = get_geo();
388
geo::const_iterator iter_K = m.begin();
389
geo::const_iterator last_K = m.end();
390
geo::const_iterator_node p = m.begin_node(); // random access
391
size_type K_idx = 0 ;
392
while (iter_K != last_K)
394
const geo_element& K = *iter_K++;
399
size_type n_dof = _V.get_basis().size(K.type()) ;
400
tiny_vector<size_type> dof(n_dof) ;
402
mtv_point( mtv, _V.x_dof(K, 0), at(dof(0)) ) ;
403
mtv_point( mtv, _V.x_dof(K, 3), at(dof(3)) ) ;
404
mtv_point( mtv, _V.x_dof(K, 5), at(dof(5)) ) ;
406
mtv_point( mtv, _V.x_dof(K, 3), at(dof(3)) ) ;
407
mtv_point( mtv, _V.x_dof(K, 1), at(dof(1)) ) ;
408
mtv_point( mtv, _V.x_dof(K, 4), at(dof(4)) ) ;
410
mtv_point( mtv, _V.x_dof(K, 4), at(dof(4)) ) ;
411
mtv_point( mtv, _V.x_dof(K, 2), at(dof(2)) ) ;
412
mtv_point( mtv, _V.x_dof(K, 5), at(dof(5)) ) ;
414
mtv_point( mtv, _V.x_dof(K, 3), at(dof(3)) ) ;
415
mtv_point( mtv, _V.x_dof(K, 4), at(dof(4)) ) ;
416
mtv_point( mtv, _V.x_dof(K, 5), at(dof(5)) ) ;
421
size_type n_dof = _V.get_basis().size(K.type()) ;
422
tiny_vector<size_type> dof(n_dof) ;
424
mtv_point( mtv, _V.x_dof(K, 0), at(dof(0)) ) ;
425
mtv_point( mtv, _V.x_dof(K, 4), at(dof(4)) ) ;
426
mtv_point( mtv, _V.x_dof(K, 8), at(dof(8)) ) ;
428
mtv_point( mtv, _V.x_dof(K, 0), at(dof(0)) ) ;
429
mtv_point( mtv, _V.x_dof(K, 8), at(dof(8)) ) ;
430
mtv_point( mtv, _V.x_dof(K, 7), at(dof(7)) ) ;
432
mtv_point( mtv, _V.x_dof(K, 4), at(dof(4)) ) ;
433
mtv_point( mtv, _V.x_dof(K, 1), at(dof(1)) ) ;
434
mtv_point( mtv, _V.x_dof(K, 8), at(dof(8)) ) ;
436
mtv_point( mtv, _V.x_dof(K, 1), at(dof(1)) ) ;
437
mtv_point( mtv, _V.x_dof(K, 5), at(dof(5)) ) ;
438
mtv_point( mtv, _V.x_dof(K, 8), at(dof(8)) ) ;
440
mtv_point( mtv, _V.x_dof(K, 8), at(dof(8)) ) ;
441
mtv_point( mtv, _V.x_dof(K, 5), at(dof(5)) ) ;
442
mtv_point( mtv, _V.x_dof(K, 2), at(dof(2)) ) ;
444
mtv_point( mtv, _V.x_dof(K, 8), at(dof(8)) ) ;
445
mtv_point( mtv, _V.x_dof(K, 2), at(dof(2)) ) ;
446
mtv_point( mtv, _V.x_dof(K, 6), at(dof(6)) ) ;
448
mtv_point( mtv, _V.x_dof(K, 7), at(dof(7)) ) ;
449
mtv_point( mtv, _V.x_dof(K, 8), at(dof(8)) ) ;
450
mtv_point( mtv, _V.x_dof(K, 3), at(dof(3)) ) ;
452
mtv_point( mtv, _V.x_dof(K, 8), at(dof(8)) ) ;
453
mtv_point( mtv, _V.x_dof(K, 6), at(dof(6)) ) ;
454
mtv_point( mtv, _V.x_dof(K, 3), at(dof(3)) ) ;
466
mtv << "$ DATA = CURVE2D" << endl;
467
m.put_mtv_domains(mtv,1);
475
string option = (elevation ? "-3d " : "");
476
option += (put_domains ? "-plotall " : "");
477
string command = "plotmtv " + option + basename + ".mtv";
480
clog << "! " << command << endl;
482
command += " >/dev/null";
484
status = system (command.c_str());
487
// clear plotmtv data
490
string command = "/bin/rm -f " + basename + ".mtv";
491
if (verbose) clog << "! " << command << endl;
492
status |= system (command.c_str());
497
// plot 1D P1-field as elevation in 2D
500
field::plotmtv1d_P1 (
501
const string& basename,
502
bool execute, bool clean, bool verbose) const
504
string mtv_name = basename + ".mtv";
505
ofstream mtv (mtv_name.c_str());
506
if (verbose) clog << "! file \"" << mtv_name << "\" created.\n";
507
int digits10 = numeric_limits<Float>::digits10;
508
mtv << setprecision(digits10);
513
<< "$ DATA = CURVE2D\n"
514
<< "% comment = \"rheolef\"\n"
515
<< "% toplabel = \"" << basename << "\"\n"
516
<< "% subtitle = \"\"\n"
517
<< "% linecolor = 1\n"
519
const geo& g = get_geo();
520
geo::const_iterator_node p = g.begin_node();
521
geo::const_iterator last_K = g.end();
522
for (geo::const_iterator iter_K = g.begin(); iter_K != last_K; iter_K++) {
523
const geo_element& K = *iter_K;
524
Float x0 = p[K[0]][0];
525
Float x1 = p[K[1]][0];
528
mtv << x0 << " " << y0 << endl
529
<< x1 << " " << y1 << endl
540
command = "plotmtv " + basename + ".mtv 1>&2";
541
clog << "! " << command << endl;
543
command = "plotmtv " + basename + ".mtv >/dev/null";
545
status = system (command.c_str());
548
// clear plotmtv data
551
string command = "/bin/rm -f " + basename + ".mtv";
552
if (verbose) clog << "! " << command << endl;
553
status |= system (command.c_str());
558
// plot 1D P2-field as elevation in 2D
561
field::plotmtv1d_P2 (
562
const string& basename,
563
bool execute, bool clean, bool verbose) const
565
string mtv_name = basename + ".mtv";
566
ofstream mtv (mtv_name.c_str());
567
if (verbose) clog << "! file \"" << mtv_name << "\" created.\n";
568
int digits10 = numeric_limits<Float>::digits10;
569
mtv << setprecision(digits10);
574
<< "$ DATA = CURVE2D\n"
575
<< "% comment = \"rheolef\"\n"
576
<< "% toplabel = \"" << basename << "\"\n"
577
<< "% subtitle = \"\"\n"
578
<< "% linecolor = 1\n"
580
const geo& g = get_geo();
581
tiny_vector<size_type> dof;
582
geo::const_iterator last_K = g.end();
583
for (geo::const_iterator iter_K = g.begin(); iter_K != last_K; iter_K++) {
584
const geo_element& K = *iter_K;
586
Float y0 = at(dof(0));
587
Float ym = at(dof(2));
588
Float y1 = at(dof(1));
589
point p0 = _V.x_dof(K, 0);
590
point pm = _V.x_dof(K, 2);
591
point p1 = _V.x_dof(K, 1);
592
mtv << p0[0] << " " << y0 << endl
593
<< pm[0] << " " << ym << endl
595
<< pm[0] << " " << ym << endl
596
<< p1[0] << " " << y1 << endl
607
command = "plotmtv " + basename + ".mtv 1>&2";
608
clog << "! " << command << endl;
610
command = "plotmtv " + basename + ".mtv >/dev/null";
612
status = system (command.c_str());
615
// clear plotmtv data
618
string command = "/bin/rm -f " + basename + ".mtv";
619
if (verbose) clog << "! " << command << endl;
620
status |= system (command.c_str());