cuIBM
A GPU-based Immersed Boundary Method code
generateE.cu
Go to the documentation of this file.
1 
7 #include "generateE.h"
8 
9 
18 __device__
20 {
21  real r = fabs(x)/h;
22 
23  if(r>1.5)
24  return 0.0;
25  else if(r>0.5 && r<=1.5)
26  return 1.0/(6*h)*( 5.0 - 3.0*r - sqrt(-3.0*(1-r)*(1-r) + 1.0) );
27  else
28  return 1.0/(3*h)*( 1.0 + sqrt(-3.0*r*r + 1.0) );
29 } // dhRomaDeviceE
30 
31 
41 __device__
43 {
44  return dhRomaDeviceE(x, h) * dhRomaDeviceE(y, h);
45 } // deltaDeviceE
46 
47 
52 namespace kernels
53 {
54 
72 __global__
73 void generateE(int *ERows, int *ECols, real *EVals,
74  int nx, int ny, real *x, real *y, real *dx,
75  int totalPoints, real *xB, real *yB, int *I, int *J)
76 {
77  int bodyIdx = threadIdx.x + blockIdx.x*blockDim.x;
78 
79  if(bodyIdx < totalPoints)
80  {
81  int Ib=I[bodyIdx],
82  Jb=J[bodyIdx],
83  EIdx = bodyIdx*12,
84  i, j;
85 
86  real Dx = dx[Ib];
87 
88  // uB = integral u * delta * dxdy = Ehat * u
89  // E = Ehat * R^-1 => divide by Dx
90  // E = Dx * delta
91 
92  // populate x-components
93  for(j=Jb-1; j<=Jb+1; j++)
94  {
95  for(i=Ib-2; i<=Ib+1; i++)
96  {
97  ERows[EIdx] = bodyIdx;
98  ECols[EIdx] = j*(nx-1) + i;
99  EVals[EIdx] = Dx*deltaDeviceE(x[i+1]-xB[bodyIdx], 0.5*(y[j]+y[j+1])-yB[bodyIdx], Dx);
100  EIdx++;
101  }
102  }
103 
104  // populate y-components
105  for(j=Jb-2; j<=Jb+1; j++)
106  {
107  for(i=Ib-1; i<=Ib+1; i++)
108  {
109  ERows[EIdx+12*totalPoints-12] = bodyIdx + totalPoints;
110  ECols[EIdx+12*totalPoints-12] = j*nx + i + (nx-1)*ny;
111  EVals[EIdx+12*totalPoints-12] = Dx*deltaDeviceE(0.5*(x[i]+x[i+1])-xB[bodyIdx], y[j+1]-yB[bodyIdx], Dx);
112  EIdx++;
113  }
114  }
115  }
116 } // generateE
117 
118 } // End of namespace kernels
double real
Is a float or a double depending on the machine precision.
Definition: types.h:116
__device__ real deltaDeviceE(real x, real y, real h)
Two-dimension discrete delta function.
Definition: generateE.cu:42
Contains all the custom-written CUDA kernels.
__device__ real dhRomaDeviceE(real x, real h)
Discrete delta function defined by Roma et al. (1999).
Definition: generateE.cu:19
Declaration of the kernels to generate the interpolation matrix.
__global__ void generateE(int *ERows, int *ECols, real *EVals, int nx, int ny, real *x, real *y, real *dx, int totalPoints, real *xB, real *yB, int *I, int *J)
Computes elements of the interpolation matrix.
Definition: generateE.cu:73