timprove debugging output, save bond-parallel displacement as scalar - slidergrid - grid of elastic sliders on a frictional surface
git clone git://src.adamsgaard.dk/slidergrid
Log
Files
Refs
README
LICENSE
---
commit dea4dc1c1b2f140a281656f0f58b35625d90d027
parent 3246bf804bdc996d1bd737dbeb3acadad09fae2d
Author: Anders Damsgaard 
Date:   Thu, 14 Apr 2016 12:24:45 -0700

improve debugging output, save bond-parallel displacement as scalar

Diffstat:
  M slidergrid/debug.h                  |       8 ++++----
  M slidergrid/main.c                   |      15 ++++++++++++++-
  M slidergrid/slider.c                 |      69 +++++++++++++++++--------------
  M slidergrid/slider.h                 |       2 +-

4 files changed, 58 insertions(+), 36 deletions(-)
---
diff --git a/slidergrid/debug.h b/slidergrid/debug.h
t@@ -6,18 +6,18 @@
 //#define DEBUG_FIND_AND_BOND_TO_NEIGHBORS
 
 // if defined, show information on the resolved inter-slider bond deformation
-#define DEBUG_BOND_DEFORMATION
+//#define DEBUG_BOND_DEFORMATION
 
 // if defined, verbose information to stdout will be shown about the individual 
 // components of the sum of forces
-#define DEBUG_SLIDER_FORCE_COMPONENTS
+//#define DEBUG_SLIDER_FORCE_COMPONENTS
 
 // if defined, verbose information to stdout will be shown before the slider 
 // integration
-#define DEBUG_SLIDER_FORCE_TORQUE_AND_NEIGHBORS
+//#define DEBUG_SLIDER_FORCE_TORQUE_AND_NEIGHBORS
 
 // if defined, verbose information to stdout will be shown after the slider 
 // integration
-#define DEBUG_SLIDER_KINEMATICS
+//#define DEBUG_SLIDER_KINEMATICS
 
 #endif
