Debian Codegraph @

src/exact_Cshock.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-2014 Daniel Price. All rights reserved.
19 ! Contact: [email protected]
20 !
21 !-----------------------------------------------------------------
22
23 ! ----------------------------------------------------------------------
24 ! Plot exact solution for a magnetohydrodynamic oblique C-shock
25 ! (ie. one dimensional MHD shock problem with ambipolar diffusion)
26 !
27 ! Solution from Mac-Low, Norman, Konigl & Wardle (1995), ApJ 442, 726
28 ! http://adsabs.harvard.edu/abs/1995ApJ...442..726M
29 !
30 ! ----------------------------------------------------------------------
31 module Cshock
32 implicit none
33 public :: exact_Cshock
34
35 contains
36
37 subroutine exact_Cshock(iplot,time,gamma,machs,macha,xmin,xmax,xpts,ypts,ierr)
38 integer, intent(in) :: iplot
39 integer, intent(out) :: ierr
40 real, intent(in) :: time,gamma,machs,macha,xmin,xmax
41 real, dimension(:), intent(inout) :: xpts
42 real, dimension(size(xpts)), intent(out) :: ypts
43 real, dimension(size(xpts)) :: D
44 real, parameter :: pi = 3.1415926536
45 real :: theta,xshock,ambi_gamma,ambi_rhoi,vx0,vy0,Bx,By,rhon_pre
46 real :: cs,rhon0,Bfield0,b0,shockl,vs,va,K1,K2,By_post,P_post,rhon_post,By0,Pr0
47 real :: sintheta,costheta,vx2,vx,vy,rhon,dvx,vxin
48 integer :: npts,i
49 logical printout
50
51 printout = .false.
52 npts = size(xpts)
53 theta = pi/4.
54 costheta = cos(theta)
55 sintheta = sin(theta)
56 D(npts) = 1. + 1.e-6 ! upstream
57 cs = 0.1
58 rhon0 = 1.
59 Bfield0 = 1. ! this gives Bx0 = By0 = 1/sqrt(2) as in Choi et al. (2009)
60 ambi_gamma = 1.
61 ambi_rhoi = 1.e-5
62 b0 = sintheta
63 shockl = Bfield0/(ambi_gamma*ambi_rhoi*sqrt(rhon0))
64 va = Bfield0/sqrt(rhon0)
65 xshock = 6./8.*va*time
66
67 if ( printout ) open(unit = 625,file="Cshock_splash.dat")
68
69
70 print "(4(a,g10.2))",&
71 ' Plotting exact C-shock at t = ',time,' M = ',machs,' M_A = ',macha,' theta = ',theta
72 print "(4(a,es10.3))",' shock length L = ',shockL,' shock is at x = ',xshock
73
74 call integrate(xmin,xmax,xshock,xpts,macha,machs,theta,shockl,D,npts)
75
76 !
77 ! compute velocity jump across shock: See Mac-Low et al. (1995). This is the difference
78 ! in the velocity across the shock front since we assume that the
79 ! post-shock gas is at rest
80 !
81 ! !--post-shock, assume vx = 0
82 By_post = Bfield0*get_b(b0,macha,machs,D(1))
83 rhon_post = D(1)*rhon0
84 P_post = rhon_post*cs**2
85 ! K1 = P_post + 0.5*By_post*By_post
86 ! print*,' K1 is ',K1
87
88 !--pre-shock
89 vx0 = -5.0
90 vxin = -4.45
91 dvx = vxin-vx0
92 vy0 = 0.
93 Bx = Bfield0*costheta
94 By0 = Bfield0*get_b(b0,macha,machs,D(npts))
95 rhon_pre = D(npts)*rhon0
96 Pr0 = rhon_pre*cs**2
97 K1 = Pr0 + 0.5*By0*By0 + rhon_pre*vx0**2
98 K2 = rhon_pre*vx0*vy0 - Bx*By0
99
100 vx2 = (K1 - 0.5*By_post**2 - P_post)/rhon_post
101 if (vx2 > 0.) then
102 vx = -sqrt(vx2)
103 print "(1x,a,g10.3)",'vx post-shock = ',vx
104 else
105 vx = 0.
106 print*,'error, post-shock vx is imaginary'
107 endif
108 vs = vx0 - vx
109 !print*,'vs = ',vs
110 !
111 !--determine which parameter to plot
112 !
113 do i=1,npts
114 rhon = D(i)*rhon0
115 By = Bfield0*get_b(b0,macha,machs,D(i))
116 vx2 = (K1 - 0.5*By**2 - rhon*cs**2)/rhon
117 if (vx2 > epsilon(vx2)) then
118 vx = -sqrt(vx2)
119 vy = (K2 + Bx*By)/(rhon*vx)
120 else
121 vx = 0.
122 vy = 0.
123 endif
124 vx = vx + dvx
125
126 select case(iplot)
127 case(1)
128 ypts(i) = rhon ! rho (neutrals)
129 case(2)
130 ypts(i) = By
131 case(3) ! vx (neutrals)
132 ypts(i) = vx
133 case(4) ! vy (neutrals)
134 ypts(i) = vy
135 case(5) ! Bx
136 ypts(i) = Bx
137 case default
138 ypts(i) = 0.
139 end select
140 if ( printout ) write(625,*) i,xpts(i),rhon,Bx,By,vx,vy
141 enddo
142 ierr = 0
143
144 if ( printout ) close(625)
145 return
146 end subroutine exact_Cshock
147
148 real function rhs(D,macha,machs,theta,shockl)
149 real, intent(in) :: D,macha,machs,theta,shockl
150 real :: term,sintheta,costheta2,b0,b
151
152 term = (1./D**2 - 1./machs**2)*shockl
153
154 sintheta = sin(theta)
155 costheta2 = cos(theta)**2
156 b0 = sintheta
157 b = get_b(b0,macha,machs,D)
158
159 rhs = b/macha*(b - D*((b - b0)/macha**2*costheta2 + sintheta))/(b**2 + costheta2)/term
160
161 end function rhs
162
163 real function get_b(b0,macha,machs,D)
164 real, intent(in) :: b0,macha,machs,D
165
166 get_b = sqrt(b0**2 + 2.*macha**2*(D-1.)*(1./D - 1./machs**2))
167
168 end function get_b
169
170 subroutine integrate(xmin,xmax,xshock,xpts,macha,machs,theta,shockl,D,npts)
171 integer, intent(in) :: npts
172 real, intent(in) :: xmin,xmax,xshock,macha,machs,theta,shockl
173 real, dimension(npts), intent(inout) :: xpts
174 real, dimension(npts), intent(inout) :: D
175 real :: Dhalf,dx,xminshock
176 integer :: i
177
178 !
179 ! set up grid to have good resolution around the shock
180 ! and just two points extending to xmin and xmax
181 !
182 xminshock = min(xshock - 100.*shockl,xmin)
183 dx = (xshock - xminshock)/real(npts-1)
184 xpts(npts) = xmax
185 xpts(1) = xmin
186 do i=2,npts-1
187 xpts(i) = xmin + (i-1)*dx
188 enddo
189
190 do i=npts-1,1,-1
191 if (xpts(i) > xshock) then
192 D(i) = D(i+1)
193 else
194 !--mid-point rule
195 Dhalf = D(i+1) - 0.5*dx*rhs(D(i+1),macha,machs,theta,-shockl)
196 D(i) = D(i+1) - dx*rhs(Dhalf,macha,machs,theta,-shockl)
197 endif
198 enddo
199
200 end subroutine integrate
201
202 end module Cshock