Introduction
Introduction Statistics Contact Development Disclaimer Help
tadd triangular regular packing - granular - granular dynamics simulation
git clone git://src.adamsgaard.dk/granular
Log
Files
Refs
README
LICENSE
---
commit 1927846d99dbff890b20ba9d7d13c48cfcad2fdf
parent 500ff9f09f7696dfd10e1ac9dcb3d52ed232546b
Author: Anders Damsgaard <[email protected]>
Date: Fri, 19 Mar 2021 13:33:52 +0100
add triangular regular packing
Diffstat:
M packing.c | 49 +++++++++++++++++++++++++++++…
M packing.h | 12 ++++++++----
M packingtest.c | 5 +++--
3 files changed, 58 insertions(+), 8 deletions(-)
---
diff --git a/packing.c b/packing.c
t@@ -1,5 +1,6 @@
#include <stdio.h>
#include <err.h>
+#include <math.h>
#include "util.h"
#include "granular.h"
#include "grain.h"
t@@ -10,8 +11,8 @@ rectangular_packing(struct grain *grains[],
size_t n[3],
double radius_min, double radius_max,
double (*gsd)(double min, double max),
- double padding_factor,
- double origo[3])
+ double padding_factor,
+ double origo[3])
{
size_t i, j, k, l, np, N = 0;
double dx_padding = radius_max * 2.0 * padding_factor;
t@@ -45,3 +46,47 @@ rectangular_packing(struct grain *grains[],
return N;
}
+
+size_t
+triangular_packing(struct grain *grains[],
+ 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, np, N = 0;
+ double dx_padding = radius_max * 2.0 * padding_factor;
+ double dx = radius_max * 2.0 + dx_padding;
+ double dy = dx * sin(PI/3.0);
+
+ 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], 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++) {
+ N++;
+ np = idx3(i, j, k, n[0], n[1]);
+ grain_defaults(&(*grains)[np]);
+ (*grains)[np].radius = gsd(radius_min,…
+ (*grains)[np].pos[0] = i * dx + 0.5 * …
+ if (j % 2 == 0)
+ (*grains)[np].pos[0] += 0.5 * …
+ (*grains)[np].pos[1] = j * dy + 0.5 * …
+ (*grains)[np].pos[2] = j * dx + 0.5 * …
+ for (l = 0; l < 2; l++)
+ (*grains)[np].pos[l] +=
+ random_value_uniform(-…
+ …
+#ifdef VERBOSE
+ printf("added grain %zu\n", np);
+#endif
+ }
+
+ return N;
+}
diff --git a/packing.h b/packing.h
t@@ -8,11 +8,15 @@ size_t rectangular_packing(struct grain *grains[],
size_t n[3],
double radius_min, double radius_max,
double (*gsd)(double min, double max),
- double padding_factor,
- double *origo[3]);
+ double padding_factor,
+ double *origo[3]);
-/*struct grain ** triangular_packing_2d(int nx, int ny,
- double radius_min, double radius_max);*/
+size_t triangular_packing(struct grain *grains[],
+ size_t n[3],
+ double radius_min, double radius_max,
+ double (*gsd)(double min, double max),
+ double padding_factor,
+ double *origo[3]);
/*struct grain ** irregular_packing_2d(int nx, int ny,
double radius_min, double radius_max);*/
diff --git a/packingtest.c b/packingtest.c
t@@ -10,10 +10,11 @@ main(void)
struct simulation sim;
size_t n[3], np = 0;
- n[0] = 5; n[1] = 5; n[2] = 1;
+ n[0] = 10; n[1] = 7; n[2] = 1;
double *origo = zeros(3);
- np = rectangular_packing(&sim.grains, n, 0.1, 1.0, random_value_unifor…
+ /* np = rectangular_packing(&sim.grains, n, 1.0, 1.0, random_value_uni…
+ np = triangular_packing(&sim.grains, n, 1.0, 1.0, random_value_uniform…
print_grains(stdout, sim.grains, np);
free(origo);
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.