Debian Codegraph @

src/exact_sedov.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-2015 Daniel Price. All rights reserved.
19 ! Contact: [email protected]
20 !
21 !-----------------------------------------------------------------
22
23 !---------------------------------------------------------------------------
24 ! compute exact solution for Sedov-type point-like energy injection
25 ! the solution is correct for 3D, I have attempted to fix it in 1D & 2D but
26 ! not working yet.
27 !---------------------------------------------------------------------------
28 module sedov
29 implicit none
30 public :: exact_sedov
31 private :: etau,rhou,pru,dudlneta,eta0
32
33 contains
34
35 subroutine exact_sedov(iplot,time,gam,rhozero,energy,rmax,rplot,yplot,ierr)
36 integer, intent(in) :: iplot
37 integer, intent(out) :: ierr
38 real, intent(in) :: time, gam, rhozero, energy, rmax
39 real, dimension(:), intent(inout) :: rplot
40 real, dimension(size(rplot)), intent(out) :: yplot
41
42 integer, parameter :: ndim = 3
43 integer :: npts
44 real, parameter :: pi = 3.1415926536
45 real :: rshock, dr
46 real :: rhoshock, ushock, prshock
47 real :: eta_0, power
48 real :: ubar,ubarzero,dubar
49 real :: phi,dphi
50 integer :: i,ishock
51
52 ierr = 0
53 print*,' Plotting 3D Sedov similarity solution at t = ',time
54 print*,' rhozero = ',rhozero,' energy = ',energy, ' rmax = ',rmax
55 if (abs(time) < 1.e-10) then
56 print*,'nothing at t=0, returning'
57 ierr = 1
58 return
59 endif
60
61 npts = size(rplot)
62 eta_0 = eta0(gam,ndim)
63 print*,' eta0 = ',eta_0, ' gamma = ',gam
64
65 power = 1./(ndim+2)
66 dr = rmax/float(npts-1)
67 !
68 !--calculate radius and velocity of shock from dimensional analysis
69 !
70 rshock = eta_0*(energy*time**2./rhozero)**power
71 !! ushock = 2.*power*eta_0*((energy*time**2./rhozero)**(power-1.))*energy*time/rhozero
72 ushock = 2.*power*rshock/time
73 print*,' rshock = ',rshock, ' ushock = ',ushock
74 !
75 !--on x-y plots plot a circle at radius rshock
76 !
77 if (iplot==0) then
78 dphi = 2.*pi/real(npts-1)
79 phi = 0.
80 do i=1,npts
81 phi = (i-1)*dphi
82 rplot(i) = rshock*cos(phi)
83 yplot(i) = rshock*sin(phi)
84 enddo
85 return
86 endif
87 !
88 !--jump conditions to find states behind shock
89 !
90 rhoshock = rhozero*(gam+1.)/(gam-1.)
91 prshock = 2./(gam+1.)*rhoshock*ushock**2
92
93 rplot(1) = 0.0
94 select case(iplot)
95 case(2)
96 yplot(1) = 0.0 ! shouldn't be zero for pressure
97 case default
98 yplot(1) = 0.0
99 end select
100
101 ishock = INT((rshock - rplot(1))/dr)
102
103 if (ishock > 0) then
104 ishock = min(ishock,npts)
105 !
106 !--the solution for rho is given as a function of ubar (dimensionless velocity)
107 ! ubar varies from (gamma+1)/2*gamma at eta = 0 to 1 at eta = 1
108 ! (eta is the dimensionless radius eta = r/rshock, so eta=1 is the shock position)
109 !
110 ubarzero = 0.5*(gam+1.)/gam
111 dubar = (1.0 - ubarzero)/REAL(ishock-1) ! need to check the denominator
112 !
113 !--solution behind shock front (similarity solution)
114 ! (I really want to start from ubar = ubarzero, but am having problems)
115 !
116 do i=2,ishock
117
118 ubar = ubarzero + (i-1)*dubar ! again need to check this
119 rplot(i) = etau(ubar,gam,ndim)*rshock
120
121 select case(iplot)
122 case(1) ! rho
123 yplot(i) = rhoshock*rhou(ubar,gam)
124 case(2) ! pr
125 yplot(i) = prshock*(rplot(i)/rshock)**2*pru(ubar,gam)
126 case(3) ! utherm
127 yplot(i) = prshock*(rplot(i)/rshock)**2*pru(ubar,gam)/ &
128 ((gam-1.)*rhoshock*rhou(ubar,gam))
129 case(4) ! 1/2 v^2
130 yplot(i) = 0.5*(4./(5.*(gam+1.))*rplot(i)/time*ubar)**2
131 case(5)
132 yplot(i) = (4./(5.*(gam+1.))*rplot(i)/time*ubar)
133 end select
134 !print*,'u,r, rho = ',ubar,rplot(i),rhoplot(i)
135
136 enddo
137
138 endif
139 !
140 !--solution ahead of shock front
141 !
142 ishock = max(ishock,1)
143 if (ishock < npts) then
144 do i=ishock,npts
145 rplot(i) = rshock + (i-ishock)*dr
146 select case(iplot)
147 case(1) ! rho
148 yplot(i) = rhozero
149 case default ! pr,utherm,v
150 yplot(i) = 0.
151 end select
152 enddo
153 endif
154
155 return
156 end subroutine exact_sedov
157
158 !
159 !--eta (dimensionless radius) as a function of u_bar (dimensionless velocity)
160 !
161 real function etau(u,gamma,ndim)
162 integer, intent(in) :: ndim
163 real, intent(in) :: u,gamma
164 real :: gam1,term1,term2,power1,power2
165 gam1 = gamma-1.
166 power1 = (-12.+7.*gamma-13.*gamma**2)/(5.*(-1.+gamma+6.*gamma**2))
167 power2 = gam1/(1.+2.*gamma)
168 term1 = ((5.+5.*gamma+2.*u-6.*gamma*u)/(7.-gamma))**power1
169 term2 = ((2.*gamma*u-gamma-1.)/gam1)**power2
170
171 etau = u**(-2./(ndim+2.))*term1*term2
172 end function etau
173
174 !
175 !--rhobar (dimensionless density) as a function of u_bar (dimensionless velocity)
176 !
177 real function rhou(u,gamma)
178 real, intent(in) :: u,gamma
179 real :: gam1,power1,power2,power3,term1,term2,term3
180
181 gam1 = gamma-1.
182 power1 = (2./(gamma-2.))
183 power2 = -(12.-7.*gamma+13.*gamma**2)/(2.-3.*gamma-11.*gamma**2+6.*gamma**3)
184 power3 = 3./(1.+2.*gamma)
185 term1 = ((1.+ gamma - 2.*u)/gam1)**power1
186 term2 = ((5.+5.*gamma+2.*u-6.*gamma*u)/(7.-gamma))**power2
187 term3 = ((2.*gamma*u - gamma -1.)/gam1)**power3
188
189 rhou = term1*term2*term3
190
191 end function rhou
192 !
193 !--prbar (dimensionless pressure) as a function of u_bar (dimensionless velocity)
194 !
195 real function pru(u,gamma)
196 real, intent(in) :: u,gamma
197
198 pru = (gamma+1. - 2.*u)/(2.*gamma*u - gamma - 1.)*u**2*rhou(u,gamma)
199
200 end function pru
201 !
202 !--du /dln eta - required for the integral to compute eta0
203 !
204 real function dudlneta(u,gamma)
205 real, intent(in) :: u,gamma
206 real :: term1,term2
207
208 term1 = u*(5.+5.*gamma + 2.*u - 6.*gamma*u)*(-1.-gamma+2.*gamma*u)
209 term2 = 2.*(1.+gamma)*(1.+gamma - 2.*u - 2.*gamma*u + 2.*gamma*u**2)
210
211 dudlneta = term1/term2
212
213 end function dudlneta
214
215 !
216 !--eta_0 as a function of gamma
217 !
218 real function eta0(gamma,ndim)
219 integer, parameter :: ipts = 50000
220 real, parameter :: pi = 3.1415926536
221 integer, intent(in) :: ndim
222 real, intent(in) :: gamma
223 integer :: i
224 real :: u0, u, du
225 real :: sum, term, weight, factor
226
227 ! if (abs(gamma-5./3.) < 1.e-3) then
228 ! eta0 = 1.1517
229 ! else
230 ! print*,'warning: don''t know eta0: integral not implemented'
231 ! eta0 = 1.0
232 ! endif
233
234 u0 = 0.5*(gamma+1.)/gamma
235 du = (1. - u0)/REAL(ipts)
236 !
237 !--integrate using Simpson's 1/3 rule
238 !
239 sum = 0.
240 do i=1,ipts
241 weight = 1.0
242 if (mod(i,2)==0) then
243 weight = 4./3.
244 else
245 weight = 2./3.
246 endif
247 if ((i==1).or.(i==ipts)) weight = 1./3.
248 u = u0 + i*du
249 term = (pru(u,gamma) + rhou(u,gamma)*u**2)*(etau(u,gamma,ndim)**(ndim+2))/dudlneta(u,gamma)
250 sum = sum + weight*du*term
251 enddo
252
253 if (ndim==3) then
254 factor = 4.*pi
255 elseif (ndim==2) then
256 factor = 2.*pi
257 else
258 factor = 1.
259 endif
260
261 eta0 = (factor*8.*sum/(25.*(gamma**2 - 1.)))**(-1./REAL(ndim+2))
262
263 end function eta0
264
265 end module sedov