Debian Codegraph @

src/exact_torus.f90

raw
1 !-----------------------------------------------------------------
2 !
3 ! This file is (or was) part of SPLASH, a visualisation tool
4 ! for Smoothed Particle Hydrodynamics written by Daniel Price:
5 !
6 ! http://users.monash.edu.au/~dprice/splash
7 !
8 ! SPLASH comes with ABSOLUTELY NO WARRANTY.
9 ! This is free software; and you are welcome to redistribute
10 ! it under the terms of the GNU General Public License
11 ! (see LICENSE file for details) and the provision that
12 ! this notice remains intact. If you modify this file, please
13 ! note section 2a) of the GPLv2 states that:
14 !
15 ! a) You must cause the modified files to carry prominent notices
16 ! stating that you changed the files and the date of any change.
17 !
18 ! Copyright (C) 2005-2009 Daniel Price. All rights reserved.
19 ! Contact: [email protected]
20 !
21 !-----------------------------------------------------------------
22
23 ! ----------------------------------------------------------------------
24 ! Plots solution for equilibrium torus of Papaloizou & Pringle
25 ! strictly valid for the midplane only (uses spherical r)
26 !
27 ! Added by D. Price 16.1.06
28 ! ----------------------------------------------------------------------
29 module torus
30 implicit none
31
32 contains
33
34 subroutine exact_torus(iplot,itorus,Mstar,Rtorus,AA,distortion,gamma,xplot,yplot,ierr)
35 integer, intent(in) :: iplot,itorus
36 real, intent(in) :: Mstar,Rtorus,AA,gamma,distortion
37 real, intent(in), dimension(:) :: xplot
38 real, intent(out), dimension(size(xplot)) :: yplot
39 real :: term,densi,rxy
40 integer, intent(out) :: ierr
41 integer :: i,mytorus
42 real :: ra2
43 integer, parameter :: nu = 2
44 real, parameter :: atorus = 0.2, currj0 = 1.0
45 !
46 ! check for errors
47 !
48 ierr = 0
49 if (Mstar <= 0.) then
50 print*,'error: mass <= 0 in exact_torus'
51 ierr = 2
52 return
53 elseif (Rtorus < 0.) then
54 print*,'error: rtorus < 0 in exact_torus'
55 ierr = 3
56 return
57 endif
58
59 mytorus = 1
60 select case(mytorus)
61
62 !
63 !--Tokamak torus (in torus 'r' co-ordinate)
64 !
65 case(2)
66 if (nu <= 0 .or. (iplot < 4 .and. nu > 2)) then
67 print*,'error: solution not found for nu value in tokamak torus'
68 ierr = 5
69 return
70 endif
71 print*,' plotting tokamak torus'
72
73 do i=1,size(xplot)
74 ra2 = xplot(i)**2/atorus**2
75 if (nu==1) then
76 term = currj0**2*atorus**2*(1. - ra2)*(7.*ra2**2 - 23.*ra2 + 13.)/96.
77 elseif (nu==2) then
78 term = currj0**2*atorus**2*(47. - 12.*ra2**5 + 75.*ra2**4 - 200.*ra2**3 + 270.*ra2**2 - 180*ra2)/720.
79 endif
80 if (abs(ra2) < tiny(ra2)) print*,'rho0 = ',term
81
82 select case(iplot)
83 case(1)
84 !--density
85 yplot(i) = Mstar*term**gamma
86 case(2)
87 !--pressure
88 yplot(i) = term
89 case(3)
90 !--thermal energy
91 yplot(i) = term
92 case(4)
93 !--Btheta
94 if (xplot(i) > tiny(xplot(i))) then
95 yplot(i) = 0.5*currj0*atorus**2/(nu+1)* &
96 (1.-(1.-ra2)**(nu+1))/xplot(i)
97 else
98 yplot(i) = 0.
99 endif
100 case(5)
101 !--Jphi current
102 yplot(i) = currj0*(1. - ra2)**nu
103 end select
104 enddo
105 !
106 !--Papaloizou & Pringle equilibrium torus
107 !
108 case default
109 if ((gamma-1.) <= 1e-4) then
110 print*,'error: exact solution not valid for isothermal eos'
111 ierr = 4
112 return
113 endif
114
115 do i=1,size(xplot)
116 if (iplot /= 4) then
117 !--plot quantities vs spherical r (assume z = 0)
118 term = Mstar/(AA*Rtorus)*(gamma-1.)/gamma* &
119 (Rtorus/xplot(i) - 0.5*(Rtorus/xplot(i))**2 - 1./(2.*distortion))
120 else
121 !--plots with z (assume cyl r = Rtorus)
122 rxy = sqrt(Rtorus**2 + xplot(i)**2)
123 term = Mstar/(AA*Rtorus)*(gamma-1.)/gamma* &
124 (Rtorus/rxy - 0.5 - 1./(2.*distortion))
125 endif
126 if (term > tiny(term)) then
127 densi = term**(1./(gamma-1.))
128 else
129 densi = 0.
130 endif
131 select case(iplot)
132 case(1)
133 !--density
134 yplot(i) = densi
135 case(2,4)
136 !--pressure
137 yplot(i) = AA*densi**gamma
138 case(3)
139 !--thermal energy
140 yplot(i) = AA/(gamma-1.)*densi**(gamma-1.)
141 end select
142 enddo
143 end select
144 return
145 end subroutine exact_torus
146
147 end module torus