| 1 | /* |
| 2 | * Definition of Lorene classes Eos_CompOSE |
| 3 | * Eos_consistent |
| 4 | */ |
| 5 | |
| 6 | /* |
| 7 | * Copyright (c) 2014-2015 Jerome Novak |
| 8 | * |
| 9 | * This file is part of LORENE. |
| 10 | * |
| 11 | * LORENE is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 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 | |
| 28 | #ifndef __EOS_COMPOSE_H_ |
| 29 | #define __EOS_COMPOSE_H_ |
| 30 | |
| 31 | /* |
| 32 | * $Id: eos_compose.h,v 1.1 2015/08/04 14:41:28 j_novak Exp $ |
| 33 | * $Log: eos_compose.h,v $ |
| 34 | * Revision 1.1 2015/08/04 14:41:28 j_novak |
| 35 | * Back to previous version for Eos_CompOSE. Enthalpy-consistent EoS can be accessed using Eos_consistent class (derived from Eos_CompOSE). |
| 36 | * |
| 37 | * |
| 38 | * |
| 39 | * $Header: /cvsroot/Lorene/C++/Include/eos_compose.h,v 1.1 2015/08/04 14:41:28 j_novak Exp $ |
| 40 | * |
| 41 | */ |
| 42 | |
| 43 | // Standard C++ |
| 44 | #include <string> |
| 45 | #include "headcpp.h" |
| 46 | |
| 47 | // Headers C |
| 48 | #include <cstdio> |
| 49 | |
| 50 | // Lorene classes |
| 51 | namespace Lorene { |
| 52 | class Tbl ; |
| 53 | |
| 54 | |
| 55 | //------------------------------------// |
| 56 | // class Eos_CompOSE // |
| 57 | //------------------------------------// |
| 58 | |
| 59 | |
| 60 | /** |
| 61 | * Equation of state for the <a href="http://compose.obspm.fr">CompOSE</a> |
| 62 | * database. |
| 63 | * |
| 64 | * General tabulated EOS, reading a table passed as an argument to the |
| 65 | * constructor. When built with \c Eos::eos_from_file(), the file must |
| 66 | * be composed of the following lines: |
| 67 | * \verbatim 17 Type of the EOS |
| 68 | 1 0: standard format 1: CompOSE format |
| 69 | Tabulated EoS |
| 70 | /full/path/to/the/eos/table/name_of_the_table \endverbatim |
| 71 | * On the second line '0' means that the table has the standard LORENE format |
| 72 | * for tabulated EoSs. '1' means that the files from the CompOSE database |
| 73 | * are used and that the 'name_of_the_table' should be without suffix: |
| 74 | * e.g. \c great_eos would stand for files \c great_eos.nb and |
| 75 | * \c great_eos.thermo (see CompOSE documentation). |
| 76 | */ |
| 77 | class Eos_CompOSE : public Eos_tabul { |
| 78 | |
| 79 | // Constructors - Destructor |
| 80 | // ------------------------- |
| 81 | public: |
| 82 | |
| 83 | /** Constructor from CompOSE data. |
| 84 | * |
| 85 | * @param files_path Absolute name (including path), but without |
| 86 | * extensions of the CompOSE data, e.g. |
| 87 | * \c /home/foo/eos/my_eos standing for |
| 88 | * files \c my_eos.nb and \c my_eos.thermo |
| 89 | * as dowloaded from the <a href="http://compose.obspm.fr"> |
| 90 | * CompOSE server</a>. |
| 91 | */ |
| 92 | Eos_CompOSE(const string& files_path) ; |
| 93 | |
| 94 | /** Standard constructor. |
| 95 | * |
| 96 | * @param file_name Absolute name (including path) containing |
| 97 | * the EOS file. This file should contain a header |
| 98 | * with the following first lines: |
| 99 | * \verbatim# Comments ... |
| 100 | # Name of the authors / reference |
| 101 | # Comments ... |
| 102 | # Comments ... |
| 103 | # Comments |
| 104 | XXX <-- Number of lines |
| 105 | # |
| 106 | # index n_B [fm^{-3}] rho [g/cm^3] p [dyn/cm^2] |
| 107 | # \endverbatim |
| 108 | * where 'XXX' is the number of following lines of the EoS, each line containing |
| 109 | * an index (integer), baryon density, energy total density and pressure |
| 110 | * in the units given above. |
| 111 | */ |
| 112 | Eos_CompOSE(const char* file_name) ; |
| 113 | |
| 114 | |
| 115 | protected: |
| 116 | /** Constructor from a binary file (created by the function |
| 117 | * \c sauve(FILE*) ). |
| 118 | * This constructor is protected because any EOS construction |
| 119 | * from a binary file must be done via the function |
| 120 | * \c Eos::eos_from_file(FILE*) . |
| 121 | */ |
| 122 | Eos_CompOSE(FILE* ) ; |
| 123 | |
| 124 | /** Constructor from a formatted file. |
| 125 | * This constructor is protected because any EOS construction |
| 126 | * from a formatted file must be done via the function |
| 127 | * \c Eos::eos_from_file(ifstream\& ) . |
| 128 | */ |
| 129 | Eos_CompOSE(ifstream&) ; |
| 130 | |
| 131 | private: |
| 132 | /** Copy constructor (private to make \c Eos_CompOSE |
| 133 | * a non-copiable class) |
| 134 | */ |
| 135 | Eos_CompOSE(const Eos_CompOSE& ) ; |
| 136 | |
| 137 | |
| 138 | /// The construction functions from a file |
| 139 | friend Eos* Eos::eos_from_file(FILE* ) ; |
| 140 | friend Eos* Eos::eos_from_file(ifstream& ) ; |
| 141 | |
| 142 | public: |
| 143 | virtual ~Eos_CompOSE() ; ///< Destructor |
| 144 | |
| 145 | // Miscellaneous |
| 146 | // ------------- |
| 147 | |
| 148 | public : |
| 149 | /// Comparison operator (egality) |
| 150 | virtual bool operator==(const Eos& ) const ; |
| 151 | |
| 152 | /// Comparison operator (difference) |
| 153 | virtual bool operator!=(const Eos& ) const ; |
| 154 | |
| 155 | /** Returns a number to identify the sub-classe of \c Eos the |
| 156 | * object belongs to. |
| 157 | */ |
| 158 | virtual int identify() const ; |
| 159 | |
| 160 | // Outputs |
| 161 | // ------- |
| 162 | |
| 163 | protected: |
| 164 | virtual ostream& operator>>(ostream &) const ; ///< Operator >> |
| 165 | |
| 166 | |
| 167 | }; |
| 168 | |
| 169 | //------------------------------------// |
| 170 | // class Eos_consistent // |
| 171 | //------------------------------------// |
| 172 | |
| 173 | |
| 174 | /** |
| 175 | * Equation of state for the <a href="http://compose.obspm.fr">CompOSE</a> |
| 176 | * database with a consistent computation of the log-enthalpy |
| 177 | * (derived from \c Eos_CompOSE ). |
| 178 | * |
| 179 | * General tabulated EOS, reading a table passed as an argument to the |
| 180 | * constructor. The log-enthalpy \f$h\f$ is computed to ensure the relation |
| 181 | * \f$ dp = (e+p) dh \f$, thus eventually modifying the table. When built |
| 182 | * with \c Eos::eos_from_file(), the file must be composed of the following |
| 183 | * lines: \verbatim 20 Type of the EOS |
| 184 | 1 0: standard format 1: CompOSE format |
| 185 | Tabulated EoS |
| 186 | /full/path/to/the/eos/table/name_of_the_table \endverbatim |
| 187 | * On the second line '0' means that the table has the standard LORENE format |
| 188 | * for tabulated EoSs. '1' means that the files from the CompOSE database |
| 189 | * are used and that the 'name_of_the_table' should be without suffix: |
| 190 | * e.g. \c great_eos would stand for files \c great_eos.nb and |
| 191 | * \c great_eos.thermo (see CompOSE documentation). |
| 192 | */ |
| 193 | class Eos_consistent : public Eos_CompOSE { |
| 194 | |
| 195 | // Constructors - Destructor |
| 196 | // ------------------------- |
| 197 | public: |
| 198 | |
| 199 | /** Constructor from CompOSE data. |
| 200 | * |
| 201 | * @param files_path Absolute name (including path), but without |
| 202 | * extensions of the CompOSE data, e.g. |
| 203 | * \c /home/foo/eos/my_eos standing for |
| 204 | * files \c my_eos.nb and \c my_eos.thermo |
| 205 | * as dowloaded from the <a href="http://compose.obspm.fr"> |
| 206 | * CompOSE server</a>. |
| 207 | */ |
| 208 | Eos_consistent(const string& files_path) ; |
| 209 | |
| 210 | /** Standard constructor. |
| 211 | * |
| 212 | * @param file_name Absolute name (including path) containing |
| 213 | * the EOS file. This file should contain a header |
| 214 | * with the following first lines: |
| 215 | * \verbatim# Comments ... |
| 216 | # Name of the authors / reference |
| 217 | # Comments ... |
| 218 | # Comments ... |
| 219 | # Comments |
| 220 | XXX <-- Number of lines |
| 221 | # |
| 222 | # index n_B [fm^{-3}] rho [g/cm^3] p [dyn/cm^2] |
| 223 | # \endverbatim |
| 224 | * where 'XXX' is the number of following lines of the EoS, each line containing |
| 225 | * an index (integer), baryon density, energy total density and pressure |
| 226 | * in the units given above. |
| 227 | */ |
| 228 | Eos_consistent(const char* file_name) ; |
| 229 | |
| 230 | |
| 231 | protected: |
| 232 | /** Constructor from a binary file (created by the function |
| 233 | * \c sauve(FILE*) ). |
| 234 | * This constructor is protected because any EOS construction |
| 235 | * from a binary file must be done via the function |
| 236 | * \c Eos::eos_from_file(FILE*) . |
| 237 | */ |
| 238 | Eos_consistent(FILE* ) ; |
| 239 | |
| 240 | /** Constructor from a formatted file. |
| 241 | * This constructor is protected because any EOS construction |
| 242 | * from a formatted file must be done via the function |
| 243 | * \c Eos::eos_from_file(ifstream\& ) . |
| 244 | */ |
| 245 | Eos_consistent(ifstream&) ; |
| 246 | |
| 247 | private: |
| 248 | /** Copy constructor (private to make \c Eos_consistent |
| 249 | * a non-copiable class) |
| 250 | */ |
| 251 | Eos_consistent(const Eos_consistent& ) ; |
| 252 | |
| 253 | |
| 254 | /// The construction functions from a file |
| 255 | friend Eos* Eos::eos_from_file(FILE* ) ; |
| 256 | friend Eos* Eos::eos_from_file(ifstream& ) ; |
| 257 | |
| 258 | public: |
| 259 | virtual ~Eos_consistent() ; ///< Destructor |
| 260 | |
| 261 | // Miscellaneous |
| 262 | // ------------- |
| 263 | |
| 264 | public : |
| 265 | /// Comparison operator (egality) |
| 266 | virtual bool operator==(const Eos& ) const ; |
| 267 | |
| 268 | /// Comparison operator (difference) |
| 269 | virtual bool operator!=(const Eos& ) const ; |
| 270 | |
| 271 | /** Returns a number to identify the sub-classe of \c Eos the |
| 272 | * object belongs to. |
| 273 | */ |
| 274 | virtual int identify() const ; |
| 275 | |
| 276 | // Outputs |
| 277 | // ------- |
| 278 | |
| 279 | protected: |
| 280 | virtual ostream& operator>>(ostream &) const ; ///< Operator >> |
| 281 | |
| 282 | // Computational functions |
| 283 | // ----------------------- |
| 284 | |
| 285 | public: |
| 286 | /** Computes the baryon density from the log-enthalpy. |
| 287 | * |
| 288 | * @param ent [input, unit: \f$c^2\f$] log-enthalpy \e H |
| 289 | * |
| 290 | * @return baryon density \e n [unit:\f$n_{\rm nuc}:=0.1\ {\rm fm}^{-3}\f$] |
| 291 | * |
| 292 | */ |
| 293 | virtual double nbar_ent_p(double ent, const Param* par=0x0) const ; |
| 294 | |
| 295 | /** Computes the total energy density from the log-enthalpy. |
| 296 | * |
| 297 | * @param ent [input, unit: \f$c^2\f$] log-enthalpy \e H |
| 298 | * |
| 299 | * @return energy density \e e [unit: \f$\rho_{\rm nuc} c^2\f$], where |
| 300 | * \f$\rho_{\rm nuc} := 1.66\ 10^{17} \ {\rm kg/m}^3\f$ |
| 301 | */ |
| 302 | virtual double ener_ent_p(double ent, const Param* par=0x0) const ; |
| 303 | |
| 304 | /** Computes the pressure from the log-enthalpy. |
| 305 | * |
| 306 | * @param ent [input, unit: \f$c^2\f$] log-enthalpy \e H |
| 307 | * |
| 308 | * @return pressure \e p [unit: \f$\rho_{\rm nuc} c^2\f$], where |
| 309 | * \f$\rho_{\rm nuc} := 1.66\ 10^{17} \ {\rm kg/m}^3\f$ |
| 310 | */ |
| 311 | virtual double press_ent_p(double ent, const Param* par=0x0) const ; |
| 312 | |
| 313 | }; |
| 314 | |
| 315 | |
| 316 | |
| 317 | } |
| 318 | #endif |
| 319 |