et_rot_mag.C

00001 /*
00002  * Methods for magnetized axisymmetric rotating neutron stars.
00003  *
00004  * See the file et_rot_mag.h for documentation
00005  *
00006  */
00007 
00008 /*
00009  *   Copyright (c) 2002 Emmanuel Marcq
00010  *   Copyright (c) 2002 Jerome Novak
00011  *
00012  *   This file is part of LORENE.
00013  *
00014  *   LORENE is free software; you can redistribute it and/or modify
00015  *   it under the terms of the GNU General Public License as published by
00016  *   the Free Software Foundation; either version 2 of the License, or
00017  *   (at your option) any later version.
00018  *
00019  *   LORENE is distributed in the hope that it will be useful,
00020  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  *   GNU General Public License for more details.
00023  *
00024  *   You should have received a copy of the GNU General Public License
00025  *   along with LORENE; if not, write to the Free Software
00026  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027  *
00028  */
00029 
00030 char et_rot_mag_C[] = "$Header: /cvsroot/Lorene/C++/Source/Etoile/et_rot_mag.C,v 1.18 2011/10/06 14:55:36 j_novak Exp $" ;
00031 
00032 /*
00033  * $Id: et_rot_mag.C,v 1.18 2011/10/06 14:55:36 j_novak Exp $
00034  * $Log: et_rot_mag.C,v $
00035  * Revision 1.18  2011/10/06 14:55:36  j_novak
00036  * equation_of_state() is now virtual to be able to call to the magnetized
00037  * Eos_mag.
00038  *
00039  * Revision 1.17  2005/06/02 11:35:30  j_novak
00040  * Added members for sving to a file and reading from it.
00041  *
00042  * Revision 1.16  2004/03/25 10:29:06  j_novak
00043  * All LORENE's units are now defined in the namespace Unites (in file unites.h).
00044  *
00045  * Revision 1.15  2002/09/30 14:21:21  j_novak
00046  * *** empty log message ***
00047  *
00048  * Revision 1.14  2002/09/30 08:50:37  j_novak
00049  * Output for central magnetic field value
00050  *
00051  * Revision 1.13  2002/06/05 15:15:59  j_novak
00052  * The case of non-adapted mapping is treated.
00053  * parmag.d and parrot.d have been merged.
00054  *
00055  * Revision 1.12  2002/06/03 13:00:45  e_marcq
00056  *
00057  * conduc parameter read in parmag.d
00058  *
00059  * Revision 1.10  2002/05/22 12:20:17  j_novak
00060  * *** empty log message ***
00061  *
00062  * Revision 1.9  2002/05/20 15:44:55  e_marcq
00063  *
00064  * Dimension errors corrected, parmag.d input file created and read
00065  *
00066  * Revision 1.8  2002/05/20 08:27:59  j_novak
00067  * *** empty log message ***
00068  *
00069  * Revision 1.7  2002/05/17 15:08:01  e_marcq
00070  *
00071  * Rotation progressive plug-in, units corrected, Q and a_j new member data
00072  *
00073  * Revision 1.6  2002/05/16 13:27:11  j_novak
00074  * *** empty log message ***
00075  *
00076  * Revision 1.5  2002/05/16 11:54:11  j_novak
00077  * Fixed output pbs
00078  *
00079  * Revision 1.4  2002/05/15 09:53:59  j_novak
00080  * First operational version
00081  *
00082  * Revision 1.3  2002/05/14 13:38:36  e_marcq
00083  *
00084  *
00085  * Unit update, new outputs
00086  *
00087  * Revision 1.1  2002/05/10 09:26:52  j_novak
00088  * Added new class Et_rot_mag for magnetized rotating neutron stars (under development)
00089  *
00090  *
00091  * $Header: /cvsroot/Lorene/C++/Source/Etoile/et_rot_mag.C,v 1.18 2011/10/06 14:55:36 j_novak Exp $
00092  *
00093  */
00094 
00095 // Headers C
00096 #include "math.h"
00097 
00098 // Headers Lorene
00099 #include "et_rot_mag.h"
00100 #include "utilitaires.h"
00101 #include "unites.h"
00102 #include "param.h"
00103 #include "eos.h"
00104 
00105                 //--------------//
00106                 // Constructors //
00107                 //--------------//
00108 // Standard constructor
00109 // --------------------
00110 
00111 
00112 Et_rot_mag::Et_rot_mag(Map& mp_i, int nzet_i, bool relat, const Eos& eos_i,
00113                const int cond)
00114   : Etoile_rot(mp_i, nzet_i, relat, eos_i),
00115     A_t(mp_i),
00116     A_phi(mp_i),
00117     j_t(mp_i),
00118     j_phi(mp_i),
00119     E_em(mp_i),
00120     Jp_em(mp_i),
00121     Srr_em(mp_i),
00122     Spp_em(mp_i)
00123 
00124 {
00125 
00126   A_t = 0;
00127   A_phi = 0; 
00128   j_t = 0 ;
00129   j_phi = 0 ;
00130 
00131   Q = 0 ;
00132   a_j = 0 ;
00133   conduc = cond ;
00134 
00135 set_der_0x0() ;  
00136 }
00137 
00138 // Constructor from a file
00139 // -----------------------
00140 Et_rot_mag::Et_rot_mag(Map& mp_i, const Eos& eos_i, FILE* fich)
00141     : Etoile_rot(mp_i, eos_i, fich), 
00142       A_t(mp_i),
00143       A_phi(mp_i),
00144       j_t(mp_i),
00145       j_phi(mp_i),
00146       E_em(mp_i),
00147       Jp_em(mp_i),
00148       Srr_em(mp_i),
00149       Spp_em(mp_i)
00150 
00151 {
00152 
00153     // Etoile parameters
00154     // -----------------
00155 
00156     fread_be(&conduc, sizeof(int), 1, fich) ;       
00157     fread_be(&Q, sizeof(double), 1, fich) ;     
00158     fread_be(&a_j, sizeof(double), 1, fich) ;       
00159    
00160     // Read of the saved fields:
00161     // ------------------------
00162     
00163     Cmp A_t_file(mp, *mp.get_mg(), fich) ;
00164     A_t = A_t_file ;
00165 
00166     Cmp A_phi_file(mp, *mp.get_mg(), fich) ;
00167     A_phi = A_phi_file ;
00168 
00169     Cmp j_t_file(mp, *mp.get_mg(), fich) ;
00170     j_t = j_t_file ;
00171 
00172     Cmp j_phi_file(mp, *mp.get_mg(), fich) ;
00173     j_phi = j_phi_file ;
00174 
00175     Tenseur E_em_file(mp, fich) ;
00176     E_em = E_em_file ;
00177 
00178     Tenseur Jp_em_file(mp, fich) ;
00179     Jp_em = Jp_em_file ;
00180 
00181     Tenseur Srr_em_file(mp, fich) ;
00182     Srr_em = Srr_em_file ;
00183 
00184     Tenseur Spp_em_file(mp, fich) ;
00185     Spp_em = Spp_em_file ;
00186 
00187     // Pointers of derived quantities initialized to zero 
00188     // --------------------------------------------------
00189     set_der_0x0() ;
00190     
00191 }
00192 
00193 
00194 // Copy constructor
00195 // ----------------
00196 
00197 Et_rot_mag::Et_rot_mag(const Et_rot_mag& et)
00198   : Etoile_rot(et),
00199   A_t(et.A_t),
00200   A_phi(et.A_phi),
00201   j_t(et.j_t),
00202   j_phi(et.j_phi),
00203   E_em(et.E_em),
00204   Jp_em(et.Jp_em),
00205   Srr_em(et.Srr_em),
00206   Spp_em(et.Spp_em)
00207 
00208 {
00209   Q = et.Q ;
00210   a_j = et.a_j ;
00211   conduc = et.conduc ;
00212   set_der_0x0() ;
00213 }
00214 
00215 
00216                 //------------//
00217                 // Destructor //
00218                 //------------//
00219 
00220 Et_rot_mag::~Et_rot_mag(){
00221   del_deriv() ;
00222 }
00223 
00224 
00225         //----------------------------------//
00226         // Management of derived quantities //
00227         //----------------------------------//
00228 
00229 void Et_rot_mag::del_deriv() const {
00230 
00231   Etoile_rot::del_deriv() ;
00232 
00233   set_der_0x0() ;
00234 
00235 }
00236 
00237 
00238 void Et_rot_mag::set_der_0x0() const {
00239   Etoile_rot::set_der_0x0() ;
00240 
00241 }
00242 
00243 
00244 void Et_rot_mag::del_hydro_euler() {
00245   Etoile_rot::del_hydro_euler() ;
00246 
00247   del_deriv() ;
00248 }
00249 
00250 
00251 // Assignment to another Et_rot_mag
00252 // --------------------------------
00253 
00254 void Et_rot_mag::operator=(const Et_rot_mag& et) {
00255 
00256   // Assignement of quantities common to all the derived classes of Etoile
00257   Etoile_rot::operator=(et) ;
00258   A_t    = et.A_t    ;
00259   A_phi  = et.A_phi  ;
00260   j_t    = et.j_t    ;
00261   j_phi  = et.j_phi  ;
00262   E_em   = et.E_em   ;
00263   Jp_em  = et.Jp_em  ;
00264   Srr_em = et.Srr_em ;
00265   Spp_em = et.Spp_em ;
00266   Q      = et.Q      ;
00267   a_j    = et.a_j    ;
00268   conduc = et.conduc ;
00269 
00270   del_deriv() ;
00271 
00272 }
00273 
00274 
00275 void Et_rot_mag::equation_of_state() {
00276 
00277     Cmp ent_eos = ent() ;
00278 
00279 
00280     // Slight rescale of the enthalpy field in case of 2 domains inside the
00281     //  star
00282 
00283 
00284         double epsilon = 1.e-12 ;
00285 
00286     const Mg3d* mg = mp.get_mg() ;
00287         int nz = mg->get_nzone() ;
00288 
00289         Mtbl xi(mg) ;
00290         xi.set_etat_qcq() ;
00291         for (int l=0; l<nz; l++) {
00292             xi.t[l]->set_etat_qcq() ;
00293             for (int k=0; k<mg->get_np(l); k++) {
00294                 for (int j=0; j<mg->get_nt(l); j++) {
00295                     for (int i=0; i<mg->get_nr(l); i++) {
00296                         xi.set(l,k,j,i) =
00297                             mg->get_grille3d(l)->x[i] ;
00298                     }
00299                 }
00300             }
00301 
00302         }
00303 
00304         Cmp fact_ent(mp) ;
00305         fact_ent.allocate_all() ;
00306         
00307         fact_ent.set(0) = 1 + epsilon * xi(0) * xi(0) ;
00308         fact_ent.set(1) = 1 - 0.25 * epsilon * (xi(1) - 1) * (xi(1) - 1) ;
00309         
00310         for (int l=nzet; l<nz; l++) {
00311             fact_ent.set(l) = 1 ;
00312         }
00313 
00314     if (nzet > 1) {
00315 
00316         if (nzet > 2) {
00317         
00318             cout << "Etoile::equation_of_state: not ready yet for nzet > 2 !"
00319                  << endl ;      
00320         }
00321 
00322         ent_eos = fact_ent * ent_eos ;
00323         ent_eos.std_base_scal() ;
00324     }
00325 
00326 
00327     
00328     if ( dynamic_cast<const Eos_mag*>(&eos) != 0x0) { // Call to a magnetized EOS
00329       // with the normof te magnetic field passed as an argument to the EoS.
00330 
00331       Tenseur Bmag = Magn() ;
00332       Cmp norm_B = sqrt(a_car() * ( Bmag(0)*Bmag(0) + Bmag(1)*Bmag(1) )) ;
00333       norm_B.std_base_scal() ;
00334       Param par ;
00335       double magB0 ;
00336       par.add_double_mod(magB0) ;
00337 
00338       nbar.set_etat_qcq() ; nbar.set().set_etat_qcq() ;
00339       nbar.set().va.set_etat_c_qcq() ; nbar.set().va.c->set_etat_qcq() ;
00340       ener.set_etat_qcq() ; ener.set().set_etat_qcq() ;
00341       ener.set().va.set_etat_c_qcq() ; ener.set().va.c->set_etat_qcq() ;
00342       press.set_etat_qcq() ; press.set().set_etat_qcq() ;
00343       press.set().va.set_etat_c_qcq() ; press.set().va.c->set_etat_qcq() ;
00344 
00345       for (int l=0; l< nz; l++) {
00346     Tbl* tent = ent_eos.va.c->t[l] ;
00347     if (tent->get_etat() == ETATZERO) {
00348       nbar.set().set(l).set_etat_zero() ;
00349       ener.set().set(l).set_etat_zero() ;
00350       press.set().set(l).set_etat_zero() ;
00351     }
00352     else {
00353       nbar.set().set(l).annule_hard() ;
00354       ener.set().set(l).annule_hard() ;
00355       press.set().set(l).annule_hard() ;
00356       for (int k=0; k < mg->get_np(l); k++) {
00357         for (int j=0; j < mg->get_nt(l); j++) {
00358           for (int i=0; i < mg->get_nr(l); i++) {
00359         magB0 = norm_B(l, k, j, i) ;
00360         double ent0 = ent_eos(l, k, j, i) ;
00361         nbar.set().set(l, k, j, i) = eos.nbar_ent_p(ent0, &par) ;
00362         ener.set().set(l, k, j, i) = eos.ener_ent_p(ent0, &par) ;
00363         press.set().set(l, k, j, i) = eos.press_ent_p(ent0, &par) ;
00364           }
00365         }
00366       }
00367     }
00368       }
00369     }
00370 
00371     else {
00372       // Call to a "normal" EOS (the EOS is called domain by domain in order to
00373       //          allow for the use of MEos)
00374 
00375       Cmp tempo(mp) ;
00376       
00377       nbar.set_etat_qcq() ;
00378       nbar.set() = 0 ;
00379       for (int l=0; l<nzet; l++) {
00380     
00381         Param par ;       // Paramater for multi-domain equation of state
00382         par.add_int(l) ;
00383     
00384         tempo =  eos.nbar_ent(ent_eos, 1, l, &par) ;
00385     
00386         nbar = nbar() + tempo ;
00387     
00388       }
00389       
00390       ener.set_etat_qcq() ;
00391       ener.set() = 0 ;
00392       for (int l=0; l<nzet; l++) {
00393     
00394         Param par ;    // Paramater for multi-domain equation of state
00395         par.add_int(l) ;
00396     
00397         tempo =  eos.ener_ent(ent_eos, 1, l, &par) ;
00398     
00399         ener = ener() + tempo ;
00400     
00401       }
00402       
00403       press.set_etat_qcq() ;
00404       press.set() = 0 ;
00405       for (int l=0; l<nzet; l++) {
00406     
00407         Param par ;     // Paramater for multi-domain equation of state
00408         par.add_int(l) ;
00409     
00410         tempo =  eos.press_ent(ent_eos, 1, l, &par) ;
00411     
00412         press = press() + tempo ;
00413     
00414       }
00415     }
00416 
00417     // Set the bases for spectral expansion
00418     nbar.set_std_base() ; 
00419     ener.set_std_base() ; 
00420     press.set_std_base() ; 
00421 
00422     // The derived quantities are obsolete
00423     del_deriv() ; 
00424     
00425 }
00426 
00427 
00428 
00429                 //--------------//
00430                 //    Outputs   //
00431                 //--------------//
00432 
00433 // Save in a file
00434 // --------------
00435 void Et_rot_mag::sauve(FILE* fich) const {
00436     
00437     Etoile_rot::sauve(fich) ; 
00438     
00439     fwrite_be(&conduc, sizeof(int), 1, fich) ;
00440     fwrite_be(&Q, sizeof(double), 1, fich) ;
00441     fwrite_be(&a_j, sizeof(double), 1, fich) ;
00442 
00443     A_t.sauve(fich) ;
00444     A_phi.sauve(fich) ;
00445     j_t.sauve(fich) ;
00446     j_phi.sauve(fich) ;
00447     E_em.sauve(fich) ;
00448     Jp_em.sauve(fich) ;
00449     Srr_em.sauve(fich) ;
00450     Spp_em.sauve(fich) ;
00451     
00452 }
00453 
00454 
00455 // Printing
00456 // --------
00457 
00458 
00459 ostream& Et_rot_mag::operator>>(ostream& ost) const {
00460 
00461   using namespace Unites_mag ;
00462 
00463   Etoile_rot::operator>>(ost) ;
00464   int theta_eq = mp.get_mg()->get_nt(nzet-1)-1 ;
00465   ost << endl ;
00466   ost << "Electromagnetic quantities" << endl ;
00467   ost << "----------------------" << endl ;
00468   ost << endl ;
00469   if (is_conduct()) {
00470     ost << "***************************" << endl ;
00471     ost << "**** perfect conductor ****" << endl ;
00472     ost << "***************************" << endl ;    
00473     ost << "Prescribed charge : " << Q*j_unit*pow(r_unit,3)/v_unit 
00474     << " [C]" << endl;
00475   }
00476   else {
00477     ost << "***************************" << endl ;
00478     ost << "****     isolator      ****" << endl ;
00479     ost << "***************************" << endl ;  
00480   }  
00481   ost << "Prescribed current amplitude : " << a_j*j_unit 
00482       << " [A/m2]" << endl ;
00483   ost << "Magnetic Momentum : " << MagMom()/1.e32
00484       << " [10^32 Am^2]" << endl ;
00485   ost << "Radial magnetic field polar value : " << 
00486     Magn()(0).va.val_point(l_surf()(0,0),xi_surf()(0,0),0.,0.) 
00487       << " [GT]" << endl;
00488 
00489   ost << "Tangent magnetic field equatorial value : " << 
00490   Magn()(1).va.val_point(l_surf()(0,theta_eq),xi_surf()(0,theta_eq),M_PI_2,0.) 
00491       << " [GT]" << endl;
00492 
00493   ost << "Central magnetic field values : " << 
00494     Magn()(0)(0,0,0,0)  
00495       << " [GT]" << endl;
00496 
00497    ost << "Radial electric field polar value : " << 
00498     Elec()(0).va.val_point(l_surf()(0,0),xi_surf()(0,0),0.,0.) 
00499       << " [TV]" << endl;
00500 
00501   ost << "Radial electric field equatorial value : " << 
00502   Elec()(0).va.val_point(l_surf()(0,theta_eq),xi_surf()(0,theta_eq),M_PI_2,0.) 
00503       << " [TV]" << endl;
00504 
00505   ost << "Magnetic/fluid pressure : "
00506       << 1/(2*mu_si)*(pow(Magn()(0)(0,0,0,0),2) + 
00507               pow(Magn()(1)(0,0,0,0),2) + 
00508               pow(Magn()(2)(0,0,0,0),2))*1.e18
00509     / (press()(0,0,0,0)*rho_unit*pow(v_unit,2)) << endl ;
00510   ost << "Computed charge : " << Q_comput() << " [C]" << endl ;
00511   ost << "Interior charge : " << Q_int() << " [C]" << endl ;
00512   ost << "Q^2/M^2 :" << mu_si*c_si*c_si*Q_comput()*Q_comput()/(4*M_PI*g_si*mass_g()*mass_g()*m_unit*m_unit) 
00513       << endl ;
00514   ost << "Gyromagnetic ratio : " << GyroMag() << endl ;
00515 
00516   return ost ;
00517 }
00518 
00519 
00520 
00521 
00522 
00523 
00524 
00525 
00526 
00527 
00528 
00529 
00530 
00531 
00532 
00533 

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