1#include "../../include/sph/internal_forces.cuh"
2#include "../../include/cuda_utils/cuda_launcher.cuh"
5 int *interactions,
int numRealParticles) {
7 int i, k, inc, j, numInteractions;
40 const real eps_balsara = 1e-4;
93 inc = blockDim.x * gridDim.x;
94 for (i = threadIdx.x + blockIdx.x * blockDim.x; i < numRealParticles; i += inc) {
98 numInteractions = particles->
noi[i];
112 sml1 = particles->
sml[i];
119 particles->dsmldt[i] = 0.0;
123 for (d = 0; d <
DIM; d++) {
126 accelshearj[d] = 0.0;
128 sml = particles->
sml[i];
137 vx = particles->
vx[i];
139 vy = particles->
vy[i];
141 vz = particles->
vz[i];
147 particles->
ax[i] = 0;
150 particles->
ay[i] = 0;
153 particles->
az[i] = 0;
157 particles->
drhodt[i] = 0.0;
159 particles->
dedt[i] = 0.0;
162 particles->dsmldt[i] = 0.0;
167 if (numInteractions < 1) {
174 for (d = 0; d <
DIM; d++) {
175 curli += particles->curlv[i*
DIM+d]*particles->curlv[i*
DIM+d];
179 + curli + eps_balsara*particles->
cs[i]/particles->
sml[i]);
184 for (k = 0; k < numInteractions; k++) {
196 for (d = 0; d <
DIM; d++) {
200#if (VARIABLE_SML || INTEGRATE_SML)
201 sml = 0.5 * (particles->
sml[i] + particles->
sml[j]);
204 vxj = particles->
vx[j];
206 vyj = particles->
vy[j];
208 vzj = particles->
vz[j];
212 dr[0] = x - particles->
x[j];
214 dr[1] = y - particles->
y[j];
216 dr[2] = z - particles->
z[j];
221 for (e = 0; e <
DIM; e++) {
238 kernel(&W, dWdx, &dWdr, dr, particles->
sml[i]);
239 kernel(&Wj, dWdxj, &dWdrj, dr, particles->
sml[j]);
240# if SHEPARD_CORRECTION
241 W /= p_rhs.shepard_correction[i];
242 Wj /= p_rhs.shepard_correction[j];
243 for (e = 0; e <
DIM; e++) {
244 dWdx[e] /= p_rhs.shepard_correction[i];
245 dWdxj[e] /= p_rhs.shepard_correction[j];
247 dWdr /= p_rhs.shepard_correction[i];
248 dWdrj /= p_rhs.shepard_correction[j];
251 dWdr = 0.5 * (dWdr + dWdrj);
252 for (e = 0; e <
DIM; e++) {
253 dWdx[e] = 0.5 * (dWdx[e] + dWdxj[e]);
257 kernel(&W, dWdx, &dWdr, dr, sml);
258#if SHEPARD_CORRECTION
259 W /= p_rhs.shepard_correction[i];
260 for (e = 0; e <
DIM; e++) {
261 dWdx[e] /= p_rhs.shepard_correction[i];
263 dWdr /= p_rhs.shepard_correction[i];
267 dv[0] = dvx = vx - vxj;
269 dv[1] = dvy = vy - vyj;
271 dv[2] = dvz = vz - vzj;
275 vvnablaW = dvx * dWdx[0];
277 vvnablaW += dvy * dWdx[1];
279 vvnablaW += dvz * dWdx[2];
286 for (e = 0; e <
DIM; e++) {
297 csbar = 0.5*(particles->
cs[i] + particles->
cs[j]);
301 smooth = 0.5*(sml1 + particles->
sml[j]);
303 const real eps_artvisc = 1e-2;
304 mu = smooth*vr/(rr + smooth*smooth*eps_artvisc);
309 rhobar = 0.5 * (particles->
rho[i] + particles->
rho[j]);
312 for (d = 0; d <
DIM; d++) {
313 curlj += particles->curlv[j*
DIM+d]*particles->curlv[j*
DIM+d];
317 + curlj + eps_balsara*particles->
cs[j]/particles->
sml[j]);
320 pij = (beta*mu - alpha*csbar) * mu/rhobar;
328 eta = (particles->eta[i] + particles->eta[j]) * 0.5 ;
329 for (d = 0; d <
DIM; d++) {
331 for (dd = 0; dd <
DIM; dd++) {
332# if (SPH_EQU_VERSION == 1)
334 accelshearj[d] += eta * particles->
mass[j] * (particles->Tshear[
CudaUtils::stressIndex(j,d,dd)]/(particles->sml_omega[j]*particles->
rho[j]*particles->
rho[j])+ particles->Tshear[
stressIndex(i,d,dd)]/(particles->sml_omega[i]*particles->
rho[i]*particles->
rho[i])) *dWdx[dd];
338# elif (SPH_EQU_VERSION == 2)
350 zetaij = -0.5 * (0.25*(p.h[i] + p.h[j])*(p.h[i]+p.h[j])) * (p.rho[i]+p.rho[j])*0.5 * (p_rhs.divv[i] + p_rhs.divv[j])*0.5;
352 for (d = 0; d <
DIM; d++) {
353# if (SPH_EQU_VERSION == 1)
354 accelshearj[d] += zetaij * p.m[j] * (p_rhs.divv[i] + p_rhs.divv[j]) /(p.rho[i]*p.rho[j]) * dWdx[d];
355# elif (SPH_EQU_VERSION == 2)
356 accelshearj[d] += zetaij * p.m[j] * (p_rhs.divv[i]/(p.rho[i]*p.rho[i]) + p_rhs.divv[j]/(p.rho[j]*p.rho[j])) * dWdx[d];
362#if (SPH_EQU_VERSION == 1)
364 for (d = 0; d <
DIM; d++) {
365 accelsj[d] = -particles->
mass[j] * (particles->
p[i]/(particles->
rho[i]*particles->
rho[i]) + particles->
p[j]/(particles->
rho[j]*particles->
rho[j])) * dWdx[d];
366 accels[d] += accelsj[d];
368#elif (SPH_EQU_VERSION == 2)
370 for (d = 0; d <
DIM; d++) {
371 accelsj[d] = -particles->
mass[j] * ((particles->
p[i]+particles->
p[j])/(particles->
rho[i]*particles->
rho[j])) * dWdx[d];
372 accels[d] += accelsj[d];
382 for (d = 0; d <
DIM; d++) {
383 accels[d] += accelshearj[d];
387 accels[0] += particles->
mass[j]*(-pij)*dWdx[0];
389 accels[1] += particles->
mass[j]*(-pij)*dWdx[1];
391 accels[2] += particles->
mass[j]*(-pij)*dWdx[2];
398 drhodt += particles->
rho[i]/particles->
rho[j] * particles->
mass[j] * vvnablaW;
402#if TENSORIAL_CORRECTION
403 for (d = 0; d <
DIM; d++) {
404 for (dd = 0; dd <
DIM; dd++) {
405 particles->dsmldt[i] -= 1./
DIM * particles->
sml[i] * particles->
mass[j]/particles->
rho[j] * dv[d] * dWdx[dd] * particles->tensorialCorrectionMatrix[i*
DIM*
DIM+d*
DIM+dd];
410 particles->dsmldt[i] -= 1./
DIM * particles->
sml[i] * particles->
mass[j]/particles->
rho[j] * vvnablaW;
417 dedt += 0.5 * particles->
mass[j] * pij * vvnablaW;
424 dedt += 0.5 * accelsj[0] * -dvx;
426 dedt += 0.5 * accelsj[1] * -dvy;
429 dedt += 0.5 * accelsj[2] * -dvz;
447 particles->
ax[i] = ax;
449 particles->
ay[i] = ay;
451 particles->
az[i] = az;
459 particles->
drhodt[i] = drhodt;
463 particles->
dedt[i] = dedt;
472 int *interactions,
int numRealParticles) {
Execution policy/instruction for CUDA kernel execution.
ArtificialViscosity artificialViscosity
Particle(s) class based on SoA (Structur of Arrays).
integer * noi
(pointer to) number of interactions (array)
integer * materialId
(pointer to) material identifier (array)
real * x
(pointer to) x position (array)
real * rho
(pointer to) density (array)
real * drhodt
(pointer to) time derivative of density (array)
real * ay
(pointer to) y acceleration (array)
real * az
(pointer to) z acceleration (array)
real * p
(pointer to) pressure (array)
real * cs
(pointer to) sound of speed (array)
real * y
(pointer to) y position (array)
real * ax
(pointer to) x acceleration (array)
real * sml
(pointer to) smoothing length (array)
real * dedt
(pointer to) time derivative of internal energy (array)
real * mass
(pointer to) mass (array)
real * z
(pointer to) z position (array)
real * vz
(pointer to) z velocity (array)
real * vx
(pointer to) x velocity (array)
real * vy
(pointer to) y velocity (array)
#define cudaTerminate(...)
__device__ int stressIndex(int particleIndex, int row, int col)
map [i][j] to [i*DIM*DIM+j] for the tensors
const char *const internalForces
real internalForces(::SPH::SPH_kernel kernel, Material *materials, Tree *tree, Particles *particles, int *interactions, int numRealParticles)
Wrapper for SPH::Kernel::internalForces().
__global__ void internalForces(::SPH::SPH_kernel kernel, Material *materials, Tree *tree, Particles *particles, int *interactions, int numRealParticles)
Internal SPH forces.
void(* SPH_kernel)(real *W, real dWdx[DIM], real *dWdr, real dx[DIM], real h)
Function pointer to generic SPH kernel function.
__device__ real sqrt(real a)
Square root of a floating point value.
__device__ real abs(real a)
Absolute value of a floating point value.
real launch(bool timeKernel, const ExecutionPolicy &policy, void(*f)(Arguments...), Arguments... args)
CUDA execution wrapper function.
#define MAX_NUM_INTERACTIONS
#define DIM
Dimension of the problem.
real alpha
Artificial viscosity .
real beta
Artificial viscosity .