-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoln_RK4.F90
68 lines (54 loc) · 2.05 KB
/
soln_RK4.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
subroutine soln_RK4(dt, m, Vm, Flux)
!performs the mth step of the RK4 algorithm
!Total Flux = (k1 + 2k2 + 2k3 + k4)/6
#include "definition.h"
use grid_data
use primconsflux
implicit none
real, intent(IN) :: dt
integer, intent(IN) :: m
real, dimension(NUMB_VAR,gr_imax(XDIM),gr_imax(YDIM),gr_imax(ZDIM)), intent(INOUT) :: Vm
real, dimension(NSYS_VAR,gr_imax(XDIM),gr_imax(YDIM),gr_imax(ZDIM),NDIM), intent(INOUT) :: Flux
real :: A, F, dtx, dty, dtz
integer :: i, j, k
real, dimension(NUMB_VAR,gr_imax(XDIM),gr_imax(YDIM),gr_imax(ZDIM)) :: Um
if (m == 1 .OR. m == 2) then
A = 0.5
else
A = 1.
end if
if (m == 1 .OR. m == 4) then
F = 1./6.
else
F = 1./3.
end if
dtx = A*dt/gr_dx
dty = A*dt/gr_dy
dtz = A*dt/gr_dz
call soln_reconstruct(dt, Vm)
call soln_getFlux(Vm)
if (m .NE. 4) then
!update cons variables to mth step only if not 4th step
do i = gr_ibeg(XDIM), gr_iend(XDIM)
do j = gr_ibeg(YDIM), gr_iend(YDIM)
do k = gr_ibeg(ZDIM), gr_iend(ZDIM)
Um(DENS_VAR:ENER_VAR,i,j,k) = gr_U(DENS_VAR:ENER_VAR,i,j,k) - &
dtx*(gr_flux(DENS_VAR:ENER_VAR,i+1,j,k,XDIM) - gr_flux(DENS_VAR:ENER_VAR,i,j,k,XDIM)) - &
dty*(gr_flux(DENS_VAR:ENER_VAR,i,j+1,k,YDIM) - gr_flux(DENS_VAR:ENER_VAR,i,j,k,YDIM)) - &
dtz*(gr_flux(DENS_VAR:ENER_VAR,i,j,k+1,ZDIM) - gr_flux(DENS_VAR:ENER_VAR,i,j,k,ZDIM))
!convert to primitive vars
call cons2prim(Um(DENS_VAR:ENER_VAR,i,j,k),Vm(DENS_VAR:GAME_VAR,i,j,k))
end do
end do
end do
!! get updated primitive vars from the updated conservative vars
!!$ do i = gr_ibeg(XDIM), gr_iend(XDIM)
!!$ do j = gr_ibeg(YDIM), gr_iend(YDIM)
!!$ ! Eos is automatically callled inside cons2prim
!!$ call cons2prim(Um(DENS_VAR:ENER_VAR,i,j),Vm(DENS_VAR:GAME_VAR,i,j))
!!$ end do
!!$ end do
end if
!finally add to total flux
Flux(:,:,:,:,:) = Flux(:,:,:,:,:) + F*gr_flux(:,:,:,:,:)
end subroutine soln_RK4