des_surf_scalar.C

00001 /*
00002  *  Basic routine for drawing the surface of a star
00003  */
00004 
00005 /*
00006  *   Copyright (c) 2005 Eric Gourgoulhon
00007  *
00008  *   This file is part of LORENE.
00009  *
00010  *   LORENE is free software; you can redistribute it and/or modify
00011  *   it under the terms of the GNU General Public License as published by
00012  *   the Free Software Foundation; either version 2 of the License, or
00013  *   (at your option) any later version.
00014  *
00015  *   LORENE is distributed in the hope that it will be useful,
00016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *   GNU General Public License for more details.
00019  *
00020  *   You should have received a copy of the GNU General Public License
00021  *   along with LORENE; if not, write to the Free Software
00022  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  */
00025 
00026 
00027 char des_surf_scalar_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Graphics/des_surf_scalar.C,v 1.2 2008/08/19 06:42:00 j_novak Exp $" ;
00028 
00029 /*
00030  * $Id: des_surf_scalar.C,v 1.2 2008/08/19 06:42:00 j_novak Exp $
00031  * $Log: des_surf_scalar.C,v $
00032  * Revision 1.2  2008/08/19 06:42:00  j_novak
00033  * Minor modifications to avoid warnings with gcc 4.3. Most of them concern
00034  * cast-type operations, and constant strings that must be defined as const char*
00035  *
00036  * Revision 1.1  2005/03/24 22:01:44  e_gourgoulhon
00037  * Plot of a surface defined by a Scalar.
00038  *
00039  *
00040  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Graphics/des_surf_scalar.C,v 1.2 2008/08/19 06:42:00 j_novak Exp $
00041  *
00042  */
00043 
00044 // C headers:
00045 #include <math.h>
00046 
00047 // PGPLOT headers:
00048 #include <cpgplot.h>
00049 
00050 // Lorene headers
00051 #include "scalar.h"
00052 #include "param.h"
00053 #include "utilitaires.h"
00054 #include "unites.h"
00055 
00056 // Local prototypes
00057 double fonc_des_surf_scal_x(double, const Param&) ; 
00058 double fonc_des_surf_scal_y(double, const Param&) ; 
00059 double fonc_des_surf_scal_z(double, const Param&) ; 
00060 
00061 //******************************************************************************
00062  
00063 void des_surface_x(const Scalar& defsurf, double x0, const char* device, int newgraph, 
00064            double y_min, double y_max, double z_min, double z_max, 
00065            const char* nomy, const char* nomz, const char* title, int nxpage, int nypage)
00066 {
00067   using namespace Unites ;
00068 
00069     assert(defsurf.get_etat() == ETATQCQ) ; 
00070 
00071 
00072     const Map& mp =  defsurf.get_mp();  
00073     
00074     double khi ;
00075     
00076     Param parzerosec ;
00077     parzerosec.add_double_mod(x0, 0) ;  
00078     parzerosec.add_double_mod(khi, 1) ;     
00079     parzerosec.add_scalar(defsurf) ;
00080 
00081     double rhomin = 0 ; 
00082     double rhomax = 2 * 
00083             mp.val_r(mp.get_mg()->get_nzone() - 1, -1., 0., 0.) ;  
00084     double precis = 1.e-8 ; 
00085     int nitermax = 100 ; 
00086     int niter ; 
00087     
00088     const int np = 101 ; 
00089     float yg[np] ; 
00090     float zg[np] ; 
00091 
00092     double hkhi = 2 * M_PI / (np-1) ; 
00093     
00094     bool coupe_surface = true ; 
00095     
00096     for (int i=0; i< np; i++) {
00097 
00098     khi = hkhi * i ; 
00099     
00100     // Search for the interval [rhomin0, rhomax0] which contains 
00101     //  the first zero of des_surf:
00102     
00103     double rhomin0 ;
00104     double rhomax0 ;
00105 
00106     if ( zero_premier(fonc_des_surf_scal_x, parzerosec, rhomin, rhomax, 100, 
00107              rhomin0, rhomax0) == false ) {
00108         cout << 
00109    "des_surface_x : WARNING : no interval containing a zero of defsurf"
00110         << endl ; 
00111         cout << "  has been found for khi = " << khi << " !" << endl ; 
00112 
00113         coupe_surface = false ; 
00114         break ; 
00115 
00116     }
00117         
00118              
00119     // Search for the zero in the interval [rhomin0, rhomax0] :
00120     
00121     double rho = zerosec(fonc_des_surf_scal_x, parzerosec, rhomin0, rhomax0, 
00122                  precis, nitermax, niter) ;
00123                    
00124     yg[i] = float(( rho * cos(khi) + mp.get_ori_y() ) / km) ;       
00125     zg[i] = float(( rho * sin(khi) + mp.get_ori_z() ) / km) ;
00126     }
00127     
00128     // Graphics display
00129     // ----------------
00130 
00131     if ( (newgraph == 1) || (newgraph == 3) ) {
00132 
00133     if (device == 0x0) device = "?" ; 
00134    
00135     int ier = cpgbeg(0, device, nxpage, nypage) ;
00136     if (ier != 1) {
00137     cout << "des_surface_x: problem in opening PGPLOT display !" << endl ;
00138     } 
00139     
00140     // Taille des caracteres:
00141     float size = float(1.3) ;
00142     cpgsch(size) ;
00143     
00144     // Epaisseur des traits:
00145     int lepais = 1 ; 
00146     cpgslw(lepais) ;
00147     
00148     cpgscf(2) ; // Fonte axes: caracteres romains
00149     
00150     float ymin1 = float(y_min / km) ;
00151     float ymax1 = float(y_max / km) ;
00152     float zmin1 = float(z_min / km) ;
00153     float zmax1 = float(z_max / km) ;
00154     
00155     cpgenv(ymin1, ymax1, zmin1, zmax1, 1, 0 ) ; 
00156 
00157     if (nomy == 0x0) nomy = "y [km]" ;
00158     if (nomz == 0x0) nomz = "z [km]" ; 
00159     if (title == 0x0) title = " " ; 
00160     cpglab(nomy,nomz,title) ;
00161 
00162     }
00163 
00164     if (coupe_surface) {
00165     cpgsls(1) ;     // lignes en trait plein
00166     cpgslw(6) ;     // traits gras
00167     cpgline(np, yg, zg) ;
00168     cpgslw(1) ;     // traits normaux
00169     }
00170     
00171     
00172     // Closing graphic display
00173     // -----------------------
00174 
00175     if ( (newgraph == 2) || (newgraph == 3) ) {    
00176     cpgend() ; 
00177     }
00178 
00179 }
00180 
00181 //******************************************************************************
00182  
00183 void des_surface_y(const Scalar& defsurf, double y0, const char* device, int newgraph, 
00184            double x_min, double x_max, double z_min, double z_max, 
00185            const char* nomx, const char* nomz, const char* title, int nxpage, int nypage)
00186 {
00187   using namespace Unites ;
00188 
00189     assert(defsurf.get_etat() == ETATQCQ) ; 
00190 
00191 
00192     const Map& mp =  defsurf.get_mp();  
00193     
00194     double khi ;
00195     
00196     Param parzerosec ;
00197     parzerosec.add_double_mod(y0, 0) ;  
00198     parzerosec.add_double_mod(khi, 1) ;     
00199     parzerosec.add_scalar(defsurf) ;
00200 
00201     double rhomin = 0 ; 
00202     double rhomax = 2 * 
00203             mp.val_r(mp.get_mg()->get_nzone() - 1, -1., 0., 0.) ;  
00204     double precis = 1.e-8 ; 
00205     int nitermax = 100 ; 
00206     int niter ; 
00207     
00208     const int np = 101 ; 
00209     float xg[np] ; 
00210     float zg[np] ; 
00211 
00212     double hkhi = 2 * M_PI / (np-1) ; 
00213     
00214     bool coupe_surface = true ; 
00215     
00216     for (int i=0; i< np; i++) {
00217 
00218     khi = hkhi * i ; 
00219     
00220     // Search for the interval [rhomin0, rhomax0] which contains 
00221     //  the first zero of des_surf:
00222     
00223     double rhomin0 ;
00224     double rhomax0 ;
00225 
00226     if ( zero_premier(fonc_des_surf_scal_y, parzerosec, rhomin, rhomax, 100, 
00227              rhomin0, rhomax0) == false ) {
00228         cout << 
00229    "des_surface_y : WARNING : no interval containing a zero of defsurf"
00230         << endl ; 
00231         cout << "  has been found for khi = " << khi << " !" << endl ; 
00232 
00233         coupe_surface = false ; 
00234         break ; 
00235 
00236     }
00237         
00238              
00239     // Search for the zero in the interval [rhomin0, rhomax0] :
00240     
00241     double rho = zerosec(fonc_des_surf_scal_y, parzerosec, rhomin0, rhomax0, 
00242                  precis, nitermax, niter) ;
00243                    
00244     xg[i] = float(( rho * cos(khi) + mp.get_ori_x() ) / km) ;
00245     zg[i] = float(( rho * sin(khi) + mp.get_ori_z() ) / km) ;
00246     }
00247     
00248     // Graphics display
00249     // ----------------
00250 
00251     if ( (newgraph == 1) || (newgraph == 3) ) {
00252 
00253     if (device == 0x0) device = "?" ; 
00254    
00255     int ier = cpgbeg(0, device, nxpage, nypage) ;
00256     if (ier != 1) {
00257     cout << "des_surface_y: problem in opening PGPLOT display !" << endl ;
00258     } 
00259     
00260     // Taille des caracteres:
00261     float size = float(1.3) ;
00262     cpgsch(size) ;
00263     
00264     // Epaisseur des traits:
00265     int lepais = 1 ; 
00266     cpgslw(lepais) ;
00267     
00268     cpgscf(2) ; // Fonte axes: caracteres romains
00269     
00270     float xmin1 = float(x_min / km) ;
00271     float xmax1 = float(x_max / km) ;
00272     float zmin1 = float(z_min / km) ;
00273     float zmax1 = float(z_max / km) ;
00274     
00275     cpgenv(xmin1, xmax1, zmin1, zmax1, 1, 0 ) ; 
00276 
00277     if (nomx == 0x0) nomx = "x [km]" ;
00278     if (nomz == 0x0) nomz = "z [km]" ; 
00279     if (title == 0x0) title = " " ; 
00280     cpglab(nomx,nomz,title) ;
00281 
00282     }
00283 
00284     if (coupe_surface) {
00285     cpgsls(1) ;     // lignes en trait plein
00286     cpgslw(6) ;     // traits gras
00287     cpgline(np, xg, zg) ;
00288     cpgslw(1) ;     // traits normaux
00289     }
00290     
00291     
00292     // Closing graphic display
00293     // -----------------------
00294 
00295     if ( (newgraph == 2) || (newgraph == 3) ) {    
00296     cpgend() ; 
00297     }
00298 
00299 }
00300 
00301 //******************************************************************************
00302  
00303 void des_surface_z(const Scalar& defsurf, double z0, const char* device, int newgraph, 
00304            double x_min, double x_max, double y_min, double y_max, 
00305            const char* nomx, const char* nomy, const char* title, int nxpage, int nypage)
00306 {
00307   using namespace Unites ;
00308 
00309     assert(defsurf.get_etat() == ETATQCQ) ; 
00310 
00311 
00312     const Map& mp =  defsurf.get_mp();  
00313     
00314     double khi ;
00315     
00316     Param parzerosec ;
00317     parzerosec.add_double_mod(z0, 0) ;  
00318     parzerosec.add_double_mod(khi, 1) ;     
00319     parzerosec.add_scalar(defsurf) ;
00320 
00321     double rhomin = 0 ; 
00322     double rhomax = 2 * 
00323             mp.val_r(mp.get_mg()->get_nzone() - 1, -1., 0., 0.) ;  
00324     double precis = 1.e-8 ; 
00325     int nitermax = 100 ; 
00326     int niter ; 
00327     
00328     const int np = 101 ; 
00329     float xg[np] ; 
00330     float yg[np] ; 
00331 
00332     double hkhi = 2 * M_PI / (np-1) ; 
00333     
00334     bool coupe_surface = true ; 
00335     
00336     for (int i=0; i< np; i++) {
00337 
00338     khi = hkhi * i ; 
00339     
00340     // Search for the interval [rhomin0, rhomax0] which contains 
00341     //  the first zero of des_surf:
00342     
00343     double rhomin0 ;
00344     double rhomax0 ;
00345 
00346     if ( zero_premier(fonc_des_surf_scal_z, parzerosec, rhomin, rhomax, 100, 
00347              rhomin0, rhomax0) == false ) {
00348         cout << 
00349    "des_surface_z : WARNING : no interval containing a zero of defsurf"
00350         << endl ; 
00351         cout << "  has been found for khi = " << khi << " !" << endl ; 
00352 
00353         coupe_surface = false ; 
00354         break ; 
00355 
00356     }
00357         
00358              
00359     // Search for the zero in the interval [rhomin0, rhomax0] :
00360     
00361     double rho = zerosec(fonc_des_surf_scal_z, parzerosec, rhomin0, rhomax0, 
00362                  precis, nitermax, niter) ;
00363                    
00364     xg[i] = float(( rho * cos(khi) + mp.get_ori_x() ) / km) ;
00365     yg[i] = float(( rho * sin(khi) + mp.get_ori_y() ) / km) ;
00366     }
00367     
00368     // Graphics display
00369     // ----------------
00370 
00371     if ( (newgraph == 1) || (newgraph == 3) ) {
00372 
00373     if (device == 0x0) device = "?" ; 
00374    
00375     int ier = cpgbeg(0, device, nxpage, nypage) ;
00376     if (ier != 1) {
00377     cout << "des_surface_z: problem in opening PGPLOT display !" << endl ;
00378     } 
00379     
00380     // Taille des caracteres:
00381     float size = float(1.3) ;
00382     cpgsch(size) ;
00383     
00384     // Epaisseur des traits:
00385     int lepais = 1 ; 
00386     cpgslw(lepais) ;
00387     
00388     cpgscf(2) ; // Fonte axes: caracteres romains
00389     
00390     float xmin1 = float(x_min / km) ;
00391     float xmax1 = float(x_max / km) ;
00392     float ymin1 = float(y_min / km) ;
00393     float ymax1 = float(y_max / km) ;
00394     
00395     cpgenv(xmin1, xmax1, ymin1, ymax1, 1, 0 ) ; 
00396 
00397     if (nomx == 0x0) nomx = "x [km]" ;
00398     if (nomy == 0x0) nomy = "y [km]" ; 
00399     if (title == 0x0) title = " " ; 
00400     cpglab(nomx,nomy,title) ;
00401 
00402     }
00403 
00404     if (coupe_surface) {
00405     cpgsls(1) ;     // lignes en trait plein
00406     cpgslw(6) ;     // traits gras
00407     cpgline(np, xg, yg) ;
00408     cpgslw(1) ;     // traits normaux
00409     }
00410     
00411     
00412     // Closing graphic display
00413     // -----------------------
00414 
00415     if ( (newgraph == 2) || (newgraph == 3) ) {    
00416     cpgend() ; 
00417     }
00418 
00419 }
00420 
00421 
00422 
00423 
00424 
00425 
00426 
00427 
00428 
00429 
00430 //*****************************************************************************
00431 
00432 double fonc_des_surf_scal_x(double vrho, const Param& par) {
00433     
00434     double x = par.get_double_mod(0) ; 
00435     double khi = par.get_double_mod(1) ; 
00436     const Scalar& defsurf = par.get_scalar() ; 
00437     const Map& mp = defsurf.get_mp() ; 
00438     
00439     // Absolute Cartesian coordinates: 
00440     double y = vrho * cos(khi) + mp.get_ori_y() ;     
00441     double z = vrho * sin(khi) + mp.get_ori_z() ;     
00442 
00443     // Spherical coordinates of the mapping:
00444     double r, theta, phi ; 
00445     mp.convert_absolute(x, y, z, r, theta, phi) ;
00446     
00447     return defsurf.val_point(r, theta, phi) ; 
00448     
00449 }
00450 
00451 //*****************************************************************************
00452 
00453 double fonc_des_surf_scal_y(double vrho, const Param& par) {
00454     
00455     double y = par.get_double_mod(0) ; 
00456     double khi = par.get_double_mod(1) ; 
00457     const Scalar& defsurf = par.get_scalar() ; 
00458     const Map& mp = defsurf.get_mp() ; 
00459     
00460     // Absolute Cartesian coordinates: 
00461     double x = vrho * cos(khi) + mp.get_ori_x() ; 
00462     double z = vrho * sin(khi) + mp.get_ori_z() ; 
00463 
00464     // Spherical coordinates of the mapping:
00465     double r, theta, phi ; 
00466     mp.convert_absolute(x, y, z, r, theta, phi) ;
00467     
00468     return defsurf.val_point(r, theta, phi) ; 
00469     
00470 }
00471 
00472 //*****************************************************************************
00473 
00474 double fonc_des_surf_scal_z(double vrho, const Param& par) {
00475     
00476     double z = par.get_double_mod(0) ; 
00477     double khi = par.get_double_mod(1) ; 
00478     const Scalar& defsurf = par.get_scalar() ; 
00479     const Map& mp = defsurf.get_mp() ; 
00480     
00481     // Absolute Cartesian coordinates: 
00482     double x = vrho * cos(khi) + mp.get_ori_x() ; 
00483     double y = vrho * sin(khi) + mp.get_ori_y() ; 
00484 
00485     // Spherical coordinates of the mapping:
00486     double r, theta, phi ; 
00487     mp.convert_absolute(x, y, z, r, theta, phi) ;
00488     
00489     return defsurf.val_point(r, theta, phi) ; 
00490     
00491 }

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