Debian Codegraph @

C++/Source/Eos/eos_poly_newt.C

raw
1 /*
2 * Methods of the class Eos_poly_newt.
3 *
4 * (see file eos.h for documentation).
5 */
6
7 /*
8 * Copyright (c) 2000-2001 Eric Gourgoulhon
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 as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * LORENE is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with LORENE; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 */
27
28
29 char eos_poly_newt_C[] = "$Header: /cvsroot/Lorene/C++/Source/Eos/eos_poly_newt.C,v 1.5 2014/10/13 08:52:53 j_novak Exp $" ;
30
31 /*
32 * $Id: eos_poly_newt.C,v 1.5 2014/10/13 08:52:53 j_novak Exp $
33 * $Log: eos_poly_newt.C,v $
34 * Revision 1.5 2014/10/13 08:52:53 j_novak
35 * Lorene classes and functions now belong to the namespace Lorene.
36 *
37 * Revision 1.4 2014/10/06 15:13:06 j_novak
38 * Modified #include directives to use c++ syntax.
39 *
40 * Revision 1.3 2002/10/16 14:36:35 j_novak
41 * Reorganization of #include instructions of standard C++, in order to
42 * use experimental version 3 of gcc.
43 *
44 * Revision 1.2 2002/04/09 14:32:15 e_gourgoulhon
45 * 1/ Added extra parameters in EOS computational functions (argument par)
46 * 2/ New class MEos for multi-domain EOS
47 *
48 * Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon
49 * LORENE
50 *
51 * Revision 2.5 2001/02/23 15:16:51 eric
52 * Continuite en ent=0 des quantites derivees.
53 *
54 * Revision 2.4 2001/02/07 09:50:11 eric
55 * Suppression de la fonction derent_ent_p.
56 * Ajout des fonctions donnant les derivees de l'EOS:
57 * der_nbar_ent_p
58 * der_ener_ent_p
59 * der_press_ent_p
60 *
61 * Revision 2.3 2000/02/14 14:49:41 eric
62 * Modif affichage.
63 *
64 * Revision 2.2 2000/02/14 14:33:33 eric
65 * Ajout du constructeur par lecture de fichier formate.
66 *
67 * Revision 2.1 2000/01/21 15:18:56 eric
68 * Ajout des operateurs de comparaison == et !=
69 *
70 * Revision 2.0 2000/01/18 15:14:12 eric
71 * *** empty log message ***
72 *
73 *
74 * $Header: /cvsroot/Lorene/C++/Source/Eos/eos_poly_newt.C,v 1.5 2014/10/13 08:52:53 j_novak Exp $
75 *
76 */
77
78 // Headers C
79 #include <cstdlib>
80 #include <cstring>
81 #include <cmath>
82
83 // Headers Lorene
84 #include "eos.h"
85 #include "cmp.h"
86
87 //--------------//
88 // Constructors //
89 //--------------//
90
91 // Standard constructor
92 // --------------------
93 namespace Lorene {
94 Eos_poly_newt::Eos_poly_newt(double gamma, double kappa) :
95 Eos_poly(gamma, kappa) {
96
97 set_name("Newtonian polytropic EOS") ;
98
99 }
100
101
102 // Copy constructor
103 // ----------------
104 Eos_poly_newt::Eos_poly_newt(const Eos_poly_newt& eosi) : Eos_poly(eosi) {}
105
106
107 // Constructor from a binary file
108 // ------------------------------
109 Eos_poly_newt::Eos_poly_newt(FILE* fich) : Eos_poly(fich) {}
110
111 // Constructor from a formatted file
112 // ---------------------------------
113 Eos_poly_newt::Eos_poly_newt(ifstream& fich) : Eos_poly(fich) {}
114
115
116 //--------------//
117 // Destructor //
118 //--------------//
119
120 Eos_poly_newt::~Eos_poly_newt(){
121
122 // does nothing
123
124 }
125 //--------------//
126 // Assignment //
127 //--------------//
128
129 void Eos_poly_newt::operator=(const Eos_poly_newt& eosi) {
130
131 set_name(eosi.name) ;
132
133 gam = eosi.gam ;
134 kap = eosi.kap ;
135 m_0 = eosi.m_0 ;
136
137 set_auxiliary() ;
138
139 }
140 //------------------------//
141 // Comparison operators //
142 //------------------------//
143
144 bool Eos_poly_newt::operator==(const Eos& eos_i) const {
145
146 bool resu = true ;
147
148 if ( eos_i.identify() != identify() ) {
149 cout << "The second EOS is not of type Eos_poly_newt !" << endl ;
150 resu = false ;
151 }
152 else{
153
154 const Eos_poly_newt& eos = dynamic_cast<const Eos_poly_newt&>( eos_i ) ;
155
156 if (eos.gam != gam) {
157 cout
158 << "The two Eos_poly_newt have different gamma : " << gam << " <-> "
159 << eos.gam << endl ;
160 resu = false ;
161 }
162
163 if (eos.kap != kap) {
164 cout
165 << "The two Eos_poly_newt have different kappa : " << kap << " <-> "
166 << eos.kap << endl ;
167 resu = false ;
168 }
169
170 if (eos.m_0 != m_0) {
171 cout
172 << "The two Eos_poly_newt have different m_0 : " << m_0 << " <-> "
173 << eos.m_0 << endl ;
174 resu = false ;
175 }
176
177 }
178
179 return resu ;
180
181 }
182
183 bool Eos_poly_newt::operator!=(const Eos& eos_i) const {
184
185 return !(operator==(eos_i)) ;
186
187 }
188
189
190 //------------//
191 // Outputs //
192 //------------//
193
194 void Eos_poly_newt::sauve(FILE* fich) const {
195
196 Eos_poly::sauve(fich) ;
197
198 }
199
200 ostream& Eos_poly_newt::operator>>(ostream & ost) const {
201
202 ost << "EOS of class Eos_poly_newt (Newtonian polytrope) : " << endl ;
203 ost << " Adiabatic index gamma : " << gam << endl ;
204 ost << " Pressure coefficient kappa : " << kap <<
205 " rho_nuc c^2 / n_nuc^gamma" << endl ;
206
207 return ost ;
208
209 }
210
211
212 //------------------------------//
213 // Computational routines //
214 //------------------------------//
215
216 // Baryon density from enthalpy
217 //------------------------------
218
219 double Eos_poly_newt::nbar_ent_p(double ent, const Param* ) const {
220
221 if ( ent > double(0) ) {
222
223 return pow( gam1sgamkap * ent, unsgam1 ) ;
224 }
225 else{
226 return 0 ;
227 }
228 }
229
230 // Energy density from enthalpy
231 //------------------------------
232
233 double Eos_poly_newt::ener_ent_p(double ent, const Param* ) const {
234
235 if ( ent > double(0) ) {
236
237 double nn = pow( gam1sgamkap * ent, unsgam1 ) ;
238
239 double pp = kap * pow( nn, gam ) ;
240
241 return unsgam1 * pp + m_0 * nn ;
242 }
243 else{
244 return 0 ;
245 }
246 }
247
248 // Pressure from enthalpy
249 //------------------------
250
251 double Eos_poly_newt::press_ent_p(double ent, const Param* ) const {
252
253 if ( ent > double(0) ) {
254
255 double nn = pow( gam1sgamkap * ent, unsgam1 ) ;
256
257 return kap * pow( nn, gam ) ;
258
259 }
260 else{
261 return 0 ;
262 }
263 }
264
265 // dln(n)/ln(h) from enthalpy
266 //---------------------------
267
268 double Eos_poly_newt::der_nbar_ent_p(double , const Param* ) const {
269
270 return double(1) / gam1 ;
271
272 }
273
274 // dln(e)/ln(h) from enthalpy
275 //---------------------------
276
277 double Eos_poly_newt::der_ener_ent_p(double ent, const Param* ) const {
278
279 if ( ent > double(0) ) {
280
281
282 double nn = pow( gam1sgamkap * ( exp(ent) - double(1) ),
283 unsgam1 ) ;
284
285 double pp = kap * pow( nn, gam ) ;
286
287 double ee = unsgam1 * pp + m_0 * nn ;
288
289
290 return ( double(1) + pp / ee) / gam1 ;
291
292 }
293 else{
294 return double(1) / gam1 ; // to ensure continuity at ent=0
295 }
296 }
297
298 // dln(p)/ln(h) from enthalpy
299 //---------------------------
300
301 double Eos_poly_newt::der_press_ent_p(double, const Param* ) const {
302
303 return gam / gam1 ;
304
305 }
306
307 }