~ubuntu-branches/ubuntu/trusty/rheolef/trusty-proposed

« back to all changes in this revision

Viewing changes to nfem/lib/field-mtv.cc

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2010-06-12 09:08:59 UTC
  • Revision ID: james.westby@ubuntu.com-20100612090859-8gpm2gc7j3ab43et
Tags: upstream-5.89
ImportĀ upstreamĀ versionĀ 5.89

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
///
 
2
/// This file is part of Rheolef.
 
3
///
 
4
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
 
5
///
 
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.
 
10
///
 
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.
 
15
///
 
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
 
19
///
 
20
/// =========================================================================
 
21
//
 
22
// plotmtv output
 
23
//
 
24
// authors:
 
25
//      Nicolas.Roquet@imag.fr
 
26
//      Pierre.Saramito@imag.fr
 
27
//
 
28
// date: 12 may 1997  update: 6 may 2001
 
29
//
 
30
#include "rheolef/field.h"
 
31
#include "rheolef/iorheo.h"
 
32
#include "rheolef/rheostream.h"
 
33
#include "rheolef/tiny_matvec.h"
 
34
using namespace std;
 
35
 
 
36
static inline
 
37
void
 
38
mtv_point (ostream& s, const point& p, Float value)
 
39
{
 
40
    s << p[0] << " " << p[1] << " " << value << endl;
 
41
}
 
42
 
 
43
//======================================================
 
44
 
 
45
static
 
46
inline
 
47
void mtv_segment (ostream& s, const point& p, const point& q, Float z)
 
48
{
 
49
        p.put(s, 2); s << '\t' << z << endl;
 
50
        q.put(s, 2); s << '\t' << z << endl;
 
51
}
 
52
static
 
53
inline
 
54
void mtv_element (ostream& s, const geo_element& g, geo::const_iterator_node x, Float z, Float value)
 
55
{
 
56
        // cas d'un element 't'
 
57
        s << "% fillcolor = " << value << endl;
 
58
        switch (g.name()) {
 
59
          case 't' :
 
60
            mtv_segment (s, x[g[0]], x[g[1]], z);
 
61
            mtv_segment (s, x[g[2]], x[g[0]], z); 
 
62
            break;
 
63
          case 'q' :
 
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;
 
69
            break;
 
70
          default:
 
71
            error_macro ("mtv_element: unexpected element `" << g.type() << "'");
 
72
        }
 
73
        s << endl;
 
74
}
 
75
 
 
76
// ============================================================================
 
77
 
 
78
static
 
79
void
 
80
plotmtv_2d_header (
 
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)
 
84
{
 
85
  const size_t niso = 50;
 
86
  const size_t default_isovalue_table_zero_index = 10;
 
87
  mtv << setprecision(digits10)
 
88
      << "#!plotmtv\n"
 
89
      << "$ DATA = CONTCURVE\n"
 
90
      << "% comment    = \"rheolef\"\n"
 
91
      << "% toplabel   = \"" << basename << "\"\n"
 
92
      << "% subtitle   = \"\"\n"
 
93
      << endl
 
94
      << "# scale and window\n"
 
95
      << "% equalscale\n";
 
96
  
 
97
  const point xmin = x.get_geo().xmin();
 
98
  const point xmax = x.get_geo().xmax();
 
99
  Float umin = x.min();
 
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"
 
104
      << endl;
 
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"
 
110
      << endl
 
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";
 
114
  } else {
 
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";
 
120
      mtv << "\t0\\\n";
 
121
      for (size_t i = 1; i <= npos; i++)
 
122
         mtv << "\t" << Float(i)*umax/Float(npos) << "\\\n";
 
123
      mtv << ")\n";
 
124
  }
 
125
  mtv << endl;
 
126
  if (!grid) mtv << "#";
 
127
  mtv << "%meshplot # show also grid mesh\n"
 
128
      << endl
 
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"
 
132
      << "#@filltype=1\n"
 
133
      << endl;
 
134
}
 
135
// ============================================================================
 
136
int
 
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 
 
140
{
 
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);
 
148
  //
 
149
  // header
 
150
  //
 
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";
 
159
  mtv << endl;
 
160
 
 
161
  const point p1 = get_geo().xmin();
 
162
  const point p2 = get_geo().xmax();
 
163
 
 
164
  mtv << "% xmin= " << p1[0] << " xmax= " << p2[0]
 
165
      <<   " ymin= " << p1[1] << " ymax= " << p2[1]
 
166
      <<   " zmin= " << min() << " zmax= " << max() << "\n";
 
167
  mtv << endl;
 
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";
 
172
  mtv << endl;
 
173
  mtv << "%nsteps=50  # set constant value step\n";
 
174
  mtv << "#%contours=()  # specify also values associated to lines\n";
 
175
  mtv << endl;
 
176
  if (!grid) mtv << "#";
 
177
  mtv << "%meshplot # show also grid mesh\n";
 
178
  mtv << endl;
 
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";
 
181
  mtv << endl;
 
182
  //
 
183
  // plot elements
 
184
  //
 
185
  const geo& m = get_geo();
 
186
  Float MAX = max(), MIN = min();
 
187
  Float ratio = 10./(MIN-MAX);
 
188
  
 
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)
 
193
 
 
194
      mtv_element (mtv, *iter_K++, m.begin_node(), *iter_u++,  ratio*(MIN-(*iter_u)));
 
195
 
 
196
  mtv.close();
 
197
  if (put_domains) 
 
198
   {
 
199
      mtv << "$ DATA = CURVE2D" << endl;
 
200
      m.put_mtv_domains(mtv,1);
 
201
   }
 
202
  //
 
203
  // run plotmtv
 
204
  //
 
205
  int status = 0;
 
206
  if (execute) {
 
207
      string option = (elevation ? "-3d " : "");
 
208
      option += (put_domains ? "-plotall " : ""); 
 
209
      string command = "plotmtv " + option + basename + ".mtv";
 
210
      if (verbose) {
 
211
          command += " 1>&2";
 
212
          clog << "! " << command << endl;
 
213
      } else {
 
214
          command += " >/dev/null";
 
215
      }
 
216
      status = system (command.c_str());
 
217
  }
 
218
  //
 
219
  // clear plotmtv data
 
220
  //
 
221
  if (clean) {
 
222
      string command = "/bin/rm -f " + basename + ".mtv";
 
223
      if (verbose) clog << "! " << command << endl;
 
224
      status |= system (command.c_str());
 
225
  }
 
226
  return status;
 
227
}
 
228
 
 
229
//======================================================
 
230
 
 
231
int
 
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
 
236
{
 
237
  const geo& m = get_geo();
 
238
 
 
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);
 
245
  //
 
246
  // header
 
247
  //
 
248
  plotmtv_2d_header (basename, *this, mtv, digits10, grid, put_domains, fill, label,
 
249
                  isovalue_table_zero_index);
 
250
  //
 
251
  // plot elements
 
252
  //
 
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++) {
 
255
 
 
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]));
 
259
      mtv << endl;
 
260
  }
 
261
  if (put_domains) 
 
262
   {
 
263
      mtv << "$ DATA = CURVE2D" << endl;
 
264
      m.put_mtv_domains(mtv,1);
 
265
   }
 
266
  mtv.close();
 
267
  //
 
268
  // run plotmtv
 
269
  //
 
270
  int status = 0;
 
271
  if (execute) {
 
272
      string option = (elevation ? "-3d " : "");
 
273
      option += (put_domains ? "-plotall " : ""); 
 
274
      string command = "plotmtv " + option + basename + ".mtv";
 
275
      if (verbose) {
 
276
          command += " 1>&2";
 
277
          clog << "! " << command << endl;
 
278
      } else {
 
279
          command += " >/dev/null";
 
280
      }
 
281
      status = system (command.c_str());
 
282
  }
 
283
  //
 
284
  // clear plotmtv data
 
285
  //
 
286
  if (clean) {
 
287
      string command = "/bin/rm -f " + basename + ".mtv";
 
288
      if (verbose) clog << "! " << command << endl;
 
289
      status |= system (command.c_str());
 
290
  }
 
291
  return status;
 
292
}
 
293
 
 
294
int
 
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
 
299
{
 
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);
 
306
  //
 
307
  // header
 
308
  //
 
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)
 
317
    {
 
318
      const geo_element& K = *iter_K++;
 
319
      switch (K.name())
 
320
        {
 
321
        case 't' :
 
322
        case 'q' :
 
323
          {
 
324
            size_type n_dof = _V.get_basis().size(K.type()) ;
 
325
            tiny_vector<size_type> dof(n_dof) ;
 
326
            _V.set_dof(K, 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)) ) ;
 
329
            break ;
 
330
          }
 
331
        default  :
 
332
          break ;
 
333
        }
 
334
      mtv << endl;
 
335
      K_idx++ ;
 
336
    }
 
337
  if (put_domains) 
 
338
   {
 
339
      mtv << "$ DATA = CURVE2D" << endl;
 
340
      m.put_mtv_domains(mtv,1);
 
341
   }
 
342
  mtv.close();
 
343
  //
 
344
  // run plotmtv
 
345
  //
 
346
  int status = 0;
 
347
  if (execute) {
 
348
      string option = (elevation ? "-3d " : "");
 
349
      option += (put_domains ? "-plotall " : ""); 
 
350
      string command = "plotmtv " + option + basename + ".mtv";
 
351
      if (verbose) {
 
352
          command += " 1>&2";
 
353
          clog << "! " << command << endl;
 
354
      } else {
 
355
          command += " >/dev/null";
 
356
      }
 
357
      status = system (command.c_str());
 
358
  }
 
359
  //
 
360
  // clear plotmtv data
 
361
  //
 
362
  if (clean) {
 
363
      string command = "/bin/rm -f " + basename + ".mtv";
 
364
      if (verbose) clog << "! " << command << endl;
 
365
      status |= system (command.c_str());
 
366
  }
 
367
  return status;
 
368
}
 
369
int
 
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
 
374
{
 
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;
 
379
  //
 
380
  // header
 
381
  //
 
382
  plotmtv_2d_header (basename, *this, mtv, digits10, grid, put_domains, fill, label,
 
383
                  isovalue_table_zero_index);
 
384
  //
 
385
  // plot isovalues
 
386
  //
 
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)
 
393
    {
 
394
      const geo_element& K = *iter_K++;
 
395
      switch (K.name())
 
396
        {
 
397
        case 't' :
 
398
          {
 
399
            size_type n_dof = _V.get_basis().size(K.type()) ;
 
400
            tiny_vector<size_type> dof(n_dof) ;
 
401
            _V.set_dof(K, 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)) ) ;
 
405
              mtv << endl;
 
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)) ) ;
 
409
              mtv << endl;            
 
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)) ) ;
 
413
              mtv << endl;            
 
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)) ) ;
 
417
            break ;
 
418
          }
 
419
        case 'q' :
 
420
          {
 
421
            size_type n_dof = _V.get_basis().size(K.type()) ;
 
422
            tiny_vector<size_type> dof(n_dof) ;
 
423
            _V.set_dof(K, 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)) ) ;
 
427
              mtv << endl;
 
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)) ) ;
 
431
              mtv << endl;
 
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)) ) ;
 
435
              mtv << endl;
 
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)) ) ;
 
439
              mtv << endl;
 
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)) ) ;
 
443
              mtv << endl;
 
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)) ) ;
 
447
              mtv << endl;
 
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)) ) ;
 
451
              mtv << endl;
 
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)) ) ;
 
455
              mtv << endl;
 
456
              break ;
 
457
          }
 
458
        default  :
 
459
          break ;
 
460
        }
 
461
      mtv << endl;
 
462
      K_idx++ ;
 
463
    }
 
464
  if (put_domains) 
 
465
   {
 
466
      mtv << "$ DATA = CURVE2D" << endl;
 
467
      m.put_mtv_domains(mtv,1);
 
468
   }
 
469
  mtv.close();
 
470
  //
 
471
  // run plotmtv
 
472
  //
 
473
  int status = 0;
 
