Skip to content

Commit

Permalink
add mintimestep option
Browse files Browse the repository at this point in the history
  • Loading branch information
metzm committed Nov 13, 2024
1 parent 2ae8b9f commit 5b75f88
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
18 changes: 16 additions & 2 deletions raster/r.sim/r.sim.water/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,18 @@ int main(int argc, char *argv[])
parm.niter->description = _("Time used for iterations [minutes]");
parm.niter->guisection = _("Parameters");

parm.mintimestep = G_define_option();
parm.mintimestep->key = "mintimestep";
parm.mintimestep->type = TYPE_DOUBLE;
parm.mintimestep->answer = "0.0";
parm.mintimestep->required = NO;
parm.mintimestep->label =
_("Minimum tine step for the simulation [seconds]");
parm.mintimestep->description =
_("A larger minimum tine step substancially reduces processing time, "
"but at the cost of accuracy");
parm.mintimestep->guisection = _("Parameters");

parm.outiter = G_define_option();
parm.outiter->key = "output_step";
parm.outiter->type = TYPE_INTEGER;
Expand Down Expand Up @@ -319,8 +331,9 @@ int main(int argc, char *argv[])
parm.threads->type = TYPE_INTEGER;
parm.threads->answer = NUM_THREADS;
parm.threads->required = NO;
parm.threads->description =
_("Number of threads which will be used for parallel compute");
parm.threads->description = _(
"Number of threads which will be used for parallel compute. Increasing "
"the number of threads does not really speed up the simulation.");
parm.threads->guisection = _("Parameters");

if (G_parser(argc, argv))
Expand Down Expand Up @@ -388,6 +401,7 @@ int main(int argc, char *argv[])
G_debug(3, "Parsing numeric parameters");

sscanf(parm.niter->answer, "%d", &wp.timesec);
sscanf(parm.mintimestep->answer, "%lf", &wp.mintimestep);
sscanf(parm.outiter->answer, "%d", &wp.iterout);
sscanf(parm.diffc->answer, "%lf", &wp.frac);
sscanf(parm.hmax->answer, "%lf", &wp.hhmax);
Expand Down
1 change: 1 addition & 0 deletions raster/r.sim/simlib/hydro.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ int iterout, mx2o, my2o;
int miter, nwalka;
double timec;
int ts, timesec;
double mintimestep;

double rain_val;
double manin_val;
Expand Down
5 changes: 5 additions & 0 deletions raster/r.sim/simlib/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ void WaterParams_init(struct WaterParams *wp)
wp->timec = 0;
wp->ts = 0;
wp->timesec = 0;
wp->mintimestep = 0;

wp->rain_val = 0;
wp->manin_val = 0;
Expand Down Expand Up @@ -201,6 +202,7 @@ void init_library_globals(struct WaterParams *wp)
timec = wp->timec;
ts = wp->ts;
timesec = wp->timesec;
mintimestep = wp->mintimestep;

rain_val = wp->rain_val;
manin_val = wp->manin_val;
Expand Down Expand Up @@ -508,6 +510,9 @@ int grad_check(void)
deltaw = 0.8 / (sigmax * vmax); /*time step for sediment */
deltap = 0.25 * sqrt(stepx * stepy) / vmean; /*time step for water */

if (deltap < mintimestep)
deltap = mintimestep;

if (deltaw > deltap)
timec = 4.;
else
Expand Down
9 changes: 5 additions & 4 deletions raster/r.sim/simlib/simlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct WaterParams {
int miter, nwalka;
double timec;
int ts, timesec;
double mintimestep;

double rain_val;
double manin_val;
Expand Down Expand Up @@ -86,10 +87,10 @@ void free_walkers(void);

struct options {
struct Option *elevin, *dxin, *dyin, *rain, *infil, *traps, *manin,
*observation, *depth, *disch, *err, *outwalk, *nwalk, *niter, *outiter,
*density, *diffc, *hmax, *halpha, *hbeta, *wdepth, *detin, *tranin,
*tauin, *tc, *et, *conc, *flux, *erdep, *rainval, *maninval, *infilval,
*logfile, *seed, *threads;
*observation, *depth, *disch, *err, *outwalk, *nwalk, *niter,
*mintimestep, *outiter, *density, *diffc, *hmax, *halpha, *hbeta,
*wdepth, *detin, *tranin, *tauin, *tc, *et, *conc, *flux, *erdep,
*rainval, *maninval, *infilval, *logfile, *seed, *threads;
};

struct flags {
Expand Down
1 change: 1 addition & 0 deletions raster/r.sim/simlib/waterglobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ extern int iterout, mx2o, my2o;
extern int miter, nwalka;
extern double timec;
extern int ts, timesec;
extern double mintimestep;

extern double rain_val;
extern double manin_val;
Expand Down

0 comments on commit 5b75f88

Please sign in to comment.