forked from AstroSnow/PIP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshock_tube_stab.f90
167 lines (154 loc) · 5.95 KB
/
shock_tube_stab.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
subroutine shock_tube_stab
use parameters,only:pi
use globalvar,only:ix,jx,kx,U_h,U_m,flag_bnd,col,beta,flag_b_stg,dtout,&
flag_mhd,flag_mpi,my_rank,flag_pip,gm,beta,tend,&
x,y,z,dx,dy,dz,n_fraction,debug_direction,debug_option
use scheme_rot,only:pv2cq_mhd,pv2cq_hd
use model_rot, only:set_coordinate,setcq
implicit none
double precision :: ro_h(1:ix,1:jx,1:kx),ro_m(1:ix,1:jx,1:kx)
double precision :: vx_h(1:ix,1:jx,1:kx),vx_m(1:ix,1:jx,1:kx)
double precision :: vy_h(1:ix,1:jx,1:kx),vy_m(1:ix,1:jx,1:kx)
double precision :: vz_h(1:ix,1:jx,1:kx),vz_m(1:ix,1:jx,1:kx)
double precision :: P_h (1:ix,1:jx,1:kx),P_m (1:ix,1:jx,1:kx)
double precision :: B_x (1:ix,1:jx,1:kx)
double precision :: B_y (1:ix,1:jx,1:kx)
double precision :: B_z (1:ix,1:jx,1:kx)
double precision ::mask(ix,jx,kx)
double precision ::v_para(ix,jx,kx),v_perp(ix,jx,kx)
double precision ::b_para(ix,jx,kx),b_perp(ix,jx,kx)
double precision ::v_b_para(ix,jx,kx),b_b_para(ix,jx,kx)
double precision ::v_theta(ix,jx,kx),v_phi(ix,jx,kx)
double precision ::b_theta(ix,jx,kx),b_phi(ix,jx,kx)
double precision f_n,f_p,f_p_n,f_p_p,start(3),end(3),B0
double precision theta_p,phi_p,tmp,v_L(8),v_R(8),wtr,wtrf
double precision mach,rcom,rpres,alf,ang, byrat,vyrat,vu,bxu,byu,rou,pru,vxu
double precision rorand1,rorand2
integer i,j,k,dpl
!set ionization fraction-----------------
if(flag_pip.eq.0) then
f_n=1.0d0
f_p=1.0d0
f_p_n=1.0d0
f_p_p=1.0d0
else
f_n=n_fraction
f_p=1.0d0-n_fraction
f_p_n=f_n/(f_n+2.0d0*f_p)
f_p_p=2.0d0*f_p/(f_n+2.0d0*f_p)
endif
!----------------------------------------
!Set coordinate (uniform grid)--------------------------
!!set lower and upper coordinate
start(1)=000.0d0 ;end(1)=600.d0!1200.0d0 !400.0d0/f_p
start(2)=0.0d0 ;end(2)=50.0d0
start(3)=-1.0d0 ;end(3)=1.0d0
call set_coordinate(start,end)
!---------------------------------------
!!default boundary condition----------------------
if (flag_bnd(1) .eq.-1) flag_bnd(1)=10
if (flag_bnd(2) .eq.-1) flag_bnd(2)=10
if (flag_bnd(3) .eq.-1) flag_bnd(3)=1
if (flag_bnd(4) .eq.-1) flag_bnd(4)=1
if (flag_bnd(5) .eq.-1) flag_bnd(5)=10
if (flag_bnd(6) .eq.-1) flag_bnd(6)=10
!-------------------------------------------------
!!!========================================================
!parameters---------------------
! B0=sqrt(2.0*gm/beta)
B0=1.0d0
!/sqrt(2.0)
!-------------------------
mask=spread(spread(pi*x,2,jx),3,kx)
phi_p=0.0d0
theta_p=pi/2.0d0
tmp=0.0
print*,'Parallel shock'
mach=2.d0
rcom=(gm+1.d0)*mach**2/(2.d0+(gm-1.d0)*mach**2)
rpres=1.d0+gm*mach**2*(1.d0-1.d0/rcom)
! v_l=(/rcom,rpres,10.0d0*sqrt(gm)/rcom+10.0d0*sqrt(gm),0.0d0,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(3)-v_l(3))*(1.0d0+tanh(mask(i,j,k)/wtr-wtrf))*0.5d0)
vx_m(i,j,k)=(v_l(3)+(v_r(3)-v_l(3))*(1.0d0+tanh(mask(i,j,k)/wtr-wtrf))*0.5d0)
vy_h(i,j,k)=(v_l(4)+(v_r(4)-v_l(4))*(1.0d0+tanh(mask(i,j,k)/wtr-wtrf))*0.5d0)
vy_m(i,j,k)=(v_l(4)+(v_r(4)-v_l(4))*(1.0d0+tanh(mask(i,j,k)/wtr-wtrf))*0.5d0)
vz_h(i,j,k)=(v_l(5)+(v_r(5)-v_l(5))*(1.0d0+tanh(mask(i,j,k)/wtr-wtrf))*0.5d0)
vz_m(i,j,k)=(v_l(5)+(v_r(5)-v_l(5))*(1.0d0+tanh(mask(i,j,k)/wtr-wtrf))*0.5d0)
b_para(i,j,k)=(v_l(6)+(v_r(6)-v_l(6))*(1.0d0+tanh(mask(i,j,k)/wtr-wtrf))*0.5d0)
b_perp(i,j,k)=(v_l(7)+(v_r(7)-v_l(7))*(1.0d0+tanh(mask(i,j,k)/wtr-wtrf))*0.5d0)
call srand(81728)
wtr=1.d0
! if ((x(i) .GE. 200.0d0) .AND. (x(i) .LE. 300.0d0)) then
! do dpl=1,10
! rorand1=rand()
! rorand2=rand()
! ro_m(i,j,k)=ro_m(i,j,k)+f_p*0.1d0*rorand1*&
! dsin((x(i)-200.0d0)*3.14d0/100.0d0)* dcos((y(j)-rorand2*50.d0)*3.14d0/50.0d0*2.d0*wtr)
! ro_h(i,j,k)=ro_h(i,j,k)+f_n*0.1d0*rorand1*&
! dsin((x(i)-200.0d0)*3.14d0/100.0d0)* dcos((y(j)-rorand2*50.d0)*3.14d0/50.0d0*2.d0*wtr)
! wtr=wtr+1.d0
! enddo
!
! endif
enddo;enddo;enddo
b_theta=b_perp*sin(tmp)
b_phi =b_perp*cos(tmp)
b_x=b_para*sin(theta_p)*cos(phi_p)+ &
b_theta*cos(theta_p)*cos(phi_p)-b_phi*sin(phi_p)
b_y=b_para*sin(theta_p)*sin(phi_p)+ &
b_theta*cos(theta_p)*sin(phi_p)+b_phi*cos(phi_p)
b_z=b_para*cos(theta_p)-b_theta*sin(theta_p)
!!!========================================================
!convert PV2cq and set that value to global variable 'U_h' and/or 'U_m'
call setcq(ro_m,vx_m,vy_m,vz_m,p_m,B_x,B_y,B_z, &
ro_h,vx_h,vy_h,vz_h,p_h)
!---------------------------------------------------------------------
!set default output period and time duration--------------------------
if(tend.lt.0.0) then
tend=0.4d0
dtout=tend/10.0
if(flag_mpi.eq.0 .or.my_rank.eq.0) print *,"TEND",dtout,tend
endif
!---------------------------------------------------------------------
end subroutine shock_tube_stab