1 /*! @file NavierStokes3DFlux_GPU.cu
3 @brief Functions to compute the hyperbolic flux for 3D Navier-Stokes equations
7 #include <arrayfunctions_gpu.h>
8 #include <mathfunctions.h>
9 #include <matmult_native.h>
10 #include <physicalmodels/navierstokes3d.h>
13 #ifdef CUDA_VAR_ORDERDING_AOS
15 /*! Kernel for gpuNavierStokes3DFlux() */
17 void gpuNavierStokes3DFlux_kernel(
21 const double * __restrict__ u,
22 double * __restrict__ f
25 int p = blockDim.x * blockIdx.x + threadIdx.x;
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);
36 Compute the hyperbolic flux function for the 3D Navier-Stokes equations:
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]
42 Note: the flux function needs to be computed at the ghost points as well.
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 */
52 HyPar *solver = (HyPar*) s;
53 NavierStokes3D *param = (NavierStokes3D*) solver->physics;
55 int nblocks = (solver->npoints_local_wghosts-1)/GPU_THREADS_PER_BLOCK + 1;
57 gpuNavierStokes3DFlux_kernel<<<nblocks, GPU_THREADS_PER_BLOCK>>>(
58 solver->npoints_local_wghosts, dir, param->gamma, u, f
60 cudaDeviceSynchronize();
67 /*! Kernel for gpuNavierStokes3DFlux() */
69 void gpuNavierStokes3DFlux_kernel(
73 const double * __restrict__ u,
74 double * __restrict__ f
77 int p = blockDim.x * blockIdx.x + threadIdx.x;
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);
88 Compute the hyperbolic flux function for the 3D Navier-Stokes equations:
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]
94 Note: the flux function needs to be computed at the ghost points as well.
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 */
104 HyPar *solver = (HyPar*) s;
105 NavierStokes3D *param = (NavierStokes3D*) solver->physics;
107 int nblocks = (solver->npoints_local_wghosts-1)/GPU_THREADS_PER_BLOCK + 1;
109 gpuNavierStokes3DFlux_kernel<<<nblocks, GPU_THREADS_PER_BLOCK>>>(
110 solver->npoints_local_wghosts, dir, param->gamma, u, f
112 cudaDeviceSynchronize();