From 0a734b82665961e2e79aba115b985b6f307e496b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kn=C3=BCttel?= Date: Sat, 13 Jul 2019 15:20:50 +0200 Subject: [PATCH] made some useful changes --- c/interaction/interaction.c | 11 +++++++---- particles.py | 12 ++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/c/interaction/interaction.c b/c/interaction/interaction.c index 39d9d8d..cf720e9 100644 --- a/c/interaction/interaction.c +++ b/c/interaction/interaction.c @@ -1,8 +1,8 @@ #include "interaction.h" #include "math.h" -#define WARN_NAN_OCCUR -#define WARN_CORRECTED_R_0 +//#define WARN_NAN_OCCUR +//#define WARN_CORRECTED_R_0 #define raise2(x) (x)*(x) @@ -87,6 +87,7 @@ interaction_ufunc_float2D , npy_intp * steps , void * data) { + NPY_BEGIN_THREADS_DEF; npy_intp i; npy_intp j; npy_intp n = dimensions[0]; @@ -124,6 +125,7 @@ interaction_ufunc_float2D float this_x_j; float this_y_j; + NPY_BEGIN_THREADS; for(i = 0; i < n; i++) { @@ -152,9 +154,9 @@ interaction_ufunc_float2D else { long int rand = random(); - float random_angle = (((float)rand) / ((float)LONG_MAX)) * 2 * M_PI; + float random_angle = (((float)rand) / ((float)RAND_MAX)) * 2 * M_PI; #ifdef WARN_CORRECTED_R_0 - printf("Warning: corrected r = 0 with random angle pi*%f (from %ld, %f)\n", random_angle / M_PI, rand, random_angle); + printf("Warning: corrected r = 0 with random angle pi*%f\n", random_angle / M_PI); #endif delta_x_e = cosf(random_angle); delty_y_e = sinf(random_angle); @@ -181,6 +183,7 @@ interaction_ufunc_float2D *(float *)(p_y_new + j*p_y_new_steps) -= dt*delta_p_y; } } + NPY_END_THREADS; } static char interaction_types[] = { NPY_FLOAT, NPY_FLOAT, NPY_FLOAT, NPY_FLOAT, NPY_FLOAT, NPY_FLOAT}; diff --git a/particles.py b/particles.py index 78be61c..3fd5ce6 100644 --- a/particles.py +++ b/particles.py @@ -11,12 +11,12 @@ from coefficients import c #force_function = UFuncWrapper(0, c) #interaction2D = UFuncWrapper(1, c) -borders_x = [-100, 100] -borders_y = [-100, 100] +borders_x = [-10, 10] +borders_y = [-10, 10] n_particles = 600 -frames = 1000 +frames = 100 spawn_restriction = 1.1 -dt = 0.1 +dt = 0.001 c[-1] = dt x_coords = np.random.uniform(borders_x[0] / spawn_restriction, borders_x[1] / spawn_restriction, n_particles).astype(np.float16) @@ -43,8 +43,8 @@ center_of_mass_history_y = deque([y_coords.mean()]) brown = BrownIterator(-1, c , x_coords, y_coords , y_momenta, y_momenta - #, borders_x, borders_y - , [], [] + , borders_x, borders_y + #, [], [] , border_dampening=1 , dt=dt)