Skip to content

Commit

Permalink
Simplify calculate_timestep
Browse files Browse the repository at this point in the history
  • Loading branch information
cgmb committed Feb 27, 2020
1 parent 42a8eb5 commit 3f22137
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,19 +826,12 @@ void zero_bounds(float q[Y][X], celltype_t type) {
}

float calculate_timestep(float frame_time) {
// Bridson suggests a limit of five for stability, but my implementation of
// advection and extrapolation assume that new fluid cells are within one
// grid cell of old fluid cells
const float m = 0.75f; // maximum number of cells to traverse in one step

float dt;
// Bridson suggests a limit of five cells, but my implementation
// of advection and extrapolation assume that new fluid cells are
// within one grid cell of old fluid cells.
const float max_distance = 0.75f * k_s;
float max_velocity = sqrtf(maxsq(g_u, U) + maxsq(g_v, V));
if (max_velocity < (m*k_s / frame_time)) {
dt = frame_time;
} else {
dt = m*k_s / max_velocity;
}
return dt;
return fminf(max_distance / max_velocity, frame_time);
}

void sim_step() {
Expand Down

0 comments on commit 3f22137

Please sign in to comment.