/* * Method of class Star_bin to compute an equilibrium configuration * * (see file star.h for documentation). */ /* * Copyright (c) 2004 Francois Limousin * * 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 version 2 * as published by the Free Software Foundation. * * 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 * */ char star_bin_equilibrium_C[] = "$Header: /cvsroot/Lorene/C++/Source/Star/star_bin_equilibrium.C,v 1.29 2014/10/13 08:53:38 j_novak Exp $" ; /* * $Id: star_bin_equilibrium.C,v 1.29 2014/10/13 08:53:38 j_novak Exp $ * $Log: star_bin_equilibrium.C,v $ * Revision 1.29 2014/10/13 08:53:38 j_novak * Lorene classes and functions now belong to the namespace Lorene. * * Revision 1.28 2014/10/06 15:13:16 j_novak * Modified #include directives to use c++ syntax. * * Revision 1.27 2006/08/01 14:26:01 f_limousin * Display * * Revision 1.26 2006/05/31 09:26:04 f_limousin * Modif. of the size of the different domains * * Revision 1.25 2006/04/11 14:24:44 f_limousin * New version of the code : improvement of the computation of some * critical sources, estimation of the dirac gauge, helical symmetry... * * Revision 1.24 2005/11/03 13:27:09 f_limousin * Final version for the letter. * * Revision 1.23 2005/09/14 12:48:02 f_limousin * Comment graphical outputs. * * Revision 1.22 2005/09/14 12:30:52 f_limousin * Saving of fields lnq and logn in class Star. * * Revision 1.21 2005/09/13 19:38:31 f_limousin * Reintroduction of the resolution of the equations in cartesian coordinates. * * Revision 1.20 2005/04/08 12:36:44 f_limousin * Just to avoid warnings... * * Revision 1.19 2005/02/24 16:27:21 f_limousin * Add mermax_poisson and relax_poisson in the parameters of the function. * * Revision 1.18 2005/02/24 16:04:13 f_limousin * Change the name of some variables (for instance dcov_logn --> dlogn). * Improve the resolution of the tensorial poisson equation for hh. * * Revision 1.17 2005/02/18 13:14:18 j_novak * Changing of malloc/free to new/delete + suppression of some unused variables * (trying to avoid compilation warnings). * * Revision 1.16 2005/02/17 17:32:53 f_limousin * Change the name of some quantities to be consistent with other classes * (for instance nnn is changed to nn, shift to beta, beta to lnq...) * * Revision 1.15 2005/02/11 18:13:47 f_limousin * Important modification : all the poisson equations for the metric * quantities are now solved on an affine mapping. * * Revision 1.14 2004/12/17 16:23:19 f_limousin * Modif. comments. * * Revision 1.13 2004/06/22 12:49:12 f_limousin * Change qq, qq_auto and qq_comp to beta, beta_auto and beta_comp. * * Revision 1.12 2004/05/27 12:41:00 p_grandclement * correction of some shadowed variables * * Revision 1.11 2004/05/25 14:18:00 f_limousin * Include filters * * Revision 1.10 2004/05/10 10:26:22 f_limousin * Minor changes to avoid warnings in the compilation of Lorene * * Revision 1.9 2004/04/08 16:32:48 f_limousin * The new variable is ln(Q) instead of Q=psi^2*N. It improves the * convergence of the code. * * Revision 1.8 2004/03/25 10:29:26 j_novak * All LORENE's units are now defined in the namespace Unites (in file unites.h). * * Revision 1.7 2004/03/23 09:56:09 f_limousin * Many minor changes * * Revision 1.6 2004/02/27 21:16:32 e_gourgoulhon * Function contract_desal replaced by function contract with * argument desaliasing set to true. * * Revision 1.5 2004/02/27 09:51:51 f_limousin * Many minor changes. * * Revision 1.4 2004/02/21 17:05:13 e_gourgoulhon * Method Scalar::point renamed Scalar::val_grid_point. * Method Scalar::set_point renamed Scalar::set_grid_point. * * Revision 1.3 2004/01/20 15:17:48 f_limousin * First version * * * $Header: /cvsroot/Lorene/C++/Source/Star/star_bin_equilibrium.C,v 1.29 2014/10/13 08:53:38 j_novak Exp $ * */ // C headers #include // Lorene headers #include "cmp.h" #include "tenseur.h" #include "metrique.h" #include "star.h" #include "param.h" #include "graphique.h" #include "utilitaires.h" #include "tensor.h" #include "nbr_spx.h" #include "unites.h" namespace Lorene { void Star_bin::equilibrium(double ent_c, int mermax, int mermax_potvit, int mermax_poisson, double relax_poisson, double relax_potvit, double thres_adapt, Tbl& diff, double om) { // Fundamental constants and units // ------------------------------- using namespace Unites ; // Initializations // --------------- const Mg3d* mg = mp.get_mg() ; int nz = mg->get_nzone() ; // total number of domains // The following is required to initialize mp_prev as a Map_et: Map_et& mp_et = dynamic_cast(mp) ; // Domain and radial indices of points at the surface of the star: int l_b = nzet - 1 ; int i_b = mg->get_nr(l_b) - 1 ; int k_b ; int j_b ; // Value of the enthalpy defining the surface of the star double ent_b = 0 ; // Error indicators // ---------------- double& diff_ent = diff.set(0) ; double& diff_vel_pot = diff.set(1) ; double& diff_logn = diff.set(2) ; double& diff_lnq = diff.set(3) ; double& diff_beta_x = diff.set(4) ; double& diff_beta_y = diff.set(5) ; double& diff_beta_z = diff.set(6) ; double& diff_h11 = diff.set(7) ; double& diff_h21 = diff.set(8) ; double& diff_h31 = diff.set(9) ; double& diff_h22 = diff.set(10) ; double& diff_h32 = diff.set(11) ; double& diff_h33 = diff.set(12) ; // Parameters for te function Map_et::adapt // ----------------------------------------- Param par_adapt ; int nitermax = 100 ; int niter ; int adapt_flag = 1 ; // 1 = performs the full computation, // 0 = performs only the rescaling by // the factor alpha_r //## int nz_search = nzet + 1 ; // Number of domains for searching the // enthalpy int nz_search = nzet ; // Number of domains for searching the enthalpy // isosurfaces double precis_secant = 1.e-14 ; double alpha_r ; double reg_map = 1. ; // 1 = regular mapping, 0 = contracting mapping Tbl ent_limit(nz) ; par_adapt.add_int(nitermax, 0) ; // maximum number of iterations to // locate zeros by the secant method par_adapt.add_int(nzet, 1) ; // number of domains where the adjustment // to the isosurfaces of ent is to be // performed par_adapt.add_int(nz_search, 2) ; // number of domains to search // the enthalpy isosurface par_adapt.add_int(adapt_flag, 3) ; // 1 = performs the full computation, // 0 = performs only the rescaling by // the factor alpha_r par_adapt.add_int(j_b, 4) ; // theta index of the collocation point // (theta_*, phi_*) par_adapt.add_int(k_b, 5) ; // theta index of the collocation point // (theta_*, phi_*) par_adapt.add_int_mod(niter, 0) ; // number of iterations actually used in // the secant method par_adapt.add_double(precis_secant, 0) ; // required absolute precision in // the determination of zeros by // the secant method par_adapt.add_double(reg_map, 1) ; // 1. = regular mapping, // 0 = contracting mapping par_adapt.add_double(alpha_r, 2) ; // factor by which all the radial // distances will be multiplied par_adapt.add_tbl(ent_limit, 0) ; // array of values of the field ent // to define the isosurfaces. Cmp ssjm1logn (ssjm1_logn) ; Cmp ssjm1lnq (ssjm1_lnq) ; Cmp ssjm1h11 (ssjm1_h11) ; Cmp ssjm1h21 (ssjm1_h21) ; Cmp ssjm1h31 (ssjm1_h31) ; Cmp ssjm1h22 (ssjm1_h22) ; Cmp ssjm1h32 (ssjm1_h32) ; Cmp ssjm1h33 (ssjm1_h33) ; ssjm1logn.set_etat_qcq() ; ssjm1lnq.set_etat_qcq() ; ssjm1h11.set_etat_qcq() ; ssjm1h21.set_etat_qcq() ; ssjm1h31.set_etat_qcq() ; ssjm1h22.set_etat_qcq() ; ssjm1h32.set_etat_qcq() ; ssjm1h33.set_etat_qcq() ; double precis_poisson = 1.e-16 ; // Parameters for the function Scalar::poisson for logn_auto // --------------------------------------------------------------- Param par_logn ; par_logn.add_int(mermax_poisson, 0) ; // maximum number of iterations par_logn.add_double(relax_poisson, 0) ; // relaxation parameter par_logn.add_double(precis_poisson, 1) ; // required precision par_logn.add_int_mod(niter, 0) ; // number of iterations actually used par_logn.add_cmp_mod( ssjm1logn ) ; // Parameters for the function Scalar::poisson for lnq_auto // --------------------------------------------------------------- Param par_lnq ; par_lnq.add_int(mermax_poisson, 0) ; // maximum number of iterations par_lnq.add_double(relax_poisson, 0) ; // relaxation parameter par_lnq.add_double(precis_poisson, 1) ; // required precision par_lnq.add_int_mod(niter, 0) ; // number of iterations actually used - par_lnq.add_cmp_mod( ssjm1lnq ) ; // Parameters for the function Vector::poisson for beta method 2 // --------------------------------------------------------------- Param par_beta2 ; par_beta2.add_int(mermax_poisson, 0) ; // maximum number of iterations par_beta2.add_double(relax_poisson, 0) ; // relaxation parameter par_beta2.add_double(precis_poisson, 1) ; // required precision par_beta2.add_int_mod(niter, 0) ; // number of iterations actually used Cmp ssjm1khi (ssjm1_khi) ; Tenseur ssjm1wbeta(mp, 1, CON, mp.get_bvect_cart()) ; ssjm1wbeta.set_etat_qcq() ; for (int i=0; i<3; i++) { ssjm1wbeta.set(i) = Cmp(ssjm1_wbeta(i+1)) ; } par_beta2.add_cmp_mod(ssjm1khi) ; par_beta2.add_tenseur_mod(ssjm1wbeta) ; // Parameters for the function Scalar::poisson for h11_auto // ------------------------------------------------------------- Param par_h11 ; par_h11.add_int(mermax_poisson, 0) ; // maximum number of iterations par_h11.add_double(relax_poisson, 0) ; // relaxation parameter par_h11.add_double(precis_poisson, 1) ; // required precision par_h11.add_int_mod(niter, 0) ; // number of iterations actually used par_h11.add_cmp_mod( ssjm1h11 ) ; // Parameters for the function Scalar::poisson for h21_auto // ------------------------------------------------------------- Param par_h21 ; par_h21.add_int(mermax_poisson, 0) ; // maximum number of iterations par_h21.add_double(relax_poisson, 0) ; // relaxation parameter par_h21.add_double(precis_poisson, 1) ; // required precision par_h21.add_int_mod(niter, 0) ; // number of iterations actually used par_h21.add_cmp_mod( ssjm1h21 ) ; // Parameters for the function Scalar::poisson for h31_auto // ------------------------------------------------------------- Param par_h31 ; par_h31.add_int(mermax_poisson, 0) ; // maximum number of iterations par_h31.add_double(relax_poisson, 0) ; // relaxation parameter par_h31.add_double(precis_poisson, 1) ; // required precision par_h31.add_int_mod(niter, 0) ; // number of iterations actually used par_h31.add_cmp_mod( ssjm1h31 ) ; // Parameters for the function Scalar::poisson for h22_auto // ------------------------------------------------------------- Param par_h22 ; par_h22.add_int(mermax_poisson, 0) ; // maximum number of iterations par_h22.add_double(relax_poisson, 0) ; // relaxation parameter par_h22.add_double(precis_poisson, 1) ; // required precision par_h22.add_int_mod(niter, 0) ; // number of iterations actually used par_h22.add_cmp_mod( ssjm1h22 ) ; // Parameters for the function Scalar::poisson for h32_auto // ------------------------------------------------------------- Param par_h32 ; par_h32.add_int(mermax_poisson, 0) ; // maximum number of iterations par_h32.add_double(relax_poisson, 0) ; // relaxation parameter par_h32.add_double(precis_poisson, 1) ; // required precision par_h32.add_int_mod(niter, 0) ; // number of iterations actually used par_h32.add_cmp_mod( ssjm1h32 ) ; // Parameters for the function Scalar::poisson for h33_auto // ------------------------------------------------------------- Param par_h33 ; par_h33.add_int(mermax_poisson, 0) ; // maximum number of iterations par_h33.add_double(relax_poisson, 0) ; // relaxation parameter par_h33.add_double(precis_poisson, 1) ; // required precision par_h33.add_int_mod(niter, 0) ; // number of iterations actually used par_h33.add_cmp_mod( ssjm1h33 ) ; // External potential // See Eq (99) from Gourgoulhon et al. (2001) // ------------------ cout << "logn_comp" << norme(logn_comp) << endl ; cout << "pot_centri" << norme(pot_centri) << endl ; cout << "loggam" << norme(loggam) << endl ; Scalar pot_ext = logn_comp + pot_centri + loggam ; Scalar ent_jm1 = ent ; // Enthalpy at previous step Scalar source_tot(mp) ; // source term in the equation for hij_auto, // logn_auto and beta_auto Vector source_beta(mp, CON, mp.get_bvect_cart()) ; // source term // in the equation for beta_auto //========================================================================= // Start of iteration //========================================================================= for(int mer=0 ; mer enthalpy in all space // See Eq (98) from Gourgoulhon et al. (2001) //------------------------------------------- ent = (ent_c + logn_auto_c + pot_ext_c) - logn_auto - pot_ext ; cout.precision(8) ; cout << "pot" << norme(pot_ext) << endl ; (ent.set_spectral_va()).smooth(nzet, ent.set_spectral_va()) ; //---------------------------------------------------- // Adaptation of the mapping to the new enthalpy field //---------------------------------------------------- // Shall the adaptation be performed (cusp) ? // ------------------------------------------ double dent_eq = ent.dsdr().val_point(ray_eq(),M_PI/2.,0.) ; double dent_pole = ent.dsdr().val_point(ray_pole(),0.,0.) ; double rap_dent = fabs( dent_eq / dent_pole ) ; cout << "| dH/dr_eq / dH/dr_pole | = " << rap_dent << endl ; if ( rap_dent < thres_adapt ) { adapt_flag = 0 ; // No adaptation of the mapping cout << "******* FROZEN MAPPING *********" << endl ; } else{ adapt_flag = 1 ; // The adaptation of the mapping is to be // performed } ent_limit.set_etat_qcq() ; for (int l=0; l= 5) { double separation = 2. * fabs(mp.get_ori_x()) ; double ray_eqq = ray_eq() ; double ray_eqq_pi = ray_eq_pi() ; double new_rr_out_2 = (separation - ray_eqq) * 0.95 ; double new_rr_out_3 = (separation + ray_eqq_pi) * 1.05 ; double rr_in_1 = mp.val_r(1,-1., M_PI/2, 0.) ; double rr_out_1 = mp.val_r(1, 1., M_PI/2, 0.) ; double rr_out_2 = mp.val_r(2, 1., M_PI/2, 0.) ; double rr_out_3 = mp.val_r(3, 1., M_PI/2, 0.) ; mp.resize(1, 0.5*(new_rr_out_2 + rr_in_1) / rr_out_1) ; mp.resize(2, new_rr_out_2 / rr_out_2) ; mp.resize(3, new_rr_out_3 / rr_out_3) ; for (int dd=4; dd<=nz-2; dd++) { mp.resize(dd, new_rr_out_3 * pow(4., dd-3) / mp.val_r(dd, 1., M_PI/2, 0.)) ; } } else { cout << "too small number of domains" << endl ; } //---------------------------------------------------- // Computation of the enthalpy at the new grid points //---------------------------------------------------- mp_prev.homothetie(alpha_r) ; Cmp ent_cmp2 (ent) ; mp.reevaluate_symy(&mp_prev, nzet+1, ent_cmp2) ; ent = ent_cmp2 ; double ent_s_max = -1 ; int k_s_max = -1 ; int j_s_max = -1 ; for (int k=0; kget_np(l_b); k++) { for (int j=0; jget_nt(l_b); j++) { double xx = fabs( ent.val_grid_point(l_b, k, j, i_b) ) ; if (xx > ent_s_max) { ent_s_max = xx ; k_s_max = k ; j_s_max = j ; } } } cout << "Max. abs(enthalpy) at the boundary between domains nzet-1" << " and nzet : " << endl ; cout << " " << ent_s_max << " reached for k = " << k_s_max << " and j = " << j_s_max << endl ; //---------------------------------------------------- // Equation of state //---------------------------------------------------- equation_of_state() ; // computes new values for nbar (n), ener (e) // and press (p) from the new ent (H) //--------------------------------------------------------- // Matter source terms in the gravitational field equations //--------------------------------------------------------- hydro_euler() ; // computes new values for ener_euler (E), // s_euler (S) and u_euler (U^i) // ------------------------------- // AUXILIARY QUANTITIES // ------------------------------- // Derivatives of N and logN //-------------------------- const Vector dcov_logn_auto = logn_auto.derive_cov(flat) ; Tensor dcovdcov_logn_auto = (logn_auto.derive_cov(flat)) .derive_cov(flat) ; dcovdcov_logn_auto.inc_dzpuis() ; // Derivatives of lnq, phi and Q //------------------------------- const Scalar phi (0.5 * (lnq - logn)) ; const Scalar phi_auto (0.5 * (lnq_auto - logn_auto)) ; const Vector dcov_phi_auto = phi_auto.derive_cov(flat) ; const Vector dcov_lnq = 2*dcov_phi + dcov_logn ; const Vector dcon_lnq = 2*dcon_phi + dcon_logn ; const Vector dcov_lnq_auto = lnq_auto.derive_cov(flat) ; Tensor dcovdcov_lnq_auto = dcov_lnq_auto.derive_cov(flat) ; dcovdcov_lnq_auto.inc_dzpuis() ; Scalar qq = exp(lnq) ; qq.std_spectral_base() ; const Vector& dcov_qq = qq.derive_cov(flat) ; const Scalar& divbeta_auto = beta_auto.divergence(flat) ; const Tensor& dcov_beta_auto = beta_auto.derive_cov(flat) ; Tensor dcovdcov_beta_auto = beta_auto.derive_cov(flat) .derive_cov(flat) ; dcovdcov_beta_auto.inc_dzpuis() ; // Derivatives of hij, gtilde... //------------------------------ Scalar psi2 (pow(psi4, 0.5)) ; psi2.std_spectral_base() ; const Tensor& dcov_hij = hij.derive_cov(flat) ; const Tensor& dcon_hij = hij.derive_con(flat) ; const Tensor& dcov_hij_auto = hij_auto.derive_cov(flat) ; const Sym_tensor& gtilde_cov = gtilde.cov() ; const Sym_tensor& gtilde_con = gtilde.con() ; const Tensor& dcov_gtilde = gtilde_cov.derive_cov(flat) ; Connection gamijk (gtilde, flat) ; const Tensor& deltaijk = gamijk.get_delta() ; // H^i and its derivatives ( = O in Dirac gauge) // --------------------------------------------- double lambda_dirac = 0. ; const Vector hdirac = lambda_dirac * hij.divergence(flat) ; const Vector hdirac_auto = lambda_dirac * hij_auto.divergence(flat) ; Tensor dcov_hdirac = lambda_dirac * hdirac.derive_cov(flat) ; dcov_hdirac.inc_dzpuis() ; Tensor dcov_hdirac_auto = lambda_dirac * hdirac_auto.derive_cov(flat) ; dcov_hdirac_auto.inc_dzpuis() ; Tensor dcon_hdirac_auto = lambda_dirac * hdirac_auto.derive_con(flat) ; dcon_hdirac_auto.inc_dzpuis() ; //-------------------------------------------------------- // Poisson equation for logn_auto (nu_auto) //-------------------------------------------------------- // Source //-------- int nr = mp.get_mg()->get_nr(0) ; int nt = mp.get_mg()->get_nt(0) ; int np = mp.get_mg()->get_np(0) ; Scalar source1(mp) ; Scalar source2(mp) ; Scalar source3(mp) ; Scalar source4(mp) ; Scalar source5(mp) ; Scalar source6(mp) ; Scalar source7(mp) ; Scalar source8(mp) ; source1 = qpig * psi4 % (ener_euler + s_euler) ; source2 = psi4 % (kcar_auto + kcar_comp) ; source3 = - contract(dcov_logn_auto, 0, dcon_logn, 0, true) - 2. * contract(contract(gtilde_con, 0, dcov_phi, 0), 0, dcov_logn_auto, 0, true) ; source4 = - contract(hij, 0, 1, dcovdcov_logn_auto + dcov_logn_auto*dcov_logn, 0, 1) ; source5 = - contract(hdirac, 0, dcov_logn_auto, 0) ; source_tot = source1 + source2 + source3 + source4 + source5 ; cout << "moyenne de la source 1 pour logn_auto" << endl ; cout << norme(source1/(nr*nt*np)) << endl ; cout << "moyenne de la source 2 pour logn_auto" << endl ; cout << norme(source2/(nr*nt*np)) << endl ; cout << "moyenne de la source 3 pour logn_auto" << endl ; cout << norme(source3/(nr*nt*np)) << endl ; cout << "moyenne de la source 4 pour logn_auto" << endl ; cout << norme(source4/(nr*nt*np)) << endl ; cout << "moyenne de la source 5 pour logn_auto" << endl ; cout << norme(source5/(nr*nt*np)) << endl ; cout << "moyenne de la source pour logn_auto" << endl ; cout << norme(source_tot/(nr*nt*np)) << endl ; // Resolution of the Poisson equation // ---------------------------------- source_tot.poisson(par_logn, logn_auto) ; ssjm1_logn = ssjm1logn ; cout << "logn_auto" << endl << norme(logn_auto/(nr*nt*np)) << endl ; // Check: has the Poisson equation been correctly solved ? // ----------------------------------------------------- Tbl tdiff_logn = diffrel(logn_auto.laplacian(), source_tot) ; cout << "Relative error in the resolution of the equation for logn_auto : " << endl ; for (int l=0; l