-
-
Save mdnestor/d2982586f646ea629c4c0e0939678542 to your computer and use it in GitHub Desktop.
Solve KPP equation using py-pde
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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