-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup_rayleightaylor2D.f90
224 lines (214 loc) · 5.5 KB
/
setup_rayleightaylor2D.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
!----------------------------------------------------------------
! Set up a Rayleigh-Taylor instability test as
! in Jim Stone et al. (Athena test suite)
!----------------------------------------------------------------
subroutine setup
!
!--include relevant global variables
!
use dimen_mhd
use debug
use loguns
use bound
use options
use part
use setup_params, only:psep,pi
use eos, only:gamma
use mem_allocation, only:alloc
use uniform_distributions
use cons2prim, only:primitive2conservative
use random, only:ran1
!
!--define local variables
!
implicit none
integer :: i,iseed,ipart
real :: massp,volume,totmass,massmedium,Rfunc2,z
real :: denszero,densmedium,przero,psepmedium,pri
real, dimension(ndim) :: xminregion,xmaxregion
logical, parameter :: equalmass = .true.
logical, parameter :: perturbinterface = .true.
Rfunc2(z) = -0.01*cos(6.*pi*z) ! interface definition
!
!--allow for tracing flow
!
if (trace) write(iprint,*) ' entering subroutine setup(unifdis)'
if (ndim.ne.2) stop 'error: need ndim=2 for this problem'
!
!--set boundaries
!
ibound(1) = 2 ! periodic in x
ibound(2) = 1 ! fixed in y
nbpts = 0 ! use ghosts not fixed
if (perturbinterface) then
xmin(1) = 0. ! set position of boundaries
xmax(1) = 1./6.
xmin(2) = -0.5 !- 6.*psep ! set position of boundaries
xmax(2) = 0.5 !+ 6.*psep
else
xmin(1) = -0.25 ! set position of boundaries
xmax(1) = 0.25
xmin(2) = -0.75 !- 6.*psep ! set position of boundaries
xmax(2) = 0.75 !+ 6.*psep
endif
if (iexternal_force.ne.8) stop 'need iexternal force = 8 for this problem'
!
!--set up the uniform density grid
!
denszero = 1.0
densmedium = 2.0
przero = 2.5
psepmedium = psep*(denszero/densmedium)**(1./ndim)
massmedium = massp*(densmedium/denszero)
volume = product(xmax(:)-xmin(:))
totmass = denszero*volume
if (.not.equalmass) then
!
!--unequal masses setup whole grid
!
call set_uniform_cartesian(2,psep,xmin,xmax,fill=.true.)
massp = totmass/float(npart)
elseif (perturbinterface) then
!
!--setup whole domain to get particle mass
!
call set_uniform_cartesian(2,psep,xminregion,xmaxregion,fill=.true.)
massp = totmass/float(npart)
npart = 0
!
!--for equal mass particles setup each region separately
! (this uses a mask to get a perturbed interface)
!
call set_uniform_cartesian(1,psep,xmin,xmax,fill=.true.,mask=-5)
call set_uniform_cartesian(1,psepmedium,xmin,xmax,fill=.true.,mask=5)
ntotal = npart
else
!
!--for equal mass particles setup each region separately
!
xminregion(1) = xmin(1)
xmaxregion(1) = xmax(1) ! 0.
xminregion(2) = xmin(2)
xmaxregion(2) = 0.
call set_uniform_cartesian(2,psep,xminregion,xmaxregion,fill=.true.)
!
!--determine particle mass from npart in first region
!
volume = product(xmaxregion(:)-xminregion(:))
totmass = denszero*volume
massp = totmass/float(npart) ! average particle mass
! xminregion(2) = 0.25
! xmaxregion(2) = 0.5
! call set_uniform_cartesian(1,psep,xminregion,xmaxregion,fill=.true.)
!
!--setup -0.25 < y < 0.25
!
xminregion(2) = 0.
xmaxregion(2) = xmax(2)
call set_uniform_cartesian(2,psepmedium,xminregion,xmaxregion,fill=.true.)
!
!--reallocate memory to new size of list
!
! call alloc(2*npart)
!
!--reflect particles above and below the y axis
!
ipart = npart
! do i=1,npart
! ipart = ipart + 1
! x(1,ipart) = -x(1,i)
! x(2,ipart) = x(2,i)
! enddo
npart = ipart
ntotal = npart
endif
npart = ntotal
print*,'npart =',npart
!
!--now declare periodic boundaries
!
xmin(2) = -0.75
xmax(2) = 0.75
!
!--now assign particle properties
!
do i=1,ntotal
vel(:,i) = 0.
if (perturbinterface) then
if (x(2,i) .gt. Rfunc2(x(1,i))) then
dens(i) = densmedium
if (equalmass) then
pmass(i) = massp
else
pmass(i) = massmedium
endif
else
dens(i) = denszero
pmass(i) = massp
endif
else
if (abs(x(2,i)).lt.1./3.) then
vel(2,i) = 0.01*(1. + cos(4.*pi*x(1,i)))*(1. + cos(3.*pi*x(2,i)))/4.
else
vel(2,i) = 0.
endif
if (x(2,i).gt.0.) then
dens(i) = densmedium
if (equalmass) then
pmass(i) = massp
else
pmass(i) = massmedium
endif
else
dens(i) = denszero
pmass(i) = massp
endif
endif
pri = przero - 0.1*dens(i)*x(2,i)
uu(i) = pri/((gamma-1.)*dens(i))
!--set fixed particles in y
if (x(2,i).gt.xmax(2) .or. x(2,i).lt.xmin(2)) then
nbpts = nbpts + 1
itype(i) = 1
endif
! Bfield(:,i) = 0.
! Bfield(1,i) = 0.5
enddo
!
!--get rho from a sum and then set u to give a
! smooth pressure
!
write(iprint,*) 'calling density to make smooth pressure jump...'
call primitive2conservative
do i=1,npart
pri = przero - 0.1*rho(i)*x(2,i)
uu(i) = pri/((gamma-1.)*dens(i))
enddo
!
!--allow for tracing flow
!
if (trace) write(iprint,*) ' exiting subroutine setup'
return
end
subroutine modify_dump
use loguns, only:iprint
use part
use options, only:imhd
use timestep, only:time
use setup_params, only:pi
implicit none
integer :: i
!
!--now assign particle properties
!
write(iprint,*) 'modifying dump with velocities for Rayleigh-Taylor run'
do i=1,ntotal
vel(1,i) = 0.
if (abs(x(2,i)).lt.1./3.) then
vel(2,i) = 0.5*(1. + cos(4.*pi*x(1,i)))*(1. + cos(3.*pi*x(2,i)))/4.
else
vel(2,i) = 0.
endif
enddo
time = 0.
end subroutine modify_dump