made some useful changes

This commit is contained in:
Daniel Knüttel 2019-07-13 15:20:50 +02:00
parent fb7c109e0b
commit 0a734b8266
2 changed files with 13 additions and 10 deletions

View File

@ -1,8 +1,8 @@
#include "interaction.h" #include "interaction.h"
#include "math.h" #include "math.h"
#define WARN_NAN_OCCUR //#define WARN_NAN_OCCUR
#define WARN_CORRECTED_R_0 //#define WARN_CORRECTED_R_0
#define raise2(x) (x)*(x) #define raise2(x) (x)*(x)
@ -87,6 +87,7 @@ interaction_ufunc_float2D
, npy_intp * steps , npy_intp * steps
, void * data) , void * data)
{ {
NPY_BEGIN_THREADS_DEF;
npy_intp i; npy_intp i;
npy_intp j; npy_intp j;
npy_intp n = dimensions[0]; npy_intp n = dimensions[0];
@ -124,6 +125,7 @@ interaction_ufunc_float2D
float this_x_j; float this_x_j;
float this_y_j; float this_y_j;
NPY_BEGIN_THREADS;
for(i = 0; i < n; i++) for(i = 0; i < n; i++)
{ {
@ -152,9 +154,9 @@ interaction_ufunc_float2D
else else
{ {
long int rand = random(); 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 #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 #endif
delta_x_e = cosf(random_angle); delta_x_e = cosf(random_angle);
delty_y_e = sinf(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; *(float *)(p_y_new + j*p_y_new_steps) -= dt*delta_p_y;
} }
} }
NPY_END_THREADS;
} }
static char interaction_types[] = static char interaction_types[] =
{ NPY_FLOAT, NPY_FLOAT, NPY_FLOAT, NPY_FLOAT, NPY_FLOAT, NPY_FLOAT}; { NPY_FLOAT, NPY_FLOAT, NPY_FLOAT, NPY_FLOAT, NPY_FLOAT, NPY_FLOAT};

View File

@ -11,12 +11,12 @@ from coefficients import c
#force_function = UFuncWrapper(0, c) #force_function = UFuncWrapper(0, c)
#interaction2D = UFuncWrapper(1, c) #interaction2D = UFuncWrapper(1, c)
borders_x = [-100, 100] borders_x = [-10, 10]
borders_y = [-100, 100] borders_y = [-10, 10]
n_particles = 600 n_particles = 600
frames = 1000 frames = 100
spawn_restriction = 1.1 spawn_restriction = 1.1
dt = 0.1 dt = 0.001
c[-1] = dt c[-1] = dt
x_coords = np.random.uniform(borders_x[0] / spawn_restriction, borders_x[1] / spawn_restriction, n_particles).astype(np.float16) 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 brown = BrownIterator(-1, c
, x_coords, y_coords , x_coords, y_coords
, y_momenta, y_momenta , y_momenta, y_momenta
#, borders_x, borders_y , borders_x, borders_y
, [], [] #, [], []
, border_dampening=1 , border_dampening=1
, dt=dt) , dt=dt)