1 | #include "Python.h" |
---|
2 | #include "numpy/arrayobject.h" |
---|
3 | #include "math.h" |
---|
4 | #include <stdio.h> |
---|
5 | |
---|
6 | const double pi = 3.14159265358979; |
---|
7 | |
---|
8 | // Shared code snippets |
---|
9 | // Generic routines |
---|
10 | #include "util_ext.h" |
---|
11 | // Solver |
---|
12 | #include "solver.h" |
---|
13 | // Python-solver interface |
---|
14 | #include "python_solver.h" |
---|
15 | // square pipe solver implementation |
---|
16 | #include "sqpipe_default.h" |
---|
17 | // sqpipe-python glue |
---|
18 | #include "sqpipe_python.h" |
---|
19 | |
---|
20 | //========================================================================= |
---|
21 | // Python Glue |
---|
22 | //========================================================================= |
---|
23 | |
---|
24 | PyObject *compute_fluxes_ext(PyObject *self, PyObject *args) { |
---|
25 | struct domain *D = (struct domain *) sqpipe_default_domain_new(); |
---|
26 | double timestep; |
---|
27 | PyObject *domain; |
---|
28 | |
---|
29 | // Convert Python arguments to C |
---|
30 | if (!PyArg_ParseTuple(args, "dO", ×tep, &domain)) { |
---|
31 | PyErr_SetString(PyExc_RuntimeError, "comp_flux_ext.c: compute_fluxes_ext could not parse input"); |
---|
32 | return NULL; |
---|
33 | } |
---|
34 | |
---|
35 | // Generic sqpipe domain |
---|
36 | D = (struct domain *) sqpipe_domain_python_get((struct sqpipe_domain *)D, domain, timestep); |
---|
37 | |
---|
38 | // We need the state |
---|
39 | //state = get_consecutive_array(domain, "state"); |
---|
40 | //((struct sqpipe_default_domain *)D)->state = (long *) state->data; |
---|
41 | |
---|
42 | // Compute the fluxes and return the new timestep |
---|
43 | timestep = domain_compute_fluxes(D); |
---|
44 | domain_destroy(D); |
---|
45 | |
---|
46 | return Py_BuildValue("d", timestep); |
---|
47 | } |
---|
48 | |
---|
49 | //------------------------------- |
---|
50 | // Method table for python module |
---|
51 | //------------------------------- |
---|
52 | |
---|
53 | static struct PyMethodDef MethodTable[] = { |
---|
54 | {"compute_fluxes_ext", compute_fluxes_ext, METH_VARARGS, "Print out"}, |
---|
55 | {NULL, NULL} |
---|
56 | }; |
---|
57 | |
---|
58 | // Module initialisation |
---|
59 | void initsqpipe_comp_flux(void){ |
---|
60 | Py_InitModule("sqpipe_comp_flux", MethodTable); |
---|
61 | import_array(); |
---|
62 | } |
---|