1
// Copyright (C) 2012 Benjamin Kehlet
3
// This file is part of FFC.
5
// FFC is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU Lesser General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
10
// FFC is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU Lesser General Public License for more details.
15
// You should have received a copy of the GNU Lesser General Public License
16
// along with FFC. If not, see <http://www.gnu.org/licenses/>.
18
// First added: 2012-08-20
19
// Last changed: 2012-09-05
23
#include <numpy/arrayobject.h>
25
#include "time_elements.h"
27
static PyObject *compute_lobatto_interface(PyObject *dummy, PyObject *args)
31
/* parse argument tuple */
32
if (!PyArg_ParseTuple(args, "i", °ree))
34
return NULL; /* PyArg_ParseTuple has raised an exception */
37
npy_intp n = degree+1;
39
PyArrayObject *py_array_points = (PyArrayObject*) PyArray_SimpleNew(1, &n, NPY_DOUBLE);
41
double *points = (double*) PyArray_DATA(py_array_points);
43
compute_lobatto_points(points, degree);
46
return (PyObject*) py_array_points;
49
static PyObject *compute_radau_interface(PyObject *dummy, PyObject *args)
53
/* parse argument tuple */
54
if (!PyArg_ParseTuple(args, "i", °ree))
56
return NULL; /* PyArg_ParseTuple has raised an exception */
59
npy_intp n = degree+1;
61
PyArrayObject *py_array_points = (PyArrayObject*) PyArray_SimpleNew(1, &n, NPY_DOUBLE);
63
double *points = (double*) PyArray_DATA(py_array_points);
65
compute_radau_points(points, degree);
68
return (PyObject*) py_array_points;
71
static PyObject *compute_legendre_coeffs_interface(PyObject *dummy, PyObject *args)
73
PyArrayObject *points_array;
75
/* parse argument tuple */
76
if (!PyArg_ParseTuple(args, "O!",
77
&PyArray_Type, &points_array))
79
return NULL; /* PyArg_ParseTuple has raised an exception */
82
const npy_intp num_points = PyArray_DIMS(points_array)[0];
83
npy_intp dims[2] = { num_points, num_points };
84
PyArrayObject *py_array_coeffs = (PyArrayObject*) PyArray_SimpleNew(2, dims, NPY_DOUBLE);
86
double *coeffs = (double*) PyArray_DATA(py_array_coeffs);
88
compute_legendre_coeffs(coeffs, (double*) PyArray_DATA(points_array), num_points, num_points);
91
return (PyObject*) py_array_coeffs;
94
static char compute_lobatto_doc[] = \
95
"Doc string for compute_lobatto_points";
96
static char compute_radau_doc[] = \
97
"Doc string for compute_radau_points";
98
static char compute_legendre_coeffs_doc[] = \
99
"Doc string for compute_legendre_coeffs";
102
static PyMethodDef time_elements_ext_methods[] = {
103
{"compute_lobatto_points",
104
compute_lobatto_interface,
106
compute_lobatto_doc},
107
{"compute_radau_points",
108
compute_radau_interface,
111
{"compute_legendre_coeffs",
112
compute_legendre_coeffs_interface,
114
compute_legendre_coeffs_doc},
120
inittime_elements_ext(void)
122
(void)Py_InitModule("time_elements_ext", time_elements_ext_methods);