From 1a9ddddc6d0100565db601a9b848520150aa5b5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kn=C3=BCttel?= Date: Mon, 15 Jul 2019 16:56:16 +0200 Subject: [PATCH] some work; does not work --- c/interaction/interaction.c | 26 ++++++++++---------------- particles.py | 2 +- py/brown/brown.py | 5 ++++- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/c/interaction/interaction.c b/c/interaction/interaction.c index 7da2163..35900ea 100644 --- a/c/interaction/interaction.c +++ b/c/interaction/interaction.c @@ -64,17 +64,13 @@ interaction_ufunc_float2D char * x_old = args[0] , * y_old = args[1] - , * p_x_old = args[2] - , * p_y_old = args[3] - , * p_x_new = args[4] - , * p_y_new = args[5]; + , * p_x_new = args[2] + , * p_y_new = args[3]; npy_intp x_old_steps = steps[0] , y_old_steps = steps[1] - , p_x_old_steps = steps[2] - , p_y_old_steps = steps[3] - , p_x_new_steps = steps[4] - , p_y_new_steps = steps[5]; + , p_x_new_steps = steps[2] + , p_y_new_steps = steps[3]; float * coefficients = (float *) data; float dt = coefficients[19]; @@ -102,10 +98,8 @@ interaction_ufunc_float2D this_x_i = *(float *)(x_old + i*x_old_steps); this_y_i = *(float *)(y_old + i*y_old_steps); - // copy current momenta - *(float *)(p_x_new + i*p_x_new_steps) = *(float *)(p_x_old + i*p_x_old_steps); - *(float *)(p_y_new + i*p_y_new_steps) = *(float *)(p_y_old + i*p_y_old_steps); - + *(float *)(p_x_new + i*p_x_new_steps) = 0; + *(float *)(p_y_new + i*p_y_new_steps) = 0; // compute and add the momentum offset for(j = 0; j < i; j++) { @@ -156,7 +150,7 @@ interaction_ufunc_float2D //NPY_END_THREADS; } static char interaction_types[] = - { NPY_FLOAT, NPY_FLOAT, NPY_FLOAT, NPY_FLOAT, NPY_FLOAT, NPY_FLOAT}; + { NPY_FLOAT, NPY_FLOAT, NPY_FLOAT, NPY_FLOAT}; static char force_types[] = { NPY_FLOAT, NPY_FLOAT}; static PyUFuncGenericFunction force_funcs[1] = @@ -245,9 +239,9 @@ interaction_UFuncWrapper_init interaction_funcs , self->data , interaction_types - , 1 - , 4 - , 2 + , 1 // ntypes + , 2 // nin + , 2 // nout , PyUFunc_None , "interaction2D" , "Update the momenta according to the given coefficients and positions" diff --git a/particles.py b/particles.py index 7fbfe01..0d6099b 100644 --- a/particles.py +++ b/particles.py @@ -16,7 +16,7 @@ borders_y = [-100, 100] n_particles = 600 frames = 100 spawn_restriction = 1.1 -dt = 0.01 +dt = 0.1 c[-1] = dt x_coords = np.random.uniform(borders_x[0] / spawn_restriction, borders_x[1] / spawn_restriction, n_particles).astype(np.float16) diff --git a/py/brown/brown.py b/py/brown/brown.py index f2bec87..7e9288d 100644 --- a/py/brown/brown.py +++ b/py/brown/brown.py @@ -37,7 +37,10 @@ class BrownIterator(object): if(self._i == 1): return self.x, self.y - self.px, self.py = self._interaction(self.x, self.y, self.px, self.py) + delta_px, delta_py = self._interaction(self.x, self.y) + self.px += delta_px + self.py += delta_py + print(self.px) # XXX: We need the (-1)**i to make the problem # symmetric. self.px[np.isnan(self.px)] = self.speed_of_light * (-1)**self._i