tgrain.c: add temporal integration scheme (2nd order taylor expansion) - granul… | |
git clone git://src.adamsgaard.dk/granular | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 96dfeaee4f7fc99516cc12cb75e44c922891b3c1 | |
parent 7f62b5e0ac9c7b40bfbb7a5cfe06af79dc966d81 | |
Author: Anders Damsgaard <[email protected]> | |
Date: Sun, 28 Mar 2021 17:11:06 +0200 | |
grain.c: add temporal integration scheme (2nd order taylor expansion) | |
Diffstat: | |
M grain.c | 32 +++++++++++++++++++++++++++++… | |
M grain.h | 1 + | |
2 files changed, 33 insertions(+), 0 deletions(-) | |
--- | |
diff --git a/grain.c b/grain.c | |
t@@ -279,3 +279,35 @@ grain_kinetic_energy(const struct grain *g) | |
return grain_translational_kinetic_energy(g) + | |
grain_rotational_kinetic_energy(g); | |
} | |
+ | |
+static void | |
+grain_temporal_integration_two_term_taylor(struct grain *g, double dt) | |
+{ | |
+ size_t i; | |
+ double dx, mass = grain_mass(g); | |
+ double moment_of_inertia = grain_moment_of_inertia(g); | |
+ | |
+ for (i = 0; i < 3; i++) { | |
+ g->acc[i] = g->force[i] / mass; | |
+ g->angacc[i] = g->torque[i] / moment_of_inertia; | |
+ } | |
+ | |
+ if (g->fixed) | |
+ for (i = 0; i < 3; i++) | |
+ g->acc[i] = 0.0; | |
+ | |
+ for (i = 0; i < 3; i++) { | |
+ dx = g->vel[i] * dt + 0.5 * g->acc[i] * dt * dt; | |
+ g->pos[i] += dx; | |
+ g->disp[i] += dx; | |
+ g->angpos[i] += g->angvel[i] * dt + 0.5 * g->angacc[i] * dt * … | |
+ g->vel[i] += g->acc[i] * dt; | |
+ g->angvel[i] += g->angacc[i] * dt; | |
+ } | |
+} | |
+ | |
+void | |
+grain_temporal_integration(struct grain *g, double dt) | |
+{ | |
+ grain_temporal_integration_two_term_taylor(g, dt); | |
+} | |
diff --git a/grain.h b/grain.h | |
t@@ -48,5 +48,6 @@ void grain_zero_kinematics(struct grain *g); | |
double grain_translational_kinetic_energy(const struct grain *g); | |
double grain_rotational_kinetic_energy(const struct grain *g); | |
double grain_kinetic_energy(const struct grain *g); | |
+void grain_temporal_integration(struct grain *g, double dt); | |
#endif |