-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathm_body_forces.fpp
More file actions
183 lines (143 loc) · 5.95 KB
/
m_body_forces.fpp
File metadata and controls
183 lines (143 loc) · 5.95 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
!>
!! @file
!! @brief Contains module m_body_forces
#:include 'macros.fpp'
!> @brief Computes gravitational and user-defined body force source terms for the momentum equations
module m_body_forces
use m_derived_types !< Definitions of the derived types
use m_global_parameters !< Definitions of the global parameters
use m_variables_conversion
use m_nvtx
! $:USE_GPU_MODULE()
implicit none
private;
public :: s_compute_body_forces_rhs, &
s_initialize_body_forces_module, &
s_finalize_body_forces_module
real(wp), allocatable, dimension(:, :, :) :: rhoM
$:GPU_DECLARE(create='[rhoM]')
contains
!> This subroutine initializes the module global array of mixture
!! densities in each grid cell
impure subroutine s_initialize_body_forces_module
! Simulation is at least 2D
if (n > 0) then
! Simulation is 3D
if (p > 0) then
@:ALLOCATE (rhoM(-buff_size:buff_size + m, &
-buff_size:buff_size + n, &
-buff_size:buff_size + p))
! Simulation is 2D
else
@:ALLOCATE (rhoM(-buff_size:buff_size + m, &
-buff_size:buff_size + n, &
0:0))
end if
! Simulation is 1D
else
@:ALLOCATE (rhoM(-buff_size:buff_size + m, &
0:0, &
0:0))
end if
end subroutine s_initialize_body_forces_module
!> This subroutine computes the acceleration at time t
subroutine s_compute_acceleration(t)
real(wp), intent(in) :: t
#:for DIR, XYZ in [(1, 'x'), (2, 'y'), (3, 'z')]
if (bf_${XYZ}$) then
accel_bf(${DIR}$) = g_${XYZ}$+k_${XYZ}$*sin(w_${XYZ}$*t - p_${XYZ}$)
end if
#:endfor
$:GPU_UPDATE(device='[accel_bf]')
end subroutine s_compute_acceleration
!> This subroutine calculates the mixture density at each cell
!! center
!! @param q_cons_vf Conservative variables
subroutine s_compute_mixture_density(q_cons_vf)
type(scalar_field), dimension(sys_size), intent(in) :: q_cons_vf
integer :: i, j, k, l !< standard iterators
$:GPU_PARALLEL_LOOP(private='[j,k,l]', collapse=3)
do l = 0, p
do k = 0, n
do j = 0, m
rhoM(j, k, l) = 0._wp
do i = 1, num_fluids
rhoM(j, k, l) = rhoM(j, k, l) + &
q_cons_vf(contxb + i - 1)%sf(j, k, l)
end do
end do
end do
end do
$:END_GPU_PARALLEL_LOOP()
end subroutine s_compute_mixture_density
!> This subroutine calculates the source term due to body forces
!! so the system can be advanced in time
!! @param q_cons_vf Conservative variables
!! @param q_prim_vf Primitive variables
!! @param rhs_vf Right-hand side accumulator
subroutine s_compute_body_forces_rhs(q_prim_vf, q_cons_vf, rhs_vf)
type(scalar_field), dimension(sys_size), intent(in) :: q_prim_vf
type(scalar_field), dimension(sys_size), intent(in) :: q_cons_vf
type(scalar_field), dimension(sys_size), intent(inout) :: rhs_vf
integer :: i, j, k, l !< Loop variables
call s_compute_acceleration(mytime)
call s_compute_mixture_density(q_cons_vf)
$:GPU_PARALLEL_LOOP(private='[i,j,k,l]', collapse=4)
do i = momxb, E_idx
do l = 0, p
do k = 0, n
do j = 0, m
rhs_vf(i)%sf(j, k, l) = 0._wp
end do
end do
end do
end do
$:END_GPU_PARALLEL_LOOP()
if (bf_x) then ! x-direction body forces
$:GPU_PARALLEL_LOOP(private='[j,k,l]', collapse=3)
do l = 0, p
do k = 0, n
do j = 0, m
rhs_vf(momxb)%sf(j, k, l) = rhs_vf(momxb)%sf(j, k, l) + &
rhoM(j, k, l)*accel_bf(1)
rhs_vf(E_idx)%sf(j, k, l) = rhs_vf(E_idx)%sf(j, k, l) + &
q_cons_vf(momxb)%sf(j, k, l)*accel_bf(1)
end do
end do
end do
$:END_GPU_PARALLEL_LOOP()
end if
if (bf_y) then ! y-direction body forces
$:GPU_PARALLEL_LOOP(private='[j,k,l]', collapse=3)
do l = 0, p
do k = 0, n
do j = 0, m
rhs_vf(momxb + 1)%sf(j, k, l) = rhs_vf(momxb + 1)%sf(j, k, l) + &
rhoM(j, k, l)*accel_bf(2)
rhs_vf(E_idx)%sf(j, k, l) = rhs_vf(E_idx)%sf(j, k, l) + &
q_cons_vf(momxb + 1)%sf(j, k, l)*accel_bf(2)
end do
end do
end do
$:END_GPU_PARALLEL_LOOP()
end if
if (bf_z) then ! z-direction body forces
$:GPU_PARALLEL_LOOP(private='[j,k,l]', collapse=3)
do l = 0, p
do k = 0, n
do j = 0, m
rhs_vf(momxe)%sf(j, k, l) = rhs_vf(momxe)%sf(j, k, l) + &
rhoM(j, k, l)*accel_bf(3)
rhs_vf(E_idx)%sf(j, k, l) = rhs_vf(E_idx)%sf(j, k, l) + &
q_cons_vf(momxe)%sf(j, k, l)*accel_bf(3)
end do
end do
end do
$:END_GPU_PARALLEL_LOOP()
end if
end subroutine s_compute_body_forces_rhs
!> @brief Deallocates module variables used for body force computations.
impure subroutine s_finalize_body_forces_module
@:DEALLOCATE(rhoM)
end subroutine s_finalize_body_forces_module
end module m_body_forces