tadd contact struct, will maybe be moved outside of grains - granular - granular dynamics simulation
(HTM) git clone git://src.adamsgaard.dk/granular
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 04d5e7eefa6dad607385b133b32056e06b8d3fd4
(DIR) parent 96dfeaee4f7fc99516cc12cb75e44c922891b3c1
(HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Thu, 8 Apr 2021 21:11:03 +0200
add contact struct, will maybe be moved outside of grains
Diffstat:
M Makefile | 2 ++
A contact.h | 18 ++++++++++++++++++
M grain.c | 3 +++
M grain.h | 4 ++++
M simulation.c | 63 ++++++++++++++++++++++++++++---
5 files changed, 84 insertions(+), 6 deletions(-)
---
(DIR) diff --git a/Makefile b/Makefile
t@@ -17,6 +17,7 @@ SCRIPTS = \
SRC = \
arrays.c\
+ contact.c\
grain.c\
grains.c\
packing.c\
t@@ -25,6 +26,7 @@ SRC = \
HDR = \
arg.h\
arrays.h\
+ contact.h\
grain.h\
grains.h\
granular.h\
(DIR) diff --git a/contact.h b/contact.h
t@@ -0,0 +1,18 @@
+#ifndef GRANULAR_CONTACT_
+#define GRANULAR_CONTACT_
+
+#include <stdlib.h>
+
+struct contact {
+ int active;
+ size_t i, j;
+ double centerdist[3];
+ double overlap;
+ double age;
+ double stress[3];
+};
+
+void contact_defaults(struct contact *c);
+void contact_new(struct contact *c, size_t i, size_t j);
+
+#endif
(DIR) diff --git a/grain.c b/grain.c
t@@ -6,6 +6,7 @@
#include "util.h"
#include "grain.h"
#include "arrays.h"
+#include "contact.h"
#define FLOATPREC 17
t@@ -48,6 +49,8 @@ grain_defaults(struct grain *g)
g->shear_strength = 1e8;
g->fracture_toughness = 1e8;
g->ncontacts = 0;
+ for (i = 0; i < MAXCONTACTS; i++)
+ contact_defaults(&g->contacts[i]);
g->thermal_energy = 0.0;
g->color = 0;
}
(DIR) diff --git a/grain.h b/grain.h
t@@ -2,6 +2,9 @@
#define GRANULAR_GRAIN_
#include <stdio.h>
+#include "contact.h"
+
+#define MAXCONTACTS 32
struct grain {
t@@ -28,6 +31,7 @@ struct grain {
double fracture_toughness;
size_t gridpos[3];
size_t ncontacts;
+ struct contact contacts[MAXCONTACTS];
double contact_stress[3];
double thermal_energy;
int color;
(DIR) diff --git a/simulation.c b/simulation.c
t@@ -23,7 +23,7 @@ sim_new(void)
void
sim_defaults(struct simulation *sim)
{
- size_t i;
+ int i;
snprintf(sim->name, sizeof(sim->name), DEFAULT_SIMULATION_NAME);
sim->ng = 0;
t@@ -86,16 +86,67 @@ sim_print_grains_vtk(FILE *stream, const struct simulation *sim)
grains_print_vtk(stream, sim->grains, sim->ng);
}
+double
+sim_grain_pair_overlap(struct simulation *sim, size_t i, size_t j)
+{
+ double pos[3], overlap;
+ int d;
+
+ if (i < j) {
+ for (d = 0; d < 3; d++)
+ pos[d] = sim->grains[i].pos[d] - sim->grains[j].pos[d];
+ overlap = euclidean_norm(pos, 3)
+ - (sim->grains[i].radius + sim->grains[j].radius);
+ }
+
+ return overlap;
+}
+
+static void
+sim_check_add_contact(struct simulation *sim, size_t i, size_t j)
+{
+
+ double overlap;
+ int ic;
+
+ for (ic = 0; ic <= MAXCONTACTS; ic++) {
+ continue; /* TODO */
+ }
+
+ overlap = sim_grain_pair_overlap(sim, i, j);
+ if (overlap < 0.0) {
+ for (ic = 0; ic <= MAXCONTACTS; ic++) {
+
+ if (ic == MAXCONTACTS)
+ errx(1, "MAXCONTACTS (%d) exceeded (grains %zu, %zu)",
+ MAXCONTACTS, i, j);
+
+ /* TODO */
+ }
+ }
+}
+
+static void
+sim_detect_contacts(struct simulation *sim)
+{
+ size_t i, j;
+
+ for (i = 0; i < sim->ng; i++)
+ for (j = 0; j < sim->ng; j++)
+ if (i < j)
+ sim_check_add_contact(sim, i, j);
+}
+
void
sim_step_time(struct simulation *sim)
{
size_t i;
- for (i = 0; i < sim->ng; i++) {
- /* sim_detect_contacts(sim); */
- /* sim_resolve_interactions(sim); */
- /* grain_temporal_integration(sim->g[i], sim->dt); */
- }
+ sim_detect_contacts(sim);
+ /* sim_resolve_interactions(sim); */
+
+ for (i = 0; i < sim->ng; i++)
+ grain_temporal_integration(&sim->grains[i], sim->dt);
sim->t += sim->dt;
sim->t_file += sim->dt;