tFix time step calculation error due to wrong dx values - cngf-pf - continuum m… | |
git clone git://src.adamsgaard.dk/cngf-pf | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit bad8daf5ce300d6b13cb93fed036cc79de183afd | |
parent e77fc709072288ae7e2cbc4b66eca6307c2d23fb | |
Author: Anders Damsgaard <[email protected]> | |
Date: Fri, 28 Jun 2019 11:03:32 +0200 | |
Fix time step calculation error due to wrong dx values | |
Diffstat: | |
M arrays.c | 2 +- | |
M fluid.c | 12 +++++++++++- | |
2 files changed, 12 insertions(+), 2 deletions(-) | |
--- | |
diff --git a/arrays.c b/arrays.c | |
t@@ -74,7 +74,7 @@ spacing(const double* x, const int n) | |
dx = malloc((n-1)*sizeof(double)); | |
for (i=0; i<n-1; ++i) | |
- dx[i] = x[i+i] - x[i]; | |
+ dx[i] = x[i+1] - x[i]; | |
return dx; | |
} | |
diff --git a/fluid.c b/fluid.c | |
t@@ -26,8 +26,16 @@ set_largest_fluid_timestep(struct simulation* sim, const do… | |
dx = spacing(sim->z, sim->nz); | |
dx_min = INFINITY; | |
- for (i=0; i<sim->nz-1; ++i) | |
+ for (i=0; i<sim->nz-1; ++i) { | |
+ if (dx[i] < 0.0) { | |
+ fprintf(stderr, "error: cell spacing negative (%g) in … | |
+ dx[i], i); | |
+ free(dx); | |
+ exit(10); | |
+ } | |
if (dx[i] < dx_min) dx_min = dx[i]; | |
+ } | |
+ free(dx); | |
/* determine largest diffusion size */ | |
diff_max = -INFINITY; | |
t@@ -37,6 +45,8 @@ set_largest_fluid_timestep(struct simulation* sim, const dou… | |
} | |
sim->dt = safety*0.5*dx_min*dx_min/diff_max; | |
+ if (sim->file_dt*0.5 < sim->dt) | |
+ sim->dt = sim->file_dt*0.5; | |
} | |
static |