tpacking.c: style fixes and check radii bounds - granular - granular dynamics simulation
 (HTM) git clone git://src.adamsgaard.dk/granular
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 45a7df9609a6a4f68791e61d4fbd5ea6e11f4ef7
 (DIR) parent f8e052c489f2843bf42b19785d6e8519d5df9075
 (HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
       Date:   Thu, 18 Mar 2021 15:13:27 +0100
       
       packing.c: style fixes and check radii bounds
       
       Diffstat:
         M packing.c                           |      15 ++++++++++++---
       
       1 file changed, 12 insertions(+), 3 deletions(-)
       ---
 (DIR) diff --git a/packing.c b/packing.c
       t@@ -4,6 +4,8 @@
        #include "grain.h"
        #include "arrays.h"
        
       +#define VERBOSE
       +
        struct grain *
        rectangular_packing(size_t n[3],
                            double radius_min, double radius_max,
       t@@ -16,6 +18,10 @@ rectangular_packing(size_t n[3],
                double dx_padding = radius_max * 2.0 * padding_factor;
                double dx = radius_max * 2.0 + dx_padding;
        
       +        if (radius_max < radius_min)
       +                errx(1, "%s: radius_max (%g) is smaller than radius_min (%g)",
       +                     __func__, radius_max, radius_min);
       +
                if (!(grains = calloc(n[0] * n[1] * n[2], sizeof(struct grain))))
                        err(1, "%s: grains calloc", __func__);
        
       t@@ -25,13 +31,16 @@ rectangular_packing(size_t n[3],
                                        ig = idx3(i, j, k, n[0], n[1]);
                                        grain_defaults(&grains[ig]);
                                        grains[ig].radius = gsd(radius_min, radius_max);
       -                                grains[ig].pos[0] = i*dx + 0.5*dx + origo[0];
       -                                grains[ig].pos[1] = j*dx + 0.5*dx + origo[1];
       -                                grains[ig].pos[2] = k*dx + 0.5*dx + origo[2];
       +                                grains[ig].pos[0] = i * dx + 0.5 * dx + origo[0];
       +                                grains[ig].pos[1] = j * dx + 0.5 * dx + origo[1];
       +                                grains[ig].pos[2] = k * dx + 0.5 * dx + origo[2];
                                        for (l = 0; l < 3; l++)
                                                grains[ig].pos[l] +=
                                                        random_value_uniform(-0.5 * dx_padding,
                                                                             0.5 * dx_padding);
       +#ifdef VERBOSE
       +                                printf("added grain %zu\n", ig);
       +#endif
                                }
        
                return grains;