des_surface.C

00001 /*
00002  *  Basic routine for drawing the surface of a star
00003  */
00004 
00005 /*
00006  *   Copyright (c) 1999-2001 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_surface_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Graphics/des_surface.C,v 1.3 2008/08/19 06:42:00 j_novak Exp $" ;
00028 
00029 /*
00030  * $Id: des_surface.C,v 1.3 2008/08/19 06:42:00 j_novak Exp $
00031  * $Log: des_surface.C,v $
00032  * Revision 1.3  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.2  2004/03/25 10:29:25  j_novak
00037  * All LORENE's units are now defined in the namespace Unites (in file unites.h).
00038  *
00039  * Revision 1.1.1.1  2001/11/20 15:19:29  e_gourgoulhon
00040  * LORENE
00041  *
00042  * Revision 1.3  2000/03/21  11:14:45  eric
00043  * Le parametre precis est mis a 1e-8.
00044  *
00045  * Revision 1.2  2000/02/11  16:54:00  eric
00046  * Utilisation des coordonnees cartesiennes abolues (X,Y,Z) et non plus
00047  * des coordonnees relatives (x,y,z).
00048  *
00049  * Revision 1.1  1999/12/24  13:01:21  eric
00050  * Initial revision
00051  *
00052  *
00053  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Graphics/des_surface.C,v 1.3 2008/08/19 06:42:00 j_novak Exp $
00054  *
00055  */
00056 
00057 // C headers:
00058 #include <math.h>
00059 
00060 // PGPLOT headers:
00061 #include <cpgplot.h>
00062 
00063 // Lorene headers
00064 #include "cmp.h"
00065 #include "param.h"
00066 #include "utilitaires.h"
00067 #include "unites.h"
00068 
00069 // Local prototypes
00070 double fonc_des_surface_x(double, const Param&) ; 
00071 double fonc_des_surface_y(double, const Param&) ; 
00072 double fonc_des_surface_z(double, const Param&) ; 
00073 
00074 //******************************************************************************
00075  
00076 void des_surface_x(const Cmp& defsurf, double x0, const char* device, int newgraph, 
00077            double y_min, double y_max, double z_min, double z_max, 
00078            const char* nomy, const char* nomz, const char* title, int nxpage, int nypage)
00079 {
00080   using namespace Unites ;
00081 
00082     assert(defsurf.get_etat() == ETATQCQ) ; 
00083 
00084 
00085     const Map* mp =  defsurf.get_mp();  
00086     
00087     double khi ;
00088     
00089     Param parzerosec ;
00090     parzerosec.add_double_mod(x0, 0) ;  
00091     parzerosec.add_double_mod(khi, 1) ;     
00092     parzerosec.add_cmp(defsurf) ;
00093 
00094     double rhomin = 0 ; 
00095     double rhomax = 2 * 
00096             mp->val_r(mp->get_mg()->get_nzone() - 1, -1., 0., 0.) ;  
00097     double precis = 1.e-8 ; 
00098     int nitermax = 100 ; 
00099     int niter ; 
00100     
00101     const int np = 101 ; 
00102     float yg[np] ; 
00103     float zg[np] ; 
00104 
00105     double hkhi = 2 * M_PI / (np-1) ; 
00106     
00107     bool coupe_surface = true ; 
00108     
00109     for (int i=0; i< np; i++) {
00110 
00111     khi = hkhi * i ; 
00112     
00113     // Search for the interval [rhomin0, rhomax0] which contains 
00114     //  the first zero of des_surf:
00115     
00116     double rhomin0 ;
00117     double rhomax0 ;
00118 
00119     if ( zero_premier(fonc_des_surface_x, parzerosec, rhomin, rhomax, 100, 
00120              rhomin0, rhomax0) == false ) {
00121         cout << 
00122    "des_surface_x : WARNING : no interval containing a zero of defsurf"
00123         << endl ; 
00124         cout << "  has been found for khi = " << khi << " !" << endl ; 
00125 
00126         coupe_surface = false ; 
00127         break ; 
00128 
00129     }
00130         
00131              
00132     // Search for the zero in the interval [rhomin0, rhomax0] :
00133     
00134     double rho = zerosec(fonc_des_surface_x, parzerosec, rhomin0, rhomax0, 
00135                  precis, nitermax, niter) ;
00136                    
00137     yg[i] = float(( rho * cos(khi) + mp->get_ori_y() ) / km) ;
00138     zg[i] = float(( rho * sin(khi) + mp->get_ori_z() ) / km) ;
00139     }
00140     
00141     // Graphics display
00142     // ----------------
00143 
00144     if ( (newgraph == 1) || (newgraph == 3) ) {
00145 
00146     if (device == 0x0) device = "?" ; 
00147    
00148     int ier = cpgbeg(0, device, nxpage, nypage) ;
00149     if (ier != 1) {
00150     cout << "des_surface_x: problem in opening PGPLOT display !" << endl ;
00151     } 
00152     
00153     // Taille des caracteres:
00154     float size = float(1.3) ;
00155     cpgsch(size) ;
00156     
00157     // Epaisseur des traits:
00158     int lepais = 1 ; 
00159     cpgslw(lepais) ;
00160     
00161     cpgscf(2) ; // Fonte axes: caracteres romains
00162     
00163     float ymin1 = float(y_min / km) ;
00164     float ymax1 = float(y_max / km) ;
00165     float zmin1 = float(z_min / km) ;
00166     float zmax1 = float(z_max / km) ;
00167     
00168     cpgenv(ymin1, ymax1, zmin1, zmax1, 1, 0 ) ; 
00169 
00170     if (nomy == 0x0) nomy = "y [km]" ;
00171     if (nomz == 0x0) nomz = "z [km]" ; 
00172     if (title == 0x0) title = " " ; 
00173     cpglab(nomy,nomz,title) ;
00174 
00175     }
00176 
00177     if (coupe_surface) {
00178     cpgsls(1) ;     // lignes en trait plein
00179     cpgslw(6) ;     // traits gras
00180     cpgline(np, yg, zg) ;
00181     cpgslw(1) ;     // traits normaux
00182     }
00183     
00184     
00185     // Closing graphic display
00186     // -----------------------
00187 
00188     if ( (newgraph == 2) || (newgraph == 3) ) {    
00189     cpgend() ; 
00190     }
00191 
00192 }
00193 
00194 //******************************************************************************
00195  
00196 void des_surface_y(const Cmp& defsurf, double y0, const char* device, int newgraph, 
00197            double x_min, double x_max, double z_min, double z_max, 
00198            const char* nomx, const char* nomz, const char* title, int nxpage, int nypage)
00199 {
00200   using namespace Unites ;
00201 
00202     assert(defsurf.get_etat() == ETATQCQ) ; 
00203 
00204 
00205     const Map* mp =  defsurf.get_mp();  
00206     
00207     double khi ;
00208     
00209     Param parzerosec ;
00210     parzerosec.add_double_mod(y0, 0) ;  
00211     parzerosec.add_double_mod(khi, 1) ;     
00212     parzerosec.add_cmp(defsurf) ;
00213 
00214     double rhomin = 0 ; 
00215     double rhomax = 2 * 
00216             mp->val_r(mp->get_mg()->get_nzone() - 1, -1., 0., 0.) ;  
00217     double precis = 1.e-8 ; 
00218     int nitermax = 100 ; 
00219     int niter ; 
00220     
00221     const int np = 101 ; 
00222     float xg[np] ; 
00223     float zg[np] ; 
00224 
00225     double hkhi = 2 * M_PI / (np-1) ; 
00226     
00227     bool coupe_surface = true ; 
00228     
00229     for (int i=0; i< np; i++) {
00230 
00231     khi = hkhi * i ; 
00232     
00233     // Search for the interval [rhomin0, rhomax0] which contains 
00234     //  the first zero of des_surf:
00235     
00236     double rhomin0 ;
00237     double rhomax0 ;
00238 
00239     if ( zero_premier(fonc_des_surface_y, parzerosec, rhomin, rhomax, 100, 
00240              rhomin0, rhomax0) == false ) {
00241         cout << 
00242    "des_surface_y : WARNING : no interval containing a zero of defsurf"
00243         << endl ; 
00244         cout << "  has been found for khi = " << khi << " !" << endl ; 
00245 
00246         coupe_surface = false ; 
00247         break ; 
00248 
00249     }
00250         
00251              
00252     // Search for the zero in the interval [rhomin0, rhomax0] :
00253     
00254     double rho = zerosec(fonc_des_surface_y, parzerosec, rhomin0, rhomax0, 
00255                  precis, nitermax, niter) ;
00256                    
00257     xg[i] = float(( rho * cos(khi) + mp->get_ori_x() ) / km) ;
00258     zg[i] = float(( rho * sin(khi) + mp->get_ori_z() ) / km) ;
00259     }
00260     
00261     // Graphics display
00262     // ----------------
00263 
00264     if ( (newgraph == 1) || (newgraph == 3) ) {
00265 
00266     if (device == 0x0) device = "?" ; 
00267    
00268     int ier = cpgbeg(0, device, nxpage, nypage) ;
00269     if (ier != 1) {
00270     cout << "des_surface_y: problem in opening PGPLOT display !" << endl ;
00271     } 
00272     
00273     // Taille des caracteres:
00274     float size = float(1.3) ;
00275     cpgsch(size) ;
00276     
00277     // Epaisseur des traits:
00278     int lepais = 1 ; 
00279     cpgslw(lepais) ;
00280     
00281     cpgscf(2) ; // Fonte axes: caracteres romains
00282     
00283     float xmin1 = float(x_min / km) ;
00284     float xmax1 = float(x_max / km) ;
00285     float zmin1 = float(z_min / km) ;
00286     float zmax1 = float(z_max / km) ;
00287     
00288     cpgenv(xmin1, xmax1, zmin1, zmax1, 1, 0 ) ; 
00289 
00290     if (nomx == 0x0) nomx = "x [km]" ;
00291     if (nomz == 0x0) nomz = "z [km]" ; 
00292     if (title == 0x0) title = " " ; 
00293     cpglab(nomx,nomz,title) ;
00294 
00295     }
00296 
00297     if (coupe_surface) {
00298     cpgsls(1) ;     // lignes en trait plein
00299     cpgslw(6) ;     // traits gras
00300     cpgline(np, xg, zg) ;
00301     cpgslw(1) ;     // traits normaux
00302     }
00303     
00304     
00305     // Closing graphic display
00306     // -----------------------
00307 
00308     if ( (newgraph == 2) || (newgraph == 3) ) {    
00309     cpgend() ; 
00310     }
00311 
00312 }
00313 
00314 //******************************************************************************
00315  
00316 void des_surface_z(const Cmp& defsurf, double z0, const char* device, int newgraph, 
00317            double x_min, double x_max, double y_min, double y_max, 
00318            const char* nomx, const char* nomy, const char* title, int nxpage, int nypage)
00319 {
00320   using namespace Unites ;
00321 
00322     assert(defsurf.get_etat() == ETATQCQ) ; 
00323 
00324 
00325     const Map* mp =  defsurf.get_mp();  
00326     
00327     double khi ;
00328     
00329     Param parzerosec ;
00330     parzerosec.add_double_mod(z0, 0) ;  
00331     parzerosec.add_double_mod(khi, 1) ;     
00332     parzerosec.add_cmp(defsurf) ;
00333 
00334     double rhomin = 0 ; 
00335     double rhomax = 2 * 
00336             mp->val_r(mp->get_mg()->get_nzone() - 1, -1., 0., 0.) ;  
00337     double precis = 1.e-8 ; 
00338     int nitermax = 100 ; 
00339     int niter ; 
00340     
00341     const int np = 101 ; 
00342     float xg[np] ; 
00343     float yg[np] ; 
00344 
00345     double hkhi = 2 * M_PI / (np-1) ; 
00346     
00347     bool coupe_surface = true ; 
00348     
00349     for (int i=0; i< np; i++) {
00350 
00351     khi = hkhi * i ; 
00352     
00353     // Search for the interval [rhomin0, rhomax0] which contains 
00354     //  the first zero of des_surf:
00355     
00356     double rhomin0 ;
00357     double rhomax0 ;
00358 
00359     if ( zero_premier(fonc_des_surface_z, parzerosec, rhomin, rhomax, 100, 
00360              rhomin0, rhomax0) == false ) {
00361         cout << 
00362    "des_surface_z : WARNING : no interval containing a zero of defsurf"
00363         << endl ; 
00364         cout << "  has been found for khi = " << khi << " !" << endl ; 
00365 
00366         coupe_surface = false ; 
00367         break ; 
00368 
00369     }
00370         
00371              
00372     // Search for the zero in the interval [rhomin0, rhomax0] :
00373     
00374     double rho = zerosec(fonc_des_surface_z, parzerosec, rhomin0, rhomax0, 
00375                  precis, nitermax, niter) ;
00376                    
00377     xg[i] = float(( rho * cos(khi) + mp->get_ori_x() ) / km) ;
00378     yg[i] = float(( rho * sin(khi) + mp->get_ori_y() ) / km) ;
00379     }
00380     
00381     // Graphics display
00382     // ----------------
00383 
00384     if ( (newgraph == 1) || (newgraph == 3) ) {
00385 
00386     if (device == 0x0) device = "?" ; 
00387    
00388     int ier = cpgbeg(0, device, nxpage, nypage) ;
00389     if (ier != 1) {
00390     cout << "des_surface_z: problem in opening PGPLOT display !" << endl ;
00391     } 
00392     
00393     // Taille des caracteres:
00394     float size = float(1.3) ;
00395     cpgsch(size) ;
00396     
00397     // Epaisseur des traits:
00398     int lepais = 1 ; 
00399     cpgslw(lepais) ;
00400     
00401     cpgscf(2) ; // Fonte axes: caracteres romains
00402     
00403     float xmin1 = float(x_min / km) ;
00404     float xmax1 = float(x_max / km) ;
00405     float ymin1 = float(y_min / km) ;
00406     float ymax1 = float(y_max / km) ;
00407     
00408     cpgenv(xmin1, xmax1, ymin1, ymax1, 1, 0 ) ; 
00409 
00410     if (nomx == 0x0) nomx = "x [km]" ;
00411     if (nomy == 0x0) nomy = "y [km]" ; 
00412     if (title == 0x0) title = " " ; 
00413     cpglab(nomx,nomy,title) ;
00414 
00415     }
00416 
00417     if (coupe_surface) {
00418     cpgsls(1) ;     // lignes en trait plein
00419     cpgslw(6) ;     // traits gras
00420     cpgline(np, xg, yg) ;
00421     cpgslw(1) ;     // traits normaux
00422     }
00423     
00424     
00425     // Closing graphic display
00426     // -----------------------
00427 
00428     if ( (newgraph == 2) || (newgraph == 3) ) {    
00429     cpgend() ; 
00430     }
00431 
00432 }
00433 
00434 
00435 
00436 
00437 
00438 
00439 
00440 
00441 
00442 
00443 //*****************************************************************************
00444 
00445 double fonc_des_surface_x(double vrho, const Param& par) {
00446     
00447     double x = par.get_double_mod(0) ; 
00448     double khi = par.get_double_mod(1) ; 
00449     const Cmp& defsurf = par.get_cmp() ; 
00450     const Map& mp = *(defsurf.get_mp()) ; 
00451     
00452     // Absolute Cartesian coordinates: 
00453     double y = vrho * cos(khi) + mp.get_ori_y() ;     
00454     double z = vrho * sin(khi) + mp.get_ori_z() ;     
00455 
00456     // Spherical coordinates of the mapping:
00457     double r, theta, phi ; 
00458     mp.convert_absolute(x, y, z, r, theta, phi) ;
00459     
00460     return defsurf.val_point(r, theta, phi) ; 
00461     
00462 }
00463 
00464 //*****************************************************************************
00465 
00466 double fonc_des_surface_y(double vrho, const Param& par) {
00467     
00468     double y = par.get_double_mod(0) ; 
00469     double khi = par.get_double_mod(1) ; 
00470     const Cmp& defsurf = par.get_cmp() ; 
00471     const Map& mp = *(defsurf.get_mp()) ; 
00472     
00473     // Absolute Cartesian coordinates: 
00474     double x = vrho * cos(khi) + mp.get_ori_x() ; 
00475     double z = vrho * sin(khi) + mp.get_ori_z() ; 
00476 
00477     // Spherical coordinates of the mapping:
00478     double r, theta, phi ; 
00479     mp.convert_absolute(x, y, z, r, theta, phi) ;
00480     
00481     return defsurf.val_point(r, theta, phi) ; 
00482     
00483 }
00484 
00485 //*****************************************************************************
00486 
00487 double fonc_des_surface_z(double vrho, const Param& par) {
00488     
00489     double z = par.get_double_mod(0) ; 
00490     double khi = par.get_double_mod(1) ; 
00491     const Cmp& defsurf = par.get_cmp() ; 
00492     const Map& mp = *(defsurf.get_mp()) ; 
00493     
00494     // Absolute Cartesian coordinates: 
00495     double x = vrho * cos(khi) + mp.get_ori_x() ; 
00496     double y = vrho * sin(khi) + mp.get_ori_y() ; 
00497 
00498     // Spherical coordinates of the mapping:
00499     double r, theta, phi ; 
00500     mp.convert_absolute(x, y, z, r, theta, phi) ;
00501     
00502     return defsurf.val_point(r, theta, phi) ; 
00503     
00504 }

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