@ti.kernel def mvp(v: ti.template(), mv: ti.template()): for p in x: gradc_scp[p] = 0…
- User
@ti.kernel def mvp(v: ti.template(), mv: ti.template()): for p in x: gradc_scp[p] = 0 # matrix-vector product for p in x: Xp = x[p] / dx base = (Xp - 0.5).cast(int) fx = Xp - base
# Weight functions w = [0.5 * (1.5 - fx)**2, 0.75 - (fx - 1)**2, 0.5 * (fx - 0.5)**2] dw = [-1.5 + fx, 2 * (fx - 1), 1.5 * (fx - 0.5)] # Derivative of shape functions for i, j in ti.static(ti.ndrange(3, 3)): offset = ti.Vector([i, j]) grid_idx = base + offset weight = w[i].x * w[j].y grad_c = ti.Vector([dw[i].x * w[j].y, w[i].x * dw[j].y]) gradc_scp[p] = p_vol * F[p].determinant() *grad_c*l0**2*parabolic_M*4* v[base + offset] # matrix-vector product for p in x: Xp = x[p] / dx base = (Xp - 0.5).cast(int) fx = Xp - base # Weight functions w = [0.5 * (1.5 - fx)**2, 0.75 - (fx - 1)**2, 0.5 * (fx - 0.5)**2] dw = [-1.5 + fx, 2 * (fx - 1), 1.5 * (fx - 0.5)] # Derivative of shape functions for i, j in ti.static(ti.ndrange(3, 3)): offset = ti.Vector([i, j]) grid_idx = base + offset weight = w[i].x * w[j].y grad_c = ti.Vector([dw[i].x * w[j].y, w[i].x * dw[j].y]) Fp = (4 * l0 * parabolic_M * psi_max[p] * 0.999 / G- parabolic_M + 1/dt) # Original MVP term mv[base + offset] += p_vol * F[p].determinant() * weight * (1/dt)* v[base + offset] mv[base + offset] += gradc_scp[p].dot(grad_c) @ti.kernel def phase_g2p(): for p in range(n_particles): color[p][0] = c[p] Xp = x[p] / dx base = int(Xp - 0.5) fx = Xp - base w = [0.5 * (1.5 - fx) ** 2, 0.75 - (fx - 1) ** 2, 0.5 * (fx - 0.5) ** 2] new_c = 0. for i, j in ti.static(ti.ndrange(3, 3)): offset = ti.Vector([i, j]) grid_idx = base + offset weight = w[i][0] * w[j][1] new_c += (sol[grid_idx])*weight c[p] = max(0,min(c[p],new_c)) @ti.kernel def init(): for i in range(n_particles): x[i] = [ti.random() * 0.1 + 0.25, ti.random() * 0.8 + 0.2] v[i] = [0, -1] F[i] = ti.Matrix([[1, 0], [0, 1]]) alpha[i] = alpha0 c[i] = int(x[i][1]*2)/2 Values don't diffuse as expected
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.