map_log.C

00001 /*
00002  *  Methods of class Map_log
00003  *
00004  *   (see file map.h for documentation)
00005  *
00006  */
00007 
00008 /*
00009  *   Copyright (c) 2004 Philippe Grandclement
00010  *
00011  *   This file is part of LORENE.
00012  *
00013  *   LORENE is free software; you can redistribute it and/or modify
00014  *   it under the terms of the GNU General Public License as published by
00015  *   the Free Software Foundation; either version 2 of the License, or
00016  *   (at your option) any later version.
00017  *
00018  *   LORENE is distributed in the hope that it will be useful,
00019  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  *   GNU General Public License for more details.
00022  *
00023  *   You should have received a copy of the GNU General Public License
00024  *   along with LORENE; if not, write to the Free Software
00025  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  *
00027  */
00028 
00029 
00030 char map_log_C[] = "$Header $" ;
00031 
00032 /*
00033  * $Id: map_log.C,v 1.1 2004/06/22 08:49:58 p_grandclement Exp $
00034  * $Log: map_log.C,v $
00035  * Revision 1.1  2004/06/22 08:49:58  p_grandclement
00036  * Addition of everything needed for using the logarithmic mapping
00037  *
00038  * 
00039  * $Header: /cvsroot/Lorene/C++/Source/Map/map_log.C,v 1.1 2004/06/22 08:49:58 p_grandclement Exp $
00040  *
00041  */
00042 
00043 // headers C
00044 #include <math.h>
00045 
00046 // headers Lorene
00047 #include "itbl.h"
00048 #include "tbl.h"
00049 #include "coord.h"
00050 #include "grilles.h"
00051 #include "map.h"
00052 
00053             
00054             //---------------//
00055             // Constructeurs //
00056             //---------------//
00057 
00058 // Constructor from a grid
00059 // -----------------------
00060 Map_log::Map_log (const Mg3d& mgrille, const Tbl& bornes, const Itbl& typevar) : 
00061   Map_radial(mgrille), alpha (mgrille.get_nzone()), beta (mgrille.get_nzone()), 
00062   type_var(typevar)
00063                                         
00064 {
00065     // Les bornes
00066     int nzone = mg->get_nzone() ;
00067     
00068     alpha.set_etat_qcq() ;
00069     beta.set_etat_qcq() ;
00070 
00071     for (int l=0 ; l<nzone ; l++) {
00072       switch (type_var(l)) {
00073       case AFFINE: {
00074     switch (mg->get_type_r(l)) {
00075     case RARE:  {
00076       alpha.set(l) = bornes(l+1) - bornes(l) ;
00077       beta.set(l) = bornes(l) ;
00078       break ; 
00079     }
00080         
00081     case FIN:   {
00082       alpha.set(l) = (bornes(l+1) - bornes(l)) * .5 ;
00083       beta.set(l) = (bornes(l+1) + bornes(l)) * .5 ;
00084       break ;
00085     }
00086       
00087     case UNSURR: {
00088       double umax = 1./bornes(l) ;
00089       double umin = 1./bornes(l+1) ;
00090       alpha.set(l) = (umin - umax) * .5 ;  // u est une fonction decroissante
00091       beta.set(l) = (umin + umax) * .5 ;   //  de l'indice i en r
00092       break ;
00093     }
00094       
00095     default:    {
00096       cout << "Map_log::Map_log: unkown type_r ! " << endl ;
00097       abort () ;
00098       break ;
00099     }
00100         
00101     }
00102     break ;
00103       }
00104       case LOG:{
00105     switch (mg->get_type_r(l)) {
00106     case FIN:   {
00107       alpha.set(l) = (log(bornes(l+1)) - log(bornes(l))) * .5 ;
00108       beta.set(l) = (log(bornes(l+1)) + log(bornes(l))) * .5 ;
00109       break ;
00110     }
00111       
00112     default:    {
00113       cout << "Map_log::Map_log: unkown type_r ! " << endl ;
00114       abort () ;
00115       break ;
00116     }
00117     }
00118     break ;
00119       }
00120       
00121       default: { 
00122     cout << "Map_log::Map_log: unkown type_r ! " << endl ;
00123     abort () ;
00124     break ;
00125       }
00126       }
00127     }
00128 
00129     set_coord() ;
00130 }
00131 
00132 Map_log::Map_log (const Map_log& so) : Map_radial (*so.mg), alpha(so.alpha), beta(so.beta), 
00133                        type_var(so.type_var) {
00134   set_coord() ;
00135 }
00136 
00137 
00138 Map_log::Map_log (const Mg3d& mgrille, FILE* fd) : Map_radial (mgrille, fd), 
00139                            alpha (mgrille.get_nzone()), 
00140                            beta (mgrille.get_nzone()), 
00141                            type_var (mgrille.get_nzone()) {
00142   Tbl alpha_lu (fd) ;
00143   Tbl beta_lu (fd) ;
00144   Itbl type_lu (fd) ;
00145 
00146   alpha = alpha_lu ;
00147   beta = beta_lu ;
00148   type_var = type_lu ;
00149 
00150   set_coord() ;
00151 }
00152 
00153 Map_log::~Map_log() {}
00154 
00155 // Sauvegarde :
00156 void Map_log::sauve(FILE* fd) const {
00157 
00158   Map_radial::sauve(fd) ;
00159   alpha.sauve(fd) ;
00160   beta.sauve(fd) ;
00161   type_var.sauve(fd) ;
00162 }
00163 
00164 // Comparison operator :
00165 bool Map_log::operator==(const Map& mpi) const {
00166   
00167   // Precision of the comparison
00168   double precis = 1e-10 ;
00169   bool resu = true ;
00170 
00171   // Dynamic cast pour etre sur meme Map...
00172   const Map_log* mp0 = dynamic_cast<const Map_log*>(&mpi) ;
00173   if (mp0 == 0x0)
00174     resu = false ;
00175   else {
00176     if (*mg != *(mpi.get_mg()))
00177       resu = false ;
00178     
00179     if (fabs(ori_x-mpi.get_ori_x()) > precis) resu = false ;
00180     if (fabs(ori_y-mpi.get_ori_y()) > precis) resu = false ;
00181     if (fabs(ori_z-mpi.get_ori_z()) > precis)  resu = false ;
00182 
00183     if (bvect_spher != mpi.get_bvect_spher()) resu = false ;
00184     if (bvect_cart != mpi.get_bvect_cart()) resu = false ;
00185 
00186     if (diffrelmax (alpha, mp0->alpha) > precis) resu = false ;
00187     if (diffrelmax (beta, mp0->beta) > precis) resu = false ;
00188     if (diffrelmax(type_var, mp0->type_var) > precis) resu = false ;
00189   }
00190 
00191   return resu ;
00192 }
00193             //------------//
00194             // Impression //
00195             //------------//
00196 
00197 ostream & Map_log::operator>>(ostream & ost) const {
00198 
00199   ost << "Log mapping (class Map_log)" << endl ; 
00200   int nz = mg->get_nzone() ;
00201   for (int l=0; l<nz; l++) {
00202     ost << "     Domain #" << l << " ; Variable type " ;
00203     if (type_var(l) == AFFINE)
00204       ost << "affine : " ;
00205     if (type_var(l) == LOG)
00206       ost << "log : " ;
00207     ost << "alpha_l = " << alpha(l) 
00208      << " , beta_l = " << beta(l) << endl ;  
00209   }
00210 
00211   
00212   ost << "            Coord r : " ; 
00213   for (int l=0; l<nz; l++) {
00214     int nrm1 = mg->get_nr(l) - 1 ;
00215     ost << " " << (+r)(l, 0, 0, nrm1) ; 
00216   }
00217     ost << endl ; 
00218 
00219     return ost ;
00220 }    
00221 
00222 // Affectation to a affine mapping :
00223 void Map_log::operator=(const Map_af& mpi) {
00224     
00225   assert(mpi.get_mg() == mg) ; 
00226     
00227   set_ori( mpi.get_ori_x(), mpi.get_ori_y(), mpi.get_ori_z() ) ; 
00228     
00229   set_rot_phi( mpi.get_rot_phi() ) ; 
00230     
00231     // The members bvect_spher and bvect_cart are treated by the functions
00232     //  set_ori and set_rot_phi.
00233     
00234     for (int l=0; l<mg->get_nzone(); l++){
00235     alpha.set(l) = mpi.get_alpha()[l] ; 
00236     beta.set(l) = mpi.get_beta()[l] ; 
00237     }
00238     
00239     type_var = AFFINE ;
00240 
00241     reset_coord() ;
00242     set_coord() ;
00243 }
00244 
00245 
00246             //-------------------------------------------------//
00247         //  Assignement of the Coord building functions    //
00248         //-------------------------------------------------//
00249         
00250 void Map_log::set_coord(){
00251 
00252     // ... Coord's introduced by the base class Map : 
00253     r.set(this, map_log_fait_r) ;
00254     tet.set(this, map_log_fait_tet) ;
00255     phi.set(this, map_log_fait_phi) ;
00256     sint.set(this, map_log_fait_sint) ;
00257     cost.set(this, map_log_fait_cost) ;
00258     sinp.set(this, map_log_fait_sinp) ;
00259     cosp.set(this, map_log_fait_cosp) ;
00260 
00261     x.set(this, map_log_fait_x) ;
00262     y.set(this, map_log_fait_y) ;
00263     z.set(this, map_log_fait_z) ;
00264 
00265     xa.set(this, map_log_fait_xa) ;
00266     ya.set(this, map_log_fait_ya) ;
00267     za.set(this, map_log_fait_za) ;
00268     
00269     // ... Coord's introduced by the base class Map_radial : 
00270     xsr.set(this, map_log_fait_xsr) ;
00271     dxdr.set(this, map_log_fait_dxdr) ;
00272     drdt.set(this, map_log_fait_drdt) ;
00273     stdrdp.set(this, map_log_fait_stdrdp) ;
00274     srdrdt.set(this, map_log_fait_srdrdt) ;
00275     srstdrdp.set(this, map_log_fait_srstdrdp) ;
00276     sr2drdt.set(this, map_log_fait_sr2drdt) ;
00277     sr2stdrdp.set(this, map_log_fait_sr2stdrdp) ;
00278     d2rdx2.set(this, map_log_fait_d2rdx2) ;
00279     lapr_tp.set(this, map_log_fait_lapr_tp) ;
00280     d2rdtdx.set(this, map_log_fait_d2rdtdx) ;
00281     sstd2rdpdx.set(this, map_log_fait_sstd2rdpdx) ;
00282     sr2d2rdt2.set(this, map_log_fait_sr2d2rdt2) ;
00283     
00284     // ... Coord's introduced by the base Map_log itself
00285     dxdlnr.set(this, map_log_fait_dxdlnr) ;
00286 }

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