Blog: Erini's Update 4/16/2013: LE_module.txt

File LE_module.txt, 2.3 KB (added by Erini Lambrides, 12 years ago)
Line 
1
2Module LE_module
3
4USE DataDeclarations
5USE GlobalDeclarations
6USE PhysicalDeclarations
7
8Implicit None
9
10Private
11
12real xi, dtheta, poly_index, theta, xlast, dxdtlast,k1,k2,k3,k4,h,f,xi_last,dtheta_last,theta_last,dtheta1
13
14PUBLIC CalcParams,LE_params,
15
16CONTAINS
17
18Subroutine CalcParams(R_star,M_star,poly_index,h,rho_cent,xi_last,dtheta1,K,a_scale,p_cent,rho_profile)
19
20!requires a user input star/clump radius, a polytropic index, and a central density and integration length h
21!and calculated xi_last (root), and corresponding dtheta/dxi
22!outputs scaling constant a, mass of star/clump,gas constant K, and central Pressue
23
24Real(Kind=qPrec) :: R_star,M_star,rho_new,h,poly_index,rho_cent,xi_last,dtheta1,K,a_scale,rho_profile
25Real:: xi_last
26
27a_scale=xi_last/R_star
28
29M_star=4*pi*rho_cent*(R_star**3)*(-1/xi_last)*(dtheta1)
30
31K=4*pi*G/((poly_index+1)(a_scale**2))*rho_cent**((poly_index-1)/poly_index)
32
33p_cent=K*rho_cent**(1+1/poly_index)
34
35rho_profile=rho_cent*theta**poly_index
36
37end subroutine calcparams
38
39!initial conditions
40numsteps=0
41theta=1-(xi**2.0)/6.0+(poly_index/120.0)*(xi**4.0)-(8.0*poly_index**2.0-5.0*poly_index)/(15120.0)*(xi**5.0)
42dtheta=-xi/3.0+(poly_index/30.0)*(xi**3.0)-(8.0*poly_index**2.0-5.0*poly_index)/(2520.0)*(xi**5.0)
43
44Function LE_params(xi,dtheta,poly_index,theta,xi_last,dtheta1,dtheta_last,theta_last)
45Real:: LE_rho,xi,xi, dtheta, poly_index, theta,k1,k2,k3,k4,h,f,xi_last,dtheta_last,theta_last,dtheta1
46do while(theta.ge.0)
47xi=xi+h
48theta=theta+h*dtheta
49!calculating the runge kutta
50
51 k1=h*f(poly_index,xi,theta,dtheta)
52 k2=h*f(poly_index,xi+h/2.0,theta+k1/2.0,dtheta)
53 k3=h*f(poly_index,xi+h/2.0,theta+k2/2.0,dtheta)
54 k4=h*f(poly_index,xi+h,theta+k3,dtheta)
55
56dtheta=dtheta+(k1+2.0*k2+2.0*k3+k4)/6.0
57
58theta_last=theta
59dtheta_last=dtheta
60enddo
61
62print*,'final value for xi',xi
63print*,'final value for theta',theta
64print*,'final value for dtheta/dphi',dtheta
65
66!final conditions (for root)
67xi = xi + (theta/(theta_last-theta))*h
68dtheta1 = dtheta - (xi-xi_last)*(dtheta-dtheta_last)/h
69
70 write(unit=6,FMT=*) 'first root of phi at xi=',xi_last
71 write(unit=6,FMT=*) 'at this point dtheta/dt = ',dtheta1
72end
73
74
75!function f calculate the second order dtheta
76
77real function f(poly_index,xi,theta,dtheta)
78implicit none
79real poly_index,xi,theta,dtheta
80f=-theta**poly_index-2.0*dtheta/xi
81return
82end