/* * Main code for computing magnetized axisymmetric stars without deformations. * */ /* * Copyright (c) 2002 Jerome Novak & Emanuel Marcq * * This file is part of LORENE. * * LORENE is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * LORENE is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with LORENE; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /* * $Id: magnetstar.C,v 1.4 2014/10/13 08:53:57 j_novak Exp $ * $Log: magnetstar.C,v $ * Revision 1.4 2014/10/13 08:53:57 j_novak * Lorene classes and functions now belong to the namespace Lorene. * * Revision 1.3 2014/10/06 15:09:45 j_novak * Modified #include directives to use c++ syntax. * * Revision 1.2 2012/08/17 15:35:06 p_cerda * Small changes to match the paper * * Revision 1.1 2012/08/12 17:57:41 p_cerda * Magnetstar code * * Revision 1.10 2006/03/09 08:11:59 j_novak * Output of the divergence of B at the end of the iteration. * * Revision 1.9 2004/03/25 12:35:42 j_novak * now using namespace Unites * * Revision 1.8 2003/05/14 20:06:09 e_gourgoulhon * Suppressed the qualifier ios::nocreate in call to fstream::open * (not supported by gcc 3.2). * * * $Header: /cvsroot/Lorene/Codes/Magnetstar/magnetstar.C,v 1.4 2014/10/13 08:53:57 j_novak Exp $ * */ // headers C #include #include #include // headers Lorene #include "et_rot_mag.h" #include "eos.h" #include "utilitaires.h" #include "graphique.h" #include "nbr_spx.h" #include "unites.h" #include "metric.h" namespace Lorene{ // Local prototype (for drawings only) Cmp raccord_c1(const Cmp& uu, int l1) ; } using namespace Lorene ; // Definition de f_j et de M_j Cmp f_j(const Cmp& x, double a_j){ Cmp resu(x.get_mp() ) ; resu = a_j ; return resu ; } Cmp M_j(const Cmp& x, double a_j){ return - a_j*x ; } Cmp fn_j(const Cmp& x, const Tbl an_j){ Cmp resu(x.get_mp() ) ; Cmp xsign(x.get_mp() ) ; resu = 0.; assert ( an_j.get_dim(0) == 7); xsign = x / sqrt(x*x); // M = a0 * x + a1 * x^2 + a2 * x^3 ... // f = dM/dx = a0 + 2 * a1 * x + 3 * a2 * x^2 ... resu = resu + an_j(0); resu = resu + 2 * an_j(1) * x; resu = resu + 3 * an_j(2) * x * x; // M = c0_j * log (1 + x / rc0_j) // f = dM/dx = c0_j / (1 + x/rc0_j) / rc0_j resu = resu + an_j (3) / (1.0 + x / an_j (4)) / an_j (4); // M = c1_j * rc1_j * (x/rc1_j - atan(x / rc1_j)) // f = dM/dx = c1_j * (1 - 1 / (1 + (x/rc1_j)^2)) resu = resu + an_j (5) * (1.0 - 1.0 / (x*x/an_j(6)/an_j(6) + 1.0)); return resu ; } Cmp Mn_j(const Cmp& x, const Tbl an_j){ Cmp resu(x.get_mp() ) ; resu = 0.; assert ( an_j.get_dim(0) == 7); // M = a0 * x + a1 * x^2 + a2 * x^3 ... resu = resu - an_j(0) * x; resu = resu - an_j(1) * x * x ; resu = resu - an_j(2) * x * x * x; // M = c0_j * log (1 + x / rc0_j) resu = resu - an_j (3)*log(1.0+x/an_j(4)); // M = c1_j * rc1_j * (x/rc1_j - atan(x / rc1_j)) resu = resu - an_j (5) * an_j (6) * ( (x/an_j (6)) - atan(x/an_j(6))); return resu ; } Cmp gn_j(const Cmp& x, const Tbl bn_j){ Cmp resu(x.get_mp() ) ; Cmp N(x.get_mp() ) ; Cmp dNdx(x.get_mp() ) ; N = 0.; N = N + bn_j(0) * x ; N = N + bn_j(1) * x * x ; N = N + bn_j(2) * x * x * x; dNdx= 0.; dNdx = dNdx + bn_j (0); dNdx = dNdx + 2. * bn_j (1) * x; dNdx = dNdx + 3. * bn_j (2) * x * x; resu = N*dNdx; return resu ; } Cmp Nn_j(const Cmp& x, const Tbl bn_j){ Cmp resu(x.get_mp() ) ; resu = 0.; resu = resu + bn_j(0) * x ; resu = resu + bn_j(1) * x * x ; resu = resu + bn_j(2) * x * x * x; return resu ; } //****************************************************************************** int main(){ using namespace Unites_mag ; // Identification of all the subroutines called by the code : system("ident magnetstar > identif.d") ; // For the display : // char display_bold[]="x[1m" ; display_bold[0] = 27 ; //------------------------------------------------------------------ // Parameters of the computation //------------------------------------------------------------------ char blabla[120] ; int relat_i, mer_max, mer_rot, mer_change_omega, mer_fix_omega, delta_mer_kep, mer_mass, mermax_poisson, graph, nz, nzet, nzadapt, nt, np ; double ent_c, freq_si, fact_omega, mbar_wanted, precis, freq_ini_si, thres_adapt, aexp_mass, relax, relax_poisson, precis_adapt ; double m_max; double a0_j, a1_j, a2_j, b0_j, b1_j, b2_j, c0_j, c1_j; double rc0_j, rc1_j; double relax_mag; int initial_j; ifstream fich("parrot.d") ; fich.getline(blabla, 120) ; fich >> relat_i ; fich.getline(blabla, 120) ; bool relat = (relat_i == 1) ; fich >> ent_c ; fich.getline(blabla, 120) ; fich >> freq_si ; fich.getline(blabla, 120) ; fich >> fact_omega ; fich.getline(blabla, 120) ; fich >> mbar_wanted ; fich.getline(blabla, 120) ; mbar_wanted *= msol ; fich.getline(blabla, 120) ; fich >> m_max ; fich.getline(blabla,120) ; fich >> a0_j ; fich.getline(blabla,120) ; fich >> a1_j ; fich.getline(blabla,120) ; fich >> a2_j ; fich.getline(blabla,120) ; fich >> c0_j ; fich.getline(blabla,120) ; fich >> rc0_j ; fich.getline(blabla,120) ; // fich >> c1_j ; fich.getline(blabla,120) ; // fich >> rc1_j ; fich.getline(blabla,120) ; c1_j = 0.; rc1_j = 1.; fich >> b0_j ; fich.getline(blabla,120); fich >> b1_j ; fich.getline(blabla,120); fich >> b2_j ; fich.getline(blabla,120); fich >> relax_mag ; fich.getline(blabla,120); fich >> initial_j ; fich.getline(blabla,120); fich.getline(blabla,120); fich >> mer_max ; fich.getline(blabla, 120) ; fich >> precis ; fich.getline(blabla, 120) ; fich >> mer_rot ; fich.getline(blabla, 120) ; fich >> freq_ini_si ; fich.getline(blabla, 120) ; fich >> mer_change_omega ; fich.getline(blabla, 120) ; fich >> mer_fix_omega ; fich.getline(blabla, 120) ; fich >> delta_mer_kep ; fich.getline(blabla, 120) ; fich >> thres_adapt ; fich.getline(blabla, 120) ; fich >> mer_mass ; fich.getline(blabla, 120) ; fich >> aexp_mass ; fich.getline(blabla, 120) ; fich >> relax ; fich.getline(blabla, 120) ; fich >> mermax_poisson ; fich.getline(blabla, 120) ; fich >> relax_poisson ; fich.getline(blabla, 120) ; fich >> precis_adapt ; fich.getline(blabla, 120) ; fich >> graph ; fich.getline(blabla, 120) ; fich.getline(blabla, 120) ; fich >> nz ; fich.getline(blabla, 120) ; fich >> nzet; fich.getline(blabla, 120) ; fich >> nzadapt; fich.getline(blabla, 120) ; fich >> nt; fich.getline(blabla, 120) ; fich >> np; fich.getline(blabla, 120) ; int* nr = new int[nz]; int* nt_tab = new int[nz]; int* np_tab = new int[nz]; double* bornes = new double[nz+1]; fich.getline(blabla, 120); for (int l=0; l> nr[l]; fich >> bornes[l]; fich.getline(blabla, 120) ; np_tab[l] = np ; nt_tab[l] = nt ; } bornes[nz] = __infinity ; Tbl ent_limit(nzet) ; ent_limit.set_etat_qcq() ; ent_limit.set(nzet-1) = 0 ; // enthalpy at the stellar surface for (int l=0; l> ent_limit.set(l) ; fich.getline(blabla, 120) ; } fich.close(); Tbl an_j (7); an_j.set_etat_qcq(); an_j.set(0) = a0_j*m_max; an_j.set(1) = a1_j*m_max; an_j.set(2) = a2_j*m_max; an_j.set(3) = c0_j*m_max; an_j.set(4) = rc0_j; an_j.set(5) = c1_j*m_max; an_j.set(6) = rc1_j; Tbl bn_j (3); bn_j.set_etat_qcq(); bn_j.set(0) = b0_j; bn_j.set(1) = b1_j; bn_j.set(2) = b2_j; // Particular cases // ---------------- // Initial frequency = final frequency if ( freq_ini_si < 0 ) { freq_ini_si = freq_si ; mer_change_omega = mer_rot ; mer_fix_omega = mer_rot + 1 ; } //----------------------------------------------------------------------- // Equation of state //----------------------------------------------------------------------- fich.open("par_eos.d") ; Eos* peos = Eos::eos_from_file(fich) ; Eos& eos = *peos ; fich.close() ; // Special treatment of crust - liquid core boundary in the case // of Eos_strange if (eos.identify() == 6) { assert( nzet == 2 ) ; const Eos_strange_cr* peos_cr = dynamic_cast(peos) ; if (peos_cr == 0x0) { cout << "rotstar: problem : peos is not of type Eos_strange_cr !" << endl ; abort() ; } ent_limit.set(0) = peos_cr->get_ent_nd() ; // enthalpy at core/crust transition } //----------------------------------------------------------------------- // Construction of the multi-grid and the mapping //----------------------------------------------------------------------- // Rescale of bornes in the case where there more than 1 domain inside // the star for (int l=0; l> calcul.d") ; fichfinal.open("calcul.d", ios::app) ; fichfinal << endl << "================================================================" << endl ; fichfinal << " EOS PARAMETERS (file par_eos.d) : " << endl ; fichfinal << "================================================================" << endl ; fichfinal.close() ; system("cat par_eos.d >> calcul.d") ; // Identification du code et de ses sous-routines (no. de version RCS) : fichfinal.open("calcul.d", ios::app) ; fichfinal << endl << "================================================================" << endl ; fichfinal << " IDENTIFICATION OF THE CODE : " << endl ; fichfinal << "================================================================" << endl ; fichfinal.close() ; system("ident magnetstar >> calcul.d") ; // Saveguard of the whole configuration // ------------------------------------ FILE* fresu = fopen("resu.d", "w") ; star.get_mp().get_mg()->sauve(fresu) ; // writing of the grid star.get_mp().sauve(fresu) ; // writing of the mapping star.get_eos().sauve(fresu) ; // writing of the EOS star.sauve(fresu) ; // writing of the star fclose(fresu) ; // Drawings // -------- if (graph == 1) { // Cmp defining the surface of the star (via the enthalpy field) Cmp surf = star.get_ent()() ; Cmp surf_ext(mp) ; surf_ext = - 0.2 * surf(0, 0, 0, 0) ; surf_ext.annule(0, star.get_nzet()-1) ; surf.annule(star.get_nzet(), mg.get_nzone()-1) ; surf = surf + surf_ext ; surf = raccord_c1(surf, star.get_nzet()) ; // int nzdes = star.get_nzet() ; // des_coupe_y(star.get_At(), 0., nzdes, "A\\dt\\u Potential", &surf, // 2.) ; /* for (int i = 1; i