-
Loic Hausammann authoredLoic Hausammann authored
wrapper.c 3.42 KiB
/*******************************************************************************
* This file is part of PYSWIFTSIM.
* Copyright (c) 2018 loic hausammann (loic.hausammann@epfl.ch)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
#include "units_wrapper.h"
#include "part_wrapper.h"
#include "parser_wrapper.h"
#include "cooling_wrapper.h"
#include "cosmology_wrapper.h"
#include "chemistry_wrapper.h"
#include "pyswiftsim_tools.h"
#include "swift.h"
#include <Python.h>
#include <math.h>
#include <numpy/arrayobject.h>
/* definition of the method table */
static PyMethodDef wrapper_methods[] = {
{"parserReadFile", pyparser_read_file, METH_VARARGS,
"Read a swift params file."},
{"unitSystemInit", pyunit_system_init, METH_VARARGS,
"Construct a unit_system object and return it."},
{"coolingInit", pycooling_init, METH_VARARGS,
"Initialize cooling."},
{"chemistryInit", pychemistry_init, METH_VARARGS,
"Initialize chemistry."},
{"cosmologyInit", pycosmology_init, METH_VARARGS,
"Initialize cosmology."},
{"coolingRate", pycooling_rate, METH_VARARGS,
"Compute the cooling rate.\n\n"
"Parameters\n"
"----------\n\n"
"pyconst: swift physical constant\n"
"pyus: swift unit system\n"
"cooling: swift cooling structure\n"
"rho: np.array\n"
"\t Mass density in pyus units\n"
"energy: np.array\n"
"\t Internal energy in pyus units\n"
"dt: float, optional\n"
"\t Time step in pyus units\n"
"fractions: np.array, optional\n"
"\t Fraction of each cooling element (including metals)\n"
"Returns\n"
"-------\n\n"
"rate: np.array\n"
"\t Cooling rate\n"
},
{"doCooling", pycooling_do_cooling, METH_VARARGS,
"Compute the cooling.\n\n"
"Parameters\n"
"----------\n\n"
"pyconst: swift physical constant\n"
"pyus: swift unit system\n"
"cooling: swift cooling structure\n"
"rho: np.array\n"
"\t Mass density in pyus units\n"
"energy: np.array\n"
"\t Internal energy in pyus units\n"
"dt: float\n"
"\t Time step in pyus units\n"
"fractions: np.array, optional\n"
"\t Fraction of each cooling element (including metals)\n"
"Returns\n"
"-------\n\n"
"new_energy: np.array\n"
"\t Energy of the particle after dt\n"
},
{NULL, NULL, 0, NULL} /* Sentinel */
};
static struct PyModuleDef wrapper_cmodule = {
PyModuleDef_HEAD_INIT,
"wrapper",
"Wrapper around the SPH cosmological simulation code SWIFT",
-1,
wrapper_methods,
NULL, /* m_slots */
NULL, /* m_traverse */
NULL, /* m_clear */
NULL, /* m_free */
};
PyMODINIT_FUNC PyInit_libpyswiftsim(void)
{
PyObject *m;
/* set time for swift */
clocks_set_cpufreq(0);
import_array();
Py_Initialize();
m = PyModule_Create(&wrapper_cmodule);
return m;
}