commit 1e0a6e6406bfb66a9c64fb94e8370ea2513ecea7
parent 432185412169f2d169eaec398cfa9154642e4bd2
Author: Anders Damsgaard <adc@geo.au.dk>
Date: Tue, 25 Jun 2013 12:33:55 +0200
Added Courant criteria for ensuring numerical stability
Diffstat:
M | lbm.c | | | 16 | +++++++++++++++- |
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/lbm.c b/lbm.c
@@ -3,7 +3,6 @@
#include <math.h>
// Courant kriterie for tidsskridt
-// Check for LBM stability criteria
// No slip top og bund
// Periodiske sider
@@ -64,6 +63,9 @@ const Float rho0 = 1.0;
// Inital cell fluid velocity (dimensionless)
const Float3 u0 = {0.0, 0.0, 0.0};
+// Courant criteria limit
+const Float C_max = 1.0;
+
//// FUNCTION DEFINITIONS
@@ -254,6 +256,18 @@ Float3 find_u(
u.y += f_i*e[i].y/rho;
u.z += f_i*e[i].z/rho;
}
+
+ // Check the Courant-Frederichs-Lewy condition
+ if ((u.x*dt/dx + u.y*dt/dx + u.z*dt/dx) > C_max) {
+ fprintf(stderr, "Error, the Courant-Friderichs-Lewy condition is not ");
+ fprintf(stderr, "satisfied.\nTry one or more of the following:\n");
+ fprintf(stderr, "- Decrease the timestep (dt)\n");
+ fprintf(stderr, "- Increase the cell size (dx)\n");
+ fprintf(stderr, "- Decrease the fluid viscosity (nu)\n");
+ fprintf(stderr, "- Decrease the fluid density (rho)\n");
+ exit(EXIT_FAILURE);
+ }
+
return u;
}