Initial commit

This commit is contained in:
nigulasizhaosihe 2021-03-20 13:14:36 +08:00
commit 2998bc2155
14 changed files with 180 additions and 0 deletions

2
.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto

3
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.9 (SolidificationSimulation)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (SolidificationSimulation)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/SolidificationSimulation.iml" filepath="$PROJECT_DIR$/.idea/SolidificationSimulation.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,87 @@
import math
import numpy as np
class Heatcal:
'''传热主程序'''
def __init__(self):
self.drawdata = []
self.time = []
def heat_simulation(self,s_h,rho,delta_x,lamda,Told,Tnew,rold,rnew,L):
endflag = 0 #停止标记
delta_t = 0.01 * s_h * rho * delta_x * delta_x / (6 * lamda) #时间步长
flag = 0 #时间标记
t = 0 #时间统计
fsold = np.array([[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]],dtype = float) #旧的固相率场
fsnew = np.array([[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]],dtype = float) #新的固相率场
ns = 0 #形核数
while(endflag == 0):
for i in range(1,3):
for j in range(1,3):
for k in range(1,3):
qx = lamda * delta_x * delta_t * (Told[i - 1][j][k] - Told[i][j][k])
qy = lamda * delta_x * delta_t * (Told[i][j - 1][k] - Told[i][j][k])
qz = lamda * delta_x * delta_t * (Told[i][j][k - 1] - Told[i][j][k])
qix = lamda * delta_x * delta_t * (Told[i][j][k] - Told[i + 1][j][k])
qiy = lamda * delta_x * delta_t * (Told[i][j][k] - Told[i][j + 1][k])
qiz = lamda * delta_x * delta_t * (Told[i][j][k] - Told[i][j][k + 1])
q = qx + qy + qz - qix - qiy - qiz
Tnew[i][j][k] = Told[i][j][k] + q/(s_h * rho * delta_x * delta_x * delta_x) #求解当前时刻的温度(不考虑潜热)
if(flag >= 52 and fsold[i][j][k] != 1):
'''计算生长速度'''
rnew[i][j][k] = (0.6462 * (1148 - Told[i][j][k]) * (1148 - Told[i][j][k]) / 1000000) * delta_t + rold[i][j][k]
'''计算固相率场'''
fsnew[i][j][k] = 1 - math.exp((-4/3) * math.pi * ns * rnew[i][j][k] * rnew[i][j][k] * rnew[i][j][k])
'''计算潜热修正后的温度'''
delta_fs = fsnew[i][j][k] - fsold[i][j][k]
Tplus = delta_fs * L / s_h
Tnew[i][j][k] = Tnew[i][j][k] + Tplus
'''新场旧场交换'''
fsold[i][j][k] = fsnew[i][j][k]
rold[i][j][k] = rnew[i][j][k]
'''时间计数'''
flag += 1
'''时间统计'''
t += delta_t
#'''将数据写入文件'''
#a = Tnew[1][1][1]
#with open('data.txt', 'a') as file_object:
# file_object.write(str(a) + '\n')
'''判断是否停止计算'''
for i in range(1, 3):
for j in range(1, 3):
for k in range(1, 3):
if Tnew[i][j][k] >= 750:
pass
else:
endflag = 1
'''判断是否形核'''
if (flag == 52):
'''计算形核数'''
ns = ((658200 + 3.814 * ((Tnew[1][1][1] - Told[1][1][1]) / delta_t) * ((Tnew[1][1][1] - Told[1][1][1]) / delta_t)) ** 1.5) * 0.87
'''将计算出来的新温度赋给旧温度'''
for i in range(1,3):
for j in range(1,3):
for k in range(1,3):
Told[i][j][k] = Tnew[i][j][k]
self.drawdata.append(Told[1][1][1])
self.time.append(t)

2
README.md Normal file
View File

@ -0,0 +1,2 @@
# SolidificationSimulation

27
Settings.py Normal file
View File

@ -0,0 +1,27 @@
import numpy as np
class Settings:
def __init__(self):
'''初始化数据设置'''
self.s_h = 916.9 #比热
self.rho = 7000 #密度
self.delta_x = 0.01 #空间步长
self.lamda = 20.3 #导热系数
self.L = 250000 #潜热
self.T1 = np.array([[[300,300,300,300],[300,300,300,300],[300,300,300,300],[300,300,300,300]],
[[300,300,300,300],[300,1370,1370,300],[300,1370,1370,300],[300,300,300,300]],
[[300,300,300,300],[300,1370,1370,300],[300,1370,1370,300],[300,300,300,300]],
[[300,300,300,300],[300,300,300,300],[300,300,300,300],[300,300,300,300]]],dtype = float)
self.T2 = np.array([[[300,300,300,300],[300,300,300,300],[300,300,300,300],[300,300,300,300]],
[[300,300,300,300],[300,1370,1370,300],[300,1370,1370,300],[300,300,300,300]],
[[300,300,300,300],[300,1370,1370,300],[300,1370,1370,300],[300,300,300,300]],
[[300,300,300,300],[300,300,300,300],[300,300,300,300],[300,300,300,300]]],dtype = float)
self.rold = np.array([[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]],
[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]],
[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]],
[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]],dtype = float)
self.rnew = np.array([[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]],dtype = float)

Binary file not shown.

Binary file not shown.

Binary file not shown.

9
drawcoolingcurve.py Normal file
View File

@ -0,0 +1,9 @@
import matplotlib.pyplot as plt
import HeatTransferCalculation as HC
class Drawcoolingcurve:
def draw(self,xarr,yarr):
fig, ax = plt.subplots()
ax.plot(xarr,yarr)
plt.show()

24
main.py Normal file
View File

@ -0,0 +1,24 @@
from Settings import *
from HeatTransferCalculation import *
from drawcoolingcurve import *
class Solidificationsimulation:
'''计算主程序'''
def __init__(self):
self.hs = Heatcal()
self.settings = Settings()
self.draw = Drawcoolingcurve()
def start(self):
self.hs.heat_simulation(self.settings.s_h,self.settings.rho,self.settings.delta_x,self.settings.lamda,self.settings.T1,self.settings.T2,self.settings.rold,self.settings.rnew,self.settings.L)
self.draw.draw(self.hs.time,self.hs.drawdata)
if __name__ == '__main__':
ss = Solidificationsimulation()
ss.start()