forked from pseudospectators/FLUSI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_fields_mhd.f90
More file actions
211 lines (172 loc) · 5.57 KB
/
init_fields_mhd.f90
File metadata and controls
211 lines (172 loc) · 5.57 KB
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
! Initialize fields for mhd simulations
subroutine init_fields_mhd(n1,time,it,dt0,dt1,ubk,nlk,wj,explin)
use mpi_header
use fsi_vars
implicit none
integer,intent (inout) :: n1,it
real (kind=pr),intent (inout) :: time,dt1,dt0
complex (kind=pr),intent (out):: ubk(ca(1):cb(1),ca(2):cb(2),ca(3):cb(3),1:nd)
complex (kind=pr),intent (out)::&
nlk(ca(1):cb(1),ca(2):cb(2),ca(3):cb(3),1:nd,0:1)
real(kind=pr),intent (inout) :: wj(ra(1):rb(1),ra(2):rb(2),ra(3):rb(3),1:nd)
real (kind=pr),intent(inout)::explin(ca(1):cb(1),ca(2):cb(2),ca(3):cb(3),1:nf)
integer :: i
! Assign zero values
time=0.0d0
dt1=0.0d0
ubk=dcmplx(0.0d0,0.0d0)
nlk=dcmplx(0.0d0,0.0d0)
explin=0.0
it=0
wj=0.0d0
select case(inicond)
case("quiescent")
ubk=dcmplx(0.0d0,0.0d0)
case("constant")
call init_const(ubk,wj)
case("orszagtang")
call init_orszagtang(ubk,wj)
case("smc")
call init_smc(ubk,wj)
case("TaylorCouette")
call init_tc_mhd(ubk,wj)
case("infile")
! read in fluid velocity from files
call Read_Single_File ( file_ux, wj(:,:,:,1) )
call Read_Single_File ( file_uy, wj(:,:,:,2) )
call Read_Single_File ( file_uz, wj(:,:,:,3) )
! read in b-field from files
call Read_Single_File ( file_bx, wj(:,:,:,4) )
call Read_Single_File ( file_by, wj(:,:,:,5) )
call Read_Single_File ( file_bz, wj(:,:,:,6) )
! transform everything to fourier space
do i = 1,6
call fft( ubk(:,:,:,i), wj(:,:,:,i) )
enddo
case default
if(inicond(1:8) == "backup::") then
call Read_Runtime_Backup(inicond(9:len(inicond)),&
time,dt0,dt1,n1,it,ubk,nlk,explin,wj(:,:,:,1))
else
if (mpirank==0) then
write (*,*) inicond
write (*,*) '??? ERROR: Invalid initial condition'
endif
call abort
endif
end select
! Ensure that initial conditions are divergence-free by performing a
! Helmholtz decomposition:
call div_field_nul(ubk(:,:,:,1),ubk(:,:,:,2),ubk(:,:,:,3))
call div_field_nul(ubk(:,:,:,4),ubk(:,:,:,5),ubk(:,:,:,6))
end subroutine init_fields_mhd
! The Orszag-Tang initial conditions for mhd.
subroutine init_orszagtang(ubk,ub)
use mpi_header
use mhd_vars
implicit none
complex(kind=pr),intent(inout):: ubk(ca(1):cb(1),ca(2):cb(2),ca(3):cb(3),1:nd)
real(kind=pr),intent (inout) :: ub(ra(1):rb(1),ra(2):rb(2),ra(3):rb(3),1:nd)
real(kind=pr) :: beta
integer :: ix,iy,iz,i
real(kind=pr) :: x,y,z
beta=0.8d0
do ix=ra(1),rb(1)
x=xl*(dble(ix)/dble(nx) -0.5d0)
do iy=ra(2),rb(2)
y=yl*(dble(iy)/dble(ny) -0.5d0)
do iz=ra(3),rb(3)
z=zl*(dble(iz)/dble(nz) -0.5d0)
ub(ix,iy,iz,1)=-2.d0*dsin(y)
ub(ix,iy,iz,2)=2.d0*dsin(x)
ub(ix,iy,iz,3)=0.d0
ub(ix,iy,iz,4)=beta*(-2.d0*dsin(2.d0*y) + dsin(z))
ub(ix,iy,iz,5)=beta*(2.d0*dsin(x) + dsin(z))
ub(ix,iy,iz,6)=beta*(dsin(x) + dsin(y))
enddo
enddo
enddo
do i=1,nd
call fft(ubk(:,:,:,i),ub(:,:,:,i))
enddo
end subroutine init_orszagtang
! Constant initial conditions for MHD
subroutine init_const(ubk,wj)
use mpi_header
use mhd_vars
implicit none
complex(kind=pr),intent(inout):: ubk(ca(1):cb(1),ca(2):cb(2),ca(3):cb(3),1:nd)
real(kind=pr),intent (inout) :: wj(ra(1):rb(1),ra(2):rb(2),ra(3):rb(3),1:nd)
integer :: i
wj(:,:,:,1)=1.d0
wj(:,:,:,2)=2.d0
wj(:,:,:,3)=3.d0
wj(:,:,:,4)=4.d0
wj(:,:,:,5)=5.d0
wj(:,:,:,6)=6.d0
do i=1,nd
call fft(ubk(:,:,:,i),wj(:,:,:,i))
enddo
end subroutine init_const
! The Sean-Montgomery-Chen initial conditions
subroutine init_smc(ubk,ub)
use mpi_header
use mhd_vars
implicit none
complex(kind=pr),intent(inout):: ubk(ca(1):cb(1),ca(2):cb(2),ca(3):cb(3),1:nd)
real(kind=pr),intent (inout) :: ub(ra(1):rb(1),ra(2):rb(2),ra(3):rb(3),1:nd)
integer :: i, ix,iy,iz
real(kind=pr) :: x,y,r
real (kind=pr) :: a,b,c,d,k1,k2,h
! Create a perturbation for the velocity field:
call perturbation(ubk(:,:,:,1),ubk(:,:,:,2),ubk(:,:,:,3),&
ub(:,:,:,1),ub(:,:,:,2),ub(:,:,:,3),&
3.1017126d-07)
! Set up the magnetic field
ub(:,:,:,4)=0.d0
ub(:,:,:,5)=0.d0
ub(:,:,:,6)=B0 ! bz set to B0 everywhere
k1=Bc*r2/r1
k2=Bc/r1
A=(2.d0*k1 -k2*(r2-r3))/(r3*r3*r3 -3.d0*r2*r3*r3 +3.d0*r2*r2*r3 -r2*r2*r2)
B=(k2 -3.d0*A*(r2*r2 -r3*r3))/(2.d0*r2 -2.d0*r3)
C=-3.d0*A*r3*r3 -2.d0*B*r3
D=2.d0*A*r3*r3*r3 +B*r3*r3
do ix=ra(1),rb(1)
x=xl*(dble(ix)/dble(nx) -0.5d0)
do iy=ra(2),rb(2)
y=yl*(dble(iy)/dble(ny) -0.5d0)
r=dsqrt(x*x + y*y)
if(r < r2) then
do iz=ra(3),rb(3)
ub(ix,iy,iz,4)=-y*Bc/R1
ub(ix,iy,iz,5)= x*Bc/R1
enddo
endif
if(r >= r2 .and. r <= r3) then
h=(A*r*r*r +B*r*r +C*r +D)
do iz=ra(3),rb(3)
ub(ix,iy,iz,4)= h*y/r
ub(ix,iy,iz,5)=-h*x/r
enddo
endif
enddo
enddo
do i=3,nd
call fft(ubk(:,:,:,i),ub(:,:,:,i))
enddo
end subroutine init_smc
! The Taylor-Couette initial conditions for mhd.
subroutine init_tc_mhd(ubk,ub)
use mpi_header
use mhd_vars
implicit none
complex(kind=pr),intent(inout):: ubk(ca(1):cb(1),ca(2):cb(2),ca(3):cb(3),1:nd)
real(kind=pr),intent (inout) :: ub(ra(1):rb(1),ra(2):rb(2),ra(3):rb(3),1:nd)
! Initialize the velocity field:
call init_taylorcouette_u(ubk,ub)
! Create a perturbation for the magnetic field:
call perturbation(ubk(:,:,:,4),ubk(:,:,:,5),ubk(:,:,:,6),&
ub(:,:,:,4),ub(:,:,:,5),ub(:,:,:,6),&
3.1017126d-07)
end subroutine init_tc_mhd