Skip to content

Instantly share code, notes, and snippets.

@mdnestor
Created January 26, 2023 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdnestor/d2982586f646ea629c4c0e0939678542 to your computer and use it in GitHub Desktop.
Save mdnestor/d2982586f646ea629c4c0e0939678542 to your computer and use it in GitHub Desktop.
Solve KPP equation using py-pde
import numpy as np
import pde
# define PDE
eq = pde.PDE({'u': 'laplace(u) + u*(1-u)'})
# define grid
grid = pde.UnitGrid([32, 32])
# define initial condition
c = np.array([16, 16])
f = lambda x: np.heaviside(1 - np.linalg.norm(x - c), 1)
# hack
data = np.empty(grid.shape)
for cells in np.ndindex(*grid.shape):
data[cells] = f(grid.cell_coords[cells])
state = pde.ScalarField(grid=grid, data=data)
result = eq.solve(state, t_range=10) # solve
result.plot()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment