File: basis_visu_gnuplot.icc

package info (click to toggle)
rheolef 7.2-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 88,200 kB
  • sloc: cpp: 110,259; sh: 16,733; makefile: 5,406; python: 1,391; yacc: 218; javascript: 203; xml: 191; awk: 61; sed: 5
file content (217 lines) | stat: -rw-r--r-- 7,659 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#ifndef _RHEOLEF_BASIS_VISU_GNUPLOT_ICC
#define _RHEOLEF_BASIS_VISU_GNUPLOT_ICC
// file automatically generated by: ../../../rheolef/nfem/pbasis/make_basis_list_cxx.sh
///
/// This file is part of Rheolef.
///
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
///
/// Rheolef is free software; you can redistribute it and/or modify
/// it under the terms of the GNU General Public License as published by
/// the Free Software Foundation; either version 2 of the License, or
/// (at your option) any later version.
///
/// Rheolef is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
/// GNU General Public License for more details.
///
/// You should have received a copy of the GNU General Public License
/// along with Rheolef; if not, write to the Free Software
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
///
/// =========================================================================
#include "rheolef/basis_raw.h"
#include "rheolef/iorheo.h"
#include "rheolef/rheostream.h"
namespace rheolef { namespace details {
using namespace std;

template<class Basis>
void
put (const Basis& b, ostream& os, reference_element hat_K)
{
  typedef typename Basis::size_type  size_type;
  typedef typename Basis::value_type T;
  bool verbose  = iorheo::getverbose(os);
  bool clean    = iorheo::getclean(os);
  bool execute  = iorheo::getexecute(os);
  size_type nsub = iorheo::getsubdivide(os);
  if (nsub <= 1) nsub = 20; // default value

  size_type loc_ndof = reference_element::n_node(hat_K.variant(), b.degree());
  string basename  = "basis-" + b.name() + "-" + hat_K.name();
  string filelist;
  // --------------------
  // .plot
  // --------------------
  string plot_name = basename + ".plot";
  string gdat_name = basename + ".gdat";
  ofstream plot (plot_name.c_str());
  cerr << "! file \"" << plot_name << "\" created" << endl;
  filelist += " \"" + plot_name + "\"";
  size_t d = hat_K.dimension();
  check_macro (d==1 || d==2, "unsupported dimension " << d);
  plot << "gdat = \"" << gdat_name << "\"" << endl
       << "set colors classic" << endl
       << "set size square" << endl
    ;
  if (d == 1) {
    plot << "plot \\" << endl
      ;
    for (size_t loc_idof = 0; loc_idof < loc_ndof; ++loc_idof) {
      plot << "  gdat u 1:"<<loc_idof+2 << " t \"L" << loc_idof+1 << "\" w l";
      if (loc_idof+1 != loc_ndof) {
        plot << ",\\";
      }
      plot << endl;
    }
  } else if (d == 2) {
    plot << "pause_duration = 0.5" << endl
         << "d    = 2" << endl
         << "i    = d+1" << endl
         << "imax = d+" << loc_ndof << endl
         << "set hidden3d back # offset 1 trianglepattern 3 undefined 1 altdiagonal bentover" << endl
         << "set linetype 1 lw 1 lc rgb \"#000000\"" << endl
         << "set linetype 2 lw 1 lc rgb \"#0000ff\"" << endl
         << "splot gdat u 1:2:i t sprintf(\"P%d\",i-d) w l lc 0" << endl
         << "load \"" << basename << ".loop\"" << endl
      ;
    string loop_name = basename + ".loop";
    ofstream loop (loop_name.c_str());
    cerr << "! file \"" << loop_name << "\" created" << endl;
    filelist += " " + loop_name;
    loop << "i = i+1" << endl
         << "if (i <= imax) \\" << endl
         << "  pause pause_duration; \\" << endl
         << "  replot; \\" << endl
         << "  reread" << endl
      ;
  }
  plot << "pause -1 \"<return>\"" << endl;
  plot.close();

  // --------------------
  // .gdat
  // --------------------
  ofstream gdat (gdat_name.c_str());
  cerr << "! file \"" << gdat_name << "\" created" << endl;
  filelist += " \"" + gdat_name + "\"";
  gdat << setprecision(std::numeric_limits<T>::digits10)
       << "# basis   " << b.name() << endl
       << "# element " << hat_K.name() << endl
       << "# degree  " << b.degree() << endl
    ;
  Eigen::Matrix<T,Eigen::Dynamic,1> value;
  switch (hat_K.variant()) {
    case reference_element::p: {
      break;
    } 
    case reference_element::e: {
      gdat << "# size " << loc_ndof << endl
           << "# x";
      for (size_t loc_idof = 0; loc_idof < loc_ndof; ++loc_idof) {
        gdat << " L" << loc_idof+1;
      }
      gdat << endl;
      for (size_type i = 0; i <= nsub; i++) { 
        point_basic<T> hat_x (T(int(i))/T(int(nsub)));
        b.evaluate (hat_K, hat_x, value);
	gdat << hat_x[0];
	for (size_t loc_idof = 0, loc_ndof = value.size(); loc_idof < loc_ndof; ++loc_idof) {
	  gdat << " " << value[loc_idof];
        }
        gdat << endl;
      }
      break;
    }
    case reference_element::t: {
      for (size_type j = 0; j <= nsub; j++) {
        for (size_type i1 = 0; i1 <= nsub; i1++) {
          size_type i = std::min(i1, nsub-j);
          point_basic<T> hat_x (T(int(i))/T(int(nsub)), T(int(j))/T(int(nsub)));
          b.evaluate (hat_K, hat_x, value);
	  gdat << hat_x[0] << " " << hat_x[1];
	  for (size_t loc_idof = 0, loc_ndof = value.size(); loc_idof < loc_ndof; ++loc_idof) {
	    gdat << " " << value[loc_idof];
          }
          gdat << endl;
        }
        gdat << endl;
      }
      break;
    } 
    case reference_element::q: {
      for (size_type j = 0; j <= nsub; j++) { 
        for (size_type i = 0; i <= nsub; i++) { 
          point_basic<T> hat_x (2*T(int(i))/T(int(nsub))-1, 2*T(int(j))/T(int(nsub))-1);
          b.evaluate (hat_K, hat_x, value);
	  gdat << hat_x[0] << " " << hat_x[1];
	  for (size_t loc_idof = 0, loc_ndof = value.size(); loc_idof < loc_ndof; ++loc_idof) {
	    gdat << " " << value[loc_idof];
          }
          gdat << endl;
        }
        gdat << endl;
      }
      break;
    } 
#ifdef TODO // 3D visu ?
    case reference_element::T: {
      for (size_type k = 0; k <= nsub; k++) {
        for (size_type j = 0; j+k <= nsub; j++) {
          for (size_type i = 0; i+j+k <= nsub; i++) { 
            point_basic<T> hat_x (T(i)/T(nsub), T(j)/T(nsub), T(k)/T(nsub));
            b.eval_lagrange (hat_x, hat_K, degree, sopt, inv_vdm, value);
            Lambda = max(Lambda, norm(value,1));
          }
        }
      }
      return Lambda;
    }
    case reference_element::P: {
      for (size_type k = 0; k <= degree; k++) { 
        for (size_type j = 0; j <= degree; j++) { 
          for (size_type i = 0; i+j <= degree; i++) { 
            point_basic<T> hat_x (T(i)/T(nsub), T(j)/T(nsub), 2*T(k)/T(nsub)-1);
            b.eval_lagrange (hat_x, hat_K, degree, sopt, inv_vdm, value);
            Lambda = max(Lambda, norm(value,1));
          }
        }
      }
      break;
    } 
    case reference_element::H: {
      for (size_type k = 0; k <= degree; k++) { 
        for (size_type j = 0; j <= degree; j++) { 
          for (size_type i = 0; i <= degree; i++) { 
            point_basic<T> hat_x (2*T(i)/T(nsub)-1, 2*T(j)/T(nsub), 2*T(k)/T(nsub)-1);
            b.eval_lagrange (hat_x, hat_K, degree, sopt, inv_vdm, value);
            Lambda = max(Lambda, norm(value,1));
          }
        }
      }
      break;
    } 
#endif // TODO
    default:
      error_macro ("unexpected element type `"<<hat_K.name()<<"'");
  } 
  // -----------
  if (execute) {
  // -----------
    string command = "gnuplot \"" + plot_name + "\"";
    if (verbose) clog << "! " << command << endl;
    int status = system (command.c_str());
  }
  // -----------
  if (clean) {
  // -----------
    string command = "/bin/rm -f " + filelist;
    if (verbose) clog << "! " << command << endl;
    int status = system (command.c_str());
  }
}

}} // namespace rheolef::details
#endif // _RHEOLEF_BASIS_VISU_GNUPLOT_ICC