3.1.1-Copy1

2D Laplace equation with Drichlet boundary conditions

In [10]:
from IPython.display import Image

Image("snapshot1.png",width=250)
Out[10]:
In [14]:
import numpy as np
from matplotlib import pyplot as plt

# Taking 2D domain
N=50  #discritizing for N points
x=np.linspace(0,1,N)
y=np.linspace(0,1,N)
X,Y=np.meshgrid(x,y)  #mesh
u=np.zeros((N,N),dtype=float)  #initializing property 

for i in range(0,N-1):
    u[i,0]=i**2
    u[0,i]=-i**2
    u[N-1,i]=1-i**2
    u[i,N-1]=i**2-1


delta = 1


colorinterpolation = 500

colourMap = plt.cm.jet

maxIter = 500
# Considering the iteration is going to be converged in 500 steps
print("Solving ...")
for iteration in range(0, maxIter):
    for i in range(1, N-1, delta):
        for j in range(1, N-1, delta):
            u[i, j] = 0.25 * (u[i+1][j] + u[i-1][j] + u[i][j+1] + u[i][j-1])

print("Solver finished")

# Configure the contour
plt.title("Property contours")
plt.contourf(X, Y, T, colorinterpolation, cmap=colourMap)
plt.colorbar()
plt.show()
Solving ...
Solver finished

Instead of just using "colourMap = plt.cm.jet"

can try from plethora of contour bars from here here