forked from AMReX-Codes/amrex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions_2d.f90
122 lines (99 loc) · 3.89 KB
/
functions_2d.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
subroutine SDC_feval_F(lo, hi, domlo, domhi, phi, philo, phihi, &
fluxx, fxlo, fxhi, fluxy, fylo, fyhi,f, flo,fhi, &
dx,a,d,r,n) bind(C, name="SDC_feval_F")
! Compute the rhs terms
use amrex_fort_module, only : amrex_real
implicit none
integer lo(2), hi(2), domlo(2), domhi(2)
integer philo(2), phihi(2), fxlo(2), fxhi(2), fylo(2), fyhi(2),flo(2), fhi(2)
real(amrex_real), intent(in) :: phi (philo(1):phihi(1),philo(2):phihi(2))
real(amrex_real), intent(inout) :: fluxx( fxlo(1): fxhi(1), fxlo(2): fxhi(2))
real(amrex_real), intent(inout) :: fluxy( fylo(1): fyhi(1), fylo(2): fyhi(2))
real(amrex_real), intent(inout) :: f (flo(1):fhi(1),flo(2):fhi(2))
real(amrex_real), intent(in) :: dx(2)
real(amrex_real), intent(in) :: a,d,r
integer, intent(in) :: n
! local variables
integer i,j
select case(n)
case (0) ! Explicit term (here it is advection)
! x-fluxes
do j = lo(2), hi(2)
do i = lo(1), hi(1)+1
fluxx(i,j) = ( phi(i,j) + phi(i-1,j) ) / 2.0d0
fluxx(i,j) = (-phi(i+1,j)+ 7.0d0*( phi(i,j) + phi(i-1,j) )-phi(i-2,j)) / 12.0d0
end do
end do
! y-fluxes
do j = lo(2), hi(2)+1
do i = lo(1), hi(1)
fluxy(i,j) =(-phi(i,j+1)+7.0d0*( phi(i,j) + phi(i,j-1) )-phi(i,j-2)) / 12.0d0
end do
end do
! Function value is divergence of flux
do j = lo(2), hi(2)
do i = lo(1), hi(1)
f(i,j) = a*((fluxx(i+1,j ) - fluxx(i,j))/dx(1) &
+ (fluxy(i ,j+1) - fluxy(i,j))/dx(2))
end do
end do
case (1) ! First implicit piece (here it is diffusion)
! x-fluxes
do j = lo(2), hi(2)
do i = lo(1), hi(1)+1
fluxx(i,j) = ( phi(i,j) - phi(i-1,j) ) / dx(1)
! fluxx(i,j) = ( -phi(i+1,j) +15.0d0*(phi(i,j) - phi(i-1,j)) + phi(i-2,j) ) /(12.0d0*dx(1))
end do
end do
! y-fluxes
do j = lo(2), hi(2)+1
do i = lo(1), hi(1)
fluxy(i,j) = ( phi(i,j) - phi(i,j-1) ) / dx(2)
! fluxy(i,j) = ( -phi(i,j+1) +15.0d0*(phi(i,j) - phi(i,j-1)) + phi(i,j-2) ) /(12.0d0*dx(2))
end do
end do
! Function value is divergence of flux
do j = lo(2), hi(2)
do i = lo(1), hi(1)
f(i,j) = d*((fluxx(i+1,j ) - fluxx(i,j))/dx(1) &
+ (fluxy(i ,j+1) - fluxy(i,j))/dx(2))
end do
end do
case (2) ! Second implicit piece (here it is reaction)
do j = lo(2), hi(2)
do i = lo(1), hi(1)
! f(i,j) = r*phi(i,j)*(1.0d0-phi(i,j))*(0.5d0-phi(i,j))
f(i,j) = -r*phi(i,j)
end do
end do
case default
print *, 'bad case in advance_2d'
end select
end subroutine SDC_feval_F
subroutine SDC_fcomp_reaction_F (lo, hi, domlo, domhi, phi, philo, phihi, &
rhs, rhslo, rhshi, &
f, flo,fhi, dtq,n) bind(C, name="SDC_fcomp_reaction_F")
! Solve for the reaction term
use amrex_fort_module, only : amrex_real
implicit none
integer lo(2), hi(2), domlo(2), domhi(2)
integer philo(2), phihi(2)
integer rhslo(2), rhshi(2)
integer flo(2), fhi(2)
real(amrex_real), intent(inout) :: phi (philo(1):phihi(1),philo(2):phihi(2))
real(amrex_real), intent(in) :: rhs (rhslo(1):rhshi(1),rhslo(2):rhshi(2))
real(amrex_real), intent(in) :: f (flo(1):fhi(1),flo(2):fhi(2))
real(amrex_real), intent(in) :: dtq
integer, intent(in) :: n
! local variables
integer i,j
real(amrex_real) c
! Function
do j = lo(2), hi(2)
do i = lo(1), hi(1)
c = 1.0d0-dtq*(1.0d0-phi(i,j))*(0.5d0-phi(i,j))
c = 1.0d0+dtq
phi(i,j) = rhs(i,j)/c
end do
end do
end subroutine SDC_fcomp_reaction_F