<jupyter_start><jupyter_text>恒温无限大板中的热扩散 问题 1假设板的初始温度$T=0$,当时间 $t>= 0$ 时，板的左侧面受到高温$T=1.0$，板长为100。设$\alpha =0.25$，计算$t=200$时，板中的温度分布，并比较LBM和FDM两种方法的结果。  A.1.1 The LBM Code (D1Q2)<jupyter_code># LBM Code for 1-D, diffusion problem, D1Q2

import numpy as np
import matplotlib.pyplot as pl
% matplotlib inline

m = 100    # m is the number of lattice nodes

f1 = np.zeros(m+1,dtype=float)
f2 = np.zeros(m+1,dtype=float)
rho = np.zeros(m+1,dtype=float)
feq = np.zeros(m+1,dtype=float)
x = np.zeros(m+1,dtype=float)

dt = 1.0
dx = 1.0
x[0] = 0.0

for i in range(1,m+1):
    x[i] = x[i-1] + dx

csq = dx*dx/(dt*dt)
alpha = 0.25
omega = 1.0/(alpha/(dt*csq)+0.5)
mstep = 200    # The total number of time steps
twall = 1.0    # Left hand wall temperature

# Initial condition
for i in range(0,m+1):
    rho[i] = 0.0    # Initial value of the domain temperature
    f1[i] = 0.5 * rho[i]
    f2[i] = 0.5 * rho[i]

# main loop
for kk in range(1,mstep+1):     # time loop
    # collision process:
    for i in range(0,m+1):        # nodes loop
        rho[i] = f1[i] + f2[i]
        feq[i] = 0.5 * rho[i]
        
        # since k1 = k2 = 0.5, then feq1 = feq2 = feq
        f1[i] = (1.0 - omega)*f1[i] + omega*feq[i]
        f2[i] = (1.0 - omega)*f2[i] + omega*feq[i]
    
    # streaming process:
    for i in range(1,m):        # nodes loop
        f1[m-i] = f1[m-i-1]    # f1 streaming
        f2[i-1] = f2[i]    # f2 streaming
        
    # Boundary condition
    f1[0] = twall - f2[0]    # constant temperature boundary condition, x = 0
    f1[m] = f1[m-1]    # adiabatic(绝热的)  boundary condition, x = L
    f2[m] = f2[m-1]    # adiabatic boundary condition, x = L
    
# end of the main loop

#for i in range(0,m+1):
#    print(x[i]," ",rho[i])
pl.plot(x,rho)<jupyter_output><empty_output><jupyter_text>A.1.2 The FDM Code (1-D)显示格式的差分方程为Eqs. 3.8，如下所示$$T_i^{n+1} = T_i^n + \frac{\alpha \Delta t}{\Delta x^2}(T_{i+1}^n - 2 T_i^n + T_{i-1}^n)$$<jupyter_code># Finite Difference Code for 1-D diffusion problems

import numpy as np
import matplotlib.pyplot as pl
% matplotlib inline

m = 100    # m is the number of lattice nodes
fo = np.zeros(m+1,dtype=float)
f = np.zeros(m+1,dtype=float)

dx = 1.0
dt = 0.5
alpha = 0.25
mstep = 400
    
fo[0] = 1.0    # initial condition for old value of f at x=0
f[0] = 1.0    # initial condition for updated value of f at x=0
fo[m] = fo[m-1]    # initial condition for old value of f at x=L
f[m] = f[m-1]    # initial condition for uodated value of f at x=L

for kk in range(1,mstep+1):
    # main loop
    for i in range(1,m):
        f[i] = fo[i] + dt*alpha*(fo[i+1]-2.0*fo[i]+fo[i-1])/(dx*dx)    # Eqs. 3.8
    
    for i in range(1,m):
        fo[i] = f[i]    # updating
    
    fo[m] = f[m-1]    # updating the boundary condition at x=L
    # end of the main loop
    
x_fdm  = np.zeros(m+1,dtype=float)

for i in range(0,m+1):
    # print(x_fdm[i]," ",f[i])
    if i < m:
        x_fdm[i+1] = x_fdm[i] + dx
        
pl.plot(x_fdm,f)<jupyter_output><empty_output><jupyter_text>结果对比<jupyter_code>pl.plot(x,rho,'bo-',label='LBM')
pl.plot(x_fdm,f,'rD-',label='FDM')
pl.xlabel('x')  
pl.ylabel('T') 
pl.legend()
pl.xlim(0,30)
pl.ylim(0,1)
pl.show<jupyter_output><empty_output><jupyter_text>问题 2假设板的初始温度$T=0$,当时间 $t>= 0$ 时，板的左侧边界有$100 W/m^2$的恒热流密度存在，板长为100，板的热导系数为$20W/mK$。设$\alpha =0.25$，计算$t=200$时，板中的温度分布。  The LBM Code (D1Q2)<jupyter_code># LBM Code for 1-D, diffusion problem, D1Q2

import numpy as np
import matplotlib.pyplot as pl
% matplotlib inline

m = 100    # m is the number of lattice nodes

f1 = np.zeros(m+1,dtype=float)
f2 = np.zeros(m+1,dtype=float)
rho = np.zeros(m+1,dtype=float)
feq = np.zeros(m+1,dtype=float)
x = np.zeros(m+1,dtype=float)

dt = 1.0
dx = 1.0
x[0] = 0.0

for i in range(1,m+1):
    x[i] = x[i-1] + dx

csq = dx*dx/(dt*dt)
alpha = 0.25
omega = 1.0/(alpha/(dt*csq)+0.5)
mstep = 200    # The total number of time steps
twall = 1.0    # Left hand wall temperature
flux = 200     # Heat flux W/m^2
tk = 20     # Thermal conductivity W/mKW/mK

# Initial condition
for i in range(0,m+1):
    rho[i] = 0.0    # Initial value of the domain temperature
    f1[i] = 0.5 * rho[i]
    f2[i] = 0.5 * rho[i]

# main loop
for kk in range(1,mstep+1):     # time loop
    # collision process:
    for i in range(0,m+1):        # nodes loop
        rho[i] = f1[i] + f2[i]
        feq[i] = 0.5 * rho[i]
        
        # since k1 = k2 = 0.5, then feq1 = feq2 = feq
        f1[i] = (1.0 - omega)*f1[i] + omega*feq[i]
        f2[i] = (1.0 - omega)*f2[i] + omega*feq[i]
    
    # streaming process:
    for i in range(1,m):        # nodes loop
        f1[m-i] = f1[m-i-1]    # f1 streaming
        f2[i-1] = f2[i]    # f2 streaming
        
    # Boundary condition
    f1[0] = f1[1] + f2[1] - f2[0] + flux*dx/tk    # constant heat flux boundary condition, x = 0
    f1[m] = f1[m-1]    # adiabatic(绝热的)  boundary condition, x = L
    f2[m] = f2[m-1]    # adiabatic boundary condition, x = L
    
# end of the main loop

#for i in range(0,m+1):
#    print(x[i]," ",rho[i])
pl.plot(x,rho)
pl.xlabel('x')  
pl.ylabel('T') 
pl.xlim(0,30)
pl.show<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16956436804063293, 'fraction_numerical': 0.05567493651103731, 'mean_word_length': 2.7730287398673545, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '665500', 'license': 'MIT', 'n_tokens_mistral': 2518, 'n_tokens_neox': 2461, 'n_words': 551, 'path': 'Chapter3-1.ipynb', 'repo_name': 'huiselilun/LBM_Applications', 'size': '5119'}