No project description provided
Project description
numgrids
Working with numerical grids made easy.
Main Features
- Quickly define numerical grids for any rectangular or curvilinear coordinate system
- Differentiation and integration
- Interpolation
- Easy manipulation of meshed functions
- Using high precision spectral methods (FFT + Chebyshev) wherever possible
- Fully compatible with numpy
Installation
pip install numgrids
Quick Start
As a quick example, here is how you define a grid on the unit disk using polar coordinates. Along the azimuthal (angular) direction, choose an equidistant spacing with periodic boundary conditions:
from numgrids import *
from numpy import pi
axis_phi = Axis.of_type(AxisType.EQUIDISTANT, 50, 0, 2*pi, periodic=True)
Along the radial axis, let's choose a non-equidistant spacing:
axis_radial = Axis.of_type(AxisType.CHEBYSHEV, 20, 0, 1)
Now combine the axes to a grid:
grid = Grid(axis_radial, axis_phi)
Sample a meshed function on this grid:
from numpy import exp, sin
R, Phi = grid.meshed_coords
f = R**2 * sin(Phi)**2
Define partial derivatives $\partial/\partial r$ and $\partial/\partial \varphi$ and apply them:
# second argument means derivative order, third argument means axis index:
d_dr = Diff(grid, 1, 0)
d_dphi = Diff(grid, 1, 1)
df_dr = d_dr(f)
df_dphi = d_dphi(f)
Obtain the matrix representation of the differential operators:
d_dr.as_matrix()
Out: <1000x1000 sparse matrix of type '<class 'numpy.float64'>'
with 20000 stored elements in COOrdinate format>
Define integration operator
$$ \int \dots dr d\varphi $$
I = Integral(grid)
Calculate the area integral
$$ \int f(r, \varphi) r dr d\varphi $$
(taking into account the appropriate integration measure $r$ for polar coordinates):
I(f * R)
Setting boundary values to zero
f[grid.boundary] = 0 # grid.boundary is boolean mask selecting boundary grid points
or to something more complicated:
f[grid.boundary] = exp(-R[grid.boundary])
Usage / Example Notebooks
To get an idea how numgrids can be used, have a look at the following example notebooks:
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.