Introduction
Introduction Statistics Contact Development Disclaimer Help
timplement neighbor search - slidergrid - grid of elastic sliders on a friction…
git clone git://src.adamsgaard.dk/slidergrid
Log
Files
Refs
README
LICENSE
---
commit 732f66ba25f3f657fb4adbfa37cc27f071a05b38
parent e9b6a38b8abbc6939db719054f932214fb1fba4e
Author: Anders Damsgaard <[email protected]>
Date: Tue, 15 Mar 2016 14:58:04 -0700
implement neighbor search
Diffstat:
M grid.c | 66 +++++++++++++++++++++++++++++…
M grid.h | 12 ++++++++++--
M main.c | 2 +-
M vector_math.c | 8 ++++++++
M vector_math.h | 3 +++
5 files changed, 85 insertions(+), 6 deletions(-)
---
diff --git a/grid.c b/grid.c
t@@ -1,13 +1,19 @@
+#include <stdio.h>
#include <stdlib.h>
#include "typedefs.h"
#include "slider.h"
+#include "vector_math.h"
slider* create_regular_slider_grid(
- int nx, int ny, int nz, // number of sliders in each direction
- Float dx, Float dy, Float dz) // spacing of sliders in each direction
+ const int nx,
+ const int ny,
+ const int nz,
+ const Float dx,
+ const Float dy,
+ const Float dz)
{
slider* sliders;
- sliders = malloc(sizeof(slider) * nx * ny * nz);
+ sliders = malloc(sizeof(slider)*nx*ny*nz);
int i = 0; int ix, iy, iz;
for (iz = 0; iz < nz; iz++) {
t@@ -23,3 +29,57 @@ slider* create_regular_slider_grid(
return sliders;
}
+
+/* Find neighboring sliders within a defined cutoff distance */
+void find_neighbors_n2(
+ const slider* sliders,
+ const int N,
+ const Float cutoff)
+{
+ int i, j;
+ 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);
+
+ }
+ }
+ //sliders[i].neighbors = malloc(sizeof(int)*
+
+
+}
+
+// From the list of neighbors, find which sliders are within the debonding
+// distance
+void bond_to_neighbors(
+ const slider* sliders,
+ const int N,
+ const Float debonding_distance)
+{
+
+ // bond slider to the two closest neighbors in each direction
+ //sliders[i].neighbors = malloc(sizeof(int)*
+
+}
+
+int save_slider_positions_to_file(
+ const slider* sliders,
+ const int N,
+ const char* filename)
+{
+ FILE* f = fopen(filename, "w");
+ if (f == NULL) {
+ fprintf(stderr, "Could not open output file %s.", filename);
+ return 1;
+ }
+
+ int i;
+ for (i=0; i<N; i++)
+ printf("%f\t%f\t%f\n",
+ sliders[i].pos.x, sliders[i].pos.y, sliders[i].pos.z);
+
+ fclose(f);
+ return 0;
+}
diff --git a/grid.h b/grid.h
t@@ -3,7 +3,15 @@
#include "slider.h"
slider* create_regular_slider_grid(
- int nx, int ny, int nz, // number of sliders in each direction
- Float dx, Float dy, Float dz); // spacing of sliders in each direction
+ const int nx,
+ const int ny,
+ const int nz,
+ const Float dx,
+ const Float dy,
+ const Float dz);
+int save_slider_positions_to_file(
+ const slider* sliders,
+ const int N,
+ const char* filename);
#endif
diff --git a/main.c b/main.c
t@@ -19,7 +19,7 @@ int main(int argc, char** argv)
sliders[i].mass = 1.;
// temporal loop
- Float t = 0.;
+ Float t;
const Float t_end = 1.;
//Float dt = calculate_time_step();
Float dt = 1.0;
diff --git a/vector_math.c b/vector_math.c
t@@ -1,3 +1,4 @@
+#include <math.h>
#include "typedefs.h"
t@@ -8,11 +9,18 @@ inline Float3 make_float3(Float x, Float y, Float z)
return v;
}
+
+// single-vector operations
inline Float3 copy_float3(Float3 v)
{
return make_float3(v.x, v.y, v.z);
}
+inline Float norm_float3(Float3 v)
+{
+ return sqrt(v.x*v.x + v.y*v.y + v.z*v.z);
+}
+
// vector-vector operations
inline Float3 add_float3(Float3 v1, Float3 v2)
diff --git a/vector_math.h b/vector_math.h
t@@ -2,7 +2,10 @@
// constructor
Float3 make_float3(Float x, Float y, Float z);
+
+// single-vector operations
Float3 copy_float3(Float3 v);
+Float norm_float3(Float3 v);
// vector-vector operations
Float3 add_float3(Float3 v1, Float3 v2);
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.