Updated host_esph to extra data and cut to coeff

This commit is contained in:
Trung Nguyen
2023-12-07 11:06:17 -06:00
parent 26c7358a84
commit 379d3c8e20
4 changed files with 91 additions and 111 deletions

View File

@ -45,8 +45,8 @@ int SPHLJT::bytes_per_atom(const int max_nbors) const {
template <class numtyp, class acctyp> template <class numtyp, class acctyp>
int SPHLJT::init(const int ntypes, int SPHLJT::init(const int ntypes,
double **host_cutsq, double **host_viscosity, double **host_cutsq, double **host_cut,
double *host_special_lj, double **host_viscosity, double *host_special_lj,
const int nlocal, const int nall, const int nlocal, const int nall,
const int max_nbors, const int maxspecial, const int max_nbors, const int maxspecial,
const double cell_size, const double cell_size,
@ -92,8 +92,8 @@ int SPHLJT::init(const int ntypes,
host_write[i]=0.0; host_write[i]=0.0;
coeff.alloc(lj_types*lj_types,*(this->ucl_device),UCL_READ_ONLY); coeff.alloc(lj_types*lj_types,*(this->ucl_device),UCL_READ_ONLY);
this->atom->type_pack2(ntypes,lj_types,coeff,host_write,host_viscosity, this->atom->type_pack4(ntypes,lj_types,coeff,host_write,host_viscosity,
host_cutsq); host_cut, host_cutsq);
UCL_H_Vec<double> dview; UCL_H_Vec<double> dview;
sp_lj.alloc(4,*(this->ucl_device),UCL_READ_ONLY); sp_lj.alloc(4,*(this->ucl_device),UCL_READ_ONLY);
@ -163,9 +163,9 @@ int SPHLJT::loop(const int eflag, const int vflag) {
int idx = n+i*nstride; int idx = n+i*nstride;
numtyp4 v; numtyp4 v;
v.x = rho[i]; v.x = rho[i];
v.x = esph[i];
v.y = cv[i]; v.y = cv[i];
v.z = mass[i]; v.w = mass[i];
v.w = 0;
pextra[idx] = v; pextra[idx] = v;
} }
this->atom->add_extra_data(); this->atom->add_extra_data();
@ -202,8 +202,10 @@ int SPHLJT::loop(const int eflag, const int vflag) {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
template <class numtyp, class acctyp> template <class numtyp, class acctyp>
void SPHLJT::get_extra_data(double *host_rho, double *host_cv, double* host_mass) { void SPHLJT::get_extra_data(double *host_rho, double *host_esph,
double *host_cv, double* host_mass) {
rho = host_rho; rho = host_rho;
esph = host_esph;
cv = host_cv; cv = host_cv;
mass = host_mass; mass = host_mass;
} }

View File

@ -77,7 +77,8 @@ __kernel void k_sph_lj(const __global numtyp4 *restrict x_,
energy=(acctyp)0; energy=(acctyp)0;
for (int i=0; i<6; i++) virial[i]=(acctyp)0; for (int i=0; i<6; i++) virial[i]=(acctyp)0;
} }
acctyp Qi = (acctyp)0; acctyp2 drhoEacc;
drhoEacc.x = drhoEacc.x = (acctyp)0;
if (ii<inum) { if (ii<inum) {
int i, numj, nbor, nbor_end; int i, numj, nbor, nbor_end;
@ -88,24 +89,29 @@ __kernel void k_sph_lj(const __global numtyp4 *restrict x_,
int itype=ix.w; int itype=ix.w;
numtyp mass_itype = mass[itype]; numtyp mass_itype = mass[itype];
numtyp4 iv; fetch4(iv,i,vel_tex); //v_[i]; numtyp4 iv; fetch4(iv,i,vel_tex); //v_[i];
int itag=iv.w;
const numtyp4 Tcvi = extra[i]; const numtyp4 extrai = extra[i];
numtyp Ti = Tcvi.x; numtyp rhoi = extrai.x;
numtyp cvi = Tcvi.y; numtyp esphi = extrai.y;
numtyp cvi = extrai.z;
numtyp massi= extrai.w;
numtyp factor_dpd; // compute pressure of particle i with LJ EOS
numtyp fi, ci;
//LJEOS2(rho[i], esph[i], cv[i], &fi, &ci);
//fi /= (rho[i] * rho[i]);
numtyp factor_lj;
for ( ; nbor<nbor_end; nbor+=n_stride) { for ( ; nbor<nbor_end; nbor+=n_stride) {
ucl_prefetch(dev_packed+nbor+n_stride); ucl_prefetch(dev_packed+nbor+n_stride);
int j=dev_packed[nbor]; int j=dev_packed[nbor];
factor_dpd = sp_lj[sbmask(j)]; factor_lj = sp_lj[sbmask(j)];
j &= NEIGHMASK; j &= NEIGHMASK;
numtyp4 jx; fetch4(jx,j,pos_tex); //x_[j]; numtyp4 jx; fetch4(jx,j,pos_tex); //x_[j];
int jtype=jx.w; int jtype=jx.w;
numtyp4 jv; fetch4(jv,j,vel_tex); //v_[j]; numtyp4 jv; fetch4(jv,j,vel_tex); //v_[j];
int jtag=jv.w;
// Compute r12 // Compute r12
numtyp delx = ix.x-jx.x; numtyp delx = ix.x-jx.x;
@ -114,102 +120,70 @@ __kernel void k_sph_lj(const __global numtyp4 *restrict x_,
numtyp rsq = delx*delx+dely*dely+delz*delz; numtyp rsq = delx*delx+dely*dely+delz*delz;
int mtype=itype*lj_types+jtype; int mtype=itype*lj_types+jtype;
if (rsq<cutsq[mtype]) { if (rsq<coeff[mtype].z) { // cutsq[itype][jtype]
numtyp r=ucl_sqrt(rsq);
if (r < EPSILON) continue;
numtyp rinv=ucl_recip(r); const numtyp coeffx=coeff[mtype].x; // viscosity[itype][jtype]
const numtyp coeffy=coeff[mtype].y; // cut[itype][jtype]
const numtyp4 extraj = extra[j];
numtyp rhoj = extraj.x;
numtyp esphj = extraj.y;
numtyp cvj = extraj.z;
numtyp massj= extraj.w;
numtyp h = coeffy; // cut[itype][jtype]
ih = (numtyp) 1.0 / h;
numtyp ihsq = ih * ih;
numtyp ihcub = ihsq * ih;
numtyp wfd = h - ucl_sqrt(rsq);
// domain->dimension == 3 Lucy Kernel, 3d
wfd = -25.066903536973515383e0 * wfd * wfd * ihsq * ihsq * ihsq * ih;
// Lucy Kernel, 2d
//wfd = -19.098593171027440292e0 * wfd * wfd * ihsq * ihsq * ihsq;
// function call to LJ EOS
numtyp fj, cj;
//LJEOS2(rho[j], esph[j], cv[j], &fj, &cj);
//fj /= (rho[j] * rho[j]);
// apply long-range correction to model a LJ fluid with cutoff
// this implies that the modelled LJ fluid has cutoff == SPH cutoff
numtyp lrc = (numtyp)-11.1701 * (ihcub * ihcub * ihcub - (numtyp)1.5 * ihcub);
fi += lrc;
fj += lrc;
// dot product of velocity delta and distance vector
numtyp delvx = iv.x - jv.x; numtyp delvx = iv.x - jv.x;
numtyp delvy = iv.y - jv.y; numtyp delvy = iv.y - jv.y;
numtyp delvz = iv.z - jv.z; numtyp delvz = iv.z - jv.z;
numtyp dot = delx*delvx + dely*delvy + delz*delvz; numtyp delVdotDelR = delx*delvx + dely*delvy + delz*delvz;
numtyp vijeij = dot*rinv;
const numtyp coeffx=coeff[mtype].x; // a0[itype][jtype] // artificial viscosity (Monaghan 1992)
const numtyp coeffy=coeff[mtype].y; // gamma[itype][jtype] numtyp fvisc = (numtyp)0;
const numtyp coeffz=coeff[mtype].z; // cut[itype][jtype] if (delVdotDelR < (numyp)0) {
mu = h * delVdotDelR / (rsq + (numyp)0.01 * h * h);
const numtyp4 Tcvj = extra[j]; fvisc = -coeffx * (ci + cj) * mu / (rhoi + rhoj); // viscosity[itype][jtype]
numtyp Tj = Tcvj.x;
numtyp cvj = Tcvj.y;
unsigned int tag1=itag, tag2=jtag;
if (tag1 > tag2) {
tag1 = jtag; tag2 = itag;
} }
numtyp randnum = (numtyp)0.0; // total pair force & thermal energy increment
saru(tag1, tag2, seed, timestep, randnum); numtyp force = -massi * massj * (fi + fj + fvisc) * wfd;
numtyp deltaE = (numtyp)-0.5 * force * delVdotDelR;
numtyp T_ij=(numtyp)0.5*(Ti+Tj);
numtyp4 T_pow;
T_pow.x = T_ij - (numtyp)1.0;
T_pow.y = T_pow.x*T_pow.x;
T_pow.z = T_pow.x*T_pow.y;
T_pow.w = T_pow.x*T_pow.z;
numtyp coeff2x = coeff2[mtype].x; //power[itype][jtype]
numtyp coeff2y = coeff2[mtype].y; //kappa[itype][jtype]
numtyp coeff2z = coeff2[mtype].z; //powerT[itype][jtype]
numtyp coeff2w = coeff2[mtype].w; //cutT[itype][jtype]
numtyp power_d = coeff2x;
if (power_flag) {
numtyp factor = (numtyp)1.0;
factor += sc[mtype].x*T_pow.x + sc[mtype].y*T_pow.y +
sc[mtype].z*T_pow.z + sc[mtype].w*T_pow.w;
power_d *= factor;
}
power_d = MAX((numtyp)0.01,power_d);
numtyp wc = (numtyp)1.0 - r/coeffz; // cut[itype][jtype]
wc = MAX((numtyp)0.0,MIN((numtyp)1.0,wc));
numtyp wr = ucl_pow(wc, (numtyp)0.5*power_d);
numtyp kboltz = (numtyp)1.0;
numtyp GammaIJ = coeffy; // gamma[itype][jtype]
numtyp SigmaIJ = (numtyp)4.0*GammaIJ*kboltz*Ti*Tj/(Ti+Tj);
SigmaIJ = ucl_sqrt(SigmaIJ);
numtyp force = coeffx*T_ij*wc; // a0[itype][jtype]
force -= GammaIJ *wr*wr *dot*rinv;
force += SigmaIJ * wr *randnum * dtinvsqrt;
force *= factor_dpd*rinv;
f.x+=delx*force; f.x+=delx*force;
f.y+=dely*force; f.y+=dely*force;
f.z+=delz*force; f.z+=delz*force;
// heat transfer // and change in density, drho[i]
drhoEacc.x += massj * delVdotDelR * wfd;
if (r < coeff2w) {
numtyp wrT = (numtyp)1.0 - r/coeff2w;
wrT = MAX((numtyp)0.0,MIN((numtyp)1.0,wrT));
wrT = ucl_pow(wrT, (numtyp)0.5*coeff2z); // powerT[itype][jtype]
numtyp randnumT = (numtyp)0;
saru(tag1, tag2, seed+tag1+tag2, timestep, randnumT); // randomT->gaussian();
randnumT = MAX((numtyp)-5.0,MIN(randnum,(numtyp)5.0));
numtyp kappaT = coeff2y; // kappa[itype][jtype] // change in thermal energy, desph[i]
if (kappa_flag) { drhoEacc.y += deltaE;
numtyp factor = (numtyp)1.0;
factor += kc[mtype].x*T_pow.x + kc[mtype].y*T_pow.y +
kc[mtype].z*T_pow.z + kc[mtype].w*T_pow.w;
kappaT *= factor;
}
numtyp kij = cvi*cvj*kappaT * T_ij*T_ij;
numtyp alphaij = ucl_sqrt((numtyp)2.0*kboltz*kij);
numtyp dQc = kij * wrT*wrT * (Tj - Ti)/(Ti*Tj);
numtyp dQd = wr*wr*( GammaIJ * vijeij*vijeij - SigmaIJ*SigmaIJ/mass_itype ) - SigmaIJ * wr *vijeij *randnum;
dQd /= (cvi+cvj);
numtyp dQr = alphaij * wrT * dtinvsqrt * randnumT;
Qi += (dQc + dQd + dQr );
}
if (EVFLAG && eflag) { if (EVFLAG && eflag) {
numtyp e = (numtyp)0.5*coeffx*T_ij*coeffz * wc*wc; numtyp e = (numtyp)0;
energy+=factor_dpd*e; energy+=e;
} }
if (EVFLAG && vflag) { if (EVFLAG && vflag) {
virial[0] += delx*delx*force; virial[0] += delx*delx*force;
@ -224,12 +198,12 @@ __kernel void k_sph_lj(const __global numtyp4 *restrict x_,
} // if ii } // if ii
store_answers(f,energy,virial,ii,inum,tid,t_per_atom,offset,eflag,vflag, store_answers(f,energy,virial,ii,inum,tid,t_per_atom,offset,eflag,vflag,
ans,engv); ans,engv);
store_drhoE(Qi,ii,inum,tid,t_per_atom,offset,Q); store_drhoE(drhoEacc,ii,inum,tid,t_per_atom,offset,drhoE);
} }
__kernel void k_sph_lj_fast(const __global numtyp4 *restrict x_, __kernel void k_sph_lj_fast(const __global numtyp4 *restrict x_,
const __global numtyp4 *restrict extra, const __global numtyp4 *restrict extra,
const __global numtyp2 *restrict coeff_in, const __global numtyp4 *restrict coeff_in,
const __global numtyp *restrict sp_lj_in, const __global numtyp *restrict sp_lj_in,
const __global int * dev_nbor, const __global int * dev_nbor,
const __global int * dev_packed, const __global int * dev_packed,

View File

@ -37,7 +37,8 @@ class SPHLJ : public BaseDPD<numtyp, acctyp> {
* - -3 if there is an out of memory error * - -3 if there is an out of memory error
* - -4 if the GPU library was not compiled for GPU * - -4 if the GPU library was not compiled for GPU
* - -5 Double precision is not supported on card **/ * - -5 Double precision is not supported on card **/
int init(const int ntypes, double **host_cutsq, double **host_viscosity, int init(const int ntypes, double **host_cutsq,
double** host_cut, double **host_viscosity,
double *host_special_lj, const int nlocal, const int nall, const int max_nbors, double *host_special_lj, const int nlocal, const int nall, const int max_nbors,
const int maxspecial, const double cell_size, const double gpu_split, const int maxspecial, const double cell_size, const double gpu_split,
FILE *screen); FILE *screen);
@ -52,14 +53,15 @@ class SPHLJ : public BaseDPD<numtyp, acctyp> {
/// Total host memory used by library for pair style /// Total host memory used by library for pair style
double host_memory_usage() const; double host_memory_usage() const;
void get_extra_data(double *host_rho, double *host_cv, double* host_mass); void get_extra_data(double *host_rho, double *host_esph,
double *host_cv, double* host_mass);
/// copy drho and desph from device to host /// copy drho and desph from device to host
void update_drhoE(void **drhoE_ptr); void update_drhoE(void **drhoE_ptr);
// --------------------------- TYPE DATA -------------------------- // --------------------------- TYPE DATA --------------------------
/// coeff.x = viscosity, coeff.y = cutsq /// coeff.x = viscosity, coeff.y = cut, coeff.z = cutsq
UCL_D_Vec<numtyp2> coeff; UCL_D_Vec<numtyp2> coeff;
/// Special LJ values /// Special LJ values
@ -76,7 +78,7 @@ class SPHLJ : public BaseDPD<numtyp, acctyp> {
int _max_drhoE_size; int _max_drhoE_size;
/// pointer to host data /// pointer to host data
double *rho, *cv, *mass; double *rho, *esph, *cv, *mass;
private: private:
bool _allocated; bool _allocated;

View File

@ -27,8 +27,9 @@ static SPHLJ<PRECISION,ACC_PRECISION> SPHLJMF;
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Allocate memory on host and device and copy constants to device // Allocate memory on host and device and copy constants to device
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
int sph_lj_gpu_init(const int ntypes, double **cutsq, double **host_viscosity, int sph_lj_gpu_init(const int ntypes, double **cutsq, double** host_cut,
double *special_lj, const int inum, const int nall, double **host_viscosity, double *special_lj,
const int inum, const int nall,
const int max_nbors, const int maxspecial, const int max_nbors, const int maxspecial,
const double cell_size, int &gpu_mode, FILE *screen) { const double cell_size, int &gpu_mode, FILE *screen) {
SPHLJMF.clear(); SPHLJMF.clear();
@ -53,8 +54,8 @@ int sph_lj_gpu_init(const int ntypes, double **cutsq, double **host_viscosity,
int init_ok=0; int init_ok=0;
if (world_me==0) if (world_me==0)
init_ok=SPHLJMF.init(ntypes, cutsq, host_viscosity, special_lj, init_ok=SPHLJMF.init(ntypes, cutsq, host_cut, host_viscosity,
inum, nall, max_nbors, maxspecial, special_lj, inum, nall, max_nbors, maxspecial,
cell_size, gpu_split, screen); cell_size, gpu_split, screen);
SPHLJMF.device->world_barrier(); SPHLJMF.device->world_barrier();
@ -71,9 +72,9 @@ int sph_lj_gpu_init(const int ntypes, double **cutsq, double **host_viscosity,
fflush(screen); fflush(screen);
} }
if (gpu_rank==i && world_me!=0) if (gpu_rank==i && world_me!=0)
init_ok=SPHLJMF.init(ntypes, cutsq, host_viscosity, special_lj, init_ok=SPHLJMF.init(ntypes, cutsq, host_cut, host_viscosity,
inum, nall, max_nbors, maxspecial, special_lj, inum, nall, max_nbors, maxspecial,
cell_size, gpu_split, screen); cell_size, gpu_split, screen);
SPHLJMF.device->serialize_init(); SPHLJMF.device->serialize_init();
if (message) if (message)
@ -119,8 +120,9 @@ void sph_lj_gpu_compute(const int ago, const int inum_full, const int nall,
tag, host_v, dtinvsqrt, seed, timestep, nlocal, boxlo, prd); tag, host_v, dtinvsqrt, seed, timestep, nlocal, boxlo, prd);
} }
void sph_lj_gpu_get_extra_data(double *host_rho, double *host_cv, double *host_mass) { void sph_lj_gpu_get_extra_data(double *host_rho, double *host_esph,
SPHLJMF.get_extra_data(host_rho, host_cv, host_mass); double *host_cv, double *host_mass) {
SPHLJMF.get_extra_data(host_rho, host_esph, host_cv, host_mass);
} }
void sph_lj_gpu_update_drhoE(void **drhoE_ptr) { void sph_lj_gpu_update_drhoE(void **drhoE_ptr) {