commit 957c062f6dd340902a9812224bb06ae759d624f4
parent 07a7991cd25c38df4b7991934d5c517c23eb05dd
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Sat, 11 May 2019 13:34:59 -0500
Show default values in help text
Diffstat:
| M | Makefile | | | 4 | ++++ | 
| M | main.c | | | 88 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------ | 
2 files changed, 65 insertions(+), 27 deletions(-)
diff --git a/Makefile b/Makefile
@@ -7,6 +7,10 @@ HDR=$(wildcard *.h)
 .PHONY: default
 default: 1d_fd_simple_shear
 
+.PHONY: install
+install: 1d_fd_simple_shear
+	install $< /usr/local/bin/
+
 .PHONY: plots
 plots: 1d_fd_simple_shear.png \
 	1d_fd_simple_shear_rheology.png \
diff --git a/main.c b/main.c
@@ -13,39 +13,69 @@
 
 static void usage(void)
 {
+    struct simulation sim = init_sim();
     printf("%s: %s [OPTIONS] [NAME]\n"
             "runs a simulation and outputs state in files prefixed with NAME.\n"
+            "If NAME is not specified, the default value '%s' is used.\n"
             "optional arguments:\n"
             " -N, --normalize                 normalize output velocity\n"
-            " -G, --gravity VAL               gravity magnitude [m/s^2]\n"
-            " -P, --normal-stress VAL         normal stress on top [Pa]\n"
-            " -m, --stress-ratio VAL          applied stress ratio [-]\n"
-            " -V, --velocity-bottom VAL       base velocity at bottom [m/s]\n"
-            " -A, --nonlocal-amplitude VAL    amplitude of nonlocality [-]\n"
-            " -b, --rate-dependence VAL       rate dependence beyond yield [-]\n"
-            " -f, --friction-coefficient VAL  grain friction coefficient [-]\n"
-            " -p, --porosity VAL              porosity fraction [-]\n"
-            " -d, --grain-size VAL            representative grain size [m]\n"
-            " -r, --density VAL               grain material density [kg/m^3]\n"
-            " -n, --resolution VAL            number of cells in domain [-]\n"
-            " -o, --origo VAL                 coordinate system origo [m]\n"
-            " -L, --length VAL                domain length [m]\n"
+            " -G, --gravity VAL               gravity magnitude [m/s^2] (default %g)\n"
+            " -P, --normal-stress VAL         normal stress on top [Pa] (default %g)\n"
+            " -m, --stress-ratio VAL          applied stress ratio [-] (default %g)\n"
+            " -V, --velocity-bottom VAL       base velocity at bottom [m/s] (default %g)\n"
+            " -A, --nonlocal-amplitude VAL    amplitude of nonlocality [-] (default %g)\n"
+            " -b, --rate-dependence VAL       rate dependence beyond yield [-] (default %g)\n"
+            " -f, --friction-coefficient VAL  grain friction coefficient [-] (default %g)\n"
+            " -p, --porosity VAL              porosity fraction [-] (default %g)\n"
+            " -d, --grain-size VAL            representative grain size [m] (default %g)\n"
+            " -r, --density VAL               grain material density [kg/m^3] (default %g)\n"
+            " -n, --resolution VAL            number of cells in domain [-] (default %d)\n"
+            " -o, --origo VAL                 coordinate system origo [m] (default %g)\n"
+            " -L, --length VAL                domain length [m] (default %g)\n"
             " -F, --fluid                     enable pore fluid computations\n"
-            " -c, --fluid-compressibility VAL fluid compressibility [Pa^-1]\n"
-            " -i, --fluid-viscosity VAL       fluid viscosity [Pa*s]\n"
-            " -R, --fluid-density VAL         fluid density [kg/m^3]\n"
-            " -k, --fluid-permeability VAL    fluid intrinsic permeability [m^2]\n"
-            " -O, --fluid-pressure-top VAL    fluid pressure at +z edge [Pa]\n"
-            " -a, --fluid-pressure-ampl VAL   amplitude of pressure variations [Pa]\n"
-            " -q, --fluid-pressure-freq VAL   frequency of pressure variations [s^-1]\n"
-            " -H, --fluid-pressure-phase VAL  fluid pressure at +z edge [Pa]\n"
-            " -t, --time VAL                  simulation start time [s]\n"
-            " -T, --time-end VAL              simulation end time [s]\n"
-            " -D, --time-step VAL             computational time step length [s]\n"
-            " -I, --file-interval VAL         interval between output files [s]\n"
+            " -c, --fluid-compressibility VAL fluid compressibility [Pa^-1] (default %g)\n"
+            " -i, --fluid-viscosity VAL       fluid viscosity [Pa*s] (default %g)\n"
+            " -R, --fluid-density VAL         fluid density [kg/m^3] (default %g)\n"
+            " -k, --fluid-permeability VAL    fluid intrinsic permeability [m^2] (default %g)\n"
+            " -O, --fluid-pressure-top VAL    fluid pressure at +z edge [Pa] (default %g)\n"
+            " -a, --fluid-pressure-ampl VAL   amplitude of pressure variations [Pa] (default %g)\n"
+            " -q, --fluid-pressure-freq VAL   frequency of pressure variations [s^-1] (default %g)\n"
+            " -H, --fluid-pressure-phase VAL  fluid pressure at +z edge [Pa] (default %g)\n"
+            " -t, --time VAL                  simulation start time [s] (default %g)\n"
+            " -T, --time-end VAL              simulation end time [s] (default %g)\n"
+            " -D, --time-step VAL             computational time step length [s] (default %g)\n"
+            " -I, --file-interval VAL         interval between output files [s] (default %g)\n"
             " -v, --version                   show version information\n"
-            " -h, --help                      show this message\n"
-            , __func__, PROGNAME);
+            " -h, --help                      show this message\n",
+        __func__, PROGNAME,
+        sim.name,
+        sim.G,
+        sim.P_wall,
+        sim.mu_wall,
+        sim.v_x_bot,
+        sim.A,
+        sim.b,
+        sim.mu_s,
+        sim.phi[0],
+        sim.d,
+        sim.rho_s,
+        sim.nz,
+        sim.origo_z,
+        sim.L_z,
+        sim.beta_f,
+        sim.mu_f,
+        sim.rho_f,
+        sim.k[0],
+        sim.p_f_top,
+        sim.p_f_mod_ampl,
+        sim.p_f_mod_freq,
+        sim.p_f_mod_phase,
+        sim.t,
+        sim.t_end,
+        sim.dt,
+        sim.file_dt);
+    free(sim.phi);
+    free(sim.k);
 }
 
 static void version(void)
@@ -109,9 +139,13 @@ int main(int argc, char* argv[])
 
             case 'h':
                 usage();
+                free(sim.phi);
+                free(sim.k);
                 return 0;
             case 'v':
                 version();
+                free(sim.phi);
+                free(sim.k);
                 return 0;
             case 'n':
                 sim.nz = atoi(optarg);