474
  if (execute) {
 
475
      string option = (elevation ? "-3d " : "");
 
476
      option += (put_domains ? "-plotall " : ""); 
 
477
      string command = "plotmtv " + option + basename + ".mtv";
 
478
      if (verbose) {
 
479
          command += " 1>&2";
 
480
          clog << "! " << command << endl;
 
481
      } else {
 
482
          command += " >/dev/null";
 
483
      }
 
484
      status = system (command.c_str());
 
485
  }
 
486
  //
 
487
  // clear plotmtv data
 
488
  //
 
489
  if (clean) {
 
490
      string command = "/bin/rm -f " + basename + ".mtv";
 
491
      if (verbose) clog << "! " << command << endl;
 
492
      status |= system (command.c_str());
 
493
  }
 
494
  return status;
 
495
}
 
496
//
 
497
// plot 1D P1-field as elevation in 2D
 
498
//
 
499
int
 
500
field::plotmtv1d_P1 (
 
501
  const string& basename, 
 
502
  bool execute, bool clean, bool verbose) const
 
503
{
 
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);
 
509
  //
 
510
  // header
 
511
  //
 
512
  mtv << "#!plotmtv\n"
 
513
      << "$ DATA = CURVE2D\n"
 
514
      << "% comment    = \"rheolef\"\n"
 
515
      << "% toplabel   = \"" << basename << "\"\n"
 
516
      << "% subtitle   = \"\"\n"
 
517
      << "% linecolor  = 1\n"
 
518
      ;
 
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];
 
526
      Float y0 = at(K[0]);
 
527
      Float y1 = at(K[1]);
 
528
      mtv << x0 << " " << y0 << endl
 
529
          << x1 << " " << y1 << endl 
 
530
          << endl;
 
531
  }
 
532
  mtv.close();
 
533
  //
 
534
  // run plotmtv
 
535
  //
 
536
  int status = 0;
 
537
  if (execute) {
 
538
      string command;
 
539
      if (verbose) {
 
540
          command = "plotmtv " + basename + ".mtv 1>&2";
 
541
          clog << "! " << command << endl;
 
542
      } else {
 
543
          command = "plotmtv " + basename + ".mtv >/dev/null";
 
544
      }
 
545
      status = system (command.c_str());
 
546
  }
 
547
  //
 
548
  // clear plotmtv data
 
549
  //
 
550
  if (clean) {
 
551
      string command = "/bin/rm -f " + basename + ".mtv";
 
552
      if (verbose) clog << "! " << command << endl;
 
553
      status |= system (command.c_str());
 
554
  }
 
555
  return status;
 
556
}
 
557
//
 
558
// plot 1D P2-field as elevation in 2D
 
559
//
 
560
int
 
561
field::plotmtv1d_P2 (
 
562
  const string& basename, 
 
563
  bool execute, bool clean, bool verbose) const
 
564
{
 
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);
 
570
  //
 
571
  // header
 
572
  //
 
573
  mtv << "#!plotmtv\n"
 
574
      << "$ DATA = CURVE2D\n"
 
575
      << "% comment    = \"rheolef\"\n"
 
576
      << "% toplabel   = \"" << basename << "\"\n"
 
577
      << "% subtitle   = \"\"\n"
 
578
      << "% linecolor  = 1\n"
 
579
      ;
 
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;
 
585
      _V.set_dof(K, dof) ;
 
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 
 
594
          << endl
 
595
          << pm[0] << " " << ym << endl 
 
596
          << p1[0] << " " << y1 << endl 
 
597
          << endl;
 
598
  }
 
599
  mtv.close();
 
600
  //
 
601
  // run plotmtv
 
602
  //
 
603
  int status = 0;
 
604
  if (execute) {
 
605
      string command;
 
606
      if (verbose) {
 
607
          command = "plotmtv " + basename + ".mtv 1>&2";
 
608
          clog << "! " << command << endl;
 
609
      } else {
 
610
          command = "plotmtv " + basename + ".mtv >/dev/null";
 
611
      }
 
612
      status = system (command.c_str());
 
613
  }
 
614
  //
 
615
  // clear plotmtv data
 
616
  //
 
617
  if (clean) {
 
618
      string command = "/bin/rm -f " + basename + ".mtv";
 
619
      if (verbose) clog << "! " << command << endl;
 
620
      status |= system (command.c_str());
 
621
  }
 
622
  return status;
 
623
}