#include #include //#include #define NBLOCKS 1024 #define NTHREADS 512 __global__ void dvc_ScaLBL_D3Q7_AAodd_Poisson_ElectricPotential(int *neighborList,int *Map, double *dist, double *Psi, int start, int finish, int Np){ int n; double psi;//electric potential double fq; int nread; int idx; int S = Np/NBLOCKS/NTHREADS + 1; for (int s=0; s 10Np => odd part of dist) f1 = dist[nr1]; // reading the f1 data into register fq nr2 = neighborList[n+Np]; // neighbor 1 ( < 10Np => even part of dist) f2 = dist[nr2]; // reading the f2 data into register fq // q=3 nr3 = neighborList[n+2*Np]; // neighbor 4 f3 = dist[nr3]; // q = 4 nr4 = neighborList[n+3*Np]; // neighbor 3 f4 = dist[nr4]; // q=5 nr5 = neighborList[n+4*Np]; f5 = dist[nr5]; // q = 6 nr6 = neighborList[n+5*Np]; f6 = dist[nr6]; Ex = (f1-f2)*rlx*4.0;//NOTE the unit of electric field here is V/lu Ey = (f3-f4)*rlx*4.0;//factor 4.0 is D3Q7 lattice speed of sound Ez = (f5-f6)*rlx*4.0; ElectricField[n+0*Np] = Ex; ElectricField[n+1*Np] = Ey; ElectricField[n+2*Np] = Ez; // q = 0 dist[n] = f0*(1.0-rlx) + 0.25*(rlx*psi+rho_e); // q = 1 dist[nr2] = f1*(1.0-rlx) + 0.125*(rlx*psi+rho_e); // q = 2 dist[nr1] = f2*(1.0-rlx) + 0.125*(rlx*psi+rho_e); // q = 3 dist[nr4] = f3*(1.0-rlx) + 0.125*(rlx*psi+rho_e); // q = 4 dist[nr3] = f4*(1.0-rlx) + 0.125*(rlx*psi+rho_e); // q = 5 dist[nr6] = f5*(1.0-rlx) + 0.125*(rlx*psi+rho_e); // q = 6 dist[nr5] = f6*(1.0-rlx) + 0.125*(rlx*psi+rho_e); //........................................................................ } } } __global__ void dvc_ScaLBL_D3Q7_AAeven_Poisson(int *Map, double *dist, double *Den_charge, double *Psi, double *ElectricField, double tau, double epsilon_LB,bool UseSlippingVelBC,int start, int finish, int Np){ int n; double psi;//electric potential double Ex,Ey,Ez;//electric field double rho_e;//local charge density double f0,f1,f2,f3,f4,f5,f6; double rlx=1.0/tau; int idx; int S = Np/NBLOCKS/NTHREADS + 1; for (int s=0; s 10Np => odd part of dist) f1 = dist[nr1]; // reading the f1 data into register fq nr2 = neighborList[n + Np]; // neighbor 1 ( < 10Np => even part of dist) f2 = dist[nr2]; // reading the f2 data into register fq // q=3 nr3 = neighborList[n + 2 * Np]; // neighbor 4 f3 = dist[nr3]; // q = 4 nr4 = neighborList[n + 3 * Np]; // neighbor 3 f4 = dist[nr4]; // q=5 nr5 = neighborList[n + 4 * Np]; f5 = dist[nr5]; // q = 6 nr6 = neighborList[n + 5 * Np]; f6 = dist[nr6]; // q=7 nr7 = neighborList[n + 6 * Np]; f7 = dist[nr7]; // q = 8 nr8 = neighborList[n + 7 * Np]; f8 = dist[nr8]; // q=9 nr9 = neighborList[n + 8 * Np]; f9 = dist[nr9]; // q = 10 nr10 = neighborList[n + 9 * Np]; f10 = dist[nr10]; // q=11 nr11 = neighborList[n + 10 * Np]; f11 = dist[nr11]; // q=12 nr12 = neighborList[n + 11 * Np]; f12 = dist[nr12]; // q=13 nr13 = neighborList[n + 12 * Np]; f13 = dist[nr13]; // q=14 nr14 = neighborList[n + 13 * Np]; f14 = dist[nr14]; // q=15 nr15 = neighborList[n + 14 * Np]; f15 = dist[nr15]; // q=16 nr16 = neighborList[n + 15 * Np]; f16 = dist[nr16]; // q=17 //fq = dist[18*Np+n]; nr17 = neighborList[n + 16 * Np]; f17 = dist[nr17]; // q=18 nr18 = neighborList[n + 17 * Np]; f18 = dist[nr18]; sum_q = f1+f2+f3+f4+f5+f6+f7+f8+f9+f10+f11+f12+f13+f14+f15+f16+f17+f18; //error = 8.0*(sum_q - f0) + rho_e; psi = 2.0*(f0*(1.0 - rlx) + rlx*(sum_q + 0.125*rho_e)); idx = Map[n]; Psi[idx] = psi; Ex = (f1 - f2 + 0.5*(f7 - f8 + f9 - f10 + f11 - f12 + f13 - f14))*4.0; //NOTE the unit of electric field here is V/lu Ey = (f3 - f4 + 0.5*(f7 - f8 - f9 + f10 + f15 - f16 + f17 - f18))*4.0; Ez = (f5 - f6 + 0.5*(f11 - f12 - f13 + f14 + f15 - f16 - f17 + f18))*4.0; ElectricField[n + 0 * Np] = Ex; ElectricField[n + 1 * Np] = Ey; ElectricField[n + 2 * Np] = Ez; // q = 0 dist[n] = W0*psi; //f0 * (1.0 - rlx) - (1.0-0.5*rlx)*W0*rho_e; // q = 1 dist[nr2] = W1*psi; //f1 * (1.0 - rlx) +W1* (rlx * psi) - (1.0-0.5*rlx)*0.05555555555555555*rho_e; // q = 2 dist[nr1] = W1*psi; //f2 * (1.0 - rlx) +W1* (rlx * psi) - (1.0-0.5*rlx)*0.05555555555555555*rho_e; // q = 3 dist[nr4] = W1*psi; //f3 * (1.0 - rlx) +W1* (rlx * psi) - (1.0-0.5*rlx)*0.05555555555555555*rho_e; // q = 4 dist[nr3] = W1*psi; //f4 * (1.0 - rlx) +W1* (rlx * psi) - (1.0-0.5*rlx)*0.05555555555555555*rho_e; // q = 5 dist[nr6] = W1*psi; //f5 * (1.0 - rlx) +W1* (rlx * psi) - (1.0-0.5*rlx)*0.05555555555555555*rho_e; // q = 6 dist[nr5] = W1*psi; //f6 * (1.0 - rlx) +W1* (rlx * psi) - (1.0-0.5*rlx)*0.05555555555555555*rho_e; //........................................................................ // q = 7 dist[nr8] = W2*psi; //f7 * (1.0 - rlx) +W2* (rlx * psi) - (1.0-0.5*rlx)*0.02777777777777778*rho_e; // q = 8 dist[nr7] = W2*psi; //f8 * (1.0 - rlx) +W2* (rlx * psi) - (1.0-0.5*rlx)*0.02777777777777778*rho_e; // q = 9 dist[nr10] = W2*psi; //f9 * (1.0 - rlx) +W2* (rlx * psi) - (1.0-0.5*rlx)*0.02777777777777778*rho_e; // q = 10 dist[nr9] = W2*psi; //f10 * (1.0 - rlx) +W2* (rlx * psi) - (1.0-0.5*rlx)*0.02777777777777778*rho_e; // q = 11 dist[nr12] = W2*psi; //f11 * (1.0 - rlx) +W2* (rlx * psi) - (1.0-0.5*rlx)*0.02777777777777778*rho_e; // q = 12 dist[nr11] = W2*psi; //f12 * (1.0 - rlx) +W2* (rlx * psi) - (1.0-0.5*rlx)*0.02777777777777778*rho_e; // q = 13 dist[nr14] = W2*psi; //f13 * (1.0 - rlx) +W2* (rlx * psi) - (1.0-0.5*rlx)*0.02777777777777778*rho_e; // q= 14 dist[nr13] = W2*psi; //f14 * (1.0 - rlx) +W2* (rlx * psi) - (1.0-0.5*rlx)*0.02777777777777778*rho_e; // q = 15 dist[nr16] = W2*psi; //f15 * (1.0 - rlx) +W2* (rlx * psi) - (1.0-0.5*rlx)*0.02777777777777778*rho_e; // q = 16 dist[nr15] = W2*psi; //f16 * (1.0 - rlx) +W2* (rlx * psi) - (1.0-0.5*rlx)*0.02777777777777778*rho_e; // q = 17 dist[nr18] = W2*psi; //f17 * (1.0 - rlx) +W2* (rlx * psi) - (1.0-0.5*rlx)*0.02777777777777778*rho_e; // q = 18 dist[nr17] = W2*psi; //f18 * (1.0 - rlx) +W2* (rlx * psi) - (1.0-0.5*rlx)*0.02777777777777778*rho_e; } } } __global__ void dvc_ScaLBL_D3Q19_AAeven_Poisson(int *Map, double *dist, double *Den_charge, double *Psi, double *ElectricField, double *Error, double tau, double epsilon_LB, bool UseSlippingVelBC, int start, int finish, int Np) { int n; double psi; //electric potential double Ex, Ey, Ez; //electric field double rho_e; //local charge density double f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18; double error,sum_q; double rlx = 1.0 / tau; int idx; double W0 = 0.5; double W1 = 1.0/24.0; double W2 = 1.0/48.0; int S = Np/NBLOCKS/NTHREADS + 1; for (int s=0; s>>(neighborList, Map, dist, Den_charge, Psi, ElectricField, tau, epsilon_LB, UseSlippingVelBC, start, finish, Np); cudaError_t err = cudaGetLastError(); if (cudaSuccess != err){ printf("CUDA error in dvc_ScaLBL_D3Q19_AAodd_Poisson: %s \n",cudaGetErrorString(err)); } } extern "C" void ScaLBL_D3Q19_AAeven_Poisson(int *Map, double *dist, double *Den_charge, double *Psi, double *ElectricField, double *Error, double tau, double epsilon_LB, bool UseSlippingVelBC, int start, int finish, int Np) { dvc_ScaLBL_D3Q19_AAeven_Poisson<<>>( Map, dist, Den_charge, Psi, ElectricField, Error, tau, epsilon_LB, UseSlippingVelBC, start, finish, Np); cudaError_t err = cudaGetLastError(); if (cudaSuccess != err){ printf("CUDA error in dvc_ScaLBL_D3Q19_AAeven_Poisson: %s \n",cudaGetErrorString(err)); } } extern "C" void ScaLBL_D3Q19_Poisson_Init(int *Map, double *dist, double *Psi, int start, int finish, int Np){ //cudaProfilerStart(); dvc_ScaLBL_D3Q19_Poisson_Init<<>>(Map, dist, Psi, start, finish, Np); cudaError_t err = cudaGetLastError(); if (cudaSuccess != err){ printf("CUDA error in ScaLBL_D3Q19_Poisson_Init: %s \n",cudaGetErrorString(err)); } } extern "C" void ScaLBL_D3Q7_AAodd_Poisson_ElectricPotential(int *neighborList,int *Map, double *dist, double *Psi, int start, int finish, int Np){ //cudaProfilerStart(); dvc_ScaLBL_D3Q7_AAodd_Poisson_ElectricPotential<<>>(neighborList,Map,dist,Psi,start,finish,Np); cudaError_t err = cudaGetLastError(); if (cudaSuccess != err){ printf("CUDA error in ScaLBL_D3Q7_AAodd_Poisson_ElectricPotential: %s \n",cudaGetErrorString(err)); } //cudaProfilerStop(); } extern "C" void ScaLBL_D3Q7_AAeven_Poisson_ElectricPotential(int *Map, double *dist, double *Psi, int start, int finish, int Np){ //cudaProfilerStart(); dvc_ScaLBL_D3Q7_AAeven_Poisson_ElectricPotential<<>>(Map,dist,Psi,start,finish,Np); cudaError_t err = cudaGetLastError(); if (cudaSuccess != err){ printf("CUDA error in ScaLBL_D3Q7_AAeven_Poisson_ElectricPotential: %s \n",cudaGetErrorString(err)); } //cudaProfilerStop(); } extern "C" void ScaLBL_D3Q7_AAodd_Poisson(int *neighborList, int *Map, double *dist, double *Den_charge, double *Psi, double *ElectricField, double tau, double epsilon_LB,bool UseSlippingVelBC,int start, int finish, int Np){ //cudaProfilerStart(); dvc_ScaLBL_D3Q7_AAodd_Poisson<<>>(neighborList,Map,dist,Den_charge,Psi,ElectricField,tau,epsilon_LB,UseSlippingVelBC,start,finish,Np); cudaError_t err = cudaGetLastError(); if (cudaSuccess != err){ printf("CUDA error in ScaLBL_D3Q7_AAodd_Poisson: %s \n",cudaGetErrorString(err)); } //cudaProfilerStop(); } extern "C" void ScaLBL_D3Q7_AAeven_Poisson(int *Map, double *dist, double *Den_charge, double *Psi, double *ElectricField, double tau, double epsilon_LB,bool UseSlippingVelBC,int start, int finish, int Np){ //cudaProfilerStart(); dvc_ScaLBL_D3Q7_AAeven_Poisson<<>>(Map,dist,Den_charge,Psi,ElectricField,tau,epsilon_LB,UseSlippingVelBC,start,finish,Np); cudaError_t err = cudaGetLastError(); if (cudaSuccess != err){ printf("CUDA error in ScaLBL_D3Q7_AAeven_Poisson: %s \n",cudaGetErrorString(err)); } //cudaProfilerStop(); } extern "C" void ScaLBL_D3Q7_Poisson_Init(int *Map, double *dist, double *Psi, int start, int finish, int Np){ //cudaProfilerStart(); dvc_ScaLBL_D3Q7_Poisson_Init<<>>(Map,dist,Psi,start,finish,Np); cudaError_t err = cudaGetLastError(); if (cudaSuccess != err){ printf("CUDA error in ScaLBL_D3Q7_Poisson_Init: %s \n",cudaGetErrorString(err)); } //cudaProfilerStop(); }