| 1 | /* |
| 2 | * Definition of Lorene class Eos_multi_poly |
| 3 | * |
| 4 | */ |
| 5 | |
| 6 | /* |
| 7 | * Copyright (c) 2009 Keisuke Taniguchi |
| 8 | * Copyright (c) 2004 Keisuke Taniguchi |
| 9 | * |
| 10 | * This file is part of LORENE. |
| 11 | * |
| 12 | * LORENE is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License version 2 |
| 14 | * as published by the Free Software Foundation. |
| 15 | * |
| 16 | * LORENE is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with LORENE; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #ifndef __EOS_MULTI_POLY_H_ |
| 28 | #define __EOS_MULTI_POLY_H_ |
| 29 | |
| 30 | /* |
| 31 | * $Id: eos_multi_poly.h,v 1.6 2014/10/13 08:52:33 j_novak Exp $ |
| 32 | * $Log: eos_multi_poly.h,v $ |
| 33 | * Revision 1.6 2014/10/13 08:52:33 j_novak |
| 34 | * Lorene classes and functions now belong to the namespace Lorene. |
| 35 | * |
| 36 | * Revision 1.5 2014/10/06 15:09:39 j_novak |
| 37 | * Modified #include directives to use c++ syntax. |
| 38 | * |
| 39 | * Revision 1.4 2009/06/23 14:33:31 k_taniguchi |
| 40 | * Completely revised. |
| 41 | * |
| 42 | * Revision 1.3 2004/05/14 11:35:17 k_taniguchi |
| 43 | * Minor changes in some comments. |
| 44 | * |
| 45 | * Revision 1.2 2004/05/07 13:04:01 j_novak |
| 46 | * Forgotten #include<assert.h> |
| 47 | * |
| 48 | * Revision 1.1 2004/05/07 08:09:56 k_taniguchi |
| 49 | * Initial revision |
| 50 | * |
| 51 | * |
| 52 | * |
| 53 | * $Header: /cvsroot/Lorene/C++/Include/eos_multi_poly.h,v 1.6 2014/10/13 08:52:33 j_novak Exp $ |
| 54 | * |
| 55 | */ |
| 56 | |
| 57 | // Standard C++ |
| 58 | #include "headcpp.h" |
| 59 | |
| 60 | // Headers C |
| 61 | #include <cstdio> |
| 62 | #include <cassert> |
| 63 | |
| 64 | // Lorene classes |
| 65 | #include "eos.h" |
| 66 | #include "param.h" |
| 67 | namespace Lorene { |
| 68 | class Tbl ; |
| 69 | class Cmp ; |
| 70 | class Param ; |
| 71 | class Eos ; |
| 72 | |
| 73 | //-------------------------------------------// |
| 74 | // base class Eos for multiple polytrope // |
| 75 | //-------------------------------------------// |
| 76 | |
| 77 | /** |
| 78 | * Base class for a multiple polytropic equation of state. |
| 79 | * |
| 80 | * This equation of state mimics some realistic, tabulated EOSs. |
| 81 | * \ingroup (eos) |
| 82 | * |
| 83 | */ |
| 84 | class Eos_multi_poly : public Eos { |
| 85 | |
| 86 | // Data : |
| 87 | // ----- |
| 88 | |
| 89 | protected: |
| 90 | /// Number of polytropic equations of state |
| 91 | int npeos ; |
| 92 | |
| 93 | /// Array (size: \c npeos) of adiabatic index \f$\gamma\f$ |
| 94 | double* gamma ; |
| 95 | |
| 96 | /** Pressure coefficient for the crust |
| 97 | * [unit: \f$({\rm g/cm^3})^{1-\gamma_0}\f$] |
| 98 | */ |
| 99 | double kappa0 ; |
| 100 | |
| 101 | /// Exponent of the pressure at the fiducial density \f$\rho_1\f$ |
| 102 | double logP1 ; |
| 103 | |
| 104 | /// Array (size: \c npeos - 1) of the exponent of fiducial densities |
| 105 | double* logRho ; |
| 106 | |
| 107 | /** Array (size: \c npeos) of pressure coefficient \f$\kappa\f$ |
| 108 | * [unit: \f$\rho_{\rm nuc} c^2 / n_{\rm nuc}^\gamma\f$], |
| 109 | * where |
| 110 | * \f$\rho_{\rm nuc} := 1.66\ 10^{17} \ {\rm kg/m}^3\f$ and |
| 111 | * \f$n_{\rm nuc} := 0.1 \ {\rm fm}^{-3}\f$. |
| 112 | */ |
| 113 | double* kappa ; |
| 114 | |
| 115 | /** Array (size \c npeos - 1) of the number density |
| 116 | * at which the polytropic EOS changes its index and constant |
| 117 | */ |
| 118 | double* nbCrit ; |
| 119 | |
| 120 | /** Array (size \c npeos - 1) of the critical enthalpy |
| 121 | * at which the polytropic EOS changes its index and constant |
| 122 | */ |
| 123 | double* entCrit ; |
| 124 | |
| 125 | /** Array (size \c npeos - 1) of the percentage which detemines |
| 126 | * the terminating enthalpy for lower density and the starting |
| 127 | * enthalpy for higher density |
| 128 | */ |
| 129 | double* decInc ; |
| 130 | |
| 131 | /** Individual particule mass \f$m0\f$ |
| 132 | * [unit: \f$m_B = 1.66\ 10^{-27} \ {\rm kg}\f$]. |
| 133 | */ |
| 134 | double m0 ; |
| 135 | |
| 136 | /** Array (size: \c npeos) of the relativistic chemical potential |
| 137 | * at zero pressure |
| 138 | * [unit: \f$m_B c^2\f$, |
| 139 | * with \f$m_B = 1.66\ 10^{-27} \ {\rm kg}\f$]. |
| 140 | * (The value for the EOS which covers the lowest density: 1) |
| 141 | */ |
| 142 | double* mu0 ; |
| 143 | |
| 144 | |
| 145 | // Constructors - Destructor |
| 146 | // ------------------------- |
| 147 | public: |
| 148 | /** Standard constructor (sets \c m0 to 1). |
| 149 | * |
| 150 | * The individual particle mass \f$m0\f$ is set to the mean baryon |
| 151 | * mass \f$m_B = 1.66\ 10^{-27} \ {\rm kg}\f$. |
| 152 | * |
| 153 | * @param npoly number of polytropes |
| 154 | * @param gamma_i array of adiabatic index \f$\gamma\f$ |
| 155 | * @param kappa0_i pressure coefficient for the crust |
| 156 | * @param logP1_i exponent of the pressure at the fiducial density |
| 157 | * @param logRho_i array of the exponent of fiducial densities |
| 158 | * @param decInc_i array of percentage |
| 159 | */ |
| 160 | Eos_multi_poly(int npoly, double* gamma_i, double kappa0_i, |
| 161 | double logP1_i, double* logRho_i, double* decInc_i) ; |
| 162 | |
| 163 | Eos_multi_poly(const Eos_multi_poly& ) ; ///< Copy constructor |
| 164 | |
| 165 | protected: |
| 166 | /** Constructor from a binary file (created by the function |
| 167 | * \c sauve(FILE*) ). |
| 168 | * This constructor is protected because any EOS construction |
| 169 | * from a binary file must be done via the function |
| 170 | * \c Eos::eos_from_file(FILE*) . |
| 171 | */ |
| 172 | Eos_multi_poly(FILE* ) ; |
| 173 | |
| 174 | /** Constructor from a formatted file. |
| 175 | * This constructor is protected because any EOS construction |
| 176 | * from a formatted file must be done via the function |
| 177 | * \c Eos::eos_from_file(ifstream&) . |
| 178 | */ |
| 179 | Eos_multi_poly(ifstream& ) ; |
| 180 | |
| 181 | /// The construction functions from a file |
| 182 | friend Eos* Eos::eos_from_file(FILE* ) ; |
| 183 | friend Eos* Eos::eos_from_file(ifstream& ) ; |
| 184 | |
| 185 | public: |
| 186 | virtual ~Eos_multi_poly() ; ///< Destructor |
| 187 | |
| 188 | |
| 189 | // Assignment |
| 190 | // ---------- |
| 191 | public: |
| 192 | /// Assignment to another \c Eos_multi_poly |
| 193 | void operator=(const Eos_multi_poly&) ; |
| 194 | |
| 195 | /// Read/write kappa |
| 196 | // double& set_kappa(int n) ; |
| 197 | |
| 198 | |
| 199 | // Miscellaneous |
| 200 | // ------------- |
| 201 | public: |
| 202 | /// Comparison operator (egality) |
| 203 | virtual bool operator==(const Eos& ) const ; |
| 204 | |
| 205 | /// Comparison operator (difference) |
| 206 | virtual bool operator!=(const Eos& ) const ; |
| 207 | |
| 208 | /** Returns a number to identify the sub-classe of \c Eos |
| 209 | * the object belongs to. |
| 210 | */ |
| 211 | virtual int identify() const ; |
| 212 | |
| 213 | /// Returns the number of polytropes \c npeos |
| 214 | const int& get_npeos() const { return npeos ; } ; |
| 215 | |
| 216 | /// Returns the adiabatic index \f$\gamma\f$ |
| 217 | const double& get_gamma(int n) const { |
| 218 | assert(n>=0 && n<npeos) ; |
| 219 | return gamma[n] ; |
| 220 | } ; |
| 221 | |
| 222 | /// Returns the pressure coefficient for the crust |
| 223 | const double& get_kappa0() const { return kappa0 ; } ; |
| 224 | |
| 225 | /// Returns the exponent of the pressure at the fiducial density |
| 226 | const double& get_logP1() const { return logP1 ; } ; |
| 227 | |
| 228 | /// Returns the exponent of fiducial densities |
| 229 | const double& get_logRho(int n) const { |
| 230 | assert(n>=0 && n<npeos-1) ; |
| 231 | return logRho[n] ; |
| 232 | } ; |
| 233 | |
| 234 | /** Returns the pressure coefficient \f$\kappa\f$ |
| 235 | * [unit: \f$\rho_{\rm nuc} c^2 / n_{\rm nuc}^\gamma\f$], |
| 236 | * where |
| 237 | * \f$\rho_{\rm nuc} := 1.66\ 10^{17} \ {\rm kg/m}^3\f$ and |
| 238 | * \f$n_{\rm nuc} := 0.1 \ {\rm fm}^{-3}\f$. |
| 239 | */ |
| 240 | const double& get_kappa(int n) const { |
| 241 | assert(n>=0 && n<npeos) ; |
| 242 | return kappa[n] ; |
| 243 | } ; |
| 244 | |
| 245 | /// Returns the critical number density |
| 246 | const double& get_nbCrit(int n) const { |
| 247 | assert(n>=0 && n<npeos-1) ; |
| 248 | return nbCrit[n] ; |
| 249 | } ; |
| 250 | |
| 251 | /// Returns the critical enthalpy |
| 252 | const double& get_entCrit(int n) const { |
| 253 | assert(n>=0 && n<npeos-1) ; |
| 254 | return entCrit[n] ; |
| 255 | } ; |
| 256 | |
| 257 | protected: |
| 258 | /// Computes the auxiliary quantities |
| 259 | void set_auxiliary() ; |
| 260 | |
| 261 | |
| 262 | // Outputs |
| 263 | // ------- |
| 264 | public: |
| 265 | virtual void sauve(FILE *) const ; ///< Save in a file |
| 266 | |
| 267 | protected: |
| 268 | virtual ostream& operator>>(ostream &) const ; ///< Operator >> |
| 269 | |
| 270 | |
| 271 | // Computational functions |
| 272 | // ----------------------- |
| 273 | public: |
| 274 | /** Computes the baryon density from the log-enthalpy. |
| 275 | * |
| 276 | * @param ent [input, unit: \f$c^2\f$] log-enthalpy \e H |
| 277 | * |
| 278 | * @param par possible extra parameters of the EOS |
| 279 | * @return baryon density \e n |
| 280 | * [unit: \f$n_{\rm nuc} := 0.1 \ {\rm fm}^{-3}\f$] |
| 281 | * |
| 282 | */ |
| 283 | virtual double nbar_ent_p(double ent, const Param* par=0x0) const ; |
| 284 | |
| 285 | /** Computes the total energy density from the log-enthalpy. |
| 286 | * |
| 287 | * @param ent [input, unit: \f$c^2\f$] log-enthalpy \e H |
| 288 | * |
| 289 | * @param par possible extra parameters of the EOS |
| 290 | * @return energy density \e e [unit: \f$\rho_{\rm nuc} c^2\f$], |
| 291 | * where \f$\rho_{\rm nuc} := 1.66\ 10^{17} \ {\rm kg/m}^3\f$ |
| 292 | */ |
| 293 | virtual double ener_ent_p(double ent, const Param* par=0x0) const ; |
| 294 | |
| 295 | /** Computes the pressure from the log-enthalpy. |
| 296 | * |
| 297 | * @param ent [input, unit: \f$c^2\f$] log-enthalpy \e H |
| 298 | * |
| 299 | * @param par possible extra parameters of the EOS |
| 300 | * @return pressure \e p [unit: \f$\rho_{\rm nuc} c^2\f$], where |
| 301 | * \f$\rho_{\rm nuc} := 1.66\ 10^{17} \ {\rm kg/m}^3\f$ |
| 302 | */ |
| 303 | virtual double press_ent_p(double ent, const Param* par=0x0) const ; |
| 304 | |
| 305 | /** Computes the logarithmic derivative \f$d\ln n/d\ln H\f$ |
| 306 | * from the log-enthalpy. |
| 307 | * |
| 308 | * @param ent [input, unit: \f$c^2\f$] log-enthalpy \e H |
| 309 | * |
| 310 | * @param par possible extra parameters of the EOS |
| 311 | * @return dln(n)/dln(H) |
| 312 | */ |
| 313 | virtual double der_nbar_ent_p(double ent, const Param* par=0x0) const ; |
| 314 | |
| 315 | /** Computes the logarithmic derivative \f$d\ln e/d\ln H\f$ |
| 316 | * from the log-enthalpy. |
| 317 | * |
| 318 | * @param ent [input, unit: \f$c^2\f$] log-enthalpy \e H |
| 319 | * |
| 320 | * @param par possible extra parameters of the EOS |
| 321 | * @return dln(e)/dln(H) |
| 322 | */ |
| 323 | virtual double der_ener_ent_p(double ent, const Param* par=0x0) const ; |
| 324 | |
| 325 | /** Computes the logarithmic derivative \f$d\ln p/d\ln H\f$ |
| 326 | * from the log-enthalpy. |
| 327 | * |
| 328 | * @param ent [input, unit: \f$c^2\f$] log-enthalpy \e H |
| 329 | * |
| 330 | * @param par possible extra parameters of the EOS |
| 331 | * @return dln(p)/dln(H) |
| 332 | */ |
| 333 | virtual double der_press_ent_p(double ent, const Param* par=0x0) const ; |
| 334 | |
| 335 | /** Computes the logarithmic derivative \f$d\ln p/d\ln n\f$ |
| 336 | * from the log-enthalpy. |
| 337 | * |
| 338 | * @param ent [input, unit: \f$c^2\f$] log-enthalpy \e H |
| 339 | * |
| 340 | * @param par possible extra parameters of the EOS |
| 341 | * @return dln(p)/dln(n) |
| 342 | */ |
| 343 | virtual double der_press_nbar_p(double ent, const Param* par=0x0) const ; |
| 344 | }; |
| 345 | |
| 346 | } |
| 347 | #endif |