Examples: $ python ch13_universe_model.py .35 .35 """ from __future__ import print_function, division from helpers import start_parameter from math import fabs, exp, sqrt, log, pow, log10, pi, sin, tan, cos print('Astrophysics with a PC : UNIVERSE MODEL') print('--------------------------------------------------------') print('') print('-------Minimal solution program--------') print('') print('Input of of the parameters : ') s = start_parameter('sigma(0) : ', 1) q = start_parameter('q(0) : ', 2) # this for omputes the past (era=0) and the future (era=1) for era in [0, 1]: x = .0 y = 1.0 z = 1.0 ctn = 1 print('') # select the time step if era == 0: dx = -.02 print('Computations for the past') else:
""" return -g * m * d / pow(r, 2) # some physical constants used in the program : g = 6.673e-8 m0 = 2e33 r0 = 6.96e10 a = 6.01e22 print('Astrophysics with a PC : WHITE DWARF') print('--------------------------------------------------------') print('') print('-------Minimal solution program--------') print('') print('Input of initial conditions and model parameters : ') rhc = start_parameter('Log10 of the central density : ', 1) drkm = start_parameter('Stepsize in km : ', 2) # central values of the physical variables rhoc = pow(10, rhc) dr = 100000.0 * drkm print('') m = .0 r = .0 xc = pow(rhoc / 1964000.0, 1 / 3.0) pc = a * f(xc) i = 0 # display heading of the table with the results print(' i r Mr log(P) log(rho) x')
""" q = .7104 - .1331 * exp(-3.4488 * tau) return teff * pow(.75 * (tau + q), .25) # some physical constants used in the program : g = 6.673e-8 a = 7.56464e-15 r = 8.314e7 print('Astrophysics with a PC : STELLAR MODEL') print('--------------------------------------------------------') print('') print('-------Minimal solution program--------') print('') print('Input of initial conditions and model parameters : ') teff = start_parameter('Effective temperature : ', 1) gs = start_parameter('Surface gravit.accel.(log10) : ', 2) mu = start_parameter('Average mean molecular weight : ', 3) gs = pow(10, gs) # displat heading of main table print('') print(' i tau T Pg Pr d k ge z(km)') # compute central value of physical quantities tau = .0 d = 1e-13 t = temp(tau, teff) pg = r * d * t / mu pr = radpress(t) kk = absorp(t, d)
""" return sqrt(pow(x + 1 - mu, 2) + pow(y, 2)) def vxy(x, y, mu): """evaluates potential energy fucntion V(x,y) at point (x,y) """ return (1 - mu) / r1(x, y, mu) + mu / r2(x, y, mu) + (pow(x, 2) + pow(y, 2)) / 2 print('Astrophysics with a PC : EQUIPOTENTIAL CURVES') print('--------------------------------------------------------') print('') print('-------Minimal solution program--------') print('') print('Input of initial conditions and parameters : ') print('') mu = start_parameter('Mass parameter mu : ', 1) x = start_parameter('Initial conditions : x(0) : ', 2) y = start_parameter(' y(0) : ', 3) k = vxy(x, y, mu) print('Potential constant K = {: 11.7f}'.format(k)) # Ask user in which direction to move drc = start_parameter('Enter 1 to compute Eq.curve as y(x), 2 to compute Eq.curve as x(y)', 4) if drc == '1': dx = start_parameter('stepsize dx = ', 5) else: dy = start_parameter('stepsize dy = ', 5) # here starts main cycle
Example: $ python ch02_comet_tails.py .5 .95 1 .03 """ from __future__ import print_function from helpers import start_parameter from math import cos, sin, sqrt, pi print('Astrophysics with a PC : COMET TAILS') print('------------------------------------') print('') print('-------Minimal solution program--------') print('') print('Input parameters and orbital elements : ') ap = start_parameter('Perihelion distance (A.U.) : ', 1) ecc = start_parameter('Eccentricity of the comet orbit : ', 2) mu = start_parameter('Parameter 1 - mu : ', 3) g = start_parameter('Outflow velocity : ', 4) p = ap * (1 + ecc) # (4) for i in range(-4, 5): # this for-loop considers 9 positions of the comet in its orbit # CLS # Compute position of the nucleus and parameters A1, A2 and A3 nu = 0.5 * i r = p / (1 + ecc * cos(nu)) # (6) x = r * cos(nu) # (7) y = r * sin(nu) # (8) a1 = (sqrt(2) / sqrt(mu)) * r # (13a)
def vxy(x, y, mu): """evaluates potential energy fucntion V(x,y) at point (x,y) """ return (1 - mu) / r1(x, y, mu) + mu / r2(x, y, mu) + (pow(x, 2) + pow(y, 2)) / 2 print('Astrophysics with a PC : EQUIPOTENTIAL CURVES') print('--------------------------------------------------------') print('') print('-------Minimal solution program--------') print('') print('Input of initial conditions and parameters : ') print('') mu = start_parameter('Mass parameter mu : ', 1) x = start_parameter('Initial conditions : x(0) : ', 2) y = start_parameter(' y(0) : ', 3) k = vxy(x, y, mu) print('Potential constant K = {: 11.7f}'.format(k)) # Ask user in which direction to move drc = start_parameter( 'Enter 1 to compute Eq.curve as y(x), 2 to compute Eq.curve as x(y)', 4) if drc == '1': dx = start_parameter('stepsize dx = ', 5) else: dy = start_parameter('stepsize dy = ', 5)
q = .7104 - .1331 * exp(-3.4488 * tau) return teff * pow(.75 * (tau + q), .25) # some physical constants used in the program : g = 6.673e-8 a = 7.56464e-15 r = 8.314e7 print('Astrophysics with a PC : STELLAR MODEL') print('--------------------------------------------------------') print('') print('-------Minimal solution program--------') print('') print('Input of initial conditions and model parameters : ') teff = start_parameter('Effective temperature : ', 1) gs = start_parameter('Surface gravit.accel.(log10) : ', 2) mu = start_parameter('Average mean molecular weight : ', 3) gs = pow(10, gs) # displat heading of main table print('') print( ' i tau T Pg Pr d k ge z(km)' ) # compute central value of physical quantities tau = .0 d = 1e-13 t = temp(tau, teff) pg = r * d * t / mu
Examples: $ python ch07_polytropes.py 1.5 .05 2 3 """ from __future__ import print_function, division from helpers import start_parameter from math import fabs, exp, sqrt, log, pow, log10 print('Astrophysics with a PC : POLYTROPES') print('--------------------------------------------------------') print('') print('-------Minimal solution program--------') print('') print('Input of initial conditions and parameters : ') n = start_parameter('polytrope index : ', 1) dr = start_parameter('stepsize : ', 2) mass = start_parameter('mass : ', 3) rad = start_parameter('radius : ', 4) # show heading of main table of results on screen print(' i x = r/rn f h log(P/Pc) log(d/dC) l*mr') # compute polytrope results in center of the star x = 0 f = 1 h = 0 i = 0 p = pow(f, n + 1) d = pow(f, n) m = -x * x * h
fz1 = fz3 # multiple the two integrals with the other factors of the equations # of motion kr = -4 * pi * sqrt(1 - e * e) / pow(e, 3) * dc * r * k1 kz = -4 * pi * sqrt(1 - e * e) / pow(e, 3) * dc * z * k2 return [r, z, e, fe, a0, dc, kr, kz] print('Astrophysics with a PC : INDIVIDUAL STELLAR ORBITS') print('--------------------------------------------------------') print('') print('-------Minimal solution program--------') print('') print('Input of initial conditions and parameters : ') r = start_parameter('Initial conditions : r(0) : ', 1) z = start_parameter('Initial conditions : z(0) : ', 2) u = start_parameter('Initial conditions : u(0) : ', 3) v = start_parameter('Initial conditions : v(0) : ', 4) vt0 = start_parameter('Initial conditions : vt(0) : ', 5) # initialize galaxy model parameters dt = .001 e = .99 dc = 11613.5 a0 = 2.8 fe = 1.4292567 # initialize main cycle h = r * vt0 past = 0
for the components of the velocity for input values of x,y,u and v, and mu """ r1 = sqrt((x - mu) * (x - mu) + y * y) r2 = sqrt((x + 1 - mu) * (x + 1 - mu) + y * y) fu = -(1 - mu) * (x - mu) / r1**3 - mu * (x + 1 - mu) / r2**3 + x + 2 * v fv = -(1 - mu) * y / r1**3 - mu * y / r2**3 + y - 2 * u return [fu, fv] print('Astrophysics with a PC : RESTRICTED THREEBODY PROBLEM') print('--------------------------------------------------------') print('') print('-------Minimal solution program--------') print('') print('Input of initial conditions and parameters : ') print('') mu = start_parameter('Mass parameter mu : ', 1) x = start_parameter('Initial conditions : x(0) : ', 2) y = start_parameter(' y(0) : ', 3) u = start_parameter(' u(0) : ', 4) v = start_parameter(' v(0) : ', 5) dt = start_parameter('Time step : ', 6) t = dt n = 20 ni = 1 ch = '' while ch == '': print(' i t x y u v') print('')
fx = u fy = v s = sqrt(pow(u, 2) + pow(v, 2)) rho = datm(y) fu = -k1 * rho * s * u * exp(-1 / 3.0 * log(m)) fv = -k1 * rho * s * v * exp(-1 / 3.0 * log(m)) - 980 fm = -k2 * rho * pow(s, 3) * exp(2 / 3.0 * log(m)) return [fx, fy, fu, fv, fm, s] print('Astrophysics with a PC : METEOR') print('------------------------------------') print('') print('-------Minimal solution program--------') print('') print('Input of initial conditions and parameters : ') y = start_parameter('Initial height (km) : ', 1) u = start_parameter('Initial horizontal speed (km/s) : ', 2) v = start_parameter('Initial vertical speed (km/s) : ', 3) m = start_parameter('Initial mass (gram) : ', 4) k1 = start_parameter('Parameter K1 : ', 5) k2 = start_parameter('Parameter K2 : ', 6) tau = start_parameter('Parameter tau : ', 7) # transform input data x, y, u and v from km to cm # and make sure that y is negative y = y * 100000.0 x = .0 u = u * 100000.0 v = -1 * fabs(v * 100000.0) minit = m t = .0
return -g * m * d / pow(r, 2) # some physical constants used in the program : g = 6.673e-8 m0 = 2e33 r0 = 6.96e10 a = 6.01e22 print('Astrophysics with a PC : WHITE DWARF') print('--------------------------------------------------------') print('') print('-------Minimal solution program--------') print('') print('Input of initial conditions and model parameters : ') rhc = start_parameter('Log10 of the central density : ', 1) drkm = start_parameter('Stepsize in km : ', 2) # central values of the physical variables rhoc = pow(10, rhc) dr = 100000.0 * drkm print('') m = .0 r = .0 xc = pow(rhoc / 1964000.0, 1 / 3.0) pc = a * f(xc) i = 0 # display heading of the table with the results print(' i r Mr log(P) log(rho) x')
Examples: $ python ch06_dynamical_parallax.py 78.8 17.6 .3 1.7 .06 .3 """ from __future__ import print_function, division from helpers import start_parameter from math import fabs, exp, sqrt, log, pow print('Astrophysics with a PC : DYNAMICAL PARALLAX') print('--------------------------------------------------------') print('') print('-------Minimal solution program--------') print('') print('Input of the observed data : ') p = start_parameter('Orbital period (years) : ', 1) a = start_parameter('Apparent distance (arc seconds) : ', 2) mv1 = start_parameter('Apparent magnitude of first component : ', 3) mv2 = start_parameter('Apparent magnitude of second component : ', 4) bc1 = start_parameter('Bolometric magnitude of first component : ', 5) bc2 = start_parameter('Bolometric magnitude of second component : ', 6) print('') print(' i m1 m2 dist par Mb1 Mb2') eps = .01 # pre-defined constant in text # select starting values for the two masses m1 = 1.0 m2 = 1.0 stopcrit = 0 i = 1
variables a (atomic fraction) and m (molecular fraction) """ fa = 1 - a - m - k1 * pow(m, 2) * a if m > .0: fm = k1 * pow(m, 2) * a + k2 * (a - 1 + m) * pow(m, n) else: fm = 0 return [fa, fm] print('Astrophysics with a PC : GALACTIC STAR FORMATION') print('--------------------------------------------------------') print('') print('-------Minimal solution program--------') print('') print('Input of initial conditions and parameters : ') m = start_parameter('Initial fraction of molecular clouds : ', 1) a = start_parameter('Initial fraction of atomic gas : ', 2) n = start_parameter('Parameter n : ', 3) k1 = start_parameter('Parameter k1 : ', 4) k2 = start_parameter('Parameter k2 : ', 5) print('') s = 1 - a - m dx = .02 # heading of main cycle print(' i x a m s') # prepare for main cycle x = 0 ni = 1
""" r1 = sqrt((x - mu) * (x - mu) + y * y) r2 = sqrt((x + 1 - mu) * (x + 1 - mu) + y * y) fu = -(1 - mu) * (x - mu) / r1**3 - mu * (x + 1 - mu) / r2**3 + x + 2 * v fv = -(1 - mu) * y / r1**3 - mu * y / r2**3 + y - 2 * u return [fu, fv] print('Astrophysics with a PC : RESTRICTED THREEBODY PROBLEM') print('--------------------------------------------------------') print('') print('-------Minimal solution program--------') print('') print('Input of initial conditions and parameters : ') print('') mu = start_parameter('Mass parameter mu : ', 1) x = start_parameter('Initial conditions : x(0) : ', 2) y = start_parameter(' y(0) : ', 3) u = start_parameter(' u(0) : ', 4) v = start_parameter(' v(0) : ', 5) dt = start_parameter('Time step : ', 6) t = dt n = 20 ni = 1 ch = '' while ch == '': print(' i t x y u v') print('')
""" fa = 1 - a - m - k1 * pow(m, 2) * a if m > .0: fm = k1 * pow(m, 2) * a + k2 * (a - 1 + m) * pow(m, n) else: fm = 0 return [fa, fm] print('Astrophysics with a PC : GALACTIC STAR FORMATION') print('--------------------------------------------------------') print('') print('-------Minimal solution program--------') print('') print('Input of initial conditions and parameters : ') m = start_parameter('Initial fraction of molecular clouds : ', 1) a = start_parameter('Initial fraction of atomic gas : ', 2) n = start_parameter('Parameter n : ', 3) k1 = start_parameter('Parameter k1 : ', 4) k2 = start_parameter('Parameter k2 : ', 5) print('') s = 1 - a - m dx = .02 # heading of main cycle print(' i x a m s') # prepare for main cycle x = 0 ni = 1
a = 7.56464e-15 rgas = 8.314e7 xx = .7 yy = .27 zz = .03 mu = .618238 m0 = 2e33 r0 = 6.96e10 l0 = 3.83e33 print('Astrophysics with a PC : STELLAR MODEL') print('--------------------------------------------------------') print('') print('-------Minimal solution program--------') print('') mtot = start_parameter( 'Input parameter : Approximation of total mass (2 - 15) : ', 1) print('') # show heading of main table print( 'i Mr/Mo log(p) log(T) log(d) r/r0 log(E) log(L) x f h' ) w = log10(mtot) # central values of temperature and density tc = 7.23937 + .2724354 * w - .0401771 * w * w tc = pow(10, tc) dc = 2.27899 - 1.658707 * w + .29329095 * w * w dc = pow(10, dc)
# multiple the two integrals with the other factors of the equations # of motion kr = -4 * pi * sqrt(1 - e * e) / pow(e, 3) * dc * r * k1 kz = -4 * pi * sqrt(1 - e * e) / pow(e, 3) * dc * z * k2 return [r, z, e, fe, a0, dc, kr, kz] print('Astrophysics with a PC : INDIVIDUAL STELLAR ORBITS') print('--------------------------------------------------------') print('') print('-------Minimal solution program--------') print('') print('Input of initial conditions and parameters : ') r = start_parameter('Initial conditions : r(0) : ', 1) z = start_parameter('Initial conditions : z(0) : ', 2) u = start_parameter('Initial conditions : u(0) : ', 3) v = start_parameter('Initial conditions : v(0) : ', 4) vt0 = start_parameter('Initial conditions : vt(0) : ', 5) # initialize galaxy model parameters dt = .001 e = .99 dc = 11613.5 a0 = 2.8 fe = 1.4292567 # initialize main cycle h = r * vt0 past = 0
fy = v s = sqrt(pow(u, 2) + pow(v, 2)) rho = datm(y) fu = -k1 * rho * s * u * exp(-1 / 3.0 * log(m)) fv = -k1 * rho * s * v * exp(-1 / 3.0 * log(m)) - 980 fm = -k2 * rho * pow(s, 3) * exp(2 / 3.0 * log(m)) return [fx, fy, fu, fv, fm, s] print('Astrophysics with a PC : METEOR') print('------------------------------------') print('') print('-------Minimal solution program--------') print('') print('Input of initial conditions and parameters : ') y = start_parameter('Initial height (km) : ', 1) u = start_parameter('Initial horizontal speed (km/s) : ', 2) v = start_parameter('Initial vertical speed (km/s) : ', 3) m = start_parameter('Initial mass (gram) : ', 4) k1 = start_parameter('Parameter K1 : ', 5) k2 = start_parameter('Parameter K2 : ', 6) tau = start_parameter('Parameter tau : ', 7) # transform input data x, y, u and v from km to cm # and make sure that y is negative y = y * 100000.0 x = .0 u = u * 100000.0 v = -1 * fabs(v * 100000.0) minit = m t = .0