setting Boundary condition X^2-Y^2 for solving Laplace equation for NxN grid.
-
i am trying to write a code to solve Laplace equation using Successive
Over relaxation(SOR)on a NXN matrix boundary condition is X^2-y^2 i dont know how to set this boundary condition on the Mesh created by me here is the code
import numpy as np
from pylab import *
import sys
import copy
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
L =[[]for i in range(2)]
N=int(input("Enter a number N for N x N grid: "))
h=1/N
def clear_list1():
L[1].clear()
L[0].clear()
iterat=0
error=0.75
clear_list1()
xx=np.arange(0,N,h)
yy=np.arange(0,N,h)
x,y = np.meshgrid(xx,yy)
phi= copy.deepcopy((x**2-y**2))
phi[1:-1,1:-1]=0
phi_new = copy.deepcopy(phi)
resid=np.zeros((N,N))while True:
if iterat<21:for w in np.linspace(1,2,11): for i in range(1,N-1): for j in range(1,N-1): phi1=(phi\[i+1,j\]+phi\[i-1,j\]+phi\[i,j+1\]+phi\[i,j-1\])/4 phi\[i,j\]=w\*phi1+(1-w)\*phi1 Sumresidual=0 for i in range(1,N-1): for j in range(1,N-1): resid\[i,j\]= -4\*phi\[i,j\]+phi\[i+1,j\]+phi\[i-1,j\]+phi\[i,j+1\]+phi\[i,j-1\] Sumresidual=Sumresidual+(resid\[i,j\])\*\*2 else: break iterat=iterat+1 p=np.sqrt(Sumresidual) L\[0\].append(p) L\[1\].append(w)
ax = plt.axes()
ax.xaxis.set_major_locator(ticker.MaxNLocator(5))plt.plot(L[0],L[1])
plt.yscale('log')
plt.xlabel('w')
plt.ylabel('|| residual ||')
plt.title('effect of w on residual')
plt.show() -
i am trying to write a code to solve Laplace equation using Successive
Over relaxation(SOR)on a NXN matrix boundary condition is X^2-y^2 i dont know how to set this boundary condition on the Mesh created by me here is the code
import numpy as np
from pylab import *
import sys
import copy
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
L =[[]for i in range(2)]
N=int(input("Enter a number N for N x N grid: "))
h=1/N
def clear_list1():
L[1].clear()
L[0].clear()
iterat=0
error=0.75
clear_list1()
xx=np.arange(0,N,h)
yy=np.arange(0,N,h)
x,y = np.meshgrid(xx,yy)
phi= copy.deepcopy((x**2-y**2))
phi[1:-1,1:-1]=0
phi_new = copy.deepcopy(phi)
resid=np.zeros((N,N))while True:
if iterat<21:for w in np.linspace(1,2,11): for i in range(1,N-1): for j in range(1,N-1): phi1=(phi\[i+1,j\]+phi\[i-1,j\]+phi\[i,j+1\]+phi\[i,j-1\])/4 phi\[i,j\]=w\*phi1+(1-w)\*phi1 Sumresidual=0 for i in range(1,N-1): for j in range(1,N-1): resid\[i,j\]= -4\*phi\[i,j\]+phi\[i+1,j\]+phi\[i-1,j\]+phi\[i,j+1\]+phi\[i,j-1\] Sumresidual=Sumresidual+(resid\[i,j\])\*\*2 else: break iterat=iterat+1 p=np.sqrt(Sumresidual) L\[0\].append(p) L\[1\].append(w)
ax = plt.axes()
ax.xaxis.set_major_locator(ticker.MaxNLocator(5))plt.plot(L[0],L[1])
plt.yscale('log')
plt.xlabel('w')
plt.ylabel('|| residual ||')
plt.title('effect of w on residual')
plt.show()And what does your code have to do with the C / C++ / MFC Forum?