ProjectPhysX / FluidX3D

The fastest and most memory efficient lattice Boltzmann CFD software, running on all GPUs via OpenCL. Free for non-commercial use.
https://youtube.com/@ProjectPhysX
Other
3.48k stars 281 forks source link

Unnecessary neighbor calculations #199

Open Meerkov opened 1 week ago

Meerkov commented 1 week ago

https://github.com/ProjectPhysX/FluidX3D/blob/4258d2e5b69ce5966dea1237aeec4bb7cee69f46/src/kernel.cpp#L993

    j[ 1] = xp+y0+z0; j[ 2] = xm+y0+z0; // +00 -00
    j[ 3] = x0+yp+z0; j[ 4] = x0+ym+z0; // 0+0 0-0
    j[ 5] = x0+y0+zp; j[ 6] = x0+y0+zm; // 00+ 00-
    j[ 7] = xp+yp+z0; j[ 8] = xm+ym+z0; // ++0 --0
    j[ 9] = xp+y0+zp; j[10] = xm+y0+zm; // +0+ -0-
    j[11] = x0+yp+zp; j[12] = x0+ym+zm; // 0++ 0--
    j[13] = xp+ym+z0; j[14] = xm+yp+z0; // +-0 -+0
    j[15] = xp+y0+zm; j[16] = xm+y0+zp; // +0- -0+
    j[17] = x0+yp+zm; j[18] = x0+ym+zp; // 0+- 0-+
    j[19] = xp+yp+zp; j[20] = xm+ym+zm; // +++ ---
    j[21] = xp+yp+zm; j[22] = xm+ym+zp; // ++- --+
    j[23] = xp+ym+zp; j[24] = xm+yp+zm; // +-+ -+-
    j[25] = xm+yp+zp; j[26] = xp+ym+zm; // -++ +--

j[even] are only used when calclating Surface. const uchar flagsji_su = flags[j[i]]&TYPE_SU; // extract SURFACE flags when resetting velocity of nodes with only solid neighbors, which seems rare or even unnecessary because a node with only solid neighbors is likely to be solid itself, which zeros the velocity anyway. for(uint i=1u; i<def_velocity_set; i++) TYPE_ONLY_S = TYPE_ONLY_S&&(flagsj[i]&TYPE_BO)==TYPE_S;

Only half of these values are ever used in the esoteric pull algorithm. Only the odd indexes are used, while the even ones are never used.

Given the purpose seems to be to to ensure high degree of optimization, It seems like these can either be removed entirely, or guarded by a SURFACE or MOVING BOUNDARIES requirement.