cmp_import_symy.C

00001 /*
00002  * Member function of the Cmp class for initiating a Cmp from a Cmp defined
00003  *  on another mapping.
00004  * Case where both Cmp's are symmetric with respect to their y=0 plane.
00005  */
00006 
00007 /*
00008  *   Copyright (c) 1999-2001 Eric Gourgoulhon
00009  *
00010  *   This file is part of LORENE.
00011  *
00012  *   LORENE is free software; you can redistribute it and/or modify
00013  *   it under the terms of the GNU General Public License as published by
00014  *   the Free Software Foundation; either version 2 of the License, or
00015  *   (at your option) any later version.
00016  *
00017  *   LORENE is distributed in the hope that it will be useful,
00018  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  *   GNU General Public License for more details.
00021  *
00022  *   You should have received a copy of the GNU General Public License
00023  *   along with LORENE; if not, write to the Free Software
00024  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  */
00027 
00028 
00029 char cmp_import_symy_C[] = "$Header: /cvsroot/Lorene/C++/Source/Cmp/cmp_import_symy.C,v 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon Exp $" ;
00030 
00031 
00032 /*
00033  * $Id: cmp_import_symy.C,v 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon Exp $
00034  * $Log: cmp_import_symy.C,v $
00035  * Revision 1.1.1.1  2001/11/20 15:19:27  e_gourgoulhon
00036  * LORENE
00037  *
00038  * Revision 2.0  2000/03/06  10:56:16  eric
00039  * *** empty log message ***
00040  *
00041  *
00042  * $Header: /cvsroot/Lorene/C++/Source/Cmp/cmp_import_symy.C,v 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon Exp $
00043  *
00044  */
00045 
00046 
00047 
00048 // Headers C
00049 #include <math.h>
00050 
00051 // Headers Lorene
00052 #include "cmp.h"
00053 #include "param.h"
00054 #include "nbr_spx.h"
00055 
00056             //-------------------------------//
00057             //  Importation in all domains   //
00058             //-------------------------------//
00059 
00060 void Cmp::import_symy(const Cmp& ci) {
00061     
00062     int nz = mp->get_mg()->get_nzone() ; 
00063     
00064     import_symy(nz, ci) ; 
00065         
00066 }
00067 
00068             //--------------------------------------//
00069             //  Importation in inner domains only   //
00070             //--------------------------------------//
00071 
00072 void Cmp::import_symy(int nzet, const Cmp& cm_d) {
00073     
00074     const Map* mp_d = cm_d.mp ; // Departure mapping
00075 
00076     // Trivial case : mappings identical !
00077     // -----------------------------------
00078     
00079     if (mp_d == mp) {
00080     *this = cm_d ; 
00081     return ; 
00082     }
00083     
00084     // Relative orientation of the two mappings
00085     // ----------------------------------------
00086  
00087     int align_rel = (mp->get_bvect_cart()).get_align()  
00088             * (mp_d->get_bvect_cart()).get_align() ;
00089             
00090     switch (align_rel) {
00091 
00092     case 1 : {  // the two mappings have aligned Cartesian axis
00093         import_align_symy(nzet, cm_d) ; 
00094         break ; 
00095     }
00096 
00097     case -1 : {  // the two mappings have anti-aligned Cartesian axis
00098         import_anti_symy(nzet, cm_d) ; 
00099         break ; 
00100     }
00101 
00102     default : {  
00103         cout << "Cmp::import_symy : unexpected value of align_rel : " 
00104          << align_rel << endl ; 
00105         abort() ; 
00106         break ; 
00107     }
00108 
00109     }
00110     
00111 }    
00112 
00113 
00114         //-----------------------------------------//
00115         //   Case of Cartesian axis anti-aligned   //
00116         //-----------------------------------------//
00117 
00118 
00119 void Cmp::import_anti_symy(int nzet, const Cmp& cm_d) {
00120     
00121     // Trivial case : null Cmp
00122     // ------------------------
00123     
00124     if (cm_d.etat == ETATZERO) {
00125     set_etat_zero() ; 
00126     return ; 
00127     }
00128 
00129     const Map* mp_d = cm_d.mp ; // Departure mapping
00130 
00131     // Protections
00132     // -----------
00133     int align = (mp->get_bvect_cart()).get_align() ;
00134 
00135     assert( align  * (mp_d->get_bvect_cart()).get_align() == -1 ) ; 
00136     
00137     assert(cm_d.etat == ETATQCQ) ;
00138 
00139     if (cm_d.dzpuis != 0) {
00140     cout << 
00141     "Cmp::import_anti_symy : the dzpuis of the Cmp to be imported"
00142     << "  must be zero !" << endl ; 
00143     abort() ; 
00144     }
00145 
00146 
00147     const Mg3d* mg_a = mp->get_mg() ; 
00148     assert(mg_a->get_type_p() == NONSYM) ; 
00149 
00150     int nz_a = mg_a->get_nzone() ; 
00151     assert(nzet <= nz_a) ;     
00152 
00153     const Valeur& va_d = cm_d.va ; 
00154     va_d.coef() ;       // The coefficients are required
00155     
00156 
00157     // Preparations for storing the result in *this 
00158     // --------------------------------------------
00159     del_t() ;   // delete all previously computed derived quantities
00160     
00161     set_etat_qcq() ;        // Set the state to ETATQCQ
00162     
00163     va.set_etat_c_qcq() ;   // Allocates the memory for the Mtbl va.c
00164                 //  if it does not exist already
00165     va.c->set_etat_qcq() ;  // Allocates the memory for the Tbl's in each
00166                 //  domain if they do not exist already
00167 
00168 
00169     // Departure (x,y,z) coordinates of the origin of the Arrival mapping :
00170 
00171     double xx_a, yy_a, zz_a ; 
00172     if (align == 1) {
00173     xx_a = mp_d->get_ori_x() - mp->get_ori_x() ; 
00174     yy_a = mp_d->get_ori_y() - mp->get_ori_y() ; 
00175     }
00176     else {
00177     xx_a = mp->get_ori_x() - mp_d->get_ori_x() ; 
00178     yy_a = mp->get_ori_y() - mp_d->get_ori_y() ; 
00179     }
00180     zz_a = mp->get_ori_z() - mp_d->get_ori_z() ; 
00181 
00182     
00183     // r, theta, phi, x, y and z on the Arrival mapping 
00184     //  update of the corresponding Coord's if necessary
00185     
00186     if ( (mp->r).c == 0x0 ) (mp->r).fait() ; 
00187     if ( (mp->tet).c == 0x0 ) (mp->tet).fait() ; 
00188     if ( (mp->phi).c == 0x0 ) (mp->phi).fait() ; 
00189     if ( (mp->x).c == 0x0 ) (mp->x).fait() ; 
00190     if ( (mp->y).c == 0x0 ) (mp->y).fait() ; 
00191     if ( (mp->z).c == 0x0 ) (mp->z).fait() ; 
00192 
00193     const Mtbl* mr_a = (mp->r).c ; 
00194     const Mtbl* mtet_a = (mp->tet).c ; 
00195     const Mtbl* mphi_a = (mp->phi).c ; 
00196     const Mtbl* mx_a = (mp->x).c ;
00197     const Mtbl* my_a = (mp->y).c ;
00198     const Mtbl* mz_a = (mp->z).c ;
00199 
00200     Param par_precis ;      // Required precision in the method Map::val_lx
00201     int nitermax = 100 ;    // Maximum number of iteration in the secant method
00202     int niter ; 
00203     double precis = 1e-15 ; // Absolute precision in the secant method
00204     par_precis.add_int(nitermax) ;  
00205     par_precis.add_int_mod(niter) ; 
00206     par_precis.add_double(precis) ; 
00207 
00208 
00209     // Loop of the Arrival domains where the computation is to be performed
00210     // --------------------------------------------------------------------
00211     
00212     for (int l=0; l < nzet; l++) {
00213     
00214     int nr = mg_a->get_nr(l) ;
00215     int nt = mg_a->get_nt(l) ;
00216     int np = mg_a->get_np(l) ;
00217     
00218     
00219     const double* pr_a = mr_a->t[l]->t ;      // Pointer on the values of r
00220     const double* ptet_a = mtet_a->t[l]->t ;  // Pointer on the values of theta
00221     const double* pphi_a = mphi_a->t[l]->t ;  // Pointer on the values of phi
00222     const double* px_a = mx_a->t[l]->t ;      // Pointer on the values of X
00223     const double* py_a = my_a->t[l]->t ;      // Pointer on the values of Y
00224     const double* pz_a = mz_a->t[l]->t ;      // Pointer on the values of Z
00225     
00226     (va.c->t[l])->set_etat_qcq() ;       // Allocates the array of double to
00227                          //  store the result 
00228     double* ptx = (va.c->t[l])->t ;      // Pointer on the allocated array
00229     
00230     
00231     // Loop on half the grid points in the considered arrival domain
00232     // (the other half will be obtained by symmetry with respect to
00233     //  the y=0 plane). 
00234         
00235     for (int k=0 ; k<np/2+1 ; k++) {    // np/2+1 : half the grid
00236         for (int j=0 ; j<nt ; j++) {
00237         for (int i=0 ; i<nr ; i++) {
00238 
00239             double r = *pr_a ; 
00240             double rd, tetd, phid ;
00241             if (r == __infinity) {
00242             rd = r ;
00243             tetd = *ptet_a ;
00244             phid = *pphi_a + M_PI ;
00245             if (phid < 0) phid += 2*M_PI ;
00246             }
00247             else {
00248 
00249             // Cartesian coordinates on the Departure mapping
00250             double xd = - *px_a + xx_a ; 
00251             double yd = - *py_a + yy_a ; 
00252             double zd = *pz_a + zz_a ; 
00253 
00254             // Spherical coordinates on the Departure mapping
00255             double rhod2 = xd*xd + yd*yd ; 
00256             double rhod = sqrt( rhod2 ) ;
00257             rd = sqrt(rhod2 + zd*zd) ;
00258             tetd = atan2(rhod, zd) ;
00259             phid = atan2(yd, xd) ; 
00260             if (phid < 0) phid += 2*M_PI ;
00261             }           
00262 
00263 
00264             // NB: to increase the efficiency, the method Cmp::val_point
00265             //  is not invoked; the method Mtbl_cf::val_point is 
00266             //  called directly instead. 
00267 
00268             // Value of the grid coordinates (l,xi) corresponding to
00269             //  (rd,tetd,phid) :
00270             
00271             int ld ;        // domain index
00272             double xxd ;    // radial coordinate xi in [0,1] or [-1,1]
00273             mp_d->val_lx(rd, tetd, phid, par_precis, ld, xxd) ;
00274 
00275             // Value of the Departure Cmp at the obtained point:
00276             *ptx = va_d.c_cf->val_point_symy(ld, xxd, tetd, phid) ;
00277 
00278             // Next point : 
00279             ptx++ ;   
00280             pr_a++ ;  
00281             ptet_a++ ;  
00282             pphi_a++ ; 
00283             px_a++ ;  
00284             py_a++ ;  
00285             pz_a++ ;  
00286 
00287         }
00288         }
00289     }
00290     
00291     // The remaining points are obtained by symmetry with rspect to the
00292     //  y=0 plane
00293         
00294     for (int k=np/2+1 ; k<np ; k++) {
00295 
00296         // pointer on the value (already computed) at the point symmetric 
00297         // with respect to the plane y=0
00298         double* ptx_symy = (va.c->t[l])->t + (np-k)*nt*nr ;  
00299 
00300         // copy : 
00301         for (int j=0 ; j<nt ; j++) {
00302         for (int i=0 ; i<nr ; i++) {
00303             *ptx = *ptx_symy ; 
00304             ptx++ ;
00305             ptx_symy++ ; 
00306         }
00307         }
00308     }
00309     
00310         
00311     }   // End of the loop on the Arrival domains
00312     
00313     // In the remaining domains, *this is set to zero:
00314     // ----------------------------------------------
00315     
00316     if (nzet < nz_a) {
00317     annule(nzet, nz_a - 1) ; 
00318     }
00319     
00320     // Treatment of dzpuis
00321     // -------------------
00322     
00323     set_dzpuis(0) ; 
00324 
00325 }
00326 
00327 
00328         //-------------------------------------//
00329         //   Case of aligned Cartesian axis    //
00330         //-------------------------------------//
00331 
00332 
00333 void Cmp::import_align_symy(int nzet, const Cmp& cm_d) {
00334     
00335     // Trivial case : null Cmp
00336     // ------------------------
00337     
00338     if (cm_d.etat == ETATZERO) {
00339     set_etat_zero() ; 
00340     return ; 
00341     }
00342 
00343     const Map* mp_d = cm_d.mp ; // Departure mapping
00344 
00345     // Protections
00346     // -----------
00347     int align = (mp->get_bvect_cart()).get_align() ;
00348 
00349     assert( align  * (mp_d->get_bvect_cart()).get_align() == 1 ) ; 
00350     
00351     assert(cm_d.etat == ETATQCQ) ;
00352 
00353     if (cm_d.dzpuis != 0) {
00354     cout << 
00355     "Cmp::import_align_symy : the dzpuis of the Cmp to be imported"
00356     << " must be zero !" << endl ; 
00357     abort() ; 
00358     }
00359 
00360 
00361     const Mg3d* mg_a = mp->get_mg() ; 
00362     assert(mg_a->get_type_p() == NONSYM) ; 
00363 
00364     int nz_a = mg_a->get_nzone() ; 
00365     assert(nzet <= nz_a) ;     
00366 
00367     const Valeur& va_d = cm_d.va ; 
00368     va_d.coef() ;       // The coefficients are required
00369     
00370 
00371     // Preparations for storing the result in *this 
00372     // --------------------------------------------
00373     del_t() ;   // delete all previously computed derived quantities
00374     
00375     set_etat_qcq() ;        // Set the state to ETATQCQ
00376     
00377     va.set_etat_c_qcq() ;   // Allocates the memory for the Mtbl va.c
00378                 //  if it does not exist already
00379     va.c->set_etat_qcq() ;  // Allocates the memory for the Tbl's in each
00380                 //  domain if they do not exist already
00381 
00382 
00383     // Departure (x,y,z) coordinates of the origin of the Arrival mapping :
00384 
00385     double xx_a, yy_a, zz_a ; 
00386     if (align == 1) {
00387     xx_a = mp->get_ori_x() - mp_d->get_ori_x() ; 
00388     yy_a = mp->get_ori_y() - mp_d->get_ori_y() ; 
00389     }
00390     else {
00391     xx_a = mp_d->get_ori_x() - mp->get_ori_x() ; 
00392     yy_a = mp_d->get_ori_y() - mp->get_ori_y() ; 
00393     }
00394     zz_a = mp->get_ori_z() - mp_d->get_ori_z() ; 
00395 
00396     
00397     // r, theta, phi, x, y and z on the Arrival mapping 
00398     //  update of the corresponding Coord's if necessary
00399     
00400     if ( (mp->r).c == 0x0 ) (mp->r).fait() ; 
00401     if ( (mp->tet).c == 0x0 ) (mp->tet).fait() ; 
00402     if ( (mp->phi).c == 0x0 ) (mp->phi).fait() ; 
00403     if ( (mp->x).c == 0x0 ) (mp->x).fait() ; 
00404     if ( (mp->y).c == 0x0 ) (mp->y).fait() ; 
00405     if ( (mp->z).c == 0x0 ) (mp->z).fait() ; 
00406 
00407     const Mtbl* mr_a = (mp->r).c ; 
00408     const Mtbl* mtet_a = (mp->tet).c ; 
00409     const Mtbl* mphi_a = (mp->phi).c ; 
00410     const Mtbl* mx_a = (mp->x).c ;
00411     const Mtbl* my_a = (mp->y).c ;
00412     const Mtbl* mz_a = (mp->z).c ;
00413 
00414     Param par_precis ;      // Required precision in the method Map::val_lx
00415     int nitermax = 100 ;    // Maximum number of iteration in the secant method
00416     int niter ; 
00417     double precis = 1e-15 ; // Absolute precision in the secant method
00418     par_precis.add_int(nitermax) ;  
00419     par_precis.add_int_mod(niter) ; 
00420     par_precis.add_double(precis) ; 
00421 
00422 
00423     // Loop of the Arrival domains where the computation is to be performed
00424     // --------------------------------------------------------------------
00425     
00426     for (int l=0; l < nzet; l++) {
00427     
00428     int nr = mg_a->get_nr(l) ;
00429     int nt = mg_a->get_nt(l) ;
00430     int np = mg_a->get_np(l) ;
00431     
00432     
00433     const double* pr_a = mr_a->t[l]->t ;      // Pointer on the values of r
00434     const double* ptet_a = mtet_a->t[l]->t ;  // Pointer on the values of theta
00435     const double* pphi_a = mphi_a->t[l]->t ;  // Pointer on the values of phi
00436     const double* px_a = mx_a->t[l]->t ;      // Pointer on the values of X
00437     const double* py_a = my_a->t[l]->t ;      // Pointer on the values of Y
00438     const double* pz_a = mz_a->t[l]->t ;      // Pointer on the values of Z
00439     
00440     (va.c->t[l])->set_etat_qcq() ;       // Allocates the array of double to
00441                          //  store the result 
00442     double* ptx = (va.c->t[l])->t ;      // Pointer on the allocated array
00443     
00444     
00445     
00446     // Loop on half the grid points in the considered arrival domain
00447     // (the other half will be obtained by symmetry with respect to
00448     //  the y=0 plane). 
00449         
00450     for (int k=0 ; k<np/2+1 ; k++) {    // np/2+1 : half the grid
00451         for (int j=0 ; j<nt ; j++) {
00452         for (int i=0 ; i<nr ; i++) {
00453 
00454             double r = *pr_a ; 
00455             double rd, tetd, phid ;
00456             if (r == __infinity) {
00457             rd = r ;
00458             tetd = *ptet_a ;
00459             phid = *pphi_a ;
00460             }
00461             else {
00462 
00463             // Cartesian coordinates on the Departure mapping
00464             double xd = *px_a + xx_a ; 
00465             double yd = *py_a + yy_a ; 
00466             double zd = *pz_a + zz_a ; 
00467 
00468             // Spherical coordinates on the Departure mapping
00469             double rhod2 = xd*xd + yd*yd ; 
00470             double rhod = sqrt( rhod2 ) ;
00471             rd = sqrt(rhod2 + zd*zd) ;
00472             tetd = atan2(rhod, zd) ;
00473             phid = atan2(yd, xd) ; 
00474             if (phid < 0) phid += 2*M_PI ;
00475             }           
00476 
00477 
00478             // NB: to increase the efficiency, the method Cmp::val_point
00479             //  is not invoked; the method Mtbl_cf::val_point is 
00480             //  called directly instead. 
00481 
00482             // Value of the grid coordinates (l,xi) corresponding to
00483             //  (rd,tetd,phid) :
00484             
00485             int ld ;        // domain index
00486             double xxd ;    // radial coordinate xi in [0,1] or [-1,1]
00487             mp_d->val_lx(rd, tetd, phid, par_precis, ld, xxd) ;
00488 
00489             // Value of the Departure Cmp at the obtained point:
00490             *ptx = va_d.c_cf->val_point_symy(ld, xxd, tetd, phid) ;
00491 
00492             // Next point : 
00493             ptx++ ;   
00494             pr_a++ ;  
00495             ptet_a++ ;  
00496             pphi_a++ ; 
00497             px_a++ ;  
00498             py_a++ ;  
00499             pz_a++ ;  
00500 
00501         }
00502         }
00503     }   
00504     
00505         
00506     // The remaining points are obtained by symmetry with rspect to the
00507     //  y=0 plane
00508         
00509     for (int k=np/2+1 ; k<np ; k++) {
00510 
00511         // pointer on the value (already computed) at the point symmetric 
00512         // with respect to the plane y=0
00513         double* ptx_symy = (va.c->t[l])->t + (np-k)*nt*nr ;  
00514 
00515         // copy : 
00516         for (int j=0 ; j<nt ; j++) {
00517         for (int i=0 ; i<nr ; i++) {
00518             *ptx = *ptx_symy ; 
00519             ptx++ ;
00520             ptx_symy++ ; 
00521         }
00522         }
00523     } 
00524 
00525     }   // End of the loop on the Arrival domains
00526     
00527     // In the remaining domains, *this is set to zero:
00528     // ----------------------------------------------
00529     
00530     if (nzet < nz_a) {
00531     annule(nzet, nz_a - 1) ; 
00532     }
00533     
00534     // Treatment of dzpuis
00535     // -------------------
00536     
00537     set_dzpuis(0) ; 
00538 
00539 }

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