tadd first packing algorithm - granular - granular dynamics simulation
(HTM) git clone git://src.adamsgaard.dk/granular
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 2411376bd4ea88e2184dce638984407b56208f9a
(DIR) parent 054a2cc1416d4760f8a25499d5db265877f4d359
(HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Thu, 18 Mar 2021 14:33:47 +0100
add first packing algorithm
Diffstat:
A packing.c | 38 +++++++++++++++++++++++++++++++
A packing.h | 19 +++++++++++++++++++
2 files changed, 57 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/packing.c b/packing.c
t@@ -0,0 +1,38 @@
+#include <err.h>
+#include "util.h"
+#include "granular.h"
+#include "grain.h"
+#include "arrays.h"
+
+struct grain *
+rectangular_packing(size_t n[3],
+ double radius_min, double radius_max,
+ double (*gsd)(double min, double max),
+ double padding_factor,
+ double origo[3])
+{
+ size_t i, j, k, l, ig;
+ struct grain *grains;
+ double dx_padding = radius_max * 2.0 * padding_factor;
+ double dx = radius_max * 2.0 + dx_padding;
+
+ if (!(grains = calloc(n[0] * n[1] * n[2], sizeof(struct grain))))
+ err(1, "%s: grains calloc", __func__);
+
+ for (k = 0; k < n[2]; k++)
+ for (j = 0; j < n[1]; j++)
+ for (i = 0; i < n[0]; i++) {
+ 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];
+ for (l = 0; l < 3; l++)
+ grains[ig].pos[l] +=
+ random_value_uniform(-0.5 * dx_padding,
+ 0.5 * dx_padding);
+ }
+
+ return grains;
+}
(DIR) diff --git a/packing.h b/packing.h
t@@ -0,0 +1,19 @@
+#ifndef GRANULAR_PACKING_
+#define GRANULAR_PACKING_
+
+#include "grain.h"
+#include "simulation.h"
+
+struct grain * rectangular_packing(size_t n[3],
+ double radius_min, double radius_max,
+ double (*gsd)(double min, double max),
+ double padding_factor,
+ double *origo[3]);
+
+struct grain ** triangular_packing_2d(int nx, int ny,
+ double radius_min, double radius_max);
+
+struct grain ** irregular_packing_2d(int nx, int ny,
+ double radius_min, double radius_max);
+
+#endif