File: vector_visu.C

package info (click to toggle)
lorene 0.0.0~cvs20161116%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 26,472 kB
  • sloc: cpp: 212,946; fortran: 21,645; makefile: 1,750; sh: 4
file content (504 lines) | stat: -rw-r--r-- 15,810 bytes parent folder | download | duplicates (2)
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
/*
 *  3D visualization of a Vector via OpenDX 
 *
 *    (see file vector.h for documentation).
 *
 */

/*
 *   Copyright (c) 2003  Eric Gourgoulhon
 *
 *   This file is part of LORENE.
 *
 *   LORENE is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License version 2
 *   as published by the Free Software Foundation.
 *
 *   LORENE 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 LORENE; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

char vector_visu_C[] = "$Header: /cvsroot/Lorene/C++/Source/Tensor/vector_visu.C,v 1.5 2014/10/13 08:53:45 j_novak Exp $" ;

/*
 * $Id: vector_visu.C,v 1.5 2014/10/13 08:53:45 j_novak Exp $
 * $Log: vector_visu.C,v $
 * Revision 1.5  2014/10/13 08:53:45  j_novak
 * Lorene classes and functions now belong to the namespace Lorene.
 *
 * Revision 1.4  2014/10/06 15:13:21  j_novak
 * Modified #include directives to use c++ syntax.
 *
 * Revision 1.3  2005/02/16 15:31:56  m_forot
 * Add the visu_streamline function
 *
 * Revision 1.2  2003/12/15 08:30:39  p_grandclement
 * Addition of #include <string.h>
 *
 * Revision 1.1  2003/12/14 21:48:26  e_gourgoulhon
 * First version
 *
 *
 * $Header: /cvsroot/Lorene/C++/Source/Tensor/vector_visu.C,v 1.5 2014/10/13 08:53:45 j_novak Exp $
 *
 */

// C headers
#include <cstdlib>
#include <cstring>

