des_prof_scalar.C

00001 /*
00002  * Draws the profile of a {\tt Scalar} along some radial axis determined by
00003  *  a fixed value of $(\theta, \phi)$.
00004  */
00005 
00006 /*
00007  *   Copyright (c) 2004-2005 Eric Gourgoulhon & Philippe Grandclement
00008  *
00009  *   This file is part of LORENE.
00010  *
00011  *   LORENE is free software; you can redistribute it and/or modify
00012  *   it under the terms of the GNU General Public License as published by
00013  *   the Free Software Foundation; either version 2 of the License, or
00014  *   (at your option) any later version.
00015  *
00016  *   LORENE is distributed in the hope that it will be useful,
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *   GNU General Public License for more details.
00020  *
00021  *   You should have received a copy of the GNU General Public License
00022  *   along with LORENE; if not, write to the Free Software
00023  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  *
00025  */
00026 
00027 
00028 char des_prof_scalar_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Graphics/des_prof_scalar.C,v 1.10 2012/01/17 10:35:40 j_penner Exp $" ;
00029 
00030 
00031 /*
00032  * $Id: des_prof_scalar.C,v 1.10 2012/01/17 10:35:40 j_penner Exp $
00033  * $Log: des_prof_scalar.C,v $
00034  * Revision 1.10  2012/01/17 10:35:40  j_penner
00035  * added point plot
00036  *
00037  * Revision 1.9  2008/08/19 06:42:00  j_novak
00038  * Minor modifications to avoid warnings with gcc 4.3. Most of them concern
00039  * cast-type operations, and constant strings that must be defined as const char*
00040  *
00041  * Revision 1.8  2005/03/25 19:57:04  e_gourgoulhon
00042  * Added plot of domain boundaries (new argument draw_bound).
00043  *
00044  * Revision 1.7  2004/05/17 19:47:25  e_gourgoulhon
00045  *  -- Function des_profile_mult(const Scalar**,...): added argument
00046  *     device.
00047  *  -- Functions des_meridian: added arguments device and closeit.
00048  *
00049  * Revision 1.6  2004/04/06 07:47:29  j_novak
00050  * Added a #include "string.h"
00051  *
00052  * Revision 1.5  2004/04/05 14:42:02  e_gourgoulhon
00053  * Added functions des_meridian.
00054  *
00055  * Revision 1.4  2004/02/17 22:18:00  e_gourgoulhon
00056  * Changed prototype of des_profile_mult (added radial_scale, theta and
00057  * phi can now vary from one profile to the other, etc...)
00058  *
00059  * Revision 1.3  2004/02/16 13:23:33  e_gourgoulhon
00060  * Function des_profile_mult: added delete [] uutab at the end.
00061  *
00062  * Revision 1.2  2004/02/15 21:57:45  e_gourgoulhon
00063  * des_profile_mult: changed argument Scalar* to Scalar**.
00064  *
00065  * Revision 1.1  2004/02/12 16:21:28  e_gourgoulhon
00066  * Functions des_profile for Scalar's transfered from file des_prof_cmp.C.
00067  * Added new function des_profile_mult.
00068  *
00069  *
00070  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Graphics/des_prof_scalar.C,v 1.10 2012/01/17 10:35:40 j_penner Exp $
00071  *
00072  */
00073 
00074 // Header C
00075 #include <math.h>
00076 #include <string.h>
00077 
00078 // Header Lorene
00079 #include "scalar.h"
00080 #include "graphique.h"
00081 
00082 #include <vector>
00083 //******************************************************************************
00084 // VERSION SCALAR SANS UNITES 
00085 
00086 void des_profile(const Scalar& uu, double r_min, double r_max, 
00087              double theta, double phi, const char* nomy, const char* title,
00088                      bool draw_bound) {
00089   
00090 
00091     const int npt = 400 ;   // Number of points along the axis
00092     
00093     float uutab[npt] ;      // Value of uu at the npt points
00094     
00095     double hr = (r_max - r_min) / double(npt-1) ; 
00096     
00097     for (int i=0; i<npt; i++) {
00098     
00099     double r = hr * i + r_min ; 
00100     
00101     uutab[i] = float(uu.val_point(r, theta, phi)) ; 
00102     
00103     }
00104     
00105     float xmin = float(r_min) ;
00106     float xmax = float(r_max)  ;
00107     
00108     const char* nomx = "r" ; 
00109     
00110     if (title == 0x0) {
00111     title = "" ;
00112     }
00113 
00114     if (nomy == 0x0) {
00115     nomy = "" ;
00116     }
00117     
00118     // Preparations for the drawing of boundaries
00119     // ------------------------------------------
00120     const Map& mp = uu.get_mp() ; 
00121     int nz = mp.get_mg()->get_nzone() ;         
00122     int l_max = (mp.get_mg()->get_type_r(nz-1) == UNSURR) ? nz-2 : nz-1 ; 
00123     
00124     float* xbound = new float[l_max+1] ; 
00125     int nbound = 0 ; 
00126 
00127     if (draw_bound) {
00128         const double xi_max = 1. ; 
00129         for (int l=0; l<=l_max; l++) {
00130     
00131             double rb = mp.val_r(l, xi_max, theta, phi) ; 
00132         
00133             if ((rb >= r_min) && (rb <= r_max)) {
00134                 xbound[nbound] = float(rb) ; 
00135                 nbound++ ;    
00136             }
00137         }
00138     }
00139     
00140     des_profile(uutab, npt, xmin, xmax, nomx, nomy, title, 0x0, 
00141                 nbound, xbound) ; 
00142     
00143     delete [] xbound ; 
00144     
00145 } 
00146 
00147 //******************************************************************************
00148 
00149 void des_profile(const Scalar& uu, double r_min, double r_max, double scale,
00150              double theta, double phi, const char* nomx, const char* nomy, 
00151                      const char* title, bool draw_bound) {
00152         
00153 
00154     const int npt = 400 ;   // Number of points along the axis
00155     
00156     float uutab[npt] ;      // Value of uu at the npt points
00157     
00158     double hr = (r_max - r_min) / double(npt-1) ; 
00159     
00160     for (int i=0; i<npt; i++) {
00161     
00162     double r = hr * i + r_min ; 
00163     
00164     uutab[i] = float(uu.val_point(r, theta, phi)) ; 
00165     
00166     }
00167     
00168     float xmin = float(r_min * scale) ;
00169     float xmax = float(r_max * scale) ;
00170     
00171     
00172     if (title == 0x0) {
00173     title = "" ;
00174     }
00175 
00176     if (nomx == 0x0) {
00177     nomx = "" ;
00178     }
00179     
00180     if (nomy == 0x0) {
00181     nomy = "" ;
00182     }
00183     
00184     // Preparations for the drawing of boundaries
00185     // ------------------------------------------
00186     const Map& mp = uu.get_mp() ; 
00187     int nz = mp.get_mg()->get_nzone() ;         
00188     int l_max = (mp.get_mg()->get_type_r(nz-1) == UNSURR) ? nz-2 : nz-1 ; 
00189     
00190     float* xbound = new float[l_max+1] ; 
00191     int nbound = 0 ; 
00192 
00193     if (draw_bound) {
00194         const double xi_max = 1. ; 
00195         for (int l=0; l<=l_max; l++) {
00196     
00197             double rb = mp.val_r(l, xi_max, theta, phi) ; 
00198         
00199             if ((rb >= r_min) && (rb <= r_max)) {
00200                 xbound[nbound] = float(rb) ; 
00201                 nbound++ ;    
00202             }
00203         }
00204     }
00205 
00206     // Call to the low level routine
00207     // -----------------------------
00208     des_profile(uutab, npt, xmin, xmax, nomx, nomy, title, 0x0, 
00209                 nbound, xbound) ; 
00210     
00211     delete [] xbound ; 
00212     
00213 } 
00214 
00215 
00216 //******************************************************************************
00217 
00218 void des_profile_mult(const Scalar** uu, int nprof, double r_min, double r_max, 
00219     const double* theta, const double* phi, double radial_scale,
00220         bool closeit, const char* nomy, const char* title, int ngraph,
00221         const char* nomx, const int* line_style, const char* device,
00222         bool draw_bound) {
00223         
00224     // Special case of no graphical output:
00225     if (device != 0x0) {
00226         if ((device[0] == '/') && (device[1] == 'n')) return ; 
00227     }
00228 
00229     const int npt = 400 ;   // Number of points along the axis
00230     double rr[npt] ; 
00231     
00232     float* uutab = new float[npt*nprof] ; // Value of uu at the npt points
00233                           // for each of the nprof profiles
00234     
00235     double hr = (r_max - r_min) / double(npt-1) ; 
00236     
00237     for (int i=0; i<npt; i++) {
00238         rr[i] = hr * i + r_min ; 
00239     }
00240     
00241     
00242     for (int j=0; j<nprof; j++) {
00243     
00244         const Scalar& vv = *(uu[j]) ; 
00245         
00246         for (int i=0; i<npt; i++) {
00247             uutab[j*npt+i] = float(vv.val_point(rr[i], theta[j], phi[j])) ; 
00248         }
00249     }
00250 
00251     
00252     float xmin = float(radial_scale * r_min) ;
00253     float xmax = float(radial_scale * r_max) ;
00254     
00255     if (nomx == 0x0) nomx = "r" ;
00256 
00257     if (nomy == 0x0) nomy = "" ;
00258 
00259     if (title == 0x0) title = "" ;
00260 
00261     // Preparations for the drawing of boundaries
00262     // ------------------------------------------
00263     
00264     int nbound_max = 100 * nprof ; 
00265     float* xbound = new float[nbound_max] ; 
00266     int nbound = 0 ; 
00267 
00268     if (draw_bound) {
00269         const double xi_max = 1. ; 
00270         for (int j=0; j<nprof; j++) {
00271     
00272             const Map& mp = uu[j]->get_mp() ; 
00273             int nz = mp.get_mg()->get_nzone() ;         
00274             int l_max = (mp.get_mg()->get_type_r(nz-1) == UNSURR) ? nz-2 : nz-1 ; 
00275         
00276             for (int l=0; l<=l_max; l++) {
00277             
00278                 double rb = mp.val_r(l, xi_max, theta[j], phi[j]) ; 
00279         
00280                 if ((rb >= r_min) && (rb <= r_max)) {
00281                     xbound[nbound] = float(rb * radial_scale) ; 
00282                     nbound++ ; 
00283                     if (nbound > nbound_max-1) {
00284                         cout << "des_profile_mult : nbound too large !" << endl ; 
00285                         abort() ; 
00286                     }   
00287                 }
00288             }
00289         }
00290     }
00291 
00292     // Call to the low level routine
00293     // -----------------------------
00294     
00295     des_profile_mult(uutab, nprof, npt, xmin, xmax, nomx, nomy, title, 
00296                      line_style, ngraph, closeit, device, nbound, xbound) ; 
00297                      
00298       
00299     delete [] uutab ; 
00300     delete [] xbound ; 
00301     
00302 } 
00303 
00304 //******************************************************************************
00305 
00306 void des_meridian(const Scalar& uu, double r_min, double r_max,
00307                   const char* nomy, int ngraph, const char* device,
00308                   bool closeit, bool draw_bound) {
00309 
00310     // Special case of no graphical output:
00311     if (device != 0x0) {
00312         if ((device[0] == '/') && (device[1] == 'n')) return ; 
00313     }
00314 
00315     const Scalar* des[] = {&uu, &uu, &uu, &uu, &uu} ; 
00316     double phi1[] = {0., 0., 0., 0.25*M_PI, 0.25*M_PI} ; 
00317     double theta1[] = {0., 0.25*M_PI, 0.5*M_PI, 0., 0.25*M_PI} ;
00318          
00319     des_profile_mult(des, 5, r_min, r_max, theta1, phi1, 1., closeit, 
00320             nomy, 
00321             "phi=0: th=0, pi/4, pi/2, phi=pi/4: th=0, pi/4",
00322             ngraph, 0x0, 0x0, device, draw_bound) ;
00323         
00324 }
00325 
00326 //******************************************************************************
00327 
00328 
00329 void des_meridian(const Sym_tensor& hh, double r_min, double r_max,
00330                   const char* name, int ngraph0, const char* device,
00331                   bool closeit) {
00332     
00333     // Special case of no graphical output:
00334     if (device != 0x0) {
00335         if ((device[0] == '/') && (device[1] == 'n')) return ; 
00336     }
00337 
00338     char nomy[80] ;
00339     
00340     int k = 0 ; 
00341     for (int i=1; i<=3; i++) {
00342         for (int j=i; j<=3; j++) {
00343 
00344                 char nom_i[3] ; 
00345                 sprintf(nom_i, "%d", i) ; 
00346                 char nom_j[3] ; 
00347                 sprintf(nom_j, "%d", j) ; 
00348                 strncpy(nomy, name, 40) ; 
00349                 strcat(nomy, "  comp. ") ; 
00350                 strcat(nomy, nom_i) ; 
00351                 strcat(nomy, nom_j) ; 
00352     
00353                 des_meridian(hh(i,j), r_min, r_max, nomy, ngraph0+k, device,
00354                              closeit) ; 
00355                 k++ ; 
00356                                 
00357         }
00358     }              
00359 
00360 }
00361 
00362 
00363 //******************************************************************************
00364 // VERSION SCALAR SANS UNITES 
00365 
00366 void des_points(const Scalar& uu, 
00367              double theta, double phi, const char* nomy, const char* title,
00368                      bool draw_bound) {
00369   
00370     const Map& mp = uu.get_mp() ; 
00371     int nz = mp.get_mg()->get_nzone() ;         
00372     int nt = mp.get_mg()->get_nt(nz-1) ; 
00373     int np = mp.get_mg()->get_np(nz-1) ;
00374 
00375 //    const int npt = *(uu.get_mp().get_mg())->get_nzone() ;   // Number of points along the axis
00376     
00377 
00378     int npt=0;
00379 
00380     for(int ii = 0; ii<nz; ii++)
00381         npt += (uu.get_mp().get_mg())->get_nr(ii) ;
00382 
00383     float *uutab = new float[npt] ;     // define a dynamic array
00384     float *xtab = new float[npt] ;      // define a dynamic array
00385    
00386     Mtbl r = *(mp.r.c);
00387 
00388     for(int ii = 0; ii<nz; ii++){
00389     int nr = (uu.get_mp().get_mg())->get_nr(ii) ; 
00390     for(int ij=0; ij<nr; ij++){
00391     uutab[ii*nr+ij] = float(uu.val_grid_point(ii,np-1,nt-1,ij)) ; 
00392     xtab[ii*nr+ij] = float(r(ii,np-1,nt-1,ij)) ; 
00393     }
00394     }
00395     
00396     float xmin = float(totalmin(r)) ;
00397     float xmax = float(totalmax(r)) ;
00398     
00399     const char* nomx = "r" ; 
00400     
00401     if (title == 0x0) {
00402     title = "" ;
00403     }
00404 
00405     if (nomy == 0x0) {
00406     nomy = "" ;
00407     }
00408     
00409     // Preparations for the drawing of boundaries
00410     // ------------------------------------------
00411     int l_max = (mp.get_mg()->get_type_r(nz-1) == UNSURR) ? nz-2 : nz-1 ; 
00412     
00413     float* xbound = new float[l_max+1] ; 
00414     int nbound = 0 ; 
00415 
00416     if (draw_bound) {
00417         const double xi_max = 1. ; 
00418         for (int l=0; l<=l_max; l++) {
00419     
00420             double rb = mp.val_r(l, xi_max, theta, phi) ; 
00421         
00422             if ((rb >= xmin) && (rb <= xmax)) {
00423                 xbound[nbound] = float(rb) ; 
00424                 nbound++ ;    
00425             }
00426         }
00427     }
00428     
00429     des_profile(uutab, npt, xtab, nomx, nomy, title, 0x0, 
00430                 nbound, xbound) ; 
00431     
00432     delete [] xbound ; 
00433     
00434 } 
00435 
00436 //******************************************************************************
00437 
00438 void des_points(const Scalar& uu, double scale,
00439              double theta, double phi, const char* nomx, const char* nomy, 
00440                      const char* title, bool draw_bound) {
00441         
00442     const Map& mp = uu.get_mp() ; 
00443     int nz = mp.get_mg()->get_nzone() ;         
00444     int nt = mp.get_mg()->get_nt(nz-1) ; 
00445     int np = mp.get_mg()->get_np(nz-1) ;
00446 
00447 //    const int npt = *(uu.get_mp().get_mg())->get_nzone() ;   // Number of points along the axis
00448     
00449 
00450     int npt=0;
00451 
00452     for(int ii = 0; ii<nz; ii++)
00453         npt += (uu.get_mp().get_mg())->get_nr(ii) ;
00454 
00455     float *uutab = new float[npt] ;     // define a dynamic array
00456     float *xtab = new float[npt] ;      // define a dynamic array
00457    
00458     Mtbl r = *(mp.r.c);
00459    
00460     for(int ii = 0; ii<nz; ii++){
00461     int nr = (uu.get_mp().get_mg())->get_nr(ii) ; 
00462     for(int ij=0; ij<nr; ij++){
00463     uutab[ii*nr+ij] = float(uu.val_grid_point(ii,np-1,nt-1,ij)) ; 
00464     xtab[ii*nr+ij] = float(r(ii,np-1,nt-1,ij)) ; 
00465     }
00466     }
00467     
00468     float xmin = float(totalmin(r) * scale) ;
00469     float xmax = float(totalmax(r) * scale) ;
00470     
00471     
00472     if (title == 0x0) {
00473     title = "" ;
00474     }
00475 
00476     if (nomx == 0x0) {
00477     nomx = "" ;
00478     }
00479     
00480     if (nomy == 0x0) {
00481     nomy = "" ;
00482     }
00483     
00484     // Preparations for the drawing of boundaries
00485     // ------------------------------------------
00486     int l_max = (mp.get_mg()->get_type_r(nz-1) == UNSURR) ? nz-2 : nz-1 ; 
00487     
00488     float* xbound = new float[l_max+1] ; 
00489     int nbound = 0 ; 
00490 
00491     if (draw_bound) {
00492         const double xi_max = 1. ; 
00493         for (int l=0; l<=l_max; l++) {
00494     
00495             double rb = mp.val_r(l, xi_max, theta, phi) ; 
00496         
00497             if ((rb >= xmin/scale) && (rb <= xmax/scale)) {
00498                 xbound[nbound] = float(rb) ; 
00499                 nbound++ ;    
00500             }
00501         }
00502     }
00503 
00504     // Call to the low level routine
00505     // -----------------------------
00506     des_profile(uutab, npt, xtab, nomx, nomy, title, 0x0, 
00507                 nbound, xbound) ; 
00508     
00509     delete [] xbound ; 
00510     
00511 }

Generated on Tue Feb 7 01:35:16 2012 for LORENE by  doxygen 1.4.6