Skip to content
This repository was archived by the owner on Jul 5, 2022. It is now read-only.

Commit d67725b

Browse files
Correct the amount of neighbours cells have in 2D (#2197)
When moving from 3d to 2d the amount of neighbours each cell has changes from 6 to 4. This is needs to be taken into account because lin_solve() calculates the weighted average of the neighbours, and uses the given float c as the total weight. So the provided "c" should be adjusted to correspond with the amount of neighbours. Without the adjustment lin_solve() reduces, whatever you put into it, by 33% after each iteration. Co-authored-by: Nico Finkernagel <[email protected]>
1 parent 965408e commit d67725b

File tree

1 file changed

+2
-2
lines changed
  • CodingChallenges/CC_132_FluidSimulation/Processing/CC_132_FluidSimulation

1 file changed

+2
-2
lines changed

CodingChallenges/CC_132_FluidSimulation/Processing/CC_132_FluidSimulation/MoreFluid.pde

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
void diffuse (int b, float[] x, float[] x0, float diff, float dt) {
1313
float a = dt * diff * (N - 2) * (N - 2);
14-
lin_solve(b, x, x0, a, 1 + 6 * a);
14+
lin_solve(b, x, x0, a, 1 + 4 * a);
1515
}
1616

1717
void lin_solve(int b, float[] x, float[] x0, float a, float c) {
@@ -47,7 +47,7 @@ void project(float[] velocX, float[] velocY, float[] p, float[] div) {
4747

4848
set_bnd(0, div);
4949
set_bnd(0, p);
50-
lin_solve(0, p, div, 1, 6);
50+
lin_solve(0, p, div, 1, 4);
5151

5252
for (int j = 1; j < N - 1; j++) {
5353
for (int i = 1; i < N - 1; i++) {

0 commit comments

Comments
 (0)