目录
编译环境的搭建
Python编译环境的搭建需要花费一定的精力,包括解释器的下载与配置,集成开发环境的选择,系统变量和用户变量的配置,除此之外还需要不断完善本地第三方库的配置,流行的做法是使用anaconda对众多第三方库进行管理。
安装python
这里的安装一般是指从官网上获取python的解释器(推荐使用最新版本),然后安装,配置用户变量。详细步骤可参考:
https://blog.csdn.net/nmjuzi/article/details/79075736?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522162417350016780262511257%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=162417350016780262511257&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2alltop_positive~default-1-79075736.pc_search_result_control_group&utm_term=%E5%AE%89%E8%A3%85python&spm=1018.2226.3001.4187
系统变量的配置
Python与Java相似,在使用前需要配置系统变量,具体操作步骤因操作系统不同(win、mac),架构不同(32、64)以及处理器型号不同(AMD、intel)而不同。上一步安装完成后即可配置系统变量。可参考以下文章:
https://blog.csdn.net/pdcfighting/article/details/80983184?ops_request_misc=%7B%22request%5Fid%22%3A%22162417337616780271541533%22%2C%22scm%22%3A%2220140713.130102334…%22%7D
如果如此错做过后仍有报错,可以复制错误内容到CSDN一般都可以找到解答。
anaconda的安装与使用
Anaconda指的是一个开源的Python发行版本,其包含了Python、conda等180多个科学包及其依赖项。 因为包含了大量的科学包,Anaconda 的下载文件比较大。Anaconda对于python初学者而言及其友好,相比单独安装python主程序,选择Anaconda可以帮助省去很多麻烦,Anaconda里添加了许多常用的功能包,如果单独安装python,这些功能包则需要一条一条自行安装,在Anaconda中则不需要考虑这些,同时Anaconda还附带捆绑了两个非常好用的交互式代码编辑器(Spyder、Jupyter notebook)。
Anaconda本身也需要配置系统变量,而且与pycharm的联动需要单独设置。步骤参考https://blog.csdn.net/weixin_43715458/article/details/100096496?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522162417426616780265472493%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=162417426616780265472493&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2alltop_positive~default-2-100096496.pc_search_result_control_group&utm_term=anaconda%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B&spm=1018.2226.3001.4187
pycharm的安装与使用
C语言有VC、dev c++、LLVM等多种集成开发环境,python也是如此,事实上python解释器会自带IDEL但是并不好用,一般需要使用第三方软件。这里选用功能强大的pycharm,方法联想、快捷键等功能都可以很好地提高编程的效率。对个人开发者而言pycharm的社区版功能已经足够强大,不必购买专业版。安装步骤参考:
https://blog.csdn.net/chenggong2dm/article/details/9365437?ops_request_misc=&request_id=&biz_id=102&utm_term=pycharm%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduweb~default-8-.nonecase&spm=1018.2226.3001.4187
pycharm与anaconda的联动
这个比较简单,完成后也可以使用anaconda自带的python解释器。
https://blog.csdn.net/baoxiao7872/article/details/80328224?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522162417454216780269847297%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=162417454216780269847297&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allbaidu_landing_v2~default-6-80328224.pc_search_result_control_group&utm_term=pycharm+anaconda&spm=1018.2226.3001.4187
HITRAN数据库的使用
首先对真实气体辐射数据进行处理以得到六种气体分子吸收光谱、透射光谱、以及平均吸收系数。
HAPI第三方库的调用
参考文章列表:
1.[https://blog.csdn.net/qq_38307826/article/details/107556056]
2.[https://blog.csdn.net/Gou_Hailong/article/details/105586880]
3. https://download.csdn.net/download/qq_42183549/16616839
参考文章包含了HAPI库中各种函数的使用说明。总的来说就是从官网上下载HAPI第三方库,然后从pycharm中import,再然后就是下载数据,最后调用第三方库对数据进行必要的处理。当然HITRAN官方网站的https://hitran.org/hapi/也提供了HAPI库的使用手册。如有其他问题也可以在GitHub上与其他开发者交流https://github.com/hitranonline/hapi
当然,这个处理过程可能还会涉及到其他用于科学计算的第三方库,如numpy、sympy、matpoltlib等,可以提前学习这些泛用性第三方库的使用。
HAPI中函数的用法
参考文章列表:
1.[https://blog.csdn.net/weixin_39924198/article/details/112333256]
2.[https://blog.csdn.net/JarvisChen_/article/details/50441366]
以上两篇文章涉及了HAPI所包含的主要函数的使用方法,请重点看函数的输入输出部分。具体描述可以借用gethelp函数,也可以到官网上下载HAPI 的使用手册,使用手册对各个函数功能的表述最为准确。
当然文章1给出的例子存在某些问题,比如getStickXY()函数的输出结果并不是线强,建议使用getColumn(‘tablename’,‘sw’)函数获取准确的线强。
print(nu)
print(type(nu))
print(len(nu))
print(coef)
print(len(coef))
print(type(coef))
print(y)
print(len(y))
print(type(y))
print(x)
print(type(x))
print(len(x))
[ 11.833113 11.843113 11.853113 … 9352.933113 9352.943113
9352.953113]
<class ‘numpy.ndarray’>
934113
[1.84784746e-16 1.85421916e-16 1.85984338e-16 … 1.27157618e-13
1.26674331e-13 1.26184828e-13]
934113
<class ‘numpy.ndarray’>
[0.000e+00 2.595e-39 0.000e+00 … 0.000e+00 1.533e-39 0.000e+00]
3318
<class ‘numpy.ndarray’>
[ 11.833113 11.833113 11.833113 … 9352.959559 9352.959559
9352.959559]
<class ‘numpy.ndarray’>
3318
N2气体的谱线有1106根,但是列表X,Y的长度却是3318,列表内容也是离谱,并没有深究getStickXY的功能,感兴趣的同学可以移步github。
print(nu[:5])
print(nu)
print(len(nu))
p1 = getColumn('N2', 'sw')
print(type(p1))
print(p1)
print(len(p1))
nu1=p1 = getColumn('N2', 'nu')
print(type(nu1))
print(nu1)
print(len(nu1))
[11.833113 11.843113 11.853113 11.863113 11.873113]
[ 11.833113 11.843113 11.853113 … 9352.933113 9352.943113
9352.953113]
934113
<class ‘numpy.ndarray’>
[2.595e-39 2.286e-34 1.734e-38 … 7.174e-39 6.697e-39 1.533e-39]
1106
<class ‘numpy.ndarray’>
[ 11.833113 11.937345 19.721395 … 9350.020105 9351.566148
9352.959559]
1106
可以看出getColumn(‘N2’, ‘sw’)给出的才是辐射强度数据。
普朗克平均吸收系数的计算
参考文章:
1.[https://blog.csdn.net/qq_44930937/article/details/109610045]
2.楚化强. 高效、高精度气体非灰辐射模型的研究[D].华中科技大学,2012.
3.[https://baike.baidu.com/item/普朗克黑体辐射定律/15517836?fr=aladdin]
HAPI库并未提供普朗克平均吸收系数的计算函数,需要自己编程。
上一步getColumn(‘N2’, ‘sw’)给出的线强并不是黑体辐射强度,而且步长也与absorptionCoefficient_Voigt()函数给出的数据差异较大。只能使用传统方法进行计算。
根据文献2:
根据普朗克黑体辐射定律,黑体的半球单色辐射力仅仅是波长与温度的函数。我们只需要将黑体辐射力与absorptionCoefficient_Voigt()给出的吸收系数进行匹配并积分就可以得到有效吸收系数了。
temperature=3000#工作温度
pi=3.1415926
sigma=5.67*10**-8#斯特潘玻尔兹曼常数
#普朗克黑体辐射定律计算黑体的半球单色辐射力
def planck_formula(wavelength ):
temperature=3000
c1 = 3.7414 * 10 ** 8
c2 = 1.43879 * 10 ** 4
return (c1/wavelength**5)*(1/(np.e**(c2/wavelength/temperature)-1))
P.S.普朗克平均吸收系数还可以通过线强、黑体辐射力进行计算,但是需要自行将线强推广到其他温度,getColumn(‘tablename’, ‘sw’)给出的线强列表只是在化学标准状态下的线强分布。
目前已经发展出多个python第三方库可以对HITRAN数据库进行处理,比较有名的是RADIS库。详情请移步[https://github.com/radis/radis]
可以看RADIS开发者给我的回复。
[https://github.com/radis/radis/issues/249]
Q:I want to calculate Planck’s mean absorption coefficient using radis someday.
A:This would be very easy to implement in RADIS !
In the Planck’s mean absorption coefficient :
The only difficulty is to compute the absorption coefficient itself, and RADIS does it for you. You could have something like :
from radis import calc_spectrum
Tgas = 1000
s = calc_spectrum(100, 20000, # cm-1
molecule=...,
databank=...,
Tgas=Tgas)
w, k = s.get('abscoeff', wunit='cm-1', Iunit='cm-1') # that's an absorption coefficient in cm-1
And then derive the Planck-mean from that :
from numpy import trapz
from radis.phys.blackbody import planck_wn
planck_avg_k = trapz(k * planck_wn(w, Tgas), x=w) / trapz(I, Tgas), x=w)
Some warning points I can think about :
By default the absorption coefficient in RADIS is in cm-1, therefore it is not a molar absorption coefficient. You know which unit you’ll want for planck_avg_k anyway.
Performance-wise, RADIS may not be optimized to compute extremely large spectral ranges. It’s better to cut your spectrum in slots and combine then afterwards. Some people are working on it (@CorentinGrimaldi , also some Heat Transfer researchers at my Lab) and it may be fully automatized in the future. Or may not even be needed with the update of the algorithm we’re implementing ( @dcmvdbekerom @anandxkumar : allowing very-large-truncations and FFT-by-part )
If computing from the HITEMP database, CO2 and H2O are not downloading automatically at the moment. I expect they are gases you will be interested in ! They can be downloaded manually, of course, but #210 will help
If computing from the HITRAN database, lines are downloaded on-the-fly, and re-downloaded if you change the spectral range. This is not very efficient, downloads a lot of data, and not very environmentally-friendly 🌳. We’ll have to download HITRAN (and probably build something with the HAPI team, which already handles the database-download efficiently).
Finally, one interesting point :
If you look at this Zhang and Modest 2001 paper, you’ll find out that with a minor approximation, the Planck-mean can be computed as :
from the linestrengths Si, without having to actually resolve the lineshapes for each line. This make the computation thousands of times faster ⚡ , as the lineshape calculation is the bottleneck in any line-by-line code like RADIS or HAPI. Basically, you’d only have to compute the scaled linestrengths at the right temperature. You could use RADIS’s already implemented methods to download/load the database for you, scale the linestrengths, and then you could compute the Planck-mean absorption directly. Have a look at how eq_spectrum() is built, it would be a good starting point to build a “planck_mean_absorption()” function based on it. The get_optically_thin_power() method was based on this approach too, but for emission !
It would be interesting to compare the approximation with the ‘perfect’ value !
I assume you’ll also want to compute Rosseland-mean absorption coefficients, for optically thick cases ? Again, that would be very easy to implement here !
最后对平均吸收系数加权求和得到混合燃气的有效吸收系数。
网格划分
结构化网格,并对近壁面和喉部进行加密处理
BATES-71b喷管模型获取连接
https://download.csdn.net/download/qq_42183549/18211874
Fluent喷管烧蚀仿真
- general种修改几何参数,喷管尺寸约2m
- 定义燃气组分,包括H2O\N2\HCL\CO2\CO\H2所有的组分从fluent自带的材料库种copy。固体c虽然定义在fluid种但是在反应时应定义为沉积相。在solid选项中,自定义喷管材料为固体C,密度1830,比热1050,导热率70。
- 打开models,打开能量方程,辐射DO模型,组分输运模型,湍流模型选择k-。平均吸收系数为0.215675,需要说明的是,DO辐射模型中可以添加吸收系数和散射系数作为辐射强度的控制项,但是在不考虑燃气中颗粒等离散项时一般忽略散射作用。
- 在组分输运模型中定义反应方程。
主要反应方程式与化学动力学参数如图所示
- 设置边界条件、工作条件,in、out为压力入口、出口。入口压力为6mpa,温度为3000k
出口压力为101325pa。修改工作参数为绝对压力0。 - 在controls种修改控制条件,如果想获得更好的收敛特性,可以将参数减半,监视器选项残差修改为1e-6。
- 标准初始化。
入口速度100m/s。
辐射处理代码
print(nu)
print(type(nu))
print(len(nu))
print(coef)
print(len(coef))
print(type(coef))
print(y)
print(len(y))
print(type(y))
print(x)
print(type(x))
print(len(x))
[ 11.833113 11.843113 11.853113 … 9352.933113 9352.943113
9352.953113]
<class ‘numpy.ndarray’>
934113
[1.84784746e-16 1.85421916e-16 1.85984338e-16 … 1.27157618e-13
1.26674331e-13 1.26184828e-13]
934113
<class ‘numpy.ndarray’>
[0.000e+00 2.595e-39 0.000e+00 … 0.000e+00 1.533e-39 0.000e+00]
3318
<class ‘numpy.ndarray’>
[ 11.833113 11.833113 11.833113 … 9352.959559 9352.959559
9352.959559]
<class ‘numpy.ndarray’>
3318
N2气体的谱线有1106根,但是列表X,Y的长度却是3318,列表内容也是离谱,并没有深究getStickXY的功能,感兴趣的同学可以移步github。
print(nu[:5])
print(nu)
print(len(nu))
p1 = getColumn('N2', 'sw')
print(type(p1))
print(p1)
print(len(p1))
nu1=p1 = getColumn('N2', 'nu')
print(type(nu1))
print(nu1)
print(len(nu1))
[11.833113 11.843113 11.853113 11.863113 11.873113]
[ 11.833113 11.843113 11.853113 … 9352.933113 9352.943113
9352.953113]
934113
<class ‘numpy.ndarray’>
[2.595e-39 2.286e-34 1.734e-38 … 7.174e-39 6.697e-39 1.533e-39]
1106
<class ‘numpy.ndarray’>
[ 11.833113 11.937345 19.721395 … 9350.020105 9351.566148
9352.959559]
1106
可以看出getColumn(‘N2’, ‘sw’)给出的才是辐射强度数据。
三、普朗克平均吸收系数的计算
参考文章:
1.[https://blog.csdn.net/qq_44930937/article/details/109610045]
2.楚化强. 高效、高精度气体非灰辐射模型的研究[D].华中科技大学,2012.
3.[https://baike.baidu.com/item/普朗克黑体辐射定律/15517836?fr=aladdin]
HAPI库并未提供普朗克平均吸收系数的计算函数,需要自己编程。
上一步getColumn(‘N2’, ‘sw’)给出的线强并不是黑体辐射强度,而且步长也与absorptionCoefficient_Voigt()函数给出的数据差异较大。只能使用传统方法进行计算。
根据文献2:
根据普朗克黑体辐射定律,黑体的半球单色辐射力仅仅是波长与温度的函数。我们只需要将黑体辐射力与absorptionCoefficient_Voigt()给出的吸收系数进行匹配并积分就可以得到有效吸收系数了。
temperature=3000#工作温度
pi=3.1415926
sigma=5.67*10**-8#斯特潘玻尔兹曼常数
#普朗克黑体辐射定律计算黑体的半球单色辐射力
def planck_formula(wavelength ):
temperature=3000
c1 = 3.7414 * 10 ** 8
c2 = 1.43879 * 10 ** 4
return (c1/wavelength**5)*(1/(np.e**(c2/wavelength/temperature)-1))
P.S.普朗克平均吸收系数还可以通过线强、黑体辐射力进行计算,但是需要自行将线强推广到其他温度,getColumn(‘tablename’, ‘sw’)给出的线强列表只是在化学标准状态下的线强分布。
目前已经发展出多个python第三方库可以对HITRAN数据库进行处理,比较有名的是RADIS库。详情请移步[https://github.com/radis/radis]
可以看RADIS开发者给我的回复。
[https://github.com/radis/radis/issues/249]
Q:I want to calculate Planck’s mean absorption coefficient using radis someday.
A:This would be very easy to implement in RADIS !
In the Planck’s mean absorption coefficient :
The only difficulty is to compute the absorption coefficient itself, and RADIS does it for you. You could have something like :
from radis import calc_spectrum
Tgas = 1000
s = calc_spectrum(100, 20000, # cm-1
molecule=...,
databank=...,
Tgas=Tgas)
w, k = s.get('abscoeff', wunit='cm-1', Iunit='cm-1') # that's an absorption coefficient in cm-1
And then derive the Planck-mean from that :
from numpy import trapz
from radis.phys.blackbody import planck_wn
planck_avg_k = trapz(k * planck_wn(w, Tgas), x=w) / trapz(I, Tgas), x=w)
Some warning points I can think about :
By default the absorption coefficient in RADIS is in cm-1, therefore it is not a molar absorption coefficient. You know which unit you’ll want for planck_avg_k anyway.
Performance-wise, RADIS may not be optimized to compute extremely large spectral ranges. It’s better to cut your spectrum in slots and combine then afterwards. Some people are working on it (@CorentinGrimaldi , also some Heat Transfer researchers at my Lab) and it may be fully automatized in the future. Or may not even be needed with the update of the algorithm we’re implementing ( @dcmvdbekerom @anandxkumar : allowing very-large-truncations and FFT-by-part )
If computing from the HITEMP database, CO2 and H2O are not downloading automatically at the moment. I expect they are gases you will be interested in ! They can be downloaded manually, of course, but #210 will help
If computing from the HITRAN database, lines are downloaded on-the-fly, and re-downloaded if you change the spectral range. This is not very efficient, downloads a lot of data, and not very environmentally-friendly 🌳. We’ll have to download HITRAN (and probably build something with the HAPI team, which already handles the database-download efficiently).
Finally, one interesting point :
If you look at this Zhang and Modest 2001 paper, you’ll find out that with a minor approximation, the Planck-mean can be computed as :
from the linestrengths Si, without having to actually resolve the lineshapes for each line. This make the computation thousands of times faster ⚡ , as the lineshape calculation is the bottleneck in any line-by-line code like RADIS or HAPI. Basically, you’d only have to compute the scaled linestrengths at the right temperature. You could use RADIS’s already implemented methods to download/load the database for you, scale the linestrengths, and then you could compute the Planck-mean absorption directly. Have a look at how eq_spectrum() is built, it would be a good starting point to build a “planck_mean_absorption()” function based on it. The get_optically_thin_power() method was based on this approach too, but for emission !
It would be interesting to compare the approximation with the ‘perfect’ value !
I assume you’ll also want to compute Rosseland-mean absorption coefficients, for optically thick cases ? Again, that would be very easy to implement here !
最后对平均吸收系数加权求和得到混合燃气的有效吸收系数。
网格划分
结构化网格,并对近壁面和喉部进行加密处理
BATES-71b喷管模型获取连接
https://download.csdn.net/download/qq_42183549/18211874
Fluent喷管烧蚀仿真
-
general种修改几何参数,喷管尺寸约2m
-
定义燃气组分,包括H2O\N2\HCL\CO2\CO\H2所有的组分从fluent自带的材料库种copy。固体c虽然定义在fluid种但是在反应时应定义为沉积相。在solid选项中,自定义喷管材料为固体C,密度1830,比热1050,导热率70。
-
打开models,打开能量方程,辐射DO模型,组分输运模型,湍流模型选择k-。平均吸收系数为0.215675,需要说明的是,DO辐射模型中可以添加吸收系数和散射系数作为辐射强度的控制项,但是在不考虑燃气中颗粒等离散项时一般忽略散射作用。
-
在组分输运模型中定义反应方程。
主要反应方程式与化学动力学参数如图所示
- 设置边界条件、工作条件,in、out为压力入口、出口。入口压力为6mpa,温度为3000k
出口压力为101325pa。修改工作参数为绝对压力0。 - 在controls种修改控制条件,如果想获得更好的收敛特性,可以将参数减半,监视器选项残差修改为1e-6。
- 标准初始化。
入口速度100m/s。
辐射处理代码
from hapi import *
import numpy as np
from pylab import *
from sympy import *
import scipy.constants as C
import matplotlib.pylab as plb
from matplotlib import font_manager as fm, rcParams
import matplotlib as plt
plt.rcParams['font.sans-serif']=['SimHei'] #显示中文
plt.rcParams['axes.unicode_minus']=False #这两行需要手动设置
#使用本代码前需要先使用fetch语句获取所需要的数据
#数据集位置
db_begin('data')
temperature=3000#工作温度
pi=3.1415926
sigma=5.67*10**-8#斯特潘玻尔兹曼常数
#普朗克黑体辐射定律计算黑体的半球单色辐射力
def planck_formula(wavelength ):
temperature=3000
c1 = 3.7414 * 10 ** 8
c2 = 1.43879 * 10 ** 4
return (c1/wavelength**5)*(1/(np.e**(c2/wavelength/temperature)-1))
class MainComponent :
def __init__(self,name):
self.name = name
self.nu=[]
self.coef=[]
#线强曲线
def plot_linestrength(self):
x = getColumn(self.name, 'nu')
y =getColumn(self.name, 'sw')
plb.figure()
plb.plot(x, y)
plb.xlabel('波数($cm^{-1}$)')
plb.ylabel('线强($cm^{-1}$)')
plb.title(f"{self.name},线强")
plb.show()
#吸收系数曲线
def plot_absorptionCoefficient(self):
self.nu,self.coef=absorptionCoefficient_Voigt(SourceTables=self.name, HITRAN_units=False, GammaL='gamma_self',Environment={'p': 60, 'T': 3000})
plb.figure()
plb.plot(self.nu, self.coef)
plb.xlabel('波数($cm^{-1}$)')
plb.ylabel('吸收系数($cm^{-1}$)')
plb.title(f"{self.name},吸收系数(600Pa,3000K)")
plb.show()
#吸收光谱
def plot_absorptionSpectrum(self):
myOpticalL = 1000
nu1, absorp = absorptionSpectrum(self.nu, self.coef, Environment={'l': myOpticalL})
plb.figure()
plb.plot(nu1, absorp)
plb.xlabel('波数($cm^{-1}$)')
plb.ylabel('吸光度')
plb.title(f"{self.name},吸收光谱(600atm, 3000K)")
plb.show()
#投射光谱
def polt_transmittanceSpectrum(self):
nu2, transm = transmittanceSpectrum(self.nu,self.coef, Environment={'l': 1000.})
plb.figure()
plb.plot(nu2, transm)
plb.xlabel('波数($cm^{-1}$)')
plb.ylabel('投射度')
plb.title(f"{self.name},透射光谱(600atm, 3000K)")
plb.show()
#普朗克平均吸收系数
def Planck_mean_absorption_coefficient(self):
sum1=0
for i in range(len(self.nu)):
l = (1 / self.nu[i]) * 10000
sum1 += planck_formula(l) * self.coef[i]
out = sum1 * 0.00001 * pi / (sigma * temperature ** 4)
#将有效吸收系数的计算结果写入文件
filename = 'Planck_mean_absorption_coefficient.txt'
with open(filename, 'a') as file_object:
file_object.write(f"{self.name}的普朗克平均吸收系数为{out}\n")
main_components=['CO','HCL','N2','H2','CO2','H2O']
d={}
for main_component in main_components:
d[main_component]=MainComponent(main_component)
d[main_component].plot_linestrength()
d[main_component].plot_absorptionCoefficient()
d[main_component].plot_absorptionSpectrum()
d[main_component].polt_transmittanceSpectrum()
d[main_component].Planck_mean_absorption_coefficient()