tgranularpacking: add options to change offset, packing count and mode - granular - granular dynamics simulation
(HTM) git clone git://src.adamsgaard.dk/granular
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 9da65983ddd58f63107d3afc5c6f41b43846089f
(DIR) parent f16e22a18d80e0499620356c7f8b425ead751cb7
(HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Thu, 25 Mar 2021 14:18:13 +0100
granularpacking: add options to change offset, packing count and mode
Diffstat:
M granularpacking.1 | 31 +++++++++++++++++++++++++++++++
M granularpacking.c | 69 +++++++++++++++++++++++++++++--
2 files changed, 96 insertions(+), 4 deletions(-)
---
(DIR) diff --git a/granularpacking.1 b/granularpacking.1
t@@ -6,6 +6,13 @@
.Nd generate a packing of granular data
.Sh SYNOPSIS
.Nm
+.Op Fl h
+.Op Fl X Ar x-offset
+.Op Fl x Ar nx
+.Op Fl Y Ar y-offset
+.Op Fl y Ar ny
+.Op Fl Z Ar z-offset
+.Op Fl z Ar nz
.Sh DESCRIPTION
The
.Nm
t@@ -13,6 +20,30 @@ program generates a regular or random packing of grains, and outputs
the grain data in
.Xr granular 5
format.
+.Pp
+The options are as wollows:
+.Bl -tag -width Ds
+.It Fl h
+Show help text.
+.It Fl X Ar x-offset
+Add the specified offset to all output x positions (default 0.0).
+.It Fl x Ar nx
+Generate
+.Ar nx
+grains in the x dimension (default 10).
+.It Fl Y Ar y-offset
+Add the specified offset to all output y positions (default 0.0).
+.It Fl y Ar ny
+Generate
+.Ar ny
+grains in the y dimension (default 10).
+.It Fl Z Ar x-offset
+Add the specified offset to all output z positions (default 0.0).
+.It Fl z Ar nz
+Generate
+.Ar nz
+grains in the z dimension (default 1).
+.El
.Sh EXIT STATUS
.Nm
exits 0 on success, and >0 if a runtime error occurs:
(DIR) diff --git a/granularpacking.c b/granularpacking.c
t@@ -1,20 +1,81 @@
#include <stdio.h>
#include <stdlib.h>
+#include <err.h>
#include "packing.h"
#include "simulation.h"
#include "arrays.h"
#include "util.h"
+#include "arg.h"
+
+char *argv0;
+
+static void
+usage(void)
+{
+ errx(1, "usage: %s [-ht] "
+ "[-X x-offset] "
+ "[-x nx] "
+ "[-Y y-offset] "
+ "[-y ny] "
+ "[-Z z-offset] "
+ "[-z nz]", argv0);
+}
+
int
-main(void)
+main(int argc, char *argv[])
{
size_t n[3], np = 0;
- n[0] = 10; n[1] = 5; n[2] = 1;
+ n[0] = 10; n[1] = 10; n[2] = 1;
double *origo = zeros(3);
struct simulation sim = sim_new();
+ int packing = 0;
+
+ ARGBEGIN {
+ case 'h':
+ usage();
+ break;
+ case 't':
+ packing = 1;
+ break;
+ case 'X':
+ origo[0] = atof(EARGF(usage()));
+ break;
+ case 'x':
+ n[0] = atof(EARGF(usage()));
+ break;
+ case 'Y':
+ origo[1] = atof(EARGF(usage()));
+ break;
+ case 'y':
+ n[1] = atof(EARGF(usage()));
+ break;
+ case 'Z':
+ origo[2] = atof(EARGF(usage()));
+ break;
+ case 'z':
+ n[2] = atof(EARGF(usage()));
+ break;
+ default:
+ usage();
+ } ARGEND;
+
+ if (argc > 1)
+ usage();
- /* np = rectangular_packing(&sim.grains, n, 1.0, 1.0, random_value_uniform, 0.0, &origo); */
- np = triangular_packing(&sim.grains, n, 0.2, 1.0, random_value_uniform, 0.0, &origo);
+ switch (packing) {
+ case 0:
+ np = rectangular_packing(&sim.grains, n, 1.0, 1.0,
+ random_value_uniform, 0.0, &origo);
+ break;
+ case 1:
+ np = triangular_packing(&sim.grains, n, 1.0, 1.0,
+ random_value_uniform, 0.0, &origo);
+ break;
+ default:
+ errx(1, "unknown packing mode");
+ }
+
sim_print_grains(stdout, sim.grains, np);
free(origo);