tgranular.c - granular - granular dynamics simulation
(HTM) git clone git://src.adamsgaard.dk/granular
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
tgranular.c (1306B)
---
1 #include <stdlib.h>
2 #include <err.h>
3 #include <unistd.h>
4 #include "granular.h"
5 #include "arg.h"
6
7 char *argv0;
8
9 static void
10 usage(void)
11 {
12 errx(1, "usage: %s "
13 "[-e end-time] "
14 "[-g gravity-accel] "
15 "[-h] "
16 "[-I file-interval] "
17 "[-j time-step] "
18 "[-t curr-time] "
19 "[name]", argv0);
20 }
21
22 int
23 main(int argc, char *argv[])
24 {
25 int ret;
26 struct simulation sim = sim_new();
27 double grav = 0.0;
28
29 #ifdef __OpenBSD__
30 if (pledge("stdio wpath cpath", NULL) == -1)
31 err(2, "pledge");
32 #endif
33
34 sim_defaults(&sim);
35
36 ARGBEGIN {
37 case 'e':
38 sim.t_end = atof(EARGF(usage()));
39 break;
40 case 'g':
41 grav = atof(EARGF(usage()));
42 break;
43 case 'h':
44 usage();
45 break;
46 case 'I':
47 sim.dt_file = atof(EARGF(usage()));
48 break;
49 case 'j':
50 sim.dt = atof(EARGF(usage()));
51 break;
52 case 't':
53 sim.t = atof(EARGF(usage()));
54 break;
55 default:
56 usage();
57 } ARGEND;
58
59 if (argc == 1 && argv[0]) {
60 ret = snprintf(sim.name, sizeof(sim.name), "%s", argv[0]);
61 if (ret < 0 || (size_t)ret >= sizeof(sim.name))
62 errx(1, "%s: sim.name snprintf", __func__);
63 } else if (argc > 1)
64 usage();
65
66 sim_read_grains(&sim, stdin);
67 sim_add_acceleration_scalar(&sim, grav, 1);
68 sim_set_timestep(&sim);
69 if (sim.t < sim.t_end)
70 sim_run_time_loop(&sim);
71 sim_print_grains(&sim, stdout);
72 sim_free(&sim);
73
74 return 0;
75 }