diff --git a/slidergrid/main.c b/slidergrid/main.c
t@@ -127,6 +127,14 @@ int main(int argc, char** argv)
             sim.time <= sim.time_end;
             sim.time += sim.dt) {
 
+#if defined(DEBUG_FIND_AND_BOND_TO_NEIGHBORS) ||\
+        defined(DEBUG_BOND_DEFORMATION) ||\
+        defined(DEBUG_SLIDER_FORCE_COMPONENTS) ||\
+        defined(DEBUG_SLIDER_FORCE_TORQUE_AND_NEIGHBORS) ||\
+        defined(DEBUG_SLIDER_KINEMATICS)
+        printf("\n---- ITERATION %d ----\n", sim.iteration);
+#endif
+
         /*for (i=0; i
diff --git a/slidergrid/slider.c b/slidergrid/slider.c
t@@ -41,7 +41,7 @@ void initialize_slider_values(slider* s)
     for (i=0; ineighbors[i] = -1;
         s->neighbor_distance[i] = zeroes_float3();
-        s->neighbor_relative_distance_displacement[i] = zeroes_float3();
+        s->neighbor_relative_distance_displacement[i] = 0.0;
         s->neighbor_relative_distance_velocity[i] = zeroes_float3();
         s->neighbor_relative_tangential_displacement[i] = zeroes_float3();
         s->neighbor_relative_tangential_velocity[i] = zeroes_float3();
t@@ -143,6 +143,17 @@ void bond_parallel_deformation(slider* s1, const slider s2,
     // unit vector pointing from neighbor (s2) to slider s1
     const Float3 n = divide_float3_scalar(dist, dist_norm);
 
+#ifdef DEBUG_BOND_DEFORMATION
+    printf("\tdist = %f %f %f\n\tdist_norm = %f\n\tn = %f %f %f\n",
+            dist.x,
+            dist.y,
+            dist.z,
+            dist_norm,
+            n.x,
+            n.y,
+            n.z);
+#endif
+
     // relative contact interface velocity w/o rolling
     const Float3 vel_linear = subtract_float3(s1->vel, s2.vel);
 
t@@ -165,12 +176,11 @@ void bond_parallel_deformation(slider* s1, const slider s2,
 
     // total relative displacement in inter-slider distance
     if (iteration == 0)
-        s1->neighbor_relative_distance_displacement[idx_neighbor] = ddist;
-    else
         s1->neighbor_relative_distance_displacement[idx_neighbor] =
-            add_float3(
-                    s1->neighbor_relative_distance_displacement[idx_neighbor],
-                    ddist);
+            dot_float3(n, ddist);
+    else
+        s1->neighbor_relative_distance_displacement[idx_neighbor] +=
+            dot_float3(n, ddist);
 
     // total relative displacement in inter-slider distance
     s1->neighbor_relative_distance_velocity[idx_neighbor] = 
t@@ -254,13 +264,17 @@ void bond_deformation(slider* s1, const slider s2,
         const int idx_neighbor, const int iteration, const Float dt)
 {
     bond_parallel_deformation(s1, s2, idx_neighbor, iteration);
-    bond_normal_deformation(s1, s2, idx_neighbor, iteration, dt);
+    //bond_normal_deformation(s1, s2, idx_neighbor, iteration, dt);
 }
 
 
 void bond_parallel_kelvin_voigt(slider* s1, const slider s2,
         const int idx_neighbor)
 {
+    // unit vector pointing from neighbor (s2) to slider s1
+    const Float3 n = divide_float3_scalar(s1->neighbor_distance[idx_neighbor],
+            norm_float3(s1->neighbor_distance[idx_neighbor]));
+
     // determine the bond-parallel KV stiffness from the harmonic mean.
     // differs from Potyondy & Stack 2004, eq. 6.
     const Float bond_parallel_kv_stiffness =
t@@ -276,8 +290,9 @@ void bond_parallel_kelvin_voigt(slider* s1, const slider s2,
 
     // bond-parallel Kelvin-Voigt elasticity
     const Float3 f_n_elastic =
-        multiply_scalar_float3(bond_parallel_kv_stiffness,
-                s1->neighbor_relative_distance_displacement[idx_neighbor]);
+        multiply_scalar_float3(bond_parallel_kv_stiffness * 
+                s1->neighbor_relative_distance_displacement[idx_neighbor],
+                n);
 
     // bond-parallel Kelvin-Voigt viscosity
     const Float3 f_n_viscous =
t@@ -292,8 +307,12 @@ void bond_parallel_kelvin_voigt(slider* s1, const slider s2,
     s1->force = add_float3(s1->force, f_n);
 
 #ifdef DEBUG_SLIDER_FORCE_COMPONENTS
-    printf("slider_interaction KV-parallel: f_n = %f %f %f, "
-            "f_n_elastic = %f %f %f, f_n_viscous = %f %f %f\n",
+    printf("  slider_interaction KV-parallel:\n"
+            "\tn = %f %f %f\n\tf_n = %f %f %f\n\t"
+            "f_n_elastic = %f %f %f\n\tf_n_viscous = %f %f %f\n",
+            n.x,
+            n.y,
+            n.z,
             f_n.x,
             f_n.y,
             f_n.z,
t@@ -354,8 +373,9 @@ void bond_shear_kelvin_voigt(slider* s1, const slider s2,
                     f_t)));*/
 
 #ifdef DEBUG_SLIDER_FORCE_COMPONENTS
-    printf("slider_interaction KV-shear: f_t = %f %f %f, torque = %f %f %f, "
-            "f_t_elastic = %f %f %f, f_t_viscous = %f %f %f\n",
+    printf("  slider_interaction KV-shear:\n\tf_t = %f %f %f\n"
+            "\ttorque = %f %f %f\n\t"
+            "f_t_elastic = %f %f %f\n\tf_t_viscous = %f %f %f\n",
             f_t.x,
             f_t.y,
             f_t.z,
t@@ -376,7 +396,7 @@ void bond_shear_kelvin_voigt(slider* s1, const slider s2,
 void slider_interaction(slider* s1, const slider s2, const int idx_neighbor)
 {
     bond_parallel_kelvin_voigt(s1, s2, idx_neighbor);
-    //bond_shear_kelvin_voigt(s1, s2, idx_neighbor);
+    bond_shear_kelvin_voigt(s1, s2, idx_neighbor);
 }
 
 
t@@ -391,32 +411,21 @@ void slider_neighbor_interaction(
     int idx_neighbor;
     for (idx_neighbor=0; idx_neighborforce.x = 0.;
-        s->force.y = 0.;
-        s->force.z = 0.;
-        s->torque.x = 0.;
-        s->torque.y = 0.;
-        s->torque.z = 0.;*/
-
         if (s->neighbors[idx_neighbor] != -1) {
 
+#ifdef DEBUG_BOND_DEFORMATION
+            printf("%p = %d:\n", s, idx_neighbor);
+#endif
             bond_deformation(
                     s, sliders[s->neighbors[idx_neighbor]],
                     idx_neighbor, iteration, dt);
 
 #ifdef DEBUG_BOND_DEFORMATION
-            int j;
-            for (j=0; jneighbor_relative_distance_displacement[idx_neighbor].x,
-                    s->neighbor_relative_distance_displacement[idx_neighbor].y,
-                    s->neighbor_relative_distance_displacement[idx_neighbor].z,
+                    s->neighbor_relative_distance_displacement[idx_neighbor],
                     s->neighbor_relative_distance_velocity[idx_neighbor].x,
                     s->neighbor_relative_distance_velocity[idx_neighbor].y,
                     s->neighbor_relative_distance_velocity[idx_neighbor].z,
diff --git a/slidergrid/slider.h b/slidergrid/slider.h
t@@ -51,7 +51,7 @@ typedef struct {
 
     // relative spatial movement between this slider and its neighbors
     Float3 neighbor_distance[MAX_NEIGHBORS];
-    Float3 neighbor_relative_distance_displacement[MAX_NEIGHBORS];
+    Float neighbor_relative_distance_displacement[MAX_NEIGHBORS];
     Float3 neighbor_relative_distance_velocity[MAX_NEIGHBORS];
     Float3 neighbor_relative_tangential_displacement[MAX_NEIGHBORS];
     Float3 neighbor_relative_tangential_velocity[MAX_NEIGHBORS];