1
// --- Return NumPy arrays for Mesh::cells() and Mesh::coordinates() ---
3
%define MAKE_ARRAY(dim_size, m, n, dataptr, TYPE)
4
npy_intp adims[dim_size];
10
PyArrayObject* array = reinterpret_cast<PyArrayObject*>(PyArray_SimpleNewFromData(dim_size, adims, TYPE, (char *)(dataptr)));
11
if ( array == NULL ) return NULL;
12
PyArray_INCREF(array);
16
%define ALL_COORDINATES(name)
18
PyObject* coordinates() {
19
// Get coordinates for all vertices in structure.
20
// returns a 3xnumVertices numpy array, x in array[0], y in array[1]
22
int m = self->numVertices();
23
int n = self->geometry().dim();
25
MAKE_ARRAY(2, m, n, self->coordinates(), NPY_DOUBLE)
27
return reinterpret_cast<PyObject*>(array);
32
%define ALL_CELLS(name)
35
// Get the node-id for all vertices.
36
int m = self->numCells();
38
if(self->topology().dim() == 1)
40
else if(self->topology().dim() == 2)
45
MAKE_ARRAY(2, m, n, self->cells(), NPY_INT)
47
return reinterpret_cast<PyObject*>(array);
52
%define ALL_VALUES(name, TYPE)
58
MAKE_ARRAY(1, m, n, self->values(), TYPE)
60
return reinterpret_cast<PyObject*>(array);
65
ALL_COORDINATES(dolfin::Mesh)
66
ALL_CELLS(dolfin::Mesh)
67
ALL_VALUES(dolfin::MeshFunction<real>, NPY_DOUBLE)
68
ALL_VALUES(dolfin::MeshFunction<int>, NPY_INT)
69
ALL_VALUES(dolfin::MeshFunction<bool>, NPY_BOOL)
70
ALL_VALUES(dolfin::MeshFunction<unsigned int>, NPY_UINT)
72
%ignore dolfin::Mesh::cells;
73
%ignore dolfin::Mesh::coordinates;
74
%ignore dolfin::MeshFunction::values;
75
%ignore dolfin::MeshEditor::open(Mesh&, CellType::Type, uint, uint);
77
//--- Mesh iterators ---
79
// Map increment operator and dereference operators for iterators
80
%rename(increment) dolfin::MeshEntityIterator::operator++;
81
%rename(dereference) dolfin::MeshEntityIterator::operator*;
83
// Rename the iterators to better match the Python syntax
84
%rename(vertices) dolfin::VertexIterator;
85
%rename(edges) dolfin::EdgeIterator;
86
%rename(faces) dolfin::FaceIterator;
87
%rename(facets) dolfin::FacetIterator;
88
%rename(cells) dolfin::CellIterator;
89
%rename(entities) dolfin::MeshEntityIterator;