pyodide/benchmark/benchmarks/diffusion.py

24 lines
680 B
Python
Raw Normal View History

2018-10-03 18:59:01 +00:00
# setup: import numpy as np;lx,ly=(2**6,2**6);u=np.zeros([lx,ly],dtype=np.double);u[lx//2,ly//2]=1000.0;tempU=np.zeros([lx,ly],dtype=np.double) # noqa
# run: diffusion(u,tempU,100)
2018-04-05 22:07:33 +00:00
2018-10-03 18:59:01 +00:00
# pythran export diffusion(float [][], float [][], int)
2018-04-05 22:07:33 +00:00
def diffusion(u, tempU, iterNum):
"""
Apply Numpy matrix for the Forward-Euler Approximation
"""
mu = 0.1
2018-04-05 22:07:33 +00:00
for n in range(iterNum):
tempU[1:-1, 1:-1] = u[1:-1, 1:-1] + mu * (
u[2:, 1:-1]
- 2 * u[1:-1, 1:-1]
+ u[0:-2, 1:-1]
+ u[1:-1, 2:]
- 2 * u[1:-1, 1:-1]
+ u[1:-1, 0:-2]
)
2018-04-05 22:07:33 +00:00
u[:, :] = tempU[:, :]
tempU[:, :] = 0.0