HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
NavierStokes3DPreStep_GPU.cu
Go to the documentation of this file.
1 
5 #include <basic_gpu.h>
6 #include <arrayfunctions_gpu.h>
7 #include <mathfunctions.h>
8 #include <matmult_native.h>
10 #include <hypar.h>
11 
12 #ifdef CUDA_VAR_ORDERDING_AOS
13 
15 __global__
17  int npoints_grid,
18  double gamma,
19  const double * __restrict__ u,
20  double * __restrict__ fast_jac
21 )
22 {
23  int p = blockDim.x * blockIdx.x + threadIdx.x;
24 
25  if (p < npoints_grid) {
26  double * __restrict__ A;
29  int JacSize = _MODEL_NVARS_*_MODEL_NVARS_;
30  int q = _MODEL_NVARS_*p;
31  int dir = _XDIR_;
32 
33  A = (fast_jac + _MODEL_NDIMS_*JacSize*p + dir*JacSize);
34  /* get the eigenvalues, and left & right eigenvectors */
38  /* remove the entropy modes (corresponding to eigenvalues u) */
39  D[0] = D[12] = D[18] = 0.0;
40  /* assemble the Jacobian */
41  MatMult5(_MODEL_NVARS_,DL,D,L );
42  MatMult5(_MODEL_NVARS_,A ,R,DL);
43 
44  dir = _YDIR_;
45  A = (fast_jac + _MODEL_NDIMS_*JacSize*p + dir*JacSize);
46  /* get the eigenvalues, and left & right eigenvectors */
49  _NavierStokes3DRightEigenvectors_((u+q),_NavierStokes3D_stride_,R,gamma,dir);
50  /* remove the entropy modes (corresponding to eigenvalues v) */
51  D[0] = D[6] = D[18] = 0.0;
52  /* assemble the Jacobian */
53  MatMult5(_MODEL_NVARS_,DL,D,L );
54  MatMult5(_MODEL_NVARS_,A ,R,DL);
55 
56  dir = _ZDIR_;
57  A = (fast_jac + _MODEL_NDIMS_*JacSize*p + dir*JacSize);
58  /* get the eigenvalues, and left & right eigenvectors */
59  _NavierStokes3DEigenvalues_ ((u+q),_NavierStokes3D_stride_,D,gamma,dir)
60  _NavierStokes3DLeftEigenvectors_ ((u+q),_NavierStokes3D_stride_,L,gamma,dir);
61  _NavierStokes3DRightEigenvectors_((u+q),_NavierStokes3D_stride_,R,gamma,dir);
62  /* remove the entropy modes (corresponding to eigenvalues v) */
63  D[0] = D[6] = D[12] = 0.0;
64  /* assemble the Jacobian */
65  MatMult5(_MODEL_NVARS_,DL,D,L );
66  MatMult5(_MODEL_NVARS_,A ,R,DL);
67  }
68  return;
69 }
70 
92 extern "C" int gpuNavierStokes3DPreStep(
93  double *u,
94  void *s,
95  void *m,
96  double waqt
97 )
98 {
99  HyPar *solver = (HyPar*) s;
100  NavierStokes3D *param = (NavierStokes3D*) solver->physics;
101 
102  int nblocks = (solver->npoints_local_wghosts-1)/GPU_THREADS_PER_BLOCK + 1;
103 
104  gpuArrayCopy1D(u,param->gpu_solution,(solver->npoints_local_wghosts)*_MODEL_NVARS_);
105  gpuNavierStokes3DPreStep_kernel<<<nblocks, GPU_THREADS_PER_BLOCK>>>(
106  solver->npoints_local_wghosts, param->gamma, u, param->gpu_fast_jac
107  );
108  cudaDeviceSynchronize();
109 
110  return 0;
111 }
112 
113 #else
114 
116 __global__
118  int npoints_grid,
119  double gamma,
120  const double * __restrict__ u,
121  double * __restrict__ fast_jac
122 )
123 {
124  int p = blockDim.x * blockIdx.x + threadIdx.x;
125 
126  if (p < npoints_grid) {
127  double * __restrict__ A;
128  double D[_MODEL_NVARS_*_MODEL_NVARS_],L[_MODEL_NVARS_*_MODEL_NVARS_],
129  R[_MODEL_NVARS_*_MODEL_NVARS_],DL[_MODEL_NVARS_*_MODEL_NVARS_];
130  int JacSize = _MODEL_NVARS_*_MODEL_NVARS_;
131  int dir = _XDIR_;
132 
133  A = (fast_jac + _MODEL_NDIMS_*JacSize*p + dir*JacSize);
134  /* get the eigenvalues, and left & right eigenvectors */
135  _NavierStokes3DEigenvalues_ ((u+p),npoints_grid,D,gamma,dir);
136  _NavierStokes3DLeftEigenvectors_ ((u+p),npoints_grid,L,gamma,dir);
137  _NavierStokes3DRightEigenvectors_((u+p),npoints_grid,R,gamma,dir);
138  /* remove the entropy modes (corresponding to eigenvalues u) */
139  D[0] = D[12] = D[18] = 0.0;
140  /* assemble the Jacobian */
141  MatMult5(_MODEL_NVARS_,DL,D,L );
142  MatMult5(_MODEL_NVARS_,A ,R,DL);
143 
144  dir = _YDIR_;
145  A = (fast_jac + _MODEL_NDIMS_*JacSize*p + dir*JacSize);
146  /* get the eigenvalues, and left & right eigenvectors */
147  _NavierStokes3DEigenvalues_ ((u+p),npoints_grid,D,gamma,dir)
148  _NavierStokes3DLeftEigenvectors_ ((u+p),npoints_grid,L,gamma,dir);
149  _NavierStokes3DRightEigenvectors_((u+p),npoints_grid,R,gamma,dir);
150  /* remove the entropy modes (corresponding to eigenvalues v) */
151  D[0] = D[6] = D[18] = 0.0;
152  /* assemble the Jacobian */
153  MatMult5(_MODEL_NVARS_,DL,D,L );
154  MatMult5(_MODEL_NVARS_,A ,R,DL);
155 
156  dir = _ZDIR_;
157  A = (fast_jac + _MODEL_NDIMS_*JacSize*p + dir*JacSize);
158  /* get the eigenvalues, and left & right eigenvectors */
159  _NavierStokes3DEigenvalues_ ((u+p),npoints_grid,D,gamma,dir)
160  _NavierStokes3DLeftEigenvectors_ ((u+p),npoints_grid,L,gamma,dir);
161  _NavierStokes3DRightEigenvectors_((u+p),npoints_grid,R,gamma,dir);
162  /* remove the entropy modes (corresponding to eigenvalues v) */
163  D[0] = D[6] = D[12] = 0.0;
164  /* assemble the Jacobian */
165  MatMult5(_MODEL_NVARS_,DL,D,L );
166  MatMult5(_MODEL_NVARS_,A ,R,DL);
167  }
168  return;
169 }
170 
193  double *u,
194  void *s,
195  void *m,
196  double waqt
197 )
198 {
199  HyPar *solver = (HyPar*) s;
200  NavierStokes3D *param = (NavierStokes3D*) solver->physics;
201 
202  int nblocks = (solver->npoints_local_wghosts-1)/GPU_THREADS_PER_BLOCK + 1;
203 
204  gpuArrayCopy1D(u,param->gpu_solution,(solver->npoints_local_wghosts)*_MODEL_NVARS_);
205  gpuNavierStokes3DPreStep_kernel<<<nblocks, GPU_THREADS_PER_BLOCK>>>(
206  solver->npoints_local_wghosts, param->gamma, u, param->gpu_fast_jac
207  );
208  cudaDeviceSynchronize();
209 
210  return 0;
211 }
212 
213 #endif
#define _YDIR_
Definition: euler2d.h:41
int npoints_local_wghosts
Definition: hypar.h:42
double * gpu_solution
3D Navier Stokes equations (compressible flows)
#define _NavierStokes3DLeftEigenvectors_(u, stride, L, ga, dir)
#define _MODEL_NVARS_
Definition: euler1d.h:58
void * physics
Definition: hypar.h:266
#define _MODEL_NDIMS_
Definition: euler1d.h:56
#define GPU_THREADS_PER_BLOCK
Definition: basic_gpu.h:7
#define _ZDIR_
#define _NavierStokes3DEigenvalues_(u, stride, D, gamma, dir)
Contains function definitions for common mathematical functions.
int gpuNavierStokes3DPreStep(double *, void *, void *, double)
Contains function definitions for common array operations on GPU.
__global__ void gpuNavierStokes3DPreStep_kernel(int npoints_grid, double gamma, const double *__restrict__ u, double *__restrict__ fast_jac)
Contains structure definition for hypar.
#define MatMult5(N, A, X, Y)
Structure containing variables and parameters specific to the 3D Navier Stokes equations. This structure contains the physical parameters, variables, and function pointers specific to the 3D Navier-Stokes equations.
#define _NavierStokes3DRightEigenvectors_(u, stride, R, ga, dir)
double * gpu_fast_jac
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _XDIR_
Definition: euler1d.h:75
void gpuArrayCopy1D(const double *, double *, int)
Contains macros and function definitions for common matrix multiplication.
static const int _NavierStokes3D_stride_