Commit e1d0f0d2 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Merge branch 'gizmo_mfm_clean' into 'master'

Gizmo mfm clean

See merge request !588
parents 7b9f99fb 880abb00
......@@ -31,12 +31,12 @@ cs2 = 2.*uconst/3.
A = 10.
fileName = "sineWavePotential.hdf5"
numPart = 100
numPart = 1000
boxSize = 1.
coords = np.zeros((numPart, 3))
v = np.zeros((numPart, 3))
m = np.zeros(numPart) + 1.
m = np.zeros(numPart) + 1000. / numPart
h = np.zeros(numPart) + 2./numPart
u = np.zeros(numPart) + uconst
ids = np.arange(numPart, dtype = 'L')
......
......@@ -23,8 +23,13 @@
import numpy as np
import h5py
import sys
import matplotlib
matplotlib.use("Agg")
import pylab as pl
pl.rcParams["figure.figsize"] = (12, 10)
pl.rcParams["text.usetex"] = True
# these should be the same as in makeIC.py
uconst = 20.2615290634
cs2 = 2.*uconst/3.
......@@ -39,15 +44,20 @@ fileName = sys.argv[1]
file = h5py.File(fileName, 'r')
coords = np.array(file["/PartType0/Coordinates"])
rho = np.array(file["/PartType0/Density"])
P = np.array(file["/PartType0/Pressure"])
u = np.array(file["/PartType0/InternalEnergy"])
agrav = np.array(file["/PartType0/GravAcceleration"])
m = np.array(file["/PartType0/Masses"])
vs = np.array(file["/PartType0/Velocities"])
ids = np.array(file["/PartType0/ParticleIDs"])
x = np.linspace(0., 1., 1000)
rho_x = 1000.*np.exp(-0.5*A/np.pi/cs2*np.cos(2.*np.pi*x))
P = cs2*rho
a = A * np.sin(2. * np.pi * x)
apart = A * np.sin(2. * np.pi * coords[:,0])
tkin = -0.5 * np.dot(apart, coords[:,0])
print tkin, 0.5 * np.dot(m, vs[:,0]**2)
ids_reverse = np.argsort(ids)
......@@ -65,13 +75,38 @@ for i in range(len(P)):
corr = 1.
idxp1 = ids_reverse[ip1]
idxm1 = ids_reverse[im1]
gradP[i] = (P[idxp1]-P[idxm1])/(coords[idxp1,0]-coords[idxm1,0])
gradP[i] = (P[idxp1] - P[idxm1])/(coords[idxp1,0] - coords[idxm1,0])
fig, ax = pl.subplots(2, 2, sharex = True)
ax[0][0].plot(coords[:,0], rho, ".", label = "gizmo-mfm")
ax[0][0].plot(x, rho_x, "-", label = "stable solution")
ax[0][0].set_ylabel("$\\rho{}$ (code units)")
ax[0][0].legend(loc = "best")
ax[0][1].plot(x, a, "-", label = "$\\nabla{}\\Phi{}$ external")
ax[0][1].plot(coords[:,0], gradP/rho, ".",
label = "$\\nabla{}P/\\rho{}$ gizmo-mfm")
ax[0][1].set_ylabel("force (code units)")
ax[0][1].legend(loc = "best")
ax[1][0].axhline(y = uconst, label = "isothermal $u$", color = "k",
linestyle = "--")
ax[1][0].plot(coords[:,0], u, ".", label = "gizmo-mfm")
ax[1][0].set_ylabel("$u$ (code units)")
ax[1][0].set_xlabel("$x$ (code units)")
ax[1][0].legend(loc = "best")
#ax[1][1].plot(coords[:,0], m, "y.")
#ax[1][1].set_ylabel("$m_i$ (code units)")
#ax[1][1].set_xlabel("$x$ (code units)")
fig, ax = pl.subplots(2, 2)
ax[1][1].axhline(y = 0., label = "target", color = "k",
linestyle = "--")
ax[1][1].plot(coords[:,0], vs[:,0], ".", label = "gizmo-mfm")
ax[1][1].set_ylabel("$v_x$ (code units)")
ax[1][1].set_xlabel("$x$ (code units)")
ax[1][1].legend(loc = "best")
ax[0][0].plot(coords[:,0], rho, "r.", markersize = 0.5)
ax[0][0].plot(x, rho_x, "g-")
ax[0][1].plot(coords[:,0], gradP/rho, "b.")
ax[1][0].plot(coords[:,0], agrav[:,0], "g.", markersize = 0.5)
ax[1][1].plot(coords[:,0], m, "y.")
pl.tight_layout()
pl.savefig("{fileName}.png".format(fileName = fileName[:-5]))
......@@ -10,7 +10,7 @@ InternalUnitSystem:
TimeIntegration:
time_begin: 0. # The starting time of the simulation (in internal units).
time_end: 10. # The end time of the simulation (in internal units).
dt_min: 1e-6 # The minimal time-step size of the simulation (in internal units).
dt_min: 1e-8 # The minimal time-step size of the simulation (in internal units).
dt_max: 1e-2 # The maximal time-step size of the simulation (in internal units).
# Parameters governing the conserved quantities statistics
......@@ -36,3 +36,6 @@ InitialConditions:
SineWavePotential:
amplitude: 10.
timestep_limit: 1.
EoS:
isothermal_internal_energy: 20.2615290634
......@@ -106,7 +106,6 @@ nobase_noinst_HEADERS = align.h approx_math.h atomic.h barrier.h cycle.h error.h
hydro/GizmoMFM/hydro_slope_limiters_face.h \
hydro/GizmoMFM/hydro_slope_limiters.h \
hydro/GizmoMFM/hydro_unphysical.h \
hydro/GizmoMFM/hydro_velocities.h \
hydro/Shadowswift/hydro_debug.h \
hydro/Shadowswift/hydro_gradients.h hydro/Shadowswift/hydro.h \
hydro/Shadowswift/hydro_iact.h \
......
This diff is collapsed.
......@@ -27,8 +27,6 @@ __attribute__((always_inline)) INLINE static void hydro_debug_particle(
"a=[%.3e,%.3e,%.3e], "
"h=%.3e, "
"time_bin=%d, "
"primitives={"
"v=[%.3e,%.3e,%.3e], "
"rho=%.3e, "
"P=%.3e, "
"gradients={"
......@@ -39,7 +37,7 @@ __attribute__((always_inline)) INLINE static void hydro_debug_particle(
"rho=[%.3e,%.3e], "
"v=[[%.3e,%.3e],[%.3e,%.3e],[%.3e,%.3e]], "
"P=[%.3e,%.3e], "
"maxr=%.3e}}, "
"maxr=%.3e}, "
"conserved={"
"momentum=[%.3e,%.3e,%.3e], "
"mass=%.3e, "
......@@ -53,24 +51,18 @@ __attribute__((always_inline)) INLINE static void hydro_debug_particle(
"wcount_dh=%.3e, "
"wcount=%.3e}\n",
p->x[0], p->x[1], p->x[2], p->v[0], p->v[1], p->v[2], p->a_hydro[0],
p->a_hydro[1], p->a_hydro[2], p->h, p->time_bin, p->primitives.v[0],
p->primitives.v[1], p->primitives.v[2], p->primitives.rho,
p->primitives.P, p->primitives.gradients.rho[0],
p->primitives.gradients.rho[1], p->primitives.gradients.rho[2],
p->primitives.gradients.v[0][0], p->primitives.gradients.v[0][1],
p->primitives.gradients.v[0][2], p->primitives.gradients.v[1][0],
p->primitives.gradients.v[1][1], p->primitives.gradients.v[1][2],
p->primitives.gradients.v[2][0], p->primitives.gradients.v[2][1],
p->primitives.gradients.v[2][2], p->primitives.gradients.P[0],
p->primitives.gradients.P[1], p->primitives.gradients.P[2],
p->primitives.limiter.rho[0], p->primitives.limiter.rho[1],
p->primitives.limiter.v[0][0], p->primitives.limiter.v[0][1],
p->primitives.limiter.v[1][0], p->primitives.limiter.v[1][1],
p->primitives.limiter.v[2][0], p->primitives.limiter.v[2][1],
p->primitives.limiter.P[0], p->primitives.limiter.P[1],
p->primitives.limiter.maxr, p->conserved.momentum[0],
p->conserved.momentum[1], p->conserved.momentum[2], p->conserved.mass,
p->conserved.energy, p->geometry.volume, p->geometry.matrix_E[0][0],
p->a_hydro[1], p->a_hydro[2], p->h, p->time_bin, p->rho, p->P,
p->gradients.rho[0], p->gradients.rho[1], p->gradients.rho[2],
p->gradients.v[0][0], p->gradients.v[0][1], p->gradients.v[0][2],
p->gradients.v[1][0], p->gradients.v[1][1], p->gradients.v[1][2],
p->gradients.v[2][0], p->gradients.v[2][1], p->gradients.v[2][2],
p->gradients.P[0], p->gradients.P[1], p->gradients.P[2],
p->limiter.rho[0], p->limiter.rho[1], p->limiter.v[0][0],
p->limiter.v[0][1], p->limiter.v[1][0], p->limiter.v[1][1],
p->limiter.v[2][0], p->limiter.v[2][1], p->limiter.P[0], p->limiter.P[1],
p->limiter.maxr, p->conserved.momentum[0], p->conserved.momentum[1],
p->conserved.momentum[2], p->conserved.mass, p->conserved.energy,
p->geometry.volume, p->geometry.matrix_E[0][0],
p->geometry.matrix_E[0][1], p->geometry.matrix_E[0][2],
p->geometry.matrix_E[1][0], p->geometry.matrix_E[1][1],
p->geometry.matrix_E[1][2], p->geometry.matrix_E[2][0],
......
......@@ -101,38 +101,28 @@ __attribute__((always_inline)) INLINE static void hydro_gradients_predict(
const float xij_j[3] = {xij_i[0] + dx[0], xij_i[1] + dx[1], xij_i[2] + dx[2]};
float dWi[5];
dWi[0] = pi->primitives.gradients.rho[0] * xij_i[0] +
pi->primitives.gradients.rho[1] * xij_i[1] +
pi->primitives.gradients.rho[2] * xij_i[2];
dWi[1] = pi->primitives.gradients.v[0][0] * xij_i[0] +
pi->primitives.gradients.v[0][1] * xij_i[1] +
pi->primitives.gradients.v[0][2] * xij_i[2];
dWi[2] = pi->primitives.gradients.v[1][0] * xij_i[0] +
pi->primitives.gradients.v[1][1] * xij_i[1] +
pi->primitives.gradients.v[1][2] * xij_i[2];
dWi[3] = pi->primitives.gradients.v[2][0] * xij_i[0] +
pi->primitives.gradients.v[2][1] * xij_i[1] +
pi->primitives.gradients.v[2][2] * xij_i[2];
dWi[4] = pi->primitives.gradients.P[0] * xij_i[0] +
pi->primitives.gradients.P[1] * xij_i[1] +
pi->primitives.gradients.P[2] * xij_i[2];
dWi[0] = pi->gradients.rho[0] * xij_i[0] + pi->gradients.rho[1] * xij_i[1] +
pi->gradients.rho[2] * xij_i[2];
dWi[1] = pi->gradients.v[0][0] * xij_i[0] + pi->gradients.v[0][1] * xij_i[1] +
pi->gradients.v[0][2] * xij_i[2];
dWi[2] = pi->gradients.v[1][0] * xij_i[0] + pi->gradients.v[1][1] * xij_i[1] +
pi->gradients.v[1][2] * xij_i[2];
dWi[3] = pi->gradients.v[2][0] * xij_i[0] + pi->gradients.v[2][1] * xij_i[1] +
pi->gradients.v[2][2] * xij_i[2];
dWi[4] = pi->gradients.P[0] * xij_i[0] + pi->gradients.P[1] * xij_i[1] +
pi->gradients.P[2] * xij_i[2];
float dWj[5];
dWj[0] = pj->primitives.gradients.rho[0] * xij_j[0] +
pj->primitives.gradients.rho[1] * xij_j[1] +
pj->primitives.gradients.rho[2] * xij_j[2];
dWj[1] = pj->primitives.gradients.v[0][0] * xij_j[0] +
pj->primitives.gradients.v[0][1] * xij_j[1] +
pj->primitives.gradients.v[0][2] * xij_j[2];
dWj[2] = pj->primitives.gradients.v[1][0] * xij_j[0] +
pj->primitives.gradients.v[1][1] * xij_j[1] +
pj->primitives.gradients.v[1][2] * xij_j[2];
dWj[3] = pj->primitives.gradients.v[2][0] * xij_j[0] +
pj->primitives.gradients.v[2][1] * xij_j[1] +
pj->primitives.gradients.v[2][2] * xij_j[2];
dWj[4] = pj->primitives.gradients.P[0] * xij_j[0] +
pj->primitives.gradients.P[1] * xij_j[1] +
pj->primitives.gradients.P[2] * xij_j[2];
dWj[0] = pj->gradients.rho[0] * xij_j[0] + pj->gradients.rho[1] * xij_j[1] +
pj->gradients.rho[2] * xij_j[2];
dWj[1] = pj->gradients.v[0][0] * xij_j[0] + pj->gradients.v[0][1] * xij_j[1] +
pj->gradients.v[0][2] * xij_j[2];
dWj[2] = pj->gradients.v[1][0] * xij_j[0] + pj->gradients.v[1][1] * xij_j[1] +
pj->gradients.v[1][2] * xij_j[2];
dWj[3] = pj->gradients.v[2][0] * xij_j[0] + pj->gradients.v[2][1] * xij_j[1] +
pj->gradients.v[2][2] * xij_j[2];
dWj[4] = pj->gradients.P[0] * xij_j[0] + pj->gradients.P[1] * xij_j[1] +
pj->gradients.P[2] * xij_j[2];
/* Apply the slope limiter at this interface */
hydro_slope_limit_face(Wi, Wj, dWi, dWj, xij_i, xij_j, r);
......
This diff is collapsed.
......@@ -28,24 +28,24 @@
__attribute__((always_inline)) INLINE static void hydro_gradients_init(
struct part *p) {
p->primitives.gradients.rho[0] = 0.0f;
p->primitives.gradients.rho[1] = 0.0f;
p->primitives.gradients.rho[2] = 0.0f;
p->gradients.rho[0] = 0.0f;
p->gradients.rho[1] = 0.0f;
p->gradients.rho[2] = 0.0f;
p->primitives.gradients.v[0][0] = 0.0f;
p->primitives.gradients.v[0][1] = 0.0f;
p->primitives.gradients.v[0][2] = 0.0f;
p->gradients.v[0][0] = 0.0f;
p->gradients.v[0][1] = 0.0f;
p->gradients.v[0][2] = 0.0f;
p->primitives.gradients.v[1][0] = 0.0f;
p->primitives.gradients.v[1][1] = 0.0f;
p->primitives.gradients.v[1][2] = 0.0f;
p->primitives.gradients.v[2][0] = 0.0f;
p->primitives.gradients.v[2][1] = 0.0f;
p->primitives.gradients.v[2][2] = 0.0f;
p->gradients.v[1][0] = 0.0f;
p->gradients.v[1][1] = 0.0f;
p->gradients.v[1][2] = 0.0f;
p->gradients.v[2][0] = 0.0f;
p->gradients.v[2][1] = 0.0f;
p->gradients.v[2][2] = 0.0f;
p->primitives.gradients.P[0] = 0.0f;
p->primitives.gradients.P[1] = 0.0f;
p->primitives.gradients.P[2] = 0.0f;
p->gradients.P[0] = 0.0f;
p->gradients.P[1] = 0.0f;
p->gradients.P[2] = 0.0f;
hydro_slope_limit_cell_init(p);
}
......@@ -64,7 +64,7 @@ __attribute__((always_inline)) INLINE static void hydro_gradients_collect(
float r2, const float *dx, float hi, float hj, struct part *restrict pi,
struct part *restrict pj) {
const float r_inv = 1.f / sqrtf(r2);
const float r_inv = 1.0f / sqrtf(r2);
const float r = r2 * r_inv;
float wi, wi_dx;
......@@ -72,41 +72,29 @@ __attribute__((always_inline)) INLINE static void hydro_gradients_collect(
const float xi = r * hi_inv;
kernel_deval(xi, &wi, &wi_dx);
/* very basic gradient estimate */
pi->primitives.gradients.rho[0] -=
wi_dx * dx[0] * (pi->primitives.rho - pj->primitives.rho) * r_inv;
pi->primitives.gradients.rho[1] -=
wi_dx * dx[1] * (pi->primitives.rho - pj->primitives.rho) * r_inv;
pi->primitives.gradients.rho[2] -=
wi_dx * dx[2] * (pi->primitives.rho - pj->primitives.rho) * r_inv;
pi->primitives.gradients.v[0][0] -=
wi_dx * dx[0] * (pi->primitives.v[0] - pj->primitives.v[0]) * r_inv;
pi->primitives.gradients.v[0][1] -=
wi_dx * dx[1] * (pi->primitives.v[0] - pj->primitives.v[0]) * r_inv;
pi->primitives.gradients.v[0][2] -=
wi_dx * dx[2] * (pi->primitives.v[0] - pj->primitives.v[0]) * r_inv;
pi->primitives.gradients.v[1][0] -=
wi_dx * dx[0] * (pi->primitives.v[1] - pj->primitives.v[1]) * r_inv;
pi->primitives.gradients.v[1][1] -=
wi_dx * dx[1] * (pi->primitives.v[1] - pj->primitives.v[1]) * r_inv;
pi->primitives.gradients.v[1][2] -=
wi_dx * dx[2] * (pi->primitives.v[1] - pj->primitives.v[1]) * r_inv;
pi->primitives.gradients.v[2][0] -=
wi_dx * dx[0] * (pi->primitives.v[2] - pj->primitives.v[2]) * r_inv;
pi->primitives.gradients.v[2][1] -=
wi_dx * dx[1] * (pi->primitives.v[2] - pj->primitives.v[2]) * r_inv;
pi->primitives.gradients.v[2][2] -=
wi_dx * dx[2] * (pi->primitives.v[2] - pj->primitives.v[2]) * r_inv;
pi->primitives.gradients.P[0] -=
wi_dx * dx[0] * (pi->primitives.P - pj->primitives.P) * r_inv;
pi->primitives.gradients.P[1] -=
wi_dx * dx[1] * (pi->primitives.P - pj->primitives.P) * r_inv;
pi->primitives.gradients.P[2] -=
wi_dx * dx[2] * (pi->primitives.P - pj->primitives.P) * r_inv;
const float dW[5] = {pi->rho - pj->rho, pi->v[0] - pj->v[0],
pi->v[1] - pj->v[1], pi->v[2] - pj->v[2], pi->P - pj->P};
const float normi = wi_dx * r_inv;
const float nidx[3] = {normi * dx[0], normi * dx[1], normi * dx[2]};
pi->gradients.rho[0] -= dW[0] * nidx[0];
pi->gradients.rho[1] -= dW[0] * nidx[1];
pi->gradients.rho[2] -= dW[0] * nidx[2];
pi->gradients.v[0][0] -= dW[1] * nidx[0];
pi->gradients.v[0][1] -= dW[1] * nidx[1];
pi->gradients.v[0][2] -= dW[1] * nidx[2];
pi->gradients.v[1][0] -= dW[2] * nidx[0];
pi->gradients.v[1][1] -= dW[2] * nidx[1];
pi->gradients.v[1][2] -= dW[2] * nidx[2];
pi->gradients.v[2][0] -= dW[3] * nidx[0];
pi->gradients.v[2][1] -= dW[3] * nidx[1];
pi->gradients.v[2][2] -= dW[3] * nidx[2];
pi->gradients.P[0] -= dW[4] * nidx[0];
pi->gradients.P[1] -= dW[4] * nidx[1];
pi->gradients.P[2] -= dW[4] * nidx[2];
hydro_slope_limit_cell_collect(pi, pj, r);
......@@ -115,40 +103,27 @@ __attribute__((always_inline)) INLINE static void hydro_gradients_collect(
const float xj = r * hj_inv;
kernel_deval(xj, &wj, &wj_dx);
const float normj = wj_dx * r_inv;
const float njdx[3] = {normj * dx[0], normj * dx[1], normj * dx[2]};
/* signs are the same as before, since we swap i and j twice */
pj->primitives.gradients.rho[0] -=
wj_dx * dx[0] * (pi->primitives.rho - pj->primitives.rho) * r_inv;
pj->primitives.gradients.rho[1] -=
wj_dx * dx[1] * (pi->primitives.rho - pj->primitives.rho) * r_inv;
pj->primitives.gradients.rho[2] -=
wj_dx * dx[2] * (pi->primitives.rho - pj->primitives.rho) * r_inv;
pj->primitives.gradients.v[0][0] -=
wj_dx * dx[0] * (pi->primitives.v[0] - pj->primitives.v[0]) * r_inv;
pj->primitives.gradients.v[0][1] -=
wj_dx * dx[1] * (pi->primitives.v[0] - pj->primitives.v[0]) * r_inv;
pj->primitives.gradients.v[0][2] -=
wj_dx * dx[2] * (pi->primitives.v[0] - pj->primitives.v[0]) * r_inv;
pj->primitives.gradients.v[1][0] -=
wj_dx * dx[0] * (pi->primitives.v[1] - pj->primitives.v[1]) * r_inv;
pj->primitives.gradients.v[1][1] -=
wj_dx * dx[1] * (pi->primitives.v[1] - pj->primitives.v[1]) * r_inv;
pj->primitives.gradients.v[1][2] -=
wj_dx * dx[2] * (pi->primitives.v[1] - pj->primitives.v[1]) * r_inv;
pj->primitives.gradients.v[2][0] -=
wj_dx * dx[0] * (pi->primitives.v[2] - pj->primitives.v[2]) * r_inv;
pj->primitives.gradients.v[2][1] -=
wj_dx * dx[1] * (pi->primitives.v[2] - pj->primitives.v[2]) * r_inv;
pj->primitives.gradients.v[2][2] -=
wj_dx * dx[2] * (pi->primitives.v[2] - pj->primitives.v[2]) * r_inv;
pj->primitives.gradients.P[0] -=
wj_dx * dx[0] * (pi->primitives.P - pj->primitives.P) * r_inv;
pj->primitives.gradients.P[1] -=
wj_dx * dx[1] * (pi->primitives.P - pj->primitives.P) * r_inv;
pj->primitives.gradients.P[2] -=
wj_dx * dx[2] * (pi->primitives.P - pj->primitives.P) * r_inv;
pj->gradients.rho[0] -= dW[0] * njdx[0];
pj->gradients.rho[1] -= dW[0] * njdx[1];
pj->gradients.rho[2] -= dW[0] * njdx[2];
pj->gradients.v[0][0] -= dW[1] * njdx[0];
pj->gradients.v[0][1] -= dW[1] * njdx[1];
pj->gradients.v[0][2] -= dW[1] * njdx[2];
pj->gradients.v[1][0] -= dW[2] * njdx[0];
pj->gradients.v[1][1] -= dW[2] * njdx[1];
pj->gradients.v[1][2] -= dW[2] * njdx[2];
pj->gradients.v[2][0] -= dW[3] * njdx[0];
pj->gradients.v[2][1] -= dW[3] * njdx[1];
pj->gradients.v[2][2] -= dW[3] * njdx[2];
pj->gradients.P[0] -= dW[4] * njdx[0];
pj->gradients.P[1] -= dW[4] * njdx[1];
pj->gradients.P[2] -= dW[4] * njdx[2];
hydro_slope_limit_cell_collect(pj, pi, r);
}
......@@ -169,7 +144,7 @@ hydro_gradients_nonsym_collect(float r2, const float *dx, float hi, float hj,
struct part *restrict pi,
struct part *restrict pj) {
const float r_inv = 1.f / sqrtf(r2);
const float r_inv = 1.0f / sqrtf(r2);
const float r = r2 * r_inv;
float wi, wi_dx;
......@@ -177,41 +152,29 @@ hydro_gradients_nonsym_collect(float r2, const float *dx, float hi, float hj,
const float xi = r * hi_inv;
kernel_deval(xi, &wi, &wi_dx);
/* very basic gradient estimate */
pi->primitives.gradients.rho[0] -=
wi_dx * dx[0] * (pi->primitives.rho - pj->primitives.rho) * r_inv;
pi->primitives.gradients.rho[1] -=
wi_dx * dx[1] * (pi->primitives.rho - pj->primitives.rho) * r_inv;
pi->primitives.gradients.rho[2] -=
wi_dx * dx[2] * (pi->primitives.rho - pj->primitives.rho) * r_inv;
pi->primitives.gradients.v[0][0] -=
wi_dx * dx[0] * (pi->primitives.v[0] - pj->primitives.v[0]) * r_inv;
pi->primitives.gradients.v[0][1] -=
wi_dx * dx[1] * (pi->primitives.v[0] - pj->primitives.v[0]) * r_inv;
pi->primitives.gradients.v[0][2] -=
wi_dx * dx[2] * (pi->primitives.v[0] - pj->primitives.v[0]) * r_inv;
pi->primitives.gradients.v[1][0] -=
wi_dx * dx[0] * (pi->primitives.v[1] - pj->primitives.v[1]) * r_inv;
pi->primitives.gradients.v[1][1] -=
wi_dx * dx[1] * (pi->primitives.v[1] - pj->primitives.v[1]) * r_inv;
pi->primitives.gradients.v[1][2] -=
wi_dx * dx[2] * (pi->primitives.v[1] - pj->primitives.v[1]) * r_inv;
pi->primitives.gradients.v[2][0] -=
wi_dx * dx[0] * (pi->primitives.v[2] - pj->primitives.v[2]) * r_inv;
pi->primitives.gradients.v[2][1] -=
wi_dx * dx[1] * (pi->primitives.v[2] - pj->primitives.v[2]) * r_inv;
pi->primitives.gradients.v[2][2] -=
wi_dx * dx[2] * (pi->primitives.v[2] - pj->primitives.v[2]) * r_inv;
pi->primitives.gradients.P[0] -=
wi_dx * dx[0] * (pi->primitives.P - pj->primitives.P) * r_inv;
pi->primitives.gradients.P[1] -=
wi_dx * dx[1] * (pi->primitives.P - pj->primitives.P) * r_inv;
pi->primitives.gradients.P[2] -=
wi_dx * dx[2] * (pi->primitives.P - pj->primitives.P) * r_inv;
const float dW[5] = {pi->rho - pj->rho, pi->v[0] - pj->v[0],
pi->v[1] - pj->v[1], pi->v[2] - pj->v[2], pi->P - pj->P};
const float normi = wi_dx * r_inv;
const float nidx[3] = {normi * dx[0], normi * dx[1], normi * dx[2]};
pi->gradients.rho[0] -= dW[0] * nidx[0];
pi->gradients.rho[1] -= dW[0] * nidx[1];
pi->gradients.rho[2] -= dW[0] * nidx[2];
pi->gradients.v[0][0] -= dW[1] * nidx[0];
pi->gradients.v[0][1] -= dW[1] * nidx[1];
pi->gradients.v[0][2] -= dW[1] * nidx[2];
pi->gradients.v[1][0] -= dW[2] * nidx[0];
pi->gradients.v[1][1] -= dW[2] * nidx[1];
pi->gradients.v[1][2] -= dW[2] * nidx[2];
pi->gradients.v[2][0] -= dW[3] * nidx[0];
pi->gradients.v[2][1] -= dW[3] * nidx[1];
pi->gradients.v[2][2] -= dW[3] * nidx[2];
pi->gradients.P[0] -= dW[4] * nidx[0];
pi->gradients.P[1] -= dW[4] * nidx[1];
pi->gradients.P[2] -= dW[4] * nidx[2];
hydro_slope_limit_cell_collect(pi, pj, r);
}
......@@ -229,26 +192,28 @@ __attribute__((always_inline)) INLINE static void hydro_gradients_finalize(
const float ihdimp1 = pow_dimension_plus_one(ih);
const float volume = p->geometry.volume;
const float norm = ihdimp1 * volume;
/* finalize gradients by multiplying with volume */
p->primitives.gradients.rho[0] *= ihdimp1 * volume;
p->primitives.gradients.rho[1] *= ihdimp1 * volume;
p->primitives.gradients.rho[2] *= ihdimp1 * volume;
p->gradients.rho[0] *= norm;
p->gradients.rho[1] *= norm;
p->gradients.rho[2] *= norm;
p->primitives.gradients.v[0][0] *= ihdimp1 * volume;
p->primitives.gradients.v[0][1] *= ihdimp1 * volume;
p->primitives.gradients.v[0][2] *= ihdimp1 * volume;
p->gradients.v[0][0] *= norm;
p->gradients.v[0][1] *= norm;
p->gradients.v[0][2] *= norm;
p->primitives.gradients.v[1][0] *= ihdimp1 * volume;
p->primitives.gradients.v[1][1] *= ihdimp1 * volume;
p->primitives.gradients.v[1][2] *= ihdimp1 * volume;
p->gradients.v[1][0] *= norm;
p->gradients.v[1][1] *= norm;
p->gradients.v[1][2] *= norm;
p->primitives.gradients.v[2][0] *= ihdimp1 * volume;
p->primitives.gradients.v[2][1] *= ihdimp1 * volume;
p->primitives.gradients.v[2][2] *= ihdimp1 * volume;
p->gradients.v[2][0] *= norm;
p->gradients.v[2][1] *= norm;
p->gradients.v[2][2] *= norm;
p->primitives.gradients.P[0] *= ihdimp1 * volume;
p->primitives.gradients.P[1] *= ihdimp1 * volume;
p->primitives.gradients.P[2] *= ihdimp1 * volume;
p->gradients.P[0] *= norm;
p->gradients.P[1] *= norm;
p->gradients.P[2] *= norm;
hydro_slope_limit_cell(p);
}