~fenics-core/ffc/main

« back to all changes in this revision

Viewing changes to ffc/ext/time_elements_interface.cpp

  • Committer: Marie E. Rognes
  • Date: 2013-04-04 19:21:30 UTC
  • mfrom: (1864.1.3 lobatto-radau)
  • Revision ID: meg@simula.no-20130404192130-c9ojl1q9xe3fhshf
Merge work of Benjamin Kehlet on including Radau and Lobatto
elements. (These are elements defined on the interval via Lobatto and
Radau quadrature points as degrees of freedom.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2012 Benjamin Kehlet
 
2
//
 
3
// This file is part of FFC.
 
4
//
 
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.
 
9
//
 
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.
 
14
//
 
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/>.
 
17
//
 
18
// First added:  2012-08-20
 
19
// Last changed: 2012-09-05
 
20
 
 
21
 
 
22
#include <Python.h>
 
23
#include <numpy/arrayobject.h>
 
24
 
 
25
#include "time_elements.h"
 
26
 
 
27
static PyObject *compute_lobatto_interface(PyObject *dummy, PyObject *args)
 
28
{
 
29
  int degree;
 
30
 
 
31
  /* parse argument tuple */
 
32
  if (!PyArg_ParseTuple(args, "i", &degree)) 
 
33
  {
 
34
    return NULL; /* PyArg_ParseTuple has raised an exception */
 
35
  } 
 
36
 
 
37
  npy_intp n = degree+1;
 
38
 
 
39
  PyArrayObject *py_array_points =  (PyArrayObject*) PyArray_SimpleNew(1, &n, NPY_DOUBLE);
 
40
 
 
41
  double *points = (double*)  PyArray_DATA(py_array_points);
 
42
 
 
43
  compute_lobatto_points(points, degree);
 
44
 
 
45
  // return values
 
46
  return (PyObject*) py_array_points;
 
47
}
 
48
 
 
49
static PyObject *compute_radau_interface(PyObject *dummy, PyObject *args)
 
50
{
 
51
  int degree;
 
52
 
 
53
  /* parse argument tuple */
 
54
  if (!PyArg_ParseTuple(args, "i", &degree)) 
 
55
  {
 
56
    return NULL; /* PyArg_ParseTuple has raised an exception */
 
57
  } 
 
58
 
 
59
  npy_intp n = degree+1;
 
60
 
 
61
  PyArrayObject *py_array_points =  (PyArrayObject*) PyArray_SimpleNew(1, &n, NPY_DOUBLE);
 
62
 
 
63
  double *points = (double*)  PyArray_DATA(py_array_points);
 
64
 
 
65
  compute_radau_points(points, degree);
 
66
 
 
67
  // return values
 
68
  return (PyObject*) py_array_points;
 
69
}
 
70
 
 
71
static PyObject *compute_legendre_coeffs_interface(PyObject *dummy, PyObject *args)
 
72
{
 
73
  PyArrayObject *points_array;
 
74
 
 
75
  /* parse argument tuple */
 
76
  if (!PyArg_ParseTuple(args, "O!", 
 
77
                        &PyArray_Type, &points_array))
 
78
  {
 
79
    return NULL; /* PyArg_ParseTuple has raised an exception */
 
80
  } 
 
81
 
 
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);
 
85
 
 
86
  double *coeffs = (double*)  PyArray_DATA(py_array_coeffs);
 
87
 
 
88
  compute_legendre_coeffs(coeffs, (double*) PyArray_DATA(points_array), num_points, num_points);
 
89
 
 
90
  // return values
 
91
  return (PyObject*) py_array_coeffs;
 
92
}
 
93
 
 
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";
 
100
 
 
101
 
 
102
static PyMethodDef time_elements_ext_methods[] = {
 
103
  {"compute_lobatto_points",
 
104
   compute_lobatto_interface, 
 
105
   METH_VARARGS,  
 
106
   compute_lobatto_doc},
 
107
  {"compute_radau_points",
 
108
   compute_radau_interface,
 
109
   METH_VARARGS,
 
110
   compute_radau_doc},
 
111
  {"compute_legendre_coeffs",
 
112
   compute_legendre_coeffs_interface,
 
113
   METH_VARARGS,
 
114
   compute_legendre_coeffs_doc},
 
115
 
 
116
  {NULL, NULL}    
 
117
};
 
118
 
 
119
PyMODINIT_FUNC
 
120
inittime_elements_ext(void)
 
121
{
 
122
   (void)Py_InitModule("time_elements_ext", time_elements_ext_methods);
 
123
   import_array();
 
124
}