Newer
Older
# About
This repository contains the `NekPy` Python wrappers for the Nektar++
spectral/_hp_ element framework. **As a disclaimer, thhese wrappings are
_experimental_ and _incomplete_.** You should not rely on their current
structure and API remaining unchanged.
Currently, representative classes from the `LibUtilities`, `StdRegions`,
`SpatialDomains` and `LocalRegions` libraries have been wrapped in order to show
the proof-of-concept.
# Features and functionality
`NekPy` uses the `Boost.Python` library to provide a set of high-quality,
hand-written Python bindings for selected functions and classes in Nektar++. A
```python
from NekPy.LibUtilities import PointsKey, PointsType, BasisKey, BasisType
ptsKey = PointsKey(numPts, PointsType.GaussLobattoLegendre)
basisKey = BasisKey(BasisType.Modified_A, numModes, ptsKey)
quadExp = StdQuadExp(basisKey, basisKey)
fx = np.sin(x) * np.cos(y)
proj = quadExp.FwdTrans(fx)
```
`NekPy` uses the `Boost.NumPy` library, contained in Boost 1.63+, to
automatically convert C++ `Array<OneD, >` objects to and from the commonly-used
`numpy.ndarray` object, which makes the integration more seamless between Python
`Boost.Python` is a pretty comprehensive package and an extended discussion is
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
really beyond the scope of this project. See `doc/wrapping-guide.md` for some
basic concepts and frequently-encountered issues.
# Compiling
NekPy has the following list of requirements:
- Boost with Python support
- Nektar++ `master` branch compiled from source (i.e. not from packages)
- Python 2.7+ (note that examples rely on Python 2.7)
- NumPy
Most of these can be installed using package managers on various operating
systems, as we describe below. We also have a requirement on the `Boost.NumPy`
package, which is available in boost 1.63 or later. If this isn't found on your
system, it will be automatically downloaded and compiled.
## Compiling and installing Nektar++
Nektar++ should be compiled as per the user guide instructions and installed
into a directory which we will refer to as `$NEKDIR`. By default this is the
`dist` directory inside the Nektar++ build directory.
Note that Nektar++ must, at a minimum, be compiled with `NEKTAR_BUILD_LIBRARY`,
`NEKTAR_BUILD_UTILITIES` and `NEKTAR_BUILD_SOLVERS`. Note that all solvers may
be disabled as long as the `NEKTAR_BUILD_SOLVERS` option is set.
## macOS
### Homebrew
Users of Homebrew should make sure their installation is up-to-date with `brew
upgrade`. Then run
```
brew install python boost-python
```
To install the NumPy package, use the `pip` package manager:
```
pip install numpy
```
### MacPorts
Users of MacPorts should sure their installation is up-to-date with `sudo port
selfupdate && sudo port upgrade outdated`. Then run
```
sudo port install python27 py27-numpy
sudo port select --set python python27
```
### Compiling the wrappers
Clone and compile the wrappers as follows:
```
git clone https://gitlab.nektar.info/nektar/nektar-python.git
cd nektar-python && mkdir builds && cd builds
cmake -DNektar++_DIR=$NEKDIR/lib/nektar++-4.5.0/cmake ..
make install
```
This will automatically download and install `Boost.NumPy` if required.
### Linux: Ubuntu/Debian
Users of Debian and Ubuntu Linux systems should sure their installation is
up-to-date with `sudo apt-get update && sudo apt-get upgrade`
```
sudo apt-get install libboost-python-dev python-numpy
```
# Using the bindings
By default, the bindings will install into the `dist` directory, along with a
number of examples that are stored in the `example` directory. To test your
installation, you can for example run one of these (e.g. `python Basis.py`) or
launch an interactive session:
```
$ cd builds
$ python
Python 2.7.13 (default, Apr 4 2017, 08:47:57)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from NekPy.LibUtilities import PointsKey, PointsType
>>> PointsKey(10, PointsType.GaussLobattoLegendre)
<NekPy.LibUtilities._LibUtilities.PointsKey object at 0x11005c310>
```
## Examples
A number of examples of the wrappers can be found in the `dist` directory, along
with a sample mesh `newsquare_2x2.xml`:
- `SessionReader.py` is the simplest example and shows how to construct a
session reader object. Run it as `python SessionReader.py mesh.xml`.
- `Basis.py` shows functionality of basic `LibUtilities` points and basis
classes. Run this as `python Basis.py`.
- `StdProject.py` shows how to use some of the `StdRegions` wrappers and
duplicates the functionality of `Basis.py` using the `StdExpansion` class. Run
this as `python StdProject.py`.
- `MeshGraph.py` loads a mesh and prints out some basic properties of its
quadrilateral elements. Run it as `python MeshGraph.py newsquare_2x2.xml`.
If you want to modify the source files, it's advisable to edit them in the
`examples` directory and re-run `make install`, otherwise local changes will be
overwritten by the next `make install`.