// Lorene headers
#include "tensor.h"

                    
namespace Lorene {
void Vector::visu_arrows(double xmin, double xmax, double ymin, double ymax,
    double zmin, double zmax, const char* title0, const char* filename0, 
    bool start_dx, int nx, int ny, int nz) const {

    const Vector* vect ; 
    Vector* vect_tmp = 0x0 ; 
    
    // The drawing is possible only in Cartesian coordinates:
    if (*triad == mp->get_bvect_cart()) {
        vect = this ; 
    }
    else {
        if (*triad == mp->get_bvect_spher()) {
            vect_tmp = new Vector(*this) ; 
            vect_tmp->change_triad( mp->get_bvect_cart() ) ; 
            vect = vect_tmp ;
        }
        else {
            cerr << "Vector::visu_arrows : unknown triad !" << endl ; 
            abort() ; 
        }
    }
    
    // The drawing is possible only if dzpuis = 0 
    bool dzpnonzero = false ; 
    for (int i=1; i<=3; i++) {
        dzpnonzero = dzpnonzero || !(operator()(i).check_dzpuis(0)) ; 
    }
    if (dzpnonzero) {
        if (vect_tmp == 0x0) {
            vect_tmp = new Vector(*this) ;                
        }
        for (int i=1; i<=3; i++) {
            Scalar& cvect = vect_tmp->set(i) ; 
            int dzpuis = cvect.get_dzpuis() ; 
            if (dzpuis != 0) {
                cvect.dec_dzpuis(dzpuis) ; 
            }
        }
        vect = vect_tmp ; 
    }
    
    char* title ;
    char* title_quotes ;
    if (title0 == 0x0) {
        title = new char[2] ; 
        strcpy(title, " ") ; 

        title_quotes = new char[4] ; 
        strcpy(title_quotes, "\" \"") ; 
    }
    else {
        title = new char[ strlen(title0)+1 ] ; 
        strcpy(title, title0) ;
         
        title_quotes = new char[ strlen(title0)+3 ] ; 
        strcpy(title_quotes, "\"") ; 
        strcat(title_quotes, title0) ; 
        strcat(title_quotes, "\"") ; 
    }
    
    // --------------------------------------------------------
    // Data file for OpenDX
    // --------------------------------------------------------

    char* filename ;
    if (filename0 == 0x0) {
        filename = new char[30] ; 
        strcpy(filename, "vector3d_arrows.dxdata") ; 
    }
    else {
        filename = new char[ strlen(filename0)+8 ] ; 
        strcpy(filename, filename0) ; 
        strcat(filename, ".dxdata") ; 
    }

    ofstream fdata(filename) ; // output file
    
    fdata << title << "\n" ; 
    fdata << "size : " << nx << " x " << ny << " x " << nz << "\n" ;
    fdata << "x_min = " << xmin << "  x_max = " << xmax << "\n" ; 
    fdata << "y_min = " << ymin << "  y_max = " << ymax << "\n" ; 
    fdata << "z_min = " << zmin << "  z_max = " << zmax << "\n" ; 
    
    // The spectral coefficients are required
    const Valeur& vax = (vect->operator()(1)).get_spectral_va() ; 
    const Valeur& vay = (vect->operator()(2)).get_spectral_va() ; 
    const Valeur& vaz = (vect->operator()(3)).get_spectral_va() ; 
    vax.coef() ; 
    vay.coef() ; 
    vaz.coef() ; 
    const Mtbl_cf& cvax = *(vax.c_cf) ; 
    const Mtbl_cf& cvay = *(vay.c_cf) ; 
    const Mtbl_cf& cvaz = *(vaz.c_cf) ; 
    
    // What follows assumes that the mapping is radial:
    assert( dynamic_cast<const Map_radial*>(mp) != 0x0 ) ; 
    
    fdata.precision(5) ; 
    fdata.setf(ios::scientific) ; 
    
    // Loop on the points of the drawing box
    // ---------------------------------------
    double dx = (xmax - xmin) / double(nx-1) ; 
    double dy = (ymax - ymin) / double(ny-1) ; 
    double dz = (zmax - zmin) / double(nz-1) ; 
    
    int npoint = 0 ;    // number of data points per line in the file

    for (int k=0; k<nz; k++) {

        double zz = zmin + dz * k ;

        for (int j=0; j<ny; j++) {
            
            double yy = ymin + dy * j ; 
            
            for (int i=0; i<nx; i++) {
                
                double xx = xmin + dx * i ; 
                    
                // Values of (r,theta,phi) corresponding to (xa,ya,za) :
                double rr, th, ph ;  // polar coordinates of the mapping associated
                                     // to *this
            
                mp->convert_absolute(xx, yy, zz, rr, th, ph) ; 

                // Values of (l,xi,theta',phi') corresponding to (r,theta,phi):
                double xi ; int l ; 
            
                mp->val_lx(rr, th, ph, l, xi) ;   // radial mapping assumption
            
                // Field value at this point:
            
                double vx = cvax.val_point(l, xi, th, ph) ;
                double vy = cvay.val_point(l, xi, th, ph) ;
                double vz = cvaz.val_point(l, xi, th, ph) ;

                fdata.width(14) ; fdata << vx ; 
                fdata.width(14) ; fdata << vy ; 
                fdata.width(14) ; fdata << vz ; 
                npoint++ ; 
             
                if (npoint == 3) {
                    fdata << "\n" ; 
                    npoint = 0 ; 
                }
            
            }
        }

    }
    
    if (npoint != 0) fdata << "\n" ; 

    fdata.close() ; 
    
    // --------------------------------------------------------
    // Header file for OpenDX
    // --------------------------------------------------------

    char* headername ;
    if (filename0 == 0x0) {
        headername = new char[30] ; 
        strcpy(headername, "vector3d_arrows.dxhead") ; 
    }
    else {
        headername = new char[ strlen(filename0)+9 ] ; 
        strcpy(headername, filename0) ; 
        strcat(headername, ".dxhead") ; 
    }

    ofstream fheader(headername) ;
    
    fheader << "file = " << filename << endl ; 
    fheader << "grid = " << nx << " x " << ny << " x " << nz << endl ; 
    fheader << "format = ascii" << endl ;  
    fheader << "interleaving = record-vector"  << endl ;
    fheader << "majority = column" << endl ; 
    fheader << "header = lines 5" << endl ; 
    fheader << "field = " << title_quotes << endl ; 
    fheader << "structure = 3-vector" << endl ; 
    fheader << "type = float" << endl ; 
    fheader << "dependency = positions" << endl ; 
    fheader << "positions = regular, regular, regular, " 
            << xmin << ", " << dx << ", " 
            << ymin << ", " << dy << ", " 
            << zmin << ", " << dz << endl ; 
    fheader << endl ; 
    fheader << "end" << endl ; 
    
    fheader.close() ; 
    

    if ( start_dx ) {       // Launch of OpenDX
        
        char* commande = new char[ strlen(headername) + 60 ] ;
        strcpy(commande, "ln -s ") ; 
        strcat(commande, headername) ; 
        strcat(commande, " visu_vector3d.dxhead") ; 
    
        system("rm -f visu_vector3d.dxhead") ; 
        system(commande) ;                      // ln -s headername visu_section.general
        system("dx -image visu_vector3d.net &") ; 
    
        delete [] commande ;    
    }


    // Final cleaning
    // --------------
    
    if (vect_tmp != 0x0) delete vect_tmp ;
    delete [] title ; 
    delete [] title_quotes ; 
    delete [] filename ; 
    delete [] headername ;    
   

}   

void Vector::visu_streamline(double xmin, double xmax, double ymin, double ymax,
			     double zmin, double zmax, const char* title0, const char* filename0, 
			     bool start_dx, int nx, int ny, int nz) const {

    const Vector* vect ; 
    Vector* vect_tmp = 0x0 ; 
    
    // The drawing is possible only in Cartesian coordinates:
    if (*triad == mp->get_bvect_cart()) {
        vect = this ; 
    }
    else {
        if (*triad == mp->get_bvect_spher()) {
            vect_tmp = new Vector(*this) ; 
            vect_tmp->change_triad( mp->get_bvect_cart() ) ; 
            vect = vect_tmp ;
        }
        else {
            cerr << "Vector::visu_streamline : unknown triad !" << endl ; 
            abort() ; 
        }
    }
    
    // The drawing is possible only if dzpuis = 0 
    bool dzpnonzero = false ; 
    for (int i=1; i<=3; i++) {
        dzpnonzero = dzpnonzero || !(operator()(i).check_dzpuis(0)) ; 
    }
    if (dzpnonzero) {
        if (vect_tmp == 0x0) {
            vect_tmp = new Vector(*this) ;                
        }
        for (int i=1; i<=3; i++) {
            Scalar& cvect = vect_tmp->set(i) ; 
            int dzpuis = cvect.get_dzpuis() ; 
            if (dzpuis != 0) {
                cvect.dec_dzpuis(dzpuis) ; 
            }
        }
        vect = vect_tmp ; 
    }
    
    char* title ;
    char* title_quotes ;
    if (title0 == 0x0) {
        title = new char[2] ; 
        strcpy(title, " ") ; 

        title_quotes = new char[4] ; 
        strcpy(title_quotes, "\" \"") ; 
    }
    else {
        title = new char[ strlen(title0)+1 ] ; 
        strcpy(title, title0) ;
         
        title_quotes = new char[ strlen(title0)+3 ] ; 
        strcpy(title_quotes, "\"") ; 
        strcat(title_quotes, title0) ; 
        strcat(title_quotes, "\"") ; 
    }
    
    // --------------------------------------------------------
    // Data file for OpenDX
    // --------------------------------------------------------

    char* filename ;
    if (filename0 == 0x0) {
        filename = new char[30] ; 
        strcpy(filename, "vector3d_streamline.dxdata") ; 
    }
    else {
        filename = new char[ strlen(filename0)+8 ] ; 
        strcpy(filename, filename0) ; 
        strcat(filename, ".dxdata") ; 
    }

    ofstream fdata(filename) ; // output file
    
    fdata << title << "\n" ; 
    fdata << "size : " << nx << " x " << ny << " x " << nz << "\n" ;
    fdata << "x_min = " << xmin << "  x_max = " << xmax << "\n" ; 
    fdata << "y_min = " << ymin << "  y_max = " << ymax << "\n" ; 
    fdata << "z_min = " << zmin << "  z_max = " << zmax << "\n" ; 
    
    // The spectral coefficients are required
    const Valeur& vax = (vect->operator()(1)).get_spectral_va() ; 
    const Valeur& vay = (vect->operator()(2)).get_spectral_va() ; 
    const Valeur& vaz = (vect->operator()(3)).get_spectral_va() ; 
    vax.coef() ; 
    vay.coef() ; 
    vaz.coef() ; 
    const Mtbl_cf& cvax = *(vax.c_cf) ; 
    const Mtbl_cf& cvay = *(vay.c_cf) ; 
    const Mtbl_cf& cvaz = *(vaz.c_cf) ; 
    
    // What follows assumes that the mapping is radial:
    assert( dynamic_cast<const Map_radial*>(mp) != 0x0 ) ; 
    
    fdata.precision(5) ; 
    fdata.setf(ios::scientific) ; 
    
    // Loop on the points of the drawing box
    // ---------------------------------------
    double dx = (xmax - xmin) / double(nx-1) ; 
    double dy = (ymax - ymin) / double(ny-1) ; 
    double dz = (zmax - zmin) / double(nz-1) ; 
    
    int npoint = 0 ;    // number of data points per line in the file

    for (int k=0; k<nz; k++) {

        double zz = zmin + dz * k ;

        for (int j=0; j<ny; j++) {
            
            double yy = ymin + dy * j ; 
            
            for (int i=0; i<nx; i++) {
                
                double xx = xmin + dx * i ; 
                    
                // Values of (r,theta,phi) corresponding to (xa,ya,za) :
                double rr, th, ph ;  // polar coordinates of the mapping associated
                                     // to *this
            
                mp->convert_absolute(xx, yy, zz, rr, th, ph) ; 

                // Values of (l,xi,theta',phi') corresponding to (r,theta,phi):
                double xi ; int l ; 
            
                mp->val_lx(rr, th, ph, l, xi) ;   // radial mapping assumption
            
                // Field value at this point:
            
                double vx = cvax.val_point(l, xi, th, ph) ;
                double vy = cvay.val_point(l, xi, th, ph) ;
                double vz = cvaz.val_point(l, xi, th, ph) ;

                fdata.width(14) ; fdata << vx ; 
                fdata.width(14) ; fdata << vy ; 
                fdata.width(14) ; fdata << vz ; 
                npoint++ ; 
             
                if (npoint == 3) {
                    fdata << "\n" ; 
                    npoint = 0 ; 
                }
            
            }
        }

    }
    
    if (npoint != 0) fdata << "\n" ; 

    fdata.close() ; 
    
    // --------------------------------------------------------
    // Header file for OpenDX
    // --------------------------------------------------------

    char* headername ;
    if (filename0 == 0x0) {
        headername = new char[30] ; 
        strcpy(headername, "vector3d_streamline.dxhead") ; 
    }
    else {
        headername = new char[ strlen(filename0)+9 ] ; 
        strcpy(headername, filename0) ; 
        strcat(headername, ".dxhead") ; 
    }

    ofstream fheader(headername) ;
    
    fheader << "file = " << filename << endl ; 
    fheader << "grid = " << nx << " x " << ny << " x " << nz << endl ; 
    fheader << "format = ascii" << endl ;  
    fheader << "interleaving = record-vector"  << endl ;
    fheader << "majority = column" << endl ; 
    fheader << "header = lines 5" << endl ; 
    fheader << "field = " << title_quotes << endl ; 
    fheader << "structure = 3-vector" << endl ; 
    fheader << "type = float" << endl ; 
    fheader << "dependency = positions" << endl ; 
    fheader << "positions = regular, regular, regular, " 
            << xmin << ", " << dx << ", " 
            << ymin << ", " << dy << ", " 
            << zmin << ", " << dz << endl ; 
    fheader << endl ; 
    fheader << "end" << endl ; 
    
    fheader.close() ; 
    

    if ( start_dx ) {       // Launch of OpenDX
        
        char* commande = new char[ strlen(headername) + 60 ] ;
        strcpy(commande, "ln -s ") ; 
        strcat(commande, headername) ; 
        strcat(commande, " visu_vector3d_SL.general") ; 
    
        system("rm -f visu_vector3d_SL.general") ; 
        system(commande) ;                      // ln -s headername visu_section.general
        system("dx -image visu_vector3d_SL.net &") ; 
    
        delete [] commande ;    
    }


    // Final cleaning
    // --------------
    
    if (vect_tmp != 0x0) delete vect_tmp ;
    delete [] title ; 
    delete [] title_quotes ; 
    delete [] filename ; 
    delete [] headername ;    
   

}   

}