@@ -293,6 +293,12 @@ def __init__(self, verbose=3):
293293 # This sets which method computes which quantity.
294294 self .__compute_methods = {'enuc_C12pg' :self .compute_enuc_C12pg , \
295295 'Hp' :self .compute_Hp , \
296+ 'nabla_rho' :self .compute_nabla_rho , \
297+ 'nabla_rho_ad' :self .compute_nabla_rho_ad , \
298+ 'prad' :self .compute_prad , \
299+ 'pgas_by_ptot' :self .compute_pgas_by_ptot , \
300+ 'g' :self .compute_g , \
301+ 'N2' :self .compute_N2 , \
296302 'm' :self .compute_m , \
297303 'mt' :self .compute_mt , \
298304 'r4rho2' :self .compute_r4rho2 , \
@@ -453,6 +459,98 @@ def compute_Hp(self, fname, num_type='ndump'):
453459 Hp = np .abs (cdiff (r ))/ (np .abs (cdiff (np .log (p ))) + 1e-100 )
454460 return Hp
455461
462+ def compute_nabla_rho (self , fname , num_type = 'ndump' ):
463+ if self .__isyprofile :
464+ rho = self .get ('Rho' , fname , num_type = num_type , resolution = 'l' )
465+ p = self .get ('P' , fname , num_type = num_type , resolution = 'l' )
466+
467+ if self .__isRprofSet :
468+ rho = self .get ('Rho0' , fname , num_type = num_type , resolution = 'l' ) + \
469+ self .get ('Rho1' , fname , num_type = num_type , resolution = 'l' )
470+ p = self .get ('P0' , fname , num_type = num_type , resolution = 'l' ) + \
471+ self .get ('P1' , fname , num_type = num_type , resolution = 'l' )
472+
473+ nabla_rho = cdiff (np .log (rho ))/ (cdiff (np .log (p )) + 1e-100 )
474+ return nabla_rho
475+
476+ def compute_nabla_rho_ad (self , fname , num_type = 'ndump' , radeos = True ):
477+ if radeos :
478+ beta = self .compute_pgas_by_ptot (fname , num_type = num_type )
479+ gamma3 = 1. + (2. / 3. )* (4. - 3. * beta )/ (8. - 7. * beta )
480+ gamma1 = beta + (4. - 3. * beta )* (gamma3 - 1. )
481+ nabla_rho_ad = 1. / gamma1
482+ else :
483+ if self .__isyprofile :
484+ r = self .get ('Y' , fname , num_type = num_type , resolution = 'l' )
485+
486+ if self .__isRprofSet :
487+ r = self .get ('R' , fname , num_type = num_type , resolution = 'l' )
488+
489+ nabla_rho_ad = (3. / 5. )* np .ones (len (r ))
490+
491+ return nabla_rho_ad
492+
493+ def compute_prad (self , fname , num_type = 'ndump' ):
494+ if self .__isyprofile :
495+ print ('compute_prad() not implemented for YProfile input.' )
496+ return None
497+
498+ if self .__isRprofSet :
499+ T9 = self .get ('T9' , fname , num_type = num_type , resolution = 'l' )
500+
501+ # rad_const = 7.56577e-15 erg/cm^3/K^4
502+ rad_const = 7.56577e-15 / 1e43 * (1e8 )** 3 * (1e9 )** 4
503+ prad = (rad_const / 3. )* T9 ** 4
504+ return prad
505+
506+ def compute_pgas_by_ptot (self , fname , num_type = 'ndump' ):
507+ if self .__isyprofile :
508+ print ('compute_pgas_by_ptot() not implemented for YProfile input.' )
509+ return None
510+
511+ if self .__isRprofSet :
512+ ptot = self .get ('P0' , fname , num_type = num_type , resolution = 'l' ) + \
513+ self .get ('P1' , fname , num_type = num_type , resolution = 'l' )
514+
515+ prad = self .compute_prad (fname , num_type = num_type )
516+ pgas = ptot - prad
517+ return pgas / ptot
518+
519+ def compute_g (self , fname , num_type = 'ndump' ):
520+ if self .__isyprofile :
521+ r = self .get ('Y' , fname , num_type = num_type , resolution = 'l' )
522+
523+ if self .__isRprofSet :
524+ r = self .get ('R' , fname , num_type = num_type , resolution = 'l' )
525+
526+ m = self .compute_m (fname , num_type = num_type )
527+ print ('WARNING: PPMtools.compute_m() integrates mass from r = 0.\n '
528+ 'This will not work for shell setups and wrong gravity will be returned.' )
529+
530+ # The unit of G in the code is 10^{-3} g cm^3 s^{-2}.
531+ G_code = ast .grav_const / 1e-3
532+ g = G_code * m / r ** 2
533+ return g
534+
535+ def compute_N2 (self , fname , num_type = 'ndump' , radeos = True ):
536+ if self .__isyprofile :
537+ if radeos :
538+ print ('radeos option not implemented for YProfile input.' )
539+ return None
540+ r = self .get ('Y' , fname , num_type = num_type , resolution = 'l' )
541+
542+ if self .__isRprofSet :
543+ r = self .get ('R' , fname , num_type = num_type , resolution = 'l' )
544+
545+ g = self .compute_g (fname , num_type = num_type )
546+ Hp = self .compute_Hp (fname , num_type = num_type )
547+ nabla_rho = self .compute_nabla_rho (fname , num_type = num_type )
548+ nabla_rho_ad = self .compute_nabla_rho_ad (fname , num_type = num_type ,
549+ radeos = radeos )
550+ N2 = (g / Hp )* (nabla_rho - nabla_rho_ad )
551+
552+ return N2
553+
456554 def compute_m (self , fname , num_type = 'ndump' ):
457555 if self .__isyprofile :
458556 r = self .get ('Y' , fname , num_type = num_type , resolution = 'l' )
0 commit comments