-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCFD_basic4.py
More file actions
44 lines (33 loc) · 1017 Bytes
/
CFD_basic4.py
File metadata and controls
44 lines (33 loc) · 1017 Bytes
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
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 14 23:29:40 2025
@author: ordi
"""
#Burgers' equation
import numpy as np
import matplotlib.pyplot as plt
###variable declarations
nx = 101
nt = 100
dx = 2 * np.pi / (nx - 1)
nu = 0.07
dt = dx * nu
x = np.linspace(0, 2 * np.pi, nx)
un = np.empty(nx)
t = 0
u = #initialize u
for n in range(nt):
un = u.copy()
for i in range(1, nx-1):
u[i] = un[i] - un[i] * dt / dx *(un[i] - un[i-1]) + nu * dt / dx**2 *\
(un[i+1] - 2 * un[i] + un[i-1])
u[0] = un[0] - un[0] * dt / dx * (un[0] - un[-2]) + nu * dt / dx**2 *\
(un[1] - 2 * un[0] + un[-2])
u[-1] = u[0]
u_analytical = #compute analytical solution of Burgers' equation
plt.figure(figsize=(11, 7), dpi=100)
plt.plot(x,u, marker='o', lw=2, label='Computational')
plt.plot(x, u_analytical, label='Analytical')
plt.xlim([0, 2 * np.pi]) #limits to be adapted
plt.ylim([0, 10]) #limits to be adapted
plt.legend()