-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCFD_basic5.py
More file actions
56 lines (45 loc) · 1.51 KB
/
CFD_basic5.py
File metadata and controls
56 lines (45 loc) · 1.51 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 17 17:12:50 2025
@author: ordin
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
###variable declarations
nx = 81
ny = 81
nt = 100
c = 1
dx = 2 / (nx - 1)
dy = 2 / (ny - 1)
sigma = .2
dt = sigma * dx
x =np.linspace(0, 2, nx)
y = np.linspace(0, 2, ny)
u = np.ones((ny, nx)) ##create a 1xn vector of 1's
un = np.ones((ny, nx)) ##
###Assign initial conditions
##set hat function I.C. : u(.5<=x<=1 && .5<=y<=1 ) is 2
u[int(.5 / dy):int(1 / dy + 1),int(.5 / dx):int(1 / dx + 1)] = 2
###Plot Initial Condition
##the figsize parameter can be used to produce different sized images
fig = plt.figure(figsize=(11, 7), dpi=100)
ax = fig.add_subplot(2, 1, 2, projection="3d")
X, Y = np.meshgrid(x, y)
plt.title("u(x,y,0)") #showing the title of the graph
surf = ax.plot_surface(X, Y, u[:], cmap=cm.viridis)
for n in range(nt + 1): ##loop across number of time steps
un=u.copy()
u[1:, 1:]=(un[1:, 1:] - (c * dt / dx * (un[1:, 1:] - un[1:, :-1])) -
(c * dt / dy * (un[1:, 1:] - un[:-1, 1:])))
u[0,:]=1
u[-1,:]=1
u[:,0]=1
u[:,-1]=1
fig=plt.figure(figsize=(11, 7), dpi=100)
ax=fig.add_subplot(2, 2, 2, projection="3d")
plt.title("u(x,y,t)") #showing the title of the graph
plt.xlabel('axes des X') #coordonates in X
plt.ylabel('axes des Y') #coordonates in Y
surf2 = ax.plot_surface(X, Y, u[:], cmap=cm.viridis)