Skip to content

Commit d8db933

Browse files
committed
Kernalize UpdateOldVariables.
1 parent c8bb901 commit d8db933

File tree

2 files changed

+46
-25
lines changed

2 files changed

+46
-25
lines changed

swm_AMReX/swm_mini_app_kernels.h

+41-18
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
#include <AMReX.H>
55

66
AMREX_GPU_DEVICE AMREX_FORCE_INLINE
7-
void UpdateIntermediateVariablesKernel( const int i, const int j, const int k, const double fsdx, const double fsdy,
7+
void UpdateIntermediateVariablesKernel( const int i, const int j, const int k,
8+
const double fsdx, const double fsdy,
89
const amrex::Array4<amrex::Real const>& p,
910
const amrex::Array4<amrex::Real const>& u,
1011
const amrex::Array4<amrex::Real const>& v,
@@ -13,30 +14,52 @@ void UpdateIntermediateVariablesKernel( const int i, const int j, const int k, c
1314
const amrex::Array4<amrex::Real>& h,
1415
const amrex::Array4<amrex::Real>& z)
1516
{
16-
cu(i,j,k) = 0.5*(p(i,j,k) + p(i+1,j,k))*u(i,j,k);
17-
cv(i,j,k) = 0.5*(p(i,j,k) + p(i,j+1,k))*v(i,j,k);
18-
z(i,j,k) = (fsdx*(v(i+1,j,k)-v(i,j,k)) + fsdy*(u(i,j+1,k)-u(i,j,k)))/(p(i,j,k)+p(i+1,j,k)+p(i,j+1,k)+p(i+1,j+1,k));
19-
h(i,j,k) = p(i,j,k) + 0.25*(u(i-1,j,k)*u(i-1,j,k) + u(i,j,k)*u(i,j,k) + v(i,j-1,k)*v(i,j-1,k) + v(i,j,k)*v(i,j,k));
17+
cu(i,j,k) = 0.5*(p(i,j,k) + p(i+1,j,k))*u(i,j,k);
18+
cv(i,j,k) = 0.5*(p(i,j,k) + p(i,j+1,k))*v(i,j,k);
19+
z(i,j,k) = (fsdx*(v(i+1,j,k)-v(i,j,k)) + fsdy*(u(i,j+1,k)-u(i,j,k)))/(p(i,j,k)+p(i+1,j,k)+p(i,j+1,k)+p(i+1,j+1,k));
20+
h(i,j,k) = p(i,j,k) + 0.25*(u(i-1,j,k)*u(i-1,j,k) + u(i,j,k)*u(i,j,k) + v(i,j-1,k)*v(i,j-1,k) + v(i,j,k)*v(i,j,k));
2021
}
2122

2223

2324
AMREX_GPU_DEVICE AMREX_FORCE_INLINE
2425
void UpdateNewVariablesKernel( const int i, const int j, const int k,
2526
const double tdtsdx, const double tdtsdy, const double tdts8,
26-
const amrex::Array4<amrex::Real const>& p_old_array,
27-
const amrex::Array4<amrex::Real const>& u_old_array,
28-
const amrex::Array4<amrex::Real const>& v_old_array,
29-
const amrex::Array4<amrex::Real const>& cu_array,
30-
const amrex::Array4<amrex::Real const>& cv_array,
31-
const amrex::Array4<amrex::Real const>& h_array,
32-
const amrex::Array4<amrex::Real const>& z_array,
33-
const amrex::Array4<amrex::Real>& p_new_array,
34-
const amrex::Array4<amrex::Real>& u_new_array,
35-
const amrex::Array4<amrex::Real>& v_new_array)
27+
const amrex::Array4<amrex::Real const>& p_old,
28+
const amrex::Array4<amrex::Real const>& u_old,
29+
const amrex::Array4<amrex::Real const>& v_old,
30+
const amrex::Array4<amrex::Real const>& cu,
31+
const amrex::Array4<amrex::Real const>& cv,
32+
const amrex::Array4<amrex::Real const>& h,
33+
const amrex::Array4<amrex::Real const>& z,
34+
const amrex::Array4<amrex::Real>& p_new,
35+
const amrex::Array4<amrex::Real>& u_new,
36+
const amrex::Array4<amrex::Real>& v_new)
3637
{
37-
u_new_array(i,j,k) = u_old_array(i,j,k) + tdts8 * (z_array(i,j-1,k)+z_array(i,j,k)) * (cv_array(i,j-1,k) + cv_array(i,j,k) + cv_array(i+1,j-1,k) + cv_array(i+1,j,k)) - tdtsdx * (h_array(i+1,j,k) - h_array(i,j,k));
38-
v_new_array(i,j,k) = v_old_array(i,j,k) - tdts8 * (z_array(i-1,j,k)+z_array(i,j,k)) * (cu_array(i-1,j,k) + cu_array(i-1,j+1,k) + cu_array(i,j,k) + cu_array(i,j+1,k)) - tdtsdy * (h_array(i,j+1,k) - h_array(i,j,k));
39-
p_new_array(i,j,k) = p_old_array(i,j,k) - tdtsdx * (cu_array(i,j,k) - cu_array(i-1,j,k)) - tdtsdy * (cv_array(i,j,k) - cv_array(i,j-1,k));
38+
u_new(i,j,k) = u_old(i,j,k) + tdts8 * (z(i,j-1,k)+z(i,j,k)) * (cv(i,j-1,k) + cv(i,j,k) + cv(i+1,j-1,k) + cv(i+1,j,k)) - tdtsdx * (h(i+1,j,k) - h(i,j,k));
39+
v_new(i,j,k) = v_old(i,j,k) - tdts8 * (z(i-1,j,k)+z(i,j,k)) * (cu(i-1,j,k) + cu(i-1,j+1,k) + cu(i,j,k) + cu(i,j+1,k)) - tdtsdy * (h(i,j+1,k) - h(i,j,k));
40+
p_new(i,j,k) = p_old(i,j,k) - tdtsdx * (cu(i,j,k) - cu(i-1,j,k)) - tdtsdy * (cv(i,j,k) - cv(i,j-1,k));
41+
}
42+
43+
AMREX_GPU_DEVICE AMREX_FORCE_INLINE
44+
void UpdateOldVariablesKernel( const int i, const int j, const int k,
45+
const double alpha,
46+
const amrex::Array4<amrex::Real const>& p,
47+
const amrex::Array4<amrex::Real const>& u,
48+
const amrex::Array4<amrex::Real const>& v,
49+
const amrex::Array4<amrex::Real const>& p_new,
50+
const amrex::Array4<amrex::Real const>& u_new,
51+
const amrex::Array4<amrex::Real const>& v_new,
52+
const amrex::Array4<amrex::Real>& p_old,
53+
const amrex::Array4<amrex::Real>& u_old,
54+
const amrex::Array4<amrex::Real>& v_old)
55+
{
56+
amrex::Real u_old_temp = u_old(i,j,k);
57+
amrex::Real v_old_temp = v_old(i,j,k);
58+
amrex::Real p_old_temp = p_old(i,j,k);
59+
60+
u_old(i,j,k) = u(i,j,k) + alpha * (u_new(i,j,k) - 2.0*u(i,j,k) + u_old_temp);
61+
v_old(i,j,k) = v(i,j,k) + alpha * (v_new(i,j,k) - 2.0*v(i,j,k) + v_old_temp);
62+
p_old(i,j,k) = p(i,j,k) + alpha * (p_new(i,j,k) - 2.0*p(i,j,k) + p_old_temp);
4063
}
4164

4265
#endif // SWM_MINI_APP_KERNELS_H_

swm_AMReX/swm_mini_app_utils.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,11 @@ void UpdateOldVariables(const double alpha, const int time_step, const amrex::Ge
430430

431431
amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k)
432432
{
433-
amrex::Real u_old_temp = u_old_array(i,j,k);
434-
amrex::Real v_old_temp = v_old_array(i,j,k);
435-
amrex::Real p_old_temp = p_old_array(i,j,k);
436-
437-
u_old_array(i,j,k) = u_array(i,j,k) + alpha * (u_new_array(i,j,k) - 2.0*u_array(i,j,k) + u_old_temp);
438-
v_old_array(i,j,k) = v_array(i,j,k) + alpha * (v_new_array(i,j,k) - 2.0*v_array(i,j,k) + v_old_temp);
439-
p_old_array(i,j,k) = p_array(i,j,k) + alpha * (p_new_array(i,j,k) - 2.0*p_array(i,j,k) + p_old_temp);
433+
UpdateOldVariablesKernel(i, j, k,
434+
alpha,
435+
p_array, u_array, v_array,
436+
p_new_array, u_new_array, v_new_array,
437+
p_old_array, u_old_array, v_old_array);
440438
});
441439
}
442440
} else {

0 commit comments

Comments
 (0)