-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExactSolution.py
41 lines (31 loc) · 1.13 KB
/
ExactSolution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'''
Exact Solution for 1D reaction-diffusion equation:
u_t = k * u_xx
with Neumann boundary conditions
at x=0: u_x(0,t) = 0 = sin(2*np.pi)
at x=L: u_x(L,t) = 0 = sin(2*np.pi)
with L = 1 and initial conditions:
u(x,0) = (1.0/2.0)+ np.cos(2.0*np.pi*x) - (1.0/2.0)*np.cos(3*np.pi*x)
'''
def ExactSolution(M, T = 0.5, L = 1):
N = (M**2) #GRID POINTS on time interval
xspan = np.linspace(0, L, M)
tspan = np.linspace(0, T, N)
Uexact = np.zeros((M, N))
for i in range(0, M):
for j in range(0, N):
Uexact[i][j] = Solution(xspan[i], tspan[j])
return (Uexact, tspan, xspan)
def plotexact(Uexact,tspan, xspan):
#meshgrid : Return coordinate matrices from coordinate vectors
X, T = np.meshgrid(tspan, xspan)
fig = plt.figure(figsize = (7.5,5.5))
ax = fig.gca(projection='3d')
surf = ax.plot_surface(X, T, Uexact, linewidth=0, cmap=cm.jet, antialiased=True)
ax.set_xlabel('Time')
ax.set_ylabel('Space')
ax.set_zlabel('U')
plt.tight_layout()
ax.view_init(30,230)
fig.savefig(path.join("plot_exact{0}.png".format(count)))
plt.draw()