variable T index 300 400 500 600 700 800 900 1000
label T_loop
# 初始化
units metal
boundary p p p
atom_style atomic
# 创建晶格
lattice fcc 3.62 # 晶胞边长 3.62 A
region box block 0 8 0 8 0 8 # 创建一个8*8*8的FCC晶胞
create_box 1 box
create_atoms 1 box
# 设置原子间势函数
pair_style eam # EAM势
pair_coeff 1 1 Cu_u3.eam
# 重置时间步
reset_timestep 0
# 初始速度
velocity all create ${T} 85979 dist gaussian
# 使用NPT系综弛豫
fix 1 all npt temp ${T} ${T} $(100*dt) iso 0 0 1 # 初始温度和结束温度为${T},$(100*dt)为阻尼系数,控制温度调节的幅度
# 定义热力学输出
thermo_style custom step temp epair press lx ly lz
thermo 1000
# 定义温度、长度和体积差值
compute actual_T all temp
variable Lx equal lx
variable V equal vol
# 平均值计算,并保存到文件
# 每100个时间步长收集一次数据,将10次数据收集进行平均,每10000个时间步长输出一次平均后的数据
fix 2 all ave/time 100 10 10000 c_actual_T v_Lx v_V file thermal_expansion_data.${T}.txt
# 开始运行
run 10000
# 取消NPT系综
unfix 1
clear
next T
jump SELF T_loop # 循环到脚本的某个位置
units metal
boundary p p p
atom_style atomic
variable Tstart equal 10.0
variable Tstop equal 1000
variable Tdamp equal 0.2
lattice fcc 3.62
region simbox block 0 8 0 8 0 8
create_box 1 simbox
create_atoms 1 box
pair_style eam
pair_coeff 1 1 Cu_u3.eam
velocity all create ${Tstart} 564646 dist gaussian
# 平衡步骤
fix 1 all nvt temp ${Tstart} ${Tstart} ${Tdamp}
thermo 100
run 5000
unfix 1
reset_timestep 0
thermo 1000
thermo_style custom step temp pe etotal
# 逐渐加热系统
fix 2 all nvt temp ${Tstart} ${Tstop} ${Tdamp}
run 120000
units lj
boundary p p p
atom_style atomic
lattice fcc 1.073
region box block 0 10 0 10 0 10
create_box 1 box
create_atoms 1 box
mass 1 1.0
pair_style lj/cut 2.5
pair_coeff 1 1 1.0 1.0 2.5
velocity all create 0.01 56465
timestep 0.005
fix 1 all nvt temp 0.01 0.01 0.2
run 50000
unfix 1
reset_timestep 0
thermo 1000
thermo_style custom step temp pe etotal press vol
fix 1 all npt temp 0.01 0.85 1.0 iso 0 0 1.0
run 1000000
# 平衡
fix 1 all nvt temp 0.85 0.85 0.2
run 50000
unfix 1
# 体系缓慢降温
reset_timestep 0
thermo 1000
thermo_style custom step temp pe etotal press vol
fix 1 all npt temp 0.85 0.01 1.0 iso 0 0 1.0
dump 1 all atom 10000 quench.lammpstrj
run 1000000
units metal
boundary p p p
atom_style atomic
lattice fcc 3.62
region box block 0 8 0 8 0 8
create_box 1 box
create_atoms 1 box
pair_style eam
pair_coeff 1 1 Cu_u3.eam
thermo 1000
thermo_style custom step temp pe etotal press vol
velocity all create 100.0 4516516 dist gaussian
fix 1 all npt temp 100.0 100.0 0.1 iso 0.0 0.0 1.0
run 10000
unfix 1
reset_timestep 0
fix 1 all npt temp 100 2000 0.1 iso 0 0 1.0
dump 1 all atom 1000 dump.lammpstrj
run 120000
compute 1 all msd
fix msd all ave/time 10 100 1000 c_1[1] c_1[2] c_1[3] c_1[4] file msd.dat
fix 1 all npt temp $x 2000 0.2 iso 0 0 10
run 500000
compute msd 命令将对每个原子计算一个四维的矢量,其中前三个分量分别代表dx、dy、dz方向的均方位移,最后一个分量是原子的总均方位移# 初始化
units metal
boundary p p p
atom_style atomic
# 生成 NiCu 纳米颗粒
variable A0 equal 3.589
lattice fcc ${A0}
region mybox block 0 40 0 40 0 40
create_box 2 mybox # 2 种原子
region CuNi_nano sphere 20 20 20 2
create_atoms 1 region CuNi_nano
set type 1 type/fraction 2 0.5 65643
mass 1 63.546 # Cu
mass 2 58.6934 # Ni
# 使用eam势函数
pair_style eam/alloy
pair_coeff * * CuNi.eam.alloy Cu Ni
write_data nanoparticle.cif
run 0
# 热力学平衡步骤
thermo 1000
variable j loop 0 20
label loop_j
variable temperature equal 900+10*$j
variable T equal temp
variable Eatom equal etotal/atoms
fix 1 all nvt temp ${temperature} ${temperature} 0.1
run 50000
unfix 1
# 统计步骤
fix 2 all ave/time 100 5 1000 v_T v_Eatom file data_ave${temperature}.txt
dump 1 all atom 5000 melt_ ${temperature}.atom
fix 1 all nvt temp ${temperature} ${temperature} 0.1
run 500000
unfix 1
undump 1
next j
jump SELF loop_j
# 计算所有时间步的平均距离和均方距离
r_ave = np.mean(np.sqrt(r_square),axis = 0)
r2_ave = np.mean(r_square,axis = 0)
# 计算上三角元素的林德曼指数
value_upper = np.sqrt(r2_ave_upper - np.power(r_ave_upper,2)) / r_ave_upper
# 所有唯一原子对的总和
total_value = np.sum(value_upper)
#
return total_value * 2 / (N * (N-1))
# 初始化
units metal # 使用 metal 单位
boundary p p p
atom_style atomic
timestep 0.001
# 获得三个纳米Pt颗粒
variable A0 equal 3.9239
lattice fcc ${A0}
region mybox block 0 20 0 20 0 20
region sphere_pt1 sphere 7 10 8 3 # 生成球形区域
region sphere_pt2 sphere 10 10 13.4 3
region sphere_pt3 sphere 13 10 8 3
create_box 1 mybox
create_atoms 1 region sphere_pt1
create_atoms 1 region sphere_pt2
create_atoms 1 region sphere_pt3
# 使用eam势函数
pair_style eam
pair_coeff 1 1 Pt_u3.eam
# 输出初始结构
dump 1 all cfg 1 crood.*.cfg mass type xs ys zs
run 0
undump 1
# 定义三个纳米颗粒的交界区域
region triple_neck block 7.5 12.5 5 15 9 13
group l dynamic all region triple_neck every 1000
# 输出tripl_neck区域的原子数
variable N equal step
variable T equal temp
variable Natom equal count(all)
variable V equal vol/v_Natom
variable sinter_atom equal count(l)
dump 1 all xyz 1000 melt.xyz
thermo 1000
fix extra all print 1000 "${N} ${T} ${sinter_atom}" file data.txt
# 分别在500K,1000K,1400K下运行
fix 1 all npt temp 500 500 0.1 iso 1 1 1
run 10000
unfix 1
fix 1 all npt temp 1000 1000 0.1 iso 1 1 1
run 10000
unfix 1
fix 1 all npt temp 1400 1400 0.1 iso 1 1 1
run 10000
unfix 1
通常采用平衡分子动力学(EMD)(Green-Kubo)、非平衡分子动力学(NEMD)(傅里叶定律)、反扰动动力学(rNEMD)(Muller-Plathe)等方法,来模拟材料的传热过程
NEMD计算思路:
采用非平衡动力学(NEMD)的进行模拟,通过在材料外部施加热流扰动,达到稳态后统计内部的温度分布,进而计算得出材料的热导率。
傅里叶定律: κ = − J A × ∇ T \kappa =-\frac{J}{A\times \nabla T} κ=−A×∇TJ 其中, J J J:热流 A A A:传热面积 ∇ T \nabla T ∇T:温度梯度
热流 J J J计算公式: J = ∂ E ∂ t J=\frac{\partial E}{\partial t} J=∂t∂E 其中, E E E:输入的能量 t t t:输入时间
温度梯度计算公式: ∇ T = ∂ T ∂ x \nabla T=\frac{\partial T}{\partial x} ∇T=∂x∂T 其中, T T T:温度 x x x:传热方向位移
建模方法:固定边界建模、周期性边界建模
冷热源设置:
1.fix langevin 命令
# 通过郎之万法控制温度
fix 3 Hot langevin 400 400 0.05 14565 tally yes
# Hot区域原子,初始温度400K,结束温度400K,温度阻尼0.05,随机种子14565,tally在恒温计算时加/减原子累计能量并保存
fix 4 Cold langevin 200 200 0.05 16576 tally yes
# Cold区域原子,初始温度200K,结束温度200K,温度阻尼0.05,随机种子14565
2.fix heat 命令
# 保持其总动量方向不变的方式添加热量
fix hot all heat 1 10 region hot #所有原子,每隔1步添加热量,热量添加速率10,单位为ev,热源区域hot
fix cold all heat 1 -10 region cold #所有原子,每隔1步添加热量,热量添加速率-10,冷源区域cold
3.fix ehex 命令
# 增强热交换法
fix hot all ehex 1 10 region hot # 所有原子,每隔1步添加热量,热量添加速率10,热源区域hot
fix cold all ehex 1 -10 region cold # 所有原子,每隔1步添加热量,热量添加速率-10,冷源区域cold
热流计算:
fix langevin 命令
fix 3 Hot langevin 400 400 0.05 14565 tally yes
fix 4 Cold langevin 200 200 0.05 16576 tally yes
variable Time equal step
variable EL equal f_3 # 输入能量保存f_3
variable ER equal f_4 # 输出能量保存f_4
fix E_out all print 2000 "${Time} ${EL} ${ER}" file Enter_equ.dat title "Time E1 E2" screen no
# 每2000步将能量数据保存为文件,设置标题,不输出屏幕
温度梯度计算:
compute ke1 all ke/atom # 计算所有原子的单原子动能
variable kb equal 8.625e-5 # 玻尔兹曼常数
variable temp1 atom c_ke1/1.5/${kb} # atom储存公式,动能转换温度
# 分块设置 chunk
compute 18 all chunk/atom bin/1d x lower ${Dscale} units reduced
# bin/1d一维分块,沿x方向,lower从低端开始,比例Dscale,units reduced 表示0-1之间的归一化无单位值
fix 11 all ave/chunk 1 10000000 10000000 18 v_temp1 file temp_equ.dat
# 块内时间平均,保存温度数据,每1步使用输入值,使用输入值10000000次数,每10000000步计算平均值
#初始基本参数设置
units metal #单位制
dimension 3 #维度
newton on #在计算对相互作用和键相互作用的时候使用牛顿第三定律
boundary p p p #周期性边界条件
atom_style full #原子类型full
timestep 0.001 #时间步长,1fs=0.001ps
neighbor 0.3 bin #邻居列表
read_data gp.data #读取data文件
#力场设置
pair_style airebo 3.0 #截断半径3.0
pair_coeff * * CH.airebo C
#计算温度
compute ke1 all ke/atom #计算所有原子的单原子动能
variable kb equal 8.625e-5 #玻尔兹曼常数
variable temp1 atom c_ke1/1.5/${kb} #atom储存公式,动能转换温度
#设置热力学输出
thermo 1000 #每1000步输出
thermo_style custom step temp pxx pyy pzz press vol #输出步数、温度、xyz方向压力、压力、体积
#温度初始化
velocity all create 300 898758 mom yes rot yes dist gaussian #初始温度300K,mom yes 速度的线动量为零,rot yes角动量为零,高斯分布
#能量最小化
min_style cg #以cg方式进行能量最小化
minimize 1.0e-8 1.0e-8 1000000 1000000 #能量容差,力容差,最大迭代次数,最大评估次数
#在npt系综下进行弛豫
thermo 1000 #每1000步输出
thermo_style custom step temp pe ke etotal vol pxx pyy pzz press #etotal动能与势能之和,pe总势能,ke动能
fix 1 all npt temp 300 300 0.1 iso 0 0 1 #恒温恒压,300K
dump 1 all custom 10000 npt.xyz id type x y z #保存所有原子信息为文件
run 250000
unfix 1 #取消
undump 1
reset_timestep 0 #设置当前时间步为第0步
write_data Gp.data #保存模型
#在nvt系综下进行弛豫
thermo 1000 #每1000步输出
thermo_style custom step temp pe ke etotal vol pxx pyy pzz press
fix 1 all nvt temp 300 300 0.1 #恒温,300K
dump 1 all custom 10000 nvt.xyz id type x y z #保存所有原子信息为文件
run 50000
unfix 1 #取消
undump 1
reset_timestep 0 #设置当前时间步为第0步
#设置分块参数
variable X1 equal xlo #最小值x
variable X2 equal xhi #最大值x
variable Nlay equal 100 #分块个数
variable Dscale equal 1/${Nlay} #比例
variable Len equal ${X2}-${X1} #总长度
variable Dz equal ${Len}/${Nlay} #单块长度
#设置冷热源端点坐标
variable BL1 equal ${X1}+2*${Dz} #热源
variable BR1 equal ${X1}+6*${Dz}
variable BL2 equal ${X2}-6*${Dz} #冷源
variable BR2 equal ${X2}-2*${Dz}
#区域设置
region reg_all block ${X1} ${X2} INF INF INF INF units box #整个区域
region fixed_L block INF ${BL1} INF INF INF INF units box #左侧固定端
region fixed_R block ${BR2} INF INF INF INF INF units box #右侧固定端
region Hot block ${BL1} ${BR1} INF INF INF INF units box #热源
region Cold block ${BL2} ${BR2} INF INF INF INF units box #冷源
#原子进行分组
group fixed_L region fixed_L
group fixed_R region fixed_R
group Hot region Hot
group Cold region Cold
group mobile subtract all fixed_L fixed_R #中间原子
#将x方向改为固定边界
change_box all boundary f p p #f为非周期固定边界
#固定两端
velocity fixed_L set 0 0 0
velocity fixed_R set 0 0 0 #设置xyz方向速度为0
fix fixed_L fixed_L setforce 0 0 0
fix fixed_R fixed_R setforce 0 0 0 #设置xyz方向受力为0
#使用langevin法设置冷热源
fix 3 Hot langevin 400 400 0.1 14565 tally yes
#Hot区域原子,初始温度400K,结束温度400K,温度阻尼0.05,随机种子14565,tally在恒温计算时加/减原子累计能量并保存
fix 4 Cold langevin 200 200 0.1 16576 tally yes
#Cold区域原子,初始温度200K,结束温度200K,温度阻尼0.05,随机种子16576
#保持nve系综
fix 5 all nve
#设置冷热源的输入输出能量
variable Time equal step #时间
variable EL equal f_3 #输入能量保存f_3
variable ER equal f_4 #输出能量保存f_4
#分块设置
compute 18 all chunk/atom bin/1d x lower ${Dscale} units reduced
#bin/1d一维分块,沿x方向,lower从低端开始,比例Dscale,units reduced 表示0-1之间的归一化无单位值
#计算每一块的温度
fix 8 all ave/chunk 1 10000 10000 18 v_temp1 file temp_relax.dat
#块内时间平均,保存温度数据,每1步使用输入值,使用输入值10000次数,每10000步计算平均值
dump 1 all xyz 10000 relax.xyz #每10000步保存原子坐标
thermo 10000 #每10000步输出
thermo_style custom step temp ke pe etotal press vol #输出类型
run 100000
unfix 8 #取消
undump 1
reset_timestep 0 #设置当前时间步是第0步
#保存温差和能量
fix 11 all ave/chunk 1 10000 10000 18 v_temp1 file temp_equ.dat
#块内时间平均,保存温度数据,每1步使用输入值,使用输入值10000次数,每10000步计算平均值
fix E_out all print 2000 "${Time} ${EL} ${ER}" file Enter_equ.dat title "Time E1 E2" screen no #每2000步将能量数据保存为文件,设置标题,不输出屏幕
dump 1 all xyz 10000 equ.xyz #每10000步保存原子坐标
thermo 10000 #每10000步输出
thermo_style custom step temp ke pe etotal press vol #输出类型
run 1000000
#基本参数设置
units metal #单位制
dimension 3 #维度
boundary p p p #边界条件
atom_style atomic #原子类型
timestep 0.01 #时间步长
#模型建立
lattice fcc 5.256 #晶格
region box block 0 20 0 4 0 4 #定义box区域
create_box 1 box #box区域一种原子
create_atoms 1 box #box区域生成类型1原子
mass 1 39.948 #设置原子质量
pair_style lj/cut 10.0 #lj/cut势,截断半径10
pair_coeff * * 1.051e-2 3.40
#速度初始化
velocity all create 60 12345 #初始温度60K
#nvt系综下弛豫
fix 1 all nvt temp 60 60 1 #恒温
thermo 1000 #每1000步输出
thermo_style custom step temp press #自定义输出步数、温度和压力
run 20000
unfix 1 #取消
reset_timestep 0 #设置当前步为第0步
#冷热源设置
region Hot block 0 1 INF INF INF INF #热源
region Cold block 10 11 INF INF INF INF #冷源
fix 1 all nve #保存nve系综
#增强热交换法
fix hot all ehex 1 0.05 region Hot #每隔1步向Hot区域添加热量,速率0.05
fix cold all ehex 1 -0.05 region Cold #每隔1步从Cold区域减少热量,速率0.05
#设置计算温度
compute KE all ke/atom #计算所有原子的单原子动能,储存在KE中
variable KB equal 8.625e-5 #玻尔兹曼常数
variable TEMP atom c_KE/1.5/${KB} #原子温度
#分块设置
compute layer all chunk/atom bin/1d x lower 0.05 units reduced
#bin/1d一维分块,沿x方向,lower从低端开始,比例0.05
fix 2 all ave/chunk 10 1000 10000 layer v_TEMP file temp.txt
#保存块内时间平均温度,每10步使用输入值,使用输入值1000次,每10000步保存数据
#计算平均温差
variable tdiff equal f_2[1][3]-f_2[11][3]
fix ave all ave/time 1 1 10000 v_tdiff ave running file tdiff.txt
#输出所有原子的时间平均,每隔1步使用输入值,输入值计算1次,每10000步计算均值,ave running输出累积均值
dump 1 all atom 10000 heat.xyz #每10000步保存原子信息
run 100000