HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
NavierStokes3DFlux_GPU.cu
Go to the documentation of this file.
1 /*! @file NavierStokes3DFlux_GPU.cu
2  @author Youngdae Kim
3  @brief Functions to compute the hyperbolic flux for 3D Navier-Stokes equations
4 */
5 
6 #include <basic_gpu.h>
7 #include <arrayfunctions_gpu.h>
8 #include <mathfunctions.h>
9 #include <matmult_native.h>
10 #include <physicalmodels/navierstokes3d.h>
11 #include <hypar.h>
12 
13 #ifdef CUDA_VAR_ORDERDING_AOS
14 
15 /*! Kernel for gpuNavierStokes3DFlux() */
16 __global__
17 void gpuNavierStokes3DFlux_kernel(
18  int npoints_grid,
19  int dir,
20  double gamma,
21  const double * __restrict__ u,
22  double * __restrict__ f
23 )
24 {
25  int p = blockDim.x * blockIdx.x + threadIdx.x;
26 
27  if (p < npoints_grid) {
28  double rho, vx, vy, vz, e, P;
29  _NavierStokes3DGetFlowVar_((u+_MODEL_NVARS_*p),_NavierStokes3D_stride_,rho,vx,vy,vz,e,P,gamma);
30  _NavierStokes3DSetFlux_((f+_MODEL_NVARS_*p),_NavierStokes3D_stride_,rho,vx,vy,vz,e,P,dir);
31  }
32  return;
33 }
34 
35 /*!
36  Compute the hyperbolic flux function for the 3D Navier-Stokes equations:
37  \f{eqnarray}{
38  dir = x, & {\bf f}\left({\bf u}\right) = \left[\begin{array}{c} \rho u \\ \rho u^2 + p \\ \rho u v \\ \rho u w \\ (e+p)u \end{array}\right], \\
39  dir = y, & {\bf f}\left({\bf u}\right) = \left[\begin{array}{c} \rho v \\ \rho u v \\ \rho v^2 + p \\ \rho v w \\ (e+p)v \end{array}\right], \\
40  dir = z, & {\bf f}\left({\bf u}\right) = \left[\begin{array}{c} \rho w \\ \rho u w \\ \rho v w \\ \rho w^2 + p \\ (e+p)w \end{array}\right]
41  \f}
42  Note: the flux function needs to be computed at the ghost points as well.
43 */
44 extern "C" int gpuNavierStokes3DFlux(
45  double *__restrict__ f, /*!< Array to hold the computed flux vector (same layout as u) */
46  double *__restrict__ u, /*!< Array with the solution vector */
47  int dir, /*!< Spatial dimension (x, y, or z) for which to compute the flux */
48  void *__restrict__ s, /*!< Solver object of type #HyPar */
49  double t /*!< Current simulation time */
50 )
51 {
52  HyPar *solver = (HyPar*) s;
53  NavierStokes3D *param = (NavierStokes3D*) solver->physics;
54 
55  int nblocks = (solver->npoints_local_wghosts-1)/GPU_THREADS_PER_BLOCK + 1;
56 
57  gpuNavierStokes3DFlux_kernel<<<nblocks, GPU_THREADS_PER_BLOCK>>>(
58  solver->npoints_local_wghosts, dir, param->gamma, u, f
59  );
60  cudaDeviceSynchronize();
61 
62  return 0;
63 }
64 
65 #else
66 
67 /*! Kernel for gpuNavierStokes3DFlux() */
68 __global__
69 void gpuNavierStokes3DFlux_kernel(
70  int npoints_grid,
71  int dir,
72  double gamma,
73  const double * __restrict__ u,
74  double * __restrict__ f
75 )
76 {
77  int p = blockDim.x * blockIdx.x + threadIdx.x;
78 
79  if (p < npoints_grid) {
80  double rho, vx, vy, vz, e, P;
81  _NavierStokes3DGetFlowVar_((u+p),npoints_grid,rho,vx,vy,vz,e,P,gamma);
82  _NavierStokes3DSetFlux_((f+p),npoints_grid,rho,vx,vy,vz,e,P,dir);
83  }
84  return;
85 }
86 
87 /*!
88  Compute the hyperbolic flux function for the 3D Navier-Stokes equations:
89  \f{eqnarray}{
90  dir = x, & {\bf f}\left({\bf u}\right) = \left[\begin{array}{c} \rho u \\ \rho u^2 + p \\ \rho u v \\ \rho u w \\ (e+p)u \end{array}\right], \\
91  dir = y, & {\bf f}\left({\bf u}\right) = \left[\begin{array}{c} \rho v \\ \rho u v \\ \rho v^2 + p \\ \rho v w \\ (e+p)v \end{array}\right], \\
92  dir = z, & {\bf f}\left({\bf u}\right) = \left[\begin{array}{c} \rho w \\ \rho u w \\ \rho v w \\ \rho w^2 + p \\ (e+p)w \end{array}\right]
93  \f}
94  Note: the flux function needs to be computed at the ghost points as well.
95 */
96 extern "C" int gpuNavierStokes3DFlux(
97  double *__restrict__ f, /*!< Array to hold the computed flux vector (same layout as u) */
98  double *__restrict__ u, /*!< Array with the solution vector */
99  int dir, /*!< Spatial dimension (x, y, or z) for which to compute the flux */
100  void *__restrict__ s, /*!< Solver object of type #HyPar */
101  double t /*!< Current simulation time */
102 )
103 {
104  HyPar *solver = (HyPar*) s;
105  NavierStokes3D *param = (NavierStokes3D*) solver->physics;
106 
107  int nblocks = (solver->npoints_local_wghosts-1)/GPU_THREADS_PER_BLOCK + 1;
108 
109  gpuNavierStokes3DFlux_kernel<<<nblocks, GPU_THREADS_PER_BLOCK>>>(
110  solver->npoints_local_wghosts, dir, param->gamma, u, f
111  );
112  cudaDeviceSynchronize();
113 
114  return 0;
115 }
116 
117 #endif