Introduction
Introduction Statistics Contact Development Disclaimer Help
tadd simple neighbor search - slidergrid - grid of elastic sliders on a frictio…
git clone git://src.adamsgaard.dk/slidergrid
Log
Files
Refs
README
LICENSE
---
commit 6c55b2b5c3ebfea7827b1513dd5db5ac6cafd94b
parent 732f66ba25f3f657fb4adbfa37cc27f071a05b38
Author: Anders Damsgaard <[email protected]>
Date: Tue, 15 Mar 2016 15:11:10 -0700
add simple neighbor search
Diffstat:
M grid.c | 25 ++++++++++++++++++-------
M slider.h | 4 +++-
2 files changed, 21 insertions(+), 8 deletions(-)
---
diff --git a/grid.c b/grid.c
t@@ -15,7 +15,7 @@ slider* create_regular_slider_grid(
slider* sliders;
sliders = malloc(sizeof(slider)*nx*ny*nz);
- int i = 0; int ix, iy, iz;
+ int i = 0; int ix, iy, iz, j;
for (iz = 0; iz < nz; iz++) {
for (iy = 0; iy < ny; iy++) {
for (ix = 0; ix < nx; ix++) {
t@@ -23,6 +23,9 @@ slider* create_regular_slider_grid(
sliders[i].pos.y = dy * iy;
sliders[i].pos.z = dz * iz;
i++;
+
+ for (j=0; j<MAX_NEIGHBORS; j++)
+ sliders[i].neighbors[j] = -1;
}
}
}
t@@ -32,21 +35,29 @@ slider* create_regular_slider_grid(
/* Find neighboring sliders within a defined cutoff distance */
void find_neighbors_n2(
- const slider* sliders,
+ slider* sliders,
const int N,
const Float cutoff)
{
int i, j;
+ int n_neighbors = 0;
Float3 dist;
Float dist_norm;
- for (j=0; j<N; j++) {
- for (i=0; i<N; i++) {
- dist = subtract_float3(sliders[i].pos, sliders[j].pos);
- dist_norm = norm_float3(dist);
+ for (i=0; i<N; i++) {
+ for (j=0; j<N; j++) {
+ if (i != j) {
+ dist = subtract_float3(sliders[i].pos, sliders[j].pos);
+ dist_norm = norm_float3(dist);
+ if (dist_norm < cutoff) {
+ sliders[i].neighbors[n_neighbors++] = j;
+
+ if (n_neighbors == MAX_NEIGHBORS - 1)
+ fprintf(stderr, "Error: MAX_NEIGHBORS exceeded.\n");
+ }
+ }
}
}
- //sliders[i].neighbors = malloc(sizeof(int)*
}
diff --git a/slider.h b/slider.h
t@@ -3,6 +3,8 @@
#include "typedefs.h"
+#define MAX_NEIGHBORS 32
+
typedef struct {
Float3 pos; // spatial position [m]
Float3 vel; // spatial velocity [m/s]
t@@ -10,7 +12,7 @@ typedef struct {
Float3 force; // sum of forces [N]
Float mass; // mass [kg]
Float spring_stiffness; // elastic compressibility [N/m]
- int neighbors[]; // indexes of sliders this one is bonded to
+ int neighbors[MAX_NEIGHBORS]; // indexes of sliders this one is bonded to
} slider;
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.