Skip to content
Snippets Groups Projects
Commit 6a0e0f99 authored by lhausamm's avatar lhausamm
Browse files

update comments

parent 4ed06166
No related branches found
No related tags found
1 merge request!1Init
...@@ -14,6 +14,7 @@ PyObject* pycooling_init(PyObject* self, PyObject* args) { ...@@ -14,6 +14,7 @@ PyObject* pycooling_init(PyObject* self, PyObject* args) {
PyObject *pyus; PyObject *pyus;
PyObject *pypconst; PyObject *pypconst;
/* parse arguments */
if (!PyArg_ParseTuple(args, "OOO", &pyparams, &pyus, &pypconst)) if (!PyArg_ParseTuple(args, "OOO", &pyparams, &pyus, &pypconst))
return NULL; return NULL;
...@@ -32,8 +33,10 @@ PyObject* pycooling_init(PyObject* self, PyObject* args) { ...@@ -32,8 +33,10 @@ PyObject* pycooling_init(PyObject* self, PyObject* args) {
struct cooling_function_data cooling; struct cooling_function_data cooling;
/* init cooling */
cooling_init_backend(params, us, pconst, &cooling); cooling_init_backend(params, us, pconst, &cooling);
/* construct python object */
PyObject *pycooling = pytools_return(&cooling, class_cooling_function_data); PyObject *pycooling = pytools_return(&cooling, class_cooling_function_data);
return pycooling; return pycooling;
...@@ -51,6 +54,7 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) { ...@@ -51,6 +54,7 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) {
float dt = 1e-3; float dt = 1e-3;
/* parse argument */
if (!PyArg_ParseTuple(args, if (!PyArg_ParseTuple(args,
"OOOOO|f", "OOOOO|f",
&pypconst, &pypconst,
...@@ -61,6 +65,7 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) { ...@@ -61,6 +65,7 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) {
&dt)) &dt))
return NULL; return NULL;
/* check numpy array */
if (pytools_check_array(energy, 1, NPY_FLOAT) != SUCCESS) if (pytools_check_array(energy, 1, NPY_FLOAT) != SUCCESS)
{ {
return NULL; return NULL;
...@@ -76,7 +81,9 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) { ...@@ -76,7 +81,9 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) {
pyerror("Density and energy should have the same dimension"); pyerror("Density and energy should have the same dimension");
} }
size_t N = PyArray_DIM(energy, 0); size_t N = PyArray_DIM(energy, 0);
/* transform PyObject to C struct */
struct cooling_function_data *cooling = (struct cooling_function_data*) pytools_construct(pycooling, class_cooling_function_data); struct cooling_function_data *cooling = (struct cooling_function_data*) pytools_construct(pycooling, class_cooling_function_data);
if (cooling == NULL) if (cooling == NULL)
...@@ -92,20 +99,19 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) { ...@@ -92,20 +99,19 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) {
struct part p; struct part p;
#ifdef COOLING_GRACKLE /* return object */
grackle_data.grackle_data_file = cooling->GrackleCloudyTable;
#endif
PyArrayObject *rate = PyArray_NewLikeArray(energy, NPY_ANYORDER, NULL, 1); PyArrayObject *rate = PyArray_NewLikeArray(energy, NPY_ANYORDER, NULL, 1);
/* loop over all particles */
for(size_t i = 0; i < N; i++) for(size_t i = 0; i < N; i++)
{ {
/* set particle data */
p.rho = *(float*) PyArray_GETPTR1(rho, i); p.rho = *(float*) PyArray_GETPTR1(rho, i);
float u = *(float*) PyArray_GETPTR1(energy, i); float u = *(float*) PyArray_GETPTR1(energy, i);
p.entropy = gas_entropy_from_internal_energy(p.rho, u); p.entropy = gas_entropy_from_internal_energy(p.rho, u);
/* compute cooling rate */
float *tmp = PyArray_GETPTR1(rate, i); float *tmp = PyArray_GETPTR1(rate, i);
#ifdef COOLING_GRACKLE #ifdef COOLING_GRACKLE
*tmp = cooling_rate(pconst, us, cooling, &p, dt); *tmp = cooling_rate(pconst, us, cooling, &p, dt);
#else #else
......
...@@ -7,13 +7,17 @@ PyObject* pyparser_read_file(PyObject *self, PyObject *args) ...@@ -7,13 +7,17 @@ PyObject* pyparser_read_file(PyObject *self, PyObject *args)
{ {
char *filename; char *filename;
/* parse argument */
if (!PyArg_ParseTuple(args, "s", &filename)) if (!PyArg_ParseTuple(args, "s", &filename))
return NULL; return NULL;
struct swift_params params; struct swift_params params;
/* parse file */
parser_read_file(filename, &params); parser_read_file(filename, &params);
/* create return python object */
PyObject* obj = pytools_return(&params, class_swift_params); PyObject* obj = pytools_return(&params, class_swift_params);
return obj; return obj;
......
...@@ -12,6 +12,7 @@ PyObject* pypart_test_struct(PyObject *self, PyObject *args) ...@@ -12,6 +12,7 @@ PyObject* pypart_test_struct(PyObject *self, PyObject *args)
size_t N = sizeof(struct part); size_t N = sizeof(struct part);
/* initialize particle */
struct part *p = malloc(N); struct part *p = malloc(N);
p->id = 0; p->id = 0;
for(size_t k = 0; k < DIM; k++) for(size_t k = 0; k < DIM; k++)
...@@ -29,6 +30,7 @@ PyObject* pypart_test_struct(PyObject *self, PyObject *args) ...@@ -29,6 +30,7 @@ PyObject* pypart_test_struct(PyObject *self, PyObject *args)
hydro_init_part(p, NULL); hydro_init_part(p, NULL);
/* create python object */
PyObject *object = pytools_return(p, class_part); PyObject *object = pytools_return(p, class_part);
free(p); free(p);
......
...@@ -51,7 +51,7 @@ PyObject* pytools_import(char* module_name, char* object_name) ...@@ -51,7 +51,7 @@ PyObject* pytools_import(char* module_name, char* object_name)
pyerror("Failed to get module '%s' dictionary", module_name); pyerror("Failed to get module '%s' dictionary", module_name);
} }
/* get right class */ /* get right object */
PyObject *python_obj = PyDict_GetItemString(dict, object_name); PyObject *python_obj = PyDict_GetItemString(dict, object_name);
Py_DECREF(dict); Py_DECREF(dict);
......
...@@ -13,6 +13,7 @@ PyObject* pyunit_system_test_struct(PyObject *self, PyObject *args) ...@@ -13,6 +13,7 @@ PyObject* pyunit_system_test_struct(PyObject *self, PyObject *args)
size_t N = sizeof(struct unit_system); size_t N = sizeof(struct unit_system);
/* initialize array */
struct unit_system *us = malloc(N); struct unit_system *us = malloc(N);
us->UnitMass_in_cgs = 1.; us->UnitMass_in_cgs = 1.;
us->UnitLength_in_cgs = 2.; us->UnitLength_in_cgs = 2.;
...@@ -20,6 +21,7 @@ PyObject* pyunit_system_test_struct(PyObject *self, PyObject *args) ...@@ -20,6 +21,7 @@ PyObject* pyunit_system_test_struct(PyObject *self, PyObject *args)
us->UnitCurrent_in_cgs = 4.; us->UnitCurrent_in_cgs = 4.;
us->UnitTemperature_in_cgs = 5.; us->UnitTemperature_in_cgs = 5.;
/* construct python object */
PyObject *object = pytools_return(us, class_unit_system); PyObject *object = pytools_return(us, class_unit_system);
free(us); free(us);
if (object == NULL) if (object == NULL)
...@@ -32,6 +34,7 @@ PyObject* pyunit_system_init(PyObject *self, PyObject *args) ...@@ -32,6 +34,7 @@ PyObject* pyunit_system_init(PyObject *self, PyObject *args)
{ {
PyObject* parser; PyObject* parser;
/* parse arguement */
if (!PyArg_ParseTuple(args, "O", &parser)) if (!PyArg_ParseTuple(args, "O", &parser))
return NULL; return NULL;
...@@ -40,12 +43,15 @@ PyObject* pyunit_system_init(PyObject *self, PyObject *args) ...@@ -40,12 +43,15 @@ PyObject* pyunit_system_init(PyObject *self, PyObject *args)
if (params == NULL) if (params == NULL)
return NULL; return NULL;
/* initialize units */
struct unit_system us; struct unit_system us;
units_init(&us, params, "InternalUnitSystem"); units_init(&us, params, "InternalUnitSystem");
/* initialize phys_const */
struct phys_const pconst; struct phys_const pconst;
phys_const_init(&us, &pconst); phys_const_init(&us, &pconst);
/* create python object to return */
PyObject *pyus = pytools_return(&us, class_unit_system); PyObject *pyus = pytools_return(&us, class_unit_system);
if (pyus == NULL) if (pyus == NULL)
return NULL; return NULL;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment