diff --git a/src/cooling_wrapper.c b/src/cooling_wrapper.c index b81e13f16511d17b5af6ac697522ea9f86c7fd71..49d6592c4cb9d4f63a61633e21f8dbedbc7379e8 100644 --- a/src/cooling_wrapper.c +++ b/src/cooling_wrapper.c @@ -14,6 +14,7 @@ PyObject* pycooling_init(PyObject* self, PyObject* args) { PyObject *pyus; PyObject *pypconst; + /* parse arguments */ if (!PyArg_ParseTuple(args, "OOO", &pyparams, &pyus, &pypconst)) return NULL; @@ -32,8 +33,10 @@ PyObject* pycooling_init(PyObject* self, PyObject* args) { struct cooling_function_data cooling; + /* init cooling */ cooling_init_backend(params, us, pconst, &cooling); + /* construct python object */ PyObject *pycooling = pytools_return(&cooling, class_cooling_function_data); return pycooling; @@ -51,6 +54,7 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) { float dt = 1e-3; + /* parse argument */ if (!PyArg_ParseTuple(args, "OOOOO|f", &pypconst, @@ -61,6 +65,7 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) { &dt)) return NULL; + /* check numpy array */ if (pytools_check_array(energy, 1, NPY_FLOAT) != SUCCESS) { return NULL; @@ -76,7 +81,9 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) { 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); if (cooling == NULL) @@ -92,20 +99,19 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) { struct part p; -#ifdef COOLING_GRACKLE - grackle_data.grackle_data_file = cooling->GrackleCloudyTable; -#endif - + /* return object */ PyArrayObject *rate = PyArray_NewLikeArray(energy, NPY_ANYORDER, NULL, 1); + /* loop over all particles */ for(size_t i = 0; i < N; i++) { + /* set particle data */ p.rho = *(float*) PyArray_GETPTR1(rho, i); float u = *(float*) PyArray_GETPTR1(energy, i); p.entropy = gas_entropy_from_internal_energy(p.rho, u); + /* compute cooling rate */ float *tmp = PyArray_GETPTR1(rate, i); - #ifdef COOLING_GRACKLE *tmp = cooling_rate(pconst, us, cooling, &p, dt); #else diff --git a/src/parser_wrapper.c b/src/parser_wrapper.c index a6ecc0b14ab8186c4c2a90400535a41d66b78552..ef164f58389ef5d3d2ecbce0de2e4aec081b2736 100644 --- a/src/parser_wrapper.c +++ b/src/parser_wrapper.c @@ -7,13 +7,17 @@ PyObject* pyparser_read_file(PyObject *self, PyObject *args) { char *filename; + + /* parse argument */ if (!PyArg_ParseTuple(args, "s", &filename)) return NULL; struct swift_params params; + /* parse file */ parser_read_file(filename, ¶ms); + /* create return python object */ PyObject* obj = pytools_return(¶ms, class_swift_params); return obj; diff --git a/src/part_wrapper.c b/src/part_wrapper.c index 0fd32209abd6d4ac3cf4413de130232ff61e4b92..a4765eecae376cd000fb4c4850bee4b420cd8b0a 100644 --- a/src/part_wrapper.c +++ b/src/part_wrapper.c @@ -12,6 +12,7 @@ PyObject* pypart_test_struct(PyObject *self, PyObject *args) size_t N = sizeof(struct part); + /* initialize particle */ struct part *p = malloc(N); p->id = 0; for(size_t k = 0; k < DIM; k++) @@ -29,6 +30,7 @@ PyObject* pypart_test_struct(PyObject *self, PyObject *args) hydro_init_part(p, NULL); + /* create python object */ PyObject *object = pytools_return(p, class_part); free(p); diff --git a/src/pyswiftsim_tools.c b/src/pyswiftsim_tools.c index 07ba9337b6c23d78966f85ef576bf801dd2a1c7e..41814598be72886abeb35ca6a750fb59b3748a1e 100644 --- a/src/pyswiftsim_tools.c +++ b/src/pyswiftsim_tools.c @@ -51,7 +51,7 @@ PyObject* pytools_import(char* module_name, char* object_name) pyerror("Failed to get module '%s' dictionary", module_name); } - /* get right class */ + /* get right object */ PyObject *python_obj = PyDict_GetItemString(dict, object_name); Py_DECREF(dict); diff --git a/src/units_wrapper.c b/src/units_wrapper.c index 1858c2b1672bb2699b0ff49c5bc104283cd0634f..aeda170ac6f6e74e55ce10e0c11c637ae3621778 100644 --- a/src/units_wrapper.c +++ b/src/units_wrapper.c @@ -13,6 +13,7 @@ PyObject* pyunit_system_test_struct(PyObject *self, PyObject *args) size_t N = sizeof(struct unit_system); + /* initialize array */ struct unit_system *us = malloc(N); us->UnitMass_in_cgs = 1.; us->UnitLength_in_cgs = 2.; @@ -20,6 +21,7 @@ PyObject* pyunit_system_test_struct(PyObject *self, PyObject *args) us->UnitCurrent_in_cgs = 4.; us->UnitTemperature_in_cgs = 5.; + /* construct python object */ PyObject *object = pytools_return(us, class_unit_system); free(us); if (object == NULL) @@ -32,6 +34,7 @@ PyObject* pyunit_system_init(PyObject *self, PyObject *args) { PyObject* parser; + /* parse arguement */ if (!PyArg_ParseTuple(args, "O", &parser)) return NULL; @@ -40,12 +43,15 @@ PyObject* pyunit_system_init(PyObject *self, PyObject *args) if (params == NULL) return NULL; + /* initialize units */ struct unit_system us; units_init(&us, params, "InternalUnitSystem"); + /* initialize phys_const */ struct phys_const pconst; phys_const_init(&us, &pconst); + /* create python object to return */ PyObject *pyus = pytools_return(&us, class_unit_system); if (pyus == NULL) return NULL;