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) {
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
......
......@@ -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, &params);
/* create return python object */
PyObject* obj = pytools_return(&params, class_swift_params);
return obj;
......
......@@ -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);
......
......@@ -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);
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment