everything is technically working
This commit is contained in:
parent
d3a227ac19
commit
c52fbe796d
|
@ -13,7 +13,6 @@ interaction_force_function
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < 7; i++)
|
for(i = 0; i < 7; i++)
|
||||||
{
|
{
|
||||||
printf("%x\n", coefficients);
|
|
||||||
result += coefficients[i] * powf(r, i);
|
result += coefficients[i] * powf(r, i);
|
||||||
}
|
}
|
||||||
result *= coefficients[7] * expf(coefficients[8] * (r - coefficients[9]));
|
result *= coefficients[7] * expf(coefficients[8] * (r - coefficients[9]));
|
||||||
|
@ -28,7 +27,7 @@ interaction_ufunc_force
|
||||||
( char ** args
|
( char ** args
|
||||||
, npy_intp * dimensions
|
, npy_intp * dimensions
|
||||||
, npy_intp * steps
|
, npy_intp * steps
|
||||||
, void ** data)
|
, void * data)
|
||||||
{
|
{
|
||||||
char * in = args[0]
|
char * in = args[0]
|
||||||
, * out = args[1];
|
, * out = args[1];
|
||||||
|
@ -38,9 +37,7 @@ interaction_ufunc_force
|
||||||
|
|
||||||
npy_intp i;
|
npy_intp i;
|
||||||
|
|
||||||
printf("DATA IS: %x\n", data);
|
float * coefficients = (float *) data;
|
||||||
printf("DATA[0] IS: %x\n", data[0]);
|
|
||||||
float * coefficients = (float *) data[0];
|
|
||||||
|
|
||||||
for(i = 0; i < n; i++)
|
for(i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
|
@ -139,6 +136,7 @@ typedef struct
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
float coefficients[19];
|
float coefficients[19];
|
||||||
PyObject * ufunc;
|
PyObject * ufunc;
|
||||||
|
void *data[1];
|
||||||
} interaction_UFuncWrapper;
|
} interaction_UFuncWrapper;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -189,29 +187,30 @@ interaction_UFuncWrapper_init
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self->data[0] = (void *)self->coefficients;
|
||||||
|
|
||||||
switch(type)
|
switch(type)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
{
|
{
|
||||||
self->ufunc = PyUFunc_FromFuncAndData(
|
self->ufunc = PyUFunc_FromFuncAndData(
|
||||||
force_funcs
|
force_funcs // func
|
||||||
, (void **) &(self->coefficients)
|
, self->data // data
|
||||||
, force_types
|
, force_types //types
|
||||||
, 1
|
, 1 // ntypes
|
||||||
, 1
|
, 1 // nin
|
||||||
, 1
|
, 1 // nout
|
||||||
, PyUFunc_None
|
, PyUFunc_None // identity
|
||||||
, "force_function"
|
, "force_function" // name
|
||||||
, "computes the scalar force between two particles with given coefficients"
|
, "computes the scalar force between two particles with given coefficients" // doc
|
||||||
, 0);
|
, 0); // unused
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
self->ufunc = PyUFunc_FromFuncAndData(
|
self->ufunc = PyUFunc_FromFuncAndData(
|
||||||
interaction_funcs
|
interaction_funcs
|
||||||
, (void **) &(self->coefficients)
|
, self->data
|
||||||
, interaction_types
|
, interaction_types
|
||||||
, 1
|
, 1
|
||||||
, 4
|
, 4
|
||||||
|
@ -229,8 +228,6 @@ interaction_UFuncWrapper_init
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Py_INCREF(self->ufunc);
|
Py_INCREF(self->ufunc);
|
||||||
printf("PASSED = %x\n", &(self->coefficients));
|
|
||||||
printf("PASSED[0] = %x\n", self->coefficients);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,6 @@ interaction_ufunc_force
|
||||||
( char ** args
|
( char ** args
|
||||||
, npy_intp * dimensions
|
, npy_intp * dimensions
|
||||||
, npy_intp * steps
|
, npy_intp * steps
|
||||||
, void ** data);
|
, void * data);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
75
test.py
75
test.py
|
@ -4,48 +4,45 @@ from collections import deque
|
||||||
from copy import copy
|
from copy import copy
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
c = np.array([5, 10, 20, 0, 0, 0, 0, 1, -2, 0, -2, -0.1, 2, 0, 0, 0, 0, 0, 0], dtype=np.float16)
|
c = np.array([5, 10, 20, 30, 0, 0, 0, 1, -20, 0, -2, -0.1, 2, 0, 0, 0, 0, 0, 0], dtype=np.float16)
|
||||||
print(c)
|
|
||||||
print(len(c))
|
|
||||||
|
|
||||||
#x_coords = np.array([0, 1], dtype=np.float16)
|
|
||||||
#y_coords = np.array([0, 0], dtype=np.float16)
|
|
||||||
#
|
|
||||||
#x_momenta = np.array([0, 0], dtype=np.float16)
|
|
||||||
#y_momenta = np.array([0, 0], dtype=np.float16)
|
|
||||||
#
|
|
||||||
#time = np.arange(0, 5, 1, dtype=np.float16)
|
|
||||||
#
|
|
||||||
#time_evolution = deque()
|
|
||||||
#
|
|
||||||
#for t in time:
|
|
||||||
# x_momenta, y_momenta = interaction2D(x_coords, y_coords, x_momenta, y_momenta, c)
|
|
||||||
# x_coords += x_momenta
|
|
||||||
# y_coords += y_momenta
|
|
||||||
#
|
|
||||||
# time_evolution.append(copy(x_coords))
|
|
||||||
#
|
|
||||||
#time_evolution = np.array(time_evolution)
|
|
||||||
#
|
|
||||||
#particle_one_evolution = time_evolution[:, 0]
|
|
||||||
#particle_two_evolution = time_evolution[:, 1]
|
|
||||||
|
|
||||||
#plt.subplot(2, 1, 1)
|
|
||||||
|
|
||||||
force_function = UFuncWrapper(0, c)
|
force_function = UFuncWrapper(0, c)
|
||||||
r = np.arange(0, 0.5, 0.01, dtype=np.float16)
|
interaction2D = UFuncWrapper(1, c)
|
||||||
|
|
||||||
|
x_coords = np.array([0, 1], dtype=np.float16)
|
||||||
|
y_coords = np.array([0, 0], dtype=np.float16)
|
||||||
|
|
||||||
|
x_momenta = np.array([0, 0], dtype=np.float16)
|
||||||
|
y_momenta = np.array([0, 0], dtype=np.float16)
|
||||||
|
|
||||||
|
time = np.arange(0, 5, 1, dtype=np.float16)
|
||||||
|
|
||||||
|
time_evolution = deque()
|
||||||
|
|
||||||
|
for t in time:
|
||||||
|
x_momenta, y_momenta = interaction2D(x_coords, y_coords, x_momenta, y_momenta)
|
||||||
|
x_coords += x_momenta
|
||||||
|
y_coords += y_momenta
|
||||||
|
|
||||||
|
time_evolution.append(copy(x_coords))
|
||||||
|
|
||||||
|
time_evolution = np.array(time_evolution)
|
||||||
|
|
||||||
|
particle_one_evolution = time_evolution[:, 0]
|
||||||
|
particle_two_evolution = time_evolution[:, 1]
|
||||||
|
|
||||||
|
plt.subplot(2, 1, 1)
|
||||||
|
|
||||||
|
r = np.arange(0, 50, 0.1, dtype=np.float16)
|
||||||
plt.title("Force")
|
plt.title("Force")
|
||||||
plt.xlabel("particle distance")
|
plt.xlabel("particle distance")
|
||||||
plt.ylabel("scalar force")
|
plt.ylabel("scalar force")
|
||||||
print(r)
|
plt.plot(r, force_function(r))
|
||||||
print(force_function.ufunc(r))
|
|
||||||
plt.plot(r, force_function.ufunc(r))
|
|
||||||
|
|
||||||
#plt.subplot(2, 1, 2)
|
plt.subplot(2, 1, 2)
|
||||||
#plt.title("Particle x-positions over time")
|
plt.title("Particle x-positions over time")
|
||||||
#plt.xlabel("time")
|
plt.xlabel("time")
|
||||||
#plt.ylabel("particle x-position")
|
plt.ylabel("particle x-position")
|
||||||
#h0, = plt.plot(time, particle_one_evolution, label="particle 1")
|
h0, = plt.plot(time, particle_one_evolution, label="particle 1")
|
||||||
#h1, = plt.plot(time, particle_two_evolution, label="particle 2")
|
h1, = plt.plot(time, particle_two_evolution, label="particle 2")
|
||||||
#plt.legend(handles=[h0, h1])
|
plt.legend(handles=[h0, h1])
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user