1 Star 0 Fork 0

何琪/reptile-python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ItypeThreeLevelSepClass.py 34.17 KB
一键复制 编辑 原始数据 按行查看 历史
何琪 提交于 2024-10-12 17:03 . init:初始化代码
import numpy as np
from scipy import integrate
import equations as eqs
import curve_funcs as cfs
import plot as plot
import pprint
'''
这个类是I型三电平-分开的拓扑计算结果和曲线
'''
class ItypeThreeLevelSepCalculator:
def __init__(self, input_param, inter_param):
"""
input_param: 字典, 界面的应用工况输入参数
inter_param: 字典, 输入的中间参数
"""
# 传入的应用工况输入参数
self.input_param = input_param
self.fout = self.input_param['fout']
self.PF = self.input_param['PF']
self.Vout = self.input_param['Vout']
self.Vdc = self.input_param['Vdc']
self.I_rms = self.input_param['I_rms']
self.Rgon_T1 = self.input_param['Rgon_T1']
self.Rgoff_T1 = self.input_param['Rgoff_T1']
self.Rgon_T2 = self.input_param['Rgon_T2']
self.Rgoff_T2 = self.input_param['Rgoff_T2']
self.fsw = self.input_param['fsw']
self.Th = self.input_param['Th']
# 传入的中间参数, 积分变量为t
self.inter_param = inter_param
self.Vref = self.inter_param['Vref']
self.Rgon_T1_test = self.inter_param['Rgon_T1_test']
self.Rgoff_T1_test = self.inter_param['Rgoff_T1_test']
self.Rgon_T2_test = self.inter_param['Rgon_T2_test']
self.Rgoff_T2_test = self.inter_param['Rgoff_T2_test']
# 需要计算的中间参数
self.w = 2.0 * np.pi * self.fout
# self.theta = self.w * self.inter_param['t']
# t = 100
# self.theta = self.w * t
self.m = self.Vout * 1.414 * 2.0 / self.Vdc
self.phi = np.arccos(self.PF)
# self.IC_theta = self.I_rms * 1.414 * np.sin(self.theta)
self.Vfactor_diode = np.power((0.5 * self.Vdc / self.Vref), 0.6)
self.Vfactor_IGBT = np.power((0.5 * self.Vdc / self.Vref), 1.0)
# 计算开关电阻参数
def cal_R_param(self, coefs):
"""
coefs: 字典,存储了T1,T2, D1, D2, D5, T5的开关电阻计算公式的系数,形如{'T1_on':coef, 'T1_off':coef, 'T2_on':coef, 'T2_off':coef, 'D5_rec':coef, 'D7_rec':coef,}
coef: 列表,形如[a, b, c, d],对应每个管子的四个系数
"""
self.T1_on_coef = coefs['T1_on']
self.T1_off_coef = coefs['T1_off']
self.T2_on_coef = coefs['T2_on']
self.T2_off_coef = coefs['T2_off']
self.D5_rec_coef = coefs['D5_rec']
self.D7_rec_coef = coefs['D7_rec']
# 计算得到电阻参数
self.Rgon_factor_T1 = eqs.equ_R_param(self.Rgon_T1, self.Rgon_T1_test, self.T1_on_coef)
self.Rgoff_factor_T1 = eqs.equ_R_param(self.Rgoff_T1, self.Rgoff_T1_test, self.T1_off_coef)
self.Rgon_factor_T2 = eqs.equ_R_param(self.Rgon_T2, self.Rgon_T2_test,self.T2_on_coef)
self.Rgoff_factor_T2 = eqs.equ_R_param(self.Rgoff_T2, self.Rgoff_T2_test, self.T2_off_coef)
self.Rgrec_factor_D5 = eqs.equ_R_param(self.Rgon_T1, self.Rgon_T1_test, self.D5_rec_coef)
self.Rgrec_factor_D7 = eqs.equ_R_param(self.Rgon_T2, self.Rgon_T2_test, self.D7_rec_coef)
# 以字典形式返回
return {'Rgon_factor_T1':self.Rgon_factor_T1, 'Rgoff_factor_T1':self.Rgoff_factor_T1,
'Rgon_factor_T2':self.Rgon_factor_T2, 'Rgoff_factor_T2':self.Rgoff_factor_T2,
'Rgrec_factor_D7':self.Rgrec_factor_D7, 'Rgrec_factor_D5':self.Rgrec_factor_D5,
}
# 计算损耗
def cal_loss(self, R_coefs, loss_coefs, Rth):
"""
R_coefs: 字典,存储了T1,T2, D5, D7的开关电阻计算公式的系数,{'T1_on':coef, 'T1_off':coef, 'T2_on':coef, 'T2_off':coef, 'D5_rec':coef, 'D7_rec':coef,}
loss_coefs: 字典,{'Vce_Ic_T1':coef, 'EonT1':coef, 'EoffT1':coef,
'Vce_Ic_T2':coef, 'EonT2':coef, 'EoffT2':coef,
'Vf_IC_D1':coef, 'Erec_D1':coef,
'Vf_IC_D2':coef, 'Erec_D2':coef,}
coef: 列表,形如[a, b, c, d],对应每个管子的四个损耗系数
Rth: 字典,包含Rth_T1,Rth_T2,Rth_D1,Rth_D2
积分计算使用scipy库的 integrate.quad() 方法实现
ret, dat = integrate.quad(func, a, b, args=()); func为待积分函数(项),a为积分下限,b为积分上限,args为传入func中的常数项
integrate.quad() 函数具体用法: https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.quad.html#scipy.integrate.quad
"""
self.Rth_T1 = Rth['Rth_T1']
self.Rth_T2 = Rth['Rth_T2']
self.Rth_D7 = Rth['Rth_D7']
self.Rth_D5 = Rth['Rth_D5']
# 计算开关电阻参数,self.R_params 为包含所有管子开关电阻参数的字典
self.R_params = self.cal_R_param(R_coefs)
# self.coef_Irms 为 I_rms * 1.414,用于后续计算IC(theta)=I_rms * 1.414 * sin(theta)的传参
self.coef_Irms = self.I_rms * 1.414
# 计算 T1/T4 loss
# 读取用于计算 Vce_Ic_T1(IC)=a+b*IC+c*IC^2+d*IC^3 的四个系数
self.Vce_Ic_T1_coef_l0 = loss_coefs['Vce_Ic_T1'][0]
self.Vce_Ic_T1_coef_l1 = loss_coefs['Vce_Ic_T1'][1]
self.Vce_Ic_T1_coef_l2 = loss_coefs['Vce_Ic_T1'][2]
self.Vce_Ic_T1_coef_l3 = loss_coefs['Vce_Ic_T1'][3]
# 计算 Pcon_T1 SPWM方式
Pcon_T1_spwm, _ = integrate.quad(eqs.integrand_Pcon_T1_spwm, 0, np.pi-self.phi, args=(self.coef_Irms, self.Vce_Ic_T1_coef_l0, self.Vce_Ic_T1_coef_l1, self.Vce_Ic_T1_coef_l2, self.Vce_Ic_T1_coef_l3, self.m, self.phi))
self.Pcon_T1_spwm = Pcon_T1_spwm/(2.0*np.pi)
# 计算 Pcon_T1 SVPWM方式
Pcon_T1_svpwm, _ = integrate.quad(eqs.integrand_Pcon_T1_svpwm, 0, np.pi-self.phi, args=(self.coef_Irms, self.Vce_Ic_T1_coef_l0, self.Vce_Ic_T1_coef_l1, self.Vce_Ic_T1_coef_l2, self.Vce_Ic_T1_coef_l3, self.m, self.phi))
self.Pcon_T1_svpwm = Pcon_T1_svpwm/(2.0*np.pi)
# 读取用于计算 EonT1(IC)=a+b*IC+c*IC^2+d*IC^3 的四个系数
self.EonT1_coef_l0 = loss_coefs['EonT1'][0]
self.EonT1_coef_l1 = loss_coefs['EonT1'][1]
self.EonT1_coef_l2 = loss_coefs['EonT1'][2]
self.EonT1_coef_l3 = loss_coefs['EonT1'][3]
# 计算 PSW_T1_ON
PSW_T1_ON, _ = integrate.quad(eqs.integrand_PSW_ON_OFF, 0, np.pi-self.phi, args=(self.coef_Irms, self.EonT1_coef_l0, self.EonT1_coef_l1, self.EonT1_coef_l2, self.EonT1_coef_l3))
self.PSW_T1_ON = self.fsw * self.Vfactor_IGBT * self.R_params['Rgon_factor_T1'] * PSW_T1_ON /(2.0*np.pi)
# print('PSW_T1_ON: ', self.PSW_T1_ON)
# 读取用于计算 EoffT1(IC)=a+b*IC+c*IC^2+d*IC^3 的四个系数
self.EoffT1_coef_l0 = loss_coefs['EoffT1'][0]
self.EoffT1_coef_l1 = loss_coefs['EoffT1'][1]
self.EoffT1_coef_l2 = loss_coefs['EoffT1'][2]
self.EoffT1_coef_l3 = loss_coefs['EoffT1'][3]
# 计算 PSW_T1_OFF
PSW_T1_OFF, _ = integrate.quad(eqs.integrand_PSW_ON_OFF, 0, np.pi-self.phi, args=(self.coef_Irms, self.EoffT1_coef_l0, self.EoffT1_coef_l1, self.EoffT1_coef_l2, self.EoffT1_coef_l3))
self.PSW_T1_OFF = self.fsw * self.Vfactor_IGBT * self.R_params['Rgoff_factor_T1'] * PSW_T1_OFF /(2.0*np.pi)
# print('PSW_T1_OFF: ', self.PSW_T1_OFF)
# 计算 PSW_T1, TER_T1
self.PSW_T1 = self.PSW_T1_ON + self.PSW_T1_OFF
self.TER_T1_spwm = self.Th + self.Rth_T1*(self.Pcon_T1_spwm+self.PSW_T1)
self.TER_T1_svpwm = self.Th + self.Rth_T1*(self.Pcon_T1_svpwm+self.PSW_T1)
# 总损耗,两种调制模式
self.tot_T1_spwm = self.Pcon_T1_spwm+self.PSW_T1
self.tot_T1_svpwm = self.Pcon_T1_svpwm+self.PSW_T1
# 计算 T2/T3 loss
# 读取用于计算 Vce_Ic_T2(IC)=a+b*IC+c*IC^2+d*IC^3 的四个系数
self.Vce_Ic_T2_coef_l0 = loss_coefs['Vce_Ic_T2'][0]
self.Vce_Ic_T2_coef_l1 = loss_coefs['Vce_Ic_T2'][1]
self.Vce_Ic_T2_coef_l2 = loss_coefs['Vce_Ic_T2'][2]
self.Vce_Ic_T2_coef_l3 = loss_coefs['Vce_Ic_T2'][3]
# 计算 Pcon_T2 SPWM方式,两部分积分分开计算,再求和
Pcon_T2_spwm_part1, _ = integrate.quad(eqs.integrand_ANPC_Pcon_T2_spwm_part1, 0, np.pi-self.phi, args=(self.coef_Irms, self.Vce_Ic_T2_coef_l0, self.Vce_Ic_T2_coef_l1, self.Vce_Ic_T2_coef_l2, self.Vce_Ic_T2_coef_l3))
Pcon_T2_spwm_part2, _ = integrate.quad(eqs.integrand_Pcon_T2_spwm_part2, np.pi-self.phi, np.pi, args=(self.coef_Irms, self.Vce_Ic_T2_coef_l0, self.Vce_Ic_T2_coef_l1, self.Vce_Ic_T2_coef_l2, self.Vce_Ic_T2_coef_l3, self.m, self.phi))
self.Pcon_T2_spwm = (Pcon_T2_spwm_part1+Pcon_T2_spwm_part2)/(2.0*np.pi)
# 计算 Pcon_T2 SVPWM方式,两部分积分分开计算,再求和
Pcon_T2_svpwm_part1, _ = integrate.quad(eqs.integrand_ANPC_Pcon_T2_spwm_part1, 0, np.pi-self.phi, args=(self.coef_Irms, self.Vce_Ic_T2_coef_l0, self.Vce_Ic_T2_coef_l1, self.Vce_Ic_T2_coef_l2, self.Vce_Ic_T2_coef_l3))
Pcon_T2_svpwm_part2, _ = integrate.quad(eqs.integrand_Pcon_T2_svpwm_part2, np.pi-self.phi, np.pi, args=(self.coef_Irms, self.Vce_Ic_T2_coef_l0, self.Vce_Ic_T2_coef_l1, self.Vce_Ic_T2_coef_l2, self.Vce_Ic_T2_coef_l3, self.m, self.phi))
self.Pcon_T2_svpwm = (Pcon_T2_svpwm_part1+Pcon_T2_svpwm_part2)/(2.0*np.pi)
# 读取用于计算 EonT2(IC)=a+b*IC+c*IC^2+d*IC^3 的四个系数
self.EonT2_coef_l0 = loss_coefs['EonT2'][0]
self.EonT2_coef_l1 = loss_coefs['EonT2'][1]
self.EonT2_coef_l2 = loss_coefs['EonT2'][2]
self.EonT2_coef_l3 = loss_coefs['EonT2'][3]
# 计算 PSW_T2_ON
PSW_T2_ON, _ = integrate.quad(eqs.integrand_PSW_ON_OFF, np.pi-self.phi, np.pi, args=(self.coef_Irms, self.EonT2_coef_l0, self.EonT2_coef_l1, self.EonT2_coef_l2, self.EonT2_coef_l3))
self.PSW_T2_ON = self.fsw * self.Vfactor_IGBT * self.R_params['Rgon_factor_T2'] * PSW_T2_ON /(2.0*np.pi)
# 读取用于计算 EoffT2(IC)=a+b*IC+c*IC^2+d*IC^3 的四个系数
self.EoffT2_coef_l0 = loss_coefs['EoffT2'][0]
self.EoffT2_coef_l1 = loss_coefs['EoffT2'][1]
self.EoffT2_coef_l2 = loss_coefs['EoffT2'][2]
self.EoffT2_coef_l3 = loss_coefs['EoffT2'][3]
# 计算 PSW_T2_OFF
PSW_T2_OFF, _ = integrate.quad(eqs.integrand_PSW_ON_OFF, np.pi-self.phi, np.pi, args=(self.coef_Irms, self.EoffT2_coef_l0, self.EoffT2_coef_l1, self.EoffT2_coef_l2, self.EoffT2_coef_l3))
self.PSW_T2_OFF = self.fsw * self.Vfactor_IGBT * self.R_params['Rgoff_factor_T2'] * PSW_T2_OFF /(2.0*np.pi)
# 计算 PSW_T2, TER_T2
self.PSW_T2 = self.PSW_T2_ON + self.PSW_T2_OFF
self.TER_T2_spwm = self.Th + self.Rth_T2*(self.Pcon_T2_spwm+self.PSW_T2)
self.TER_T2_svpwm = self.Th + self.Rth_T2*(self.Pcon_T2_svpwm+self.PSW_T2)
# 总损耗,两种调制模式
self.tot_T2_spwm = self.Pcon_T2_spwm+self.PSW_T2
self.tot_T2_svpwm = self.Pcon_T2_svpwm+self.PSW_T2
# 计算 D7/D8 loss
# 读取用于计算 Vf_IC_D1(IC)=a+b*IC+c*IC^2+d*IC^3 的四个系数
self.Vf_IC_D7_coef_l0 = loss_coefs['Vf_IC_D7'][0]
self.Vf_IC_D7_coef_l1 = loss_coefs['Vf_IC_D7'][1]
self.Vf_IC_D7_coef_l2 = loss_coefs['Vf_IC_D7'][2]
self.Vf_IC_D7_coef_l3 = loss_coefs['Vf_IC_D7'][3]
# 计算 Pcon_D1 SPWM方式
Pcon_D7_spwm, _ = integrate.quad(eqs.integrand_Pcon_D1_spwm, np.pi-self.phi, np.pi, args=(self.coef_Irms, self.Vf_IC_D7_coef_l0, self.Vf_IC_D7_coef_l1, self.Vf_IC_D7_coef_l2, self.Vf_IC_D7_coef_l3, self.m, self.phi))
self.Pcon_D7_spwm = Pcon_D7_spwm/(2.0*np.pi)
# 计算 Pcon_D1 SVPWM方式
Pcon_D7_svpwm, _ = integrate.quad(eqs.integrand_Pcon_D1_svpwm, np.pi-self.phi, np.pi, args=(self.coef_Irms, self.Vf_IC_D7_coef_l0, self.Vf_IC_D7_coef_l1, self.Vf_IC_D7_coef_l2, self.Vf_IC_D7_coef_l3, self.m, self.phi))
self.Pcon_D7_svpwm = Pcon_D7_svpwm/(2.0*np.pi)
# 读取用于计算 Erec_D1(IC)=a+b*IC+c*IC^2+d*IC^3 的四个系数
self.Erec_D7_coef_l0 = loss_coefs['Erec_D7'][0]
self.Erec_D7_coef_l1 = loss_coefs['Erec_D7'][1]
self.Erec_D7_coef_l2 = loss_coefs['Erec_D7'][2]
self.Erec_D7_coef_l3 = loss_coefs['Erec_D7'][3]
# 计算 Prec_D1, TER_D7
Prec_D7, _ = integrate.quad(eqs.integrand_PSW_ON_OFF, np.pi-self.phi, np.pi, args=(self.coef_Irms, self.Erec_D7_coef_l0, self.Erec_D7_coef_l1, self.Erec_D7_coef_l2, self.Erec_D7_coef_l3))
self.Prec_D7 = self.Vfactor_diode * self.fsw * self.R_params['Rgrec_factor_D7'] * Prec_D7 /(2.0*np.pi)
self.TER_D7_spwm = self.Th + self.Rth_D7*(self.Pcon_D7_spwm+self.Prec_D7)
self.TER_D7_svpwm = self.Th + self.Rth_D7*(self.Pcon_D7_svpwm+self.Prec_D7)
# 总损耗,两种调制模式
self.tot_D7_spwm = self.Pcon_D7_spwm+self.Prec_D7
self.tot_D7_svpwm = self.Pcon_D7_svpwm+self.Prec_D7
# 计算 D5/D6 loss
self.Vf_IC_D5_coef_l0 = loss_coefs['Vf_IC_D5'][0]
self.Vf_IC_D5_coef_l1 = loss_coefs['Vf_IC_D5'][1]
self.Vf_IC_D5_coef_l2 = loss_coefs['Vf_IC_D5'][2]
self.Vf_IC_D5_coef_l3 = loss_coefs['Vf_IC_D5'][3]
Pcon_D5_spwm_part1, _ = integrate.quad(eqs.integrand_Pcon_T2_spwm_part1, 0.0, np.pi-self.phi, args=(self.coef_Irms, self.Vf_IC_D5_coef_l0, self.Vf_IC_D5_coef_l1, self.Vf_IC_D5_coef_l2, self.Vf_IC_D5_coef_l3, self.m, self.phi))
Pcon_D5_spwm_part2, _ = integrate.quad(eqs.integrand_Pcon_T2_spwm_part2, np.pi-self.phi, np.pi, args=(self.coef_Irms, self.Vf_IC_D5_coef_l0, self.Vf_IC_D5_coef_l1, self.Vf_IC_D5_coef_l2, self.Vf_IC_D5_coef_l3, self.m, self.phi))
self.Pcon_D5_spwm = (Pcon_D5_spwm_part1+Pcon_D5_spwm_part2)/(2.0*np.pi)
Pcon_D5_svpwm_part1, _ = integrate.quad(eqs.integrand_Pcon_T2_svpwm_part1, 0.0, np.pi-self.phi, args=(self.coef_Irms, self.Vf_IC_D5_coef_l0, self.Vf_IC_D5_coef_l1, self.Vf_IC_D5_coef_l2, self.Vf_IC_D5_coef_l3, self.m, self.phi))
Pcon_D5_svpwm_part2, _ = integrate.quad(eqs.integrand_Pcon_T2_svpwm_part2, np.pi-self.phi, np.pi, args=(self.coef_Irms, self.Vf_IC_D5_coef_l0, self.Vf_IC_D5_coef_l1, self.Vf_IC_D5_coef_l2, self.Vf_IC_D5_coef_l3, self.m, self.phi))
self.Pcon_D5_svpwm = (Pcon_D5_svpwm_part1+Pcon_D5_svpwm_part2)/(2.0*np.pi)
self.Erec_D5_coef_l0 = loss_coefs['Erec_D5'][0]
self.Erec_D5_coef_l1 = loss_coefs['Erec_D5'][1]
self.Erec_D5_coef_l2 = loss_coefs['Erec_D5'][2]
self.Erec_D5_coef_l3 = loss_coefs['Erec_D5'][3]
Prec_D5, _ = integrate.quad(eqs.integrand_PSW_ON_OFF, 0, np.pi-self.phi, args=(self.coef_Irms, self.Erec_D5_coef_l0, self.Erec_D5_coef_l1, self.Erec_D5_coef_l2, self.Erec_D5_coef_l3))
self.Prec_D5 = self.fsw * self.R_params['Rgrec_factor_D5'] * self.Vfactor_diode * Prec_D5 /(2.0*np.pi)
self.TER_D5_spwm = self.Th + self.Rth_D5*(self.Pcon_D5_spwm+self.Prec_D5)
self.TER_D5_svpwm = self.Th + self.Rth_D5*(self.Pcon_D5_svpwm+self.Prec_D5)
# 总损耗,两种调制模式
self.tot_D5_spwm = self.Pcon_D5_spwm+self.Prec_D5
self.tot_D5_svpwm = self.Pcon_D5_svpwm+self.Prec_D5
# 计算 系统总损耗 total loss 和 效率 eta
self.Ptot_spwm = (self.Pcon_T1_spwm+self.PSW_T1+self.Pcon_T2_spwm+self.PSW_T2+self.Pcon_D7_spwm+self.Prec_D7+self.Pcon_D5_spwm+self.Prec_D5)*2.0
self.eta_spwm = (self.Vout*self.I_rms)/(self.Ptot_spwm+self.Vout*self.I_rms)
self.Ptot_svpwm = (self.Pcon_T1_svpwm+self.PSW_T1+self.Pcon_T2_svpwm+self.PSW_T2+self.Pcon_D7_svpwm+self.Prec_D7+self.Pcon_D5_svpwm+self.Prec_D5)*2.0
self.eta_svpwm = (self.Vout*self.I_rms)/(self.Ptot_svpwm+self.Vout*self.I_rms)
# 将所有的计算结果以字典格式返回
return {'Vout':self.Vout, 'I_rms':self.I_rms,
'Pcon_T1_spwm':self.Pcon_T1_spwm, 'Pcon_T1_svpwm':self.Pcon_T1_svpwm, 'PSW_T1':self.PSW_T1, 'PSW_T1_ON':self.PSW_T1_ON, 'PSW_T1_OFF':self.PSW_T1_OFF,
'Pcon_T2_spwm':self.Pcon_T2_spwm, 'Pcon_T2_svpwm':self.Pcon_T2_svpwm, 'PSW_T2':self.PSW_T2, 'PSW_T2_ON':self.PSW_T2_ON, 'PSW_T2_OFF':self.PSW_T2_OFF,
'Pcon_D7_spwm':self.Pcon_D7_spwm, 'Pcon_D7_svpwm':self.Pcon_D7_svpwm, 'Prec_D7':self.Prec_D7,
'Pcon_D5_spwm':self.Pcon_D5_spwm, 'Pcon_D5_svpwm':self.Pcon_D5_svpwm, 'Prec_D5':self.Prec_D5,
'system_total_loss_spwm':self.Ptot_spwm, 'system_efficiency_spwm':self.eta_spwm,
'system_total_loss_svpwm':self.Ptot_svpwm, 'system_efficiency_svpwm':self.eta_svpwm,
'T1_total_loss_spwm':self.tot_T1_spwm, 'T1_total_loss_svpwm':self.tot_T1_svpwm,
'T2_total_loss_spwm':self.tot_T2_spwm, 'T2_total_loss_svpwm':self.tot_T2_svpwm,
'D7_total_loss_spwm':self.tot_D7_spwm, 'D7_total_loss_svpwm':self.tot_D7_svpwm,
'D5_total_loss_spwm':self.tot_D5_spwm, 'D5_total_loss_svpwm':self.tot_D5_svpwm,
'TER_T1_spwm':self.TER_T1_spwm, 'TER_T1_svpwm':self.TER_T1_svpwm,
'TER_T2_spwm':self.TER_T2_spwm, 'TER_T2_svpwm':self.TER_T2_svpwm,
'TER_D7_spwm':self.TER_D7_spwm, 'TER_D7_svpwm':self.TER_D7_svpwm,
'TER_D5_spwm':self.TER_D5_spwm, 'TER_D5_svpwm':self.TER_D5_svpwm,
}
# 画曲线
def draw_curve(self, rc_coefs):
'''
rc_coefs: 字典,存储 RC(用于动态结温公式)的系数,{'T1':coef, 'T2':coef, 'D1':coef, 'D2':coef,}
coef: 列表,形如[c0, c1, c2, c3, c4, c5, c6, c7], 对应每个管子的8个动态结温公式中 RC 系数
'''
# 将 时间t的区间 离散化,离散为500个点,在后续计算中,分别计算每个t值对应的损耗值,得到纵坐标,组成曲线图
t = np.linspace(0.0, 1/self.fout, 500)
# 画出 T1/T4 的曲线
# 动态损耗计算,计算每个时间t对应的损耗值
Pcon_T1_spwm_values = np.array([cfs.Pcon_T1_spwm_loss_t(t_, 2*np.pi*self.fout, self.coef_Irms, self.Vce_Ic_T1_coef_l0, self.Vce_Ic_T1_coef_l1, self.Vce_Ic_T1_coef_l2, self.Vce_Ic_T1_coef_l3, self.m, self.phi) for t_ in t])
Pcon_T1_svpwm_values = np.array([cfs.Pcon_T1_svpwm_loss_t(t_, 2*np.pi*self.fout, self.coef_Irms, self.Vce_Ic_T1_coef_l0, self.Vce_Ic_T1_coef_l1, self.Vce_Ic_T1_coef_l2, self.Vce_Ic_T1_coef_l3, self.m, self.phi) for t_ in t])
# 在计算开关损耗时,没有将fsw,Vfactor_IGBT,Rgon_factor等参数考虑进来,后续会考虑
PSW_T1_ON_values = np.array([cfs.PSW_T1_loss_t(t_, 2*np.pi*self.fout, self.coef_Irms, self.EonT1_coef_l0, self.EonT1_coef_l1, self.EonT1_coef_l2, self.EonT1_coef_l3, self.phi) for t_ in t])
PSW_T1_OFF_values = np.array([cfs.PSW_T1_loss_t(t_, 2*np.pi*self.fout, self.coef_Irms, self.EoffT1_coef_l0, self.EoffT1_coef_l1, self.EoffT1_coef_l2, self.EoffT1_coef_l3, self.phi) for t_ in t])
# 分别计算 SPWM,SVPWM方式下的损耗和,Pcon_T1+PSW_T1_ON+PSW_T1_OFF, 在这里考虑 fsw,Vfactor_IGBT,Rgon_factor等参数
P_T1_spwm_curve_values = Pcon_T1_spwm_values + self.fsw*self.Vfactor_IGBT*self.Rgon_factor_T1*PSW_T1_ON_values + self.fsw*self.Vfactor_IGBT*self.Rgoff_factor_T1*PSW_T1_OFF_values
P_T1_svpwm_curve_values = Pcon_T1_svpwm_values + self.fsw*self.Vfactor_IGBT*self.Rgon_factor_T1*PSW_T1_ON_values + self.fsw*self.Vfactor_IGBT*self.Rgoff_factor_T1*PSW_T1_OFF_values
# # 将t和损耗值 作为参数 传入 plot_curve 函数,画出动态损耗曲线
# self.Pcon_T1_spwm_curve_img = plot.plot_curve(t, P_T1_spwm_curve_values)
# self.Pcon_T1_svpwm_curve_img = plot.plot_curve(t, P_T1_svpwm_curve_values)
# 动态结温计算,计算每个时间t对应的结温值
T1_c = rc_coefs['T1']
RC_T1 = np.array([cfs.RC(t_, T1_c[0], T1_c[1], T1_c[2], T1_c[3], T1_c[4], T1_c[5], T1_c[6], T1_c[7]) for t_ in t])
TER_T1_spwm_curve_values = self.Th + RC_T1*P_T1_spwm_curve_values
TER_T1_svpwm_curve_values = self.Th + RC_T1*P_T1_svpwm_curve_values
# # 将t和结温值 作为参数 传入 plot_curve 函数,画出动态结温曲线
# self.TER_T1_spwm_curve_img = plot.plot_curve(t, TER_T1_spwm_curve_values)
# self.TER_T1_svpwm_curve_img = plot.plot_curve(t, TER_T1_svpwm_curve_values)
# 画出 T2/T3 的曲线
# 动态损耗计算
Pcon_T2_spwm_values = np.array([cfs.ANPC_Pcon_T2_spwm_loss_t(t_, 2*np.pi*self.fout, self.coef_Irms, self.Vce_Ic_T2_coef_l0, self.Vce_Ic_T2_coef_l1, self.Vce_Ic_T2_coef_l2, self.Vce_Ic_T2_coef_l3, self.m, self.phi) for t_ in t])
Pcon_T2_svpwm_values = np.array([cfs.ANPC_Pcon_T2_svpwm_loss_t(t_, 2*np.pi*self.fout, self.coef_Irms, self.Vce_Ic_T2_coef_l0, self.Vce_Ic_T2_coef_l1, self.Vce_Ic_T2_coef_l2, self.Vce_Ic_T2_coef_l3, self.m, self.phi) for t_ in t])
# 在计算开关损耗时,没有将fsw,Vfactor_IGBT,Rgon_factor等参数考虑进来,后续会考虑
PSW_T2_ON_values = np.array([cfs.PSW_T2_loss_t(t_, 2*np.pi*self.fout, self.coef_Irms, self.EonT2_coef_l0, self.EonT2_coef_l1, self.EonT2_coef_l2, self.EonT2_coef_l3, self.phi) for t_ in t])
PSW_T2_OFF_values = np.array([cfs.PSW_T2_loss_t(t_, 2*np.pi*self.fout, self.coef_Irms, self.EoffT2_coef_l0, self.EoffT2_coef_l1, self.EoffT2_coef_l2, self.EoffT2_coef_l3, self.phi) for t_ in t])
# 分别计算 SPWM,SVPWM方式下的损耗和,Pcon_T2+PSW_T2_ON+PSW_T2_OFF,在这里考虑 fsw,Vfactor_IGBT,Rgon_factor等参数
P_T2_spwm_curve_values = Pcon_T2_spwm_values + self.fsw*self.Vfactor_IGBT*self.Rgon_factor_T2*PSW_T2_ON_values + self.fsw*self.Vfactor_IGBT*self.Rgoff_factor_T2*PSW_T2_OFF_values
P_T2_svpwm_curve_values = Pcon_T2_svpwm_values + self.fsw*self.Vfactor_IGBT*self.Rgon_factor_T2*PSW_T2_ON_values + self.fsw*self.Vfactor_IGBT*self.Rgoff_factor_T2*PSW_T2_OFF_values
# # 将t和损耗值 作为参数 传入 plot_curve 函数,画出动态损耗曲线
# self.Pcon_T2_spwm_curve_img = plot.plot_curve(t, P_T2_spwm_curve_values)
# self.Pcon_T2_svpwm_curve_img = plot.plot_curve(t, P_T2_svpwm_curve_values)
# 动态结温计算,计算每个时间t对应的结温值
T2_c = rc_coefs['T2']
RC_T2 = np.array([cfs.RC(t_, T2_c[0], T2_c[1], T2_c[2], T2_c[3], T2_c[4], T2_c[5], T2_c[6], T2_c[7]) for t_ in t])
TER_T2_spwm_curve_values = self.Th + RC_T2*P_T2_spwm_curve_values
TER_T2_svpwm_curve_values = self.Th + RC_T2*P_T2_svpwm_curve_values
# # 将t和结温值 作为参数 传入 plot_curve 函数,画出动态结温曲线
# self.TER_T2_spwm_curve_img = plot.plot_curve(t, TER_T2_spwm_curve_values)
# self.TER_T2_svpwm_curve_img = plot.plot_curve(t, TER_T2_svpwm_curve_values)
# 画出 D7/D8 的损耗曲线
# 动态损耗计算
Pcon_D7_spwm_values = np.array([cfs.Pcon_D1_spwm_loss_t(t_, 2*np.pi*self.fout, self.coef_Irms, self.Vf_IC_D7_coef_l0, self.Vf_IC_D7_coef_l1, self.Vf_IC_D7_coef_l2, self.Vf_IC_D7_coef_l3, self.m, self.phi) for t_ in t])
Pcon_D7_svpwm_values = np.array([cfs.Pcon_D1_svpwm_loss_t(t_, 2*np.pi*self.fout, self.coef_Irms, self.Vf_IC_D7_coef_l0, self.Vf_IC_D7_coef_l1, self.Vf_IC_D7_coef_l2, self.Vf_IC_D7_coef_l3, self.m, self.phi) for t_ in t])
# 在计算Prec时,没有将fsw,Vfactor_diode,Rgrec_factor等参数考虑进来,后续会考虑
Prec_D7_values = np.array([cfs.Prec_D1_loss_t(t_, 2*np.pi*self.fout, self.coef_Irms, self.Erec_D7_coef_l0, self.Erec_D7_coef_l1, self.Erec_D7_coef_l2, self.Erec_D7_coef_l3, self.phi) for t_ in t])
# 分别计算 SPWM,SVPWM方式下的损耗和,Pcon_D1+Prec_D1, 在这里考虑 fsw,Vfactor_diode,Rgrec_factor等参数
P_D7_spwm_curve_values = Pcon_D7_spwm_values + self.fsw*self.Vfactor_diode*self.Rgrec_factor_D7*Prec_D7_values
P_D7_svpwm_curve_values = Pcon_D7_svpwm_values + self.fsw*self.Vfactor_diode*self.Rgrec_factor_D7*Prec_D7_values
# # 将t和损耗值 作为参数 传入 plot_curve 函数,画出动态损耗曲线
# self.Pcon_D1_spwm_curve_img = plot.plot_curve(t, P_D1_spwm_curve_values)
# self.Pcon_D1_svpwm_curve_img = plot.plot_curve(t, P_D1_svpwm_curve_values)
# 动态结温计算,计算每个时间t对应的结温值
D7_c = rc_coefs['D7']
RC_D7 = np.array([cfs.RC(t_, D7_c[0], D7_c[1], D7_c[2], D7_c[3], D7_c[4], D7_c[5], D7_c[6], D7_c[7]) for t_ in t])
TER_D7_spwm_curve_values = self.Th + RC_D7*P_D7_spwm_curve_values
TER_D7_svpwm_curve_values = self.Th + RC_D7*P_D7_svpwm_curve_values
# # 将t和结温值 作为参数 传入 plot_curve 函数,画出曲线
# self.TER_D7_spwm_curve_img = plot.plot_curve(t, TER_D7_spwm_curve_values)
# self.TER_D7_svpwm_curve_img = plot.plot_curve(t, TER_D7_svpwm_curve_values)
# 画出 D5/D6 的损耗曲线 Pcon_D5+Prec_D5
# 动态损耗计算
Pcon_D5_spwm_values = np.array([cfs.Pcon_T2_spwm_loss_t(t_, 2*np.pi*self.fout, self.coef_Irms, self.Vf_IC_D5_coef_l0, self.Vf_IC_D5_coef_l1, self.Vf_IC_D5_coef_l2, self.Vf_IC_D5_coef_l3, self.m, self.phi) for t_ in t])
Pcon_D5_svpwm_values = np.array([cfs.Pcon_T2_svpwm_loss_t(t_, 2*np.pi*self.fout, self.coef_Irms, self.Vf_IC_D5_coef_l0, self.Vf_IC_D5_coef_l1, self.Vf_IC_D5_coef_l2, self.Vf_IC_D5_coef_l3, self.m, self.phi) for t_ in t])
# 在计算Prec时,没有将fsw,Vfactor_diode,Rgrec_factor等参数考虑进来,后续会考虑
Prec_D5_values = np.array([cfs.PSW_T1_loss_t(t_, 2*np.pi*self.fout, self.coef_Irms, self.Vf_IC_D5_coef_l0, self.Vf_IC_D5_coef_l1, self.Vf_IC_D5_coef_l2, self.Vf_IC_D5_coef_l3, self.phi) for t_ in t])
# 分别计算 SPWM,SVPWM方式下的损耗和,在这里考虑 fsw,Vfactor_diode,Rgrec_factor等参数
P_D5_spwm_curve_values = Pcon_D5_spwm_values + self.fsw*self.Vfactor_diode*self.Rgrec_factor_D5*Prec_D5_values
P_D5_svpwm_curve_values = Pcon_D5_svpwm_values + self.fsw*self.Vfactor_diode*self.Rgrec_factor_D5*Prec_D5_values
# 动态结温计算,计算每个时间t对应的结温值
D5_c = rc_coefs['D5']
RC_D5 = np.array([cfs.RC(t_, D5_c[0], D5_c[1], D5_c[2], D5_c[3], D5_c[4], D5_c[5], D5_c[6], D5_c[7]) for t_ in t])
TER_D5_spwm_curve_values = self.Th + RC_D5*P_D5_spwm_curve_values
TER_D5_svpwm_curve_values = self.Th + RC_D5*P_D5_svpwm_curve_values
# 最高结温
max_T1_spwm = np.max(TER_T1_spwm_curve_values)
max_T1_svpwm = np.max(TER_T1_svpwm_curve_values)
max_T2_spwm = np.max(TER_T2_spwm_curve_values)
max_T2_svpwm = np.max(TER_T2_svpwm_curve_values)
max_D7_spwm = np.max(TER_D7_spwm_curve_values)
max_D7_svpwm = np.max(TER_D7_svpwm_curve_values)
max_D5_spwm = np.max(TER_D5_spwm_curve_values)
max_D5_svpwm = np.max(TER_D5_svpwm_curve_values)
# 返回用于画曲线的数据点,每个图500个点
# t(numpy数组)为横坐标,'spwm_Pcon'等对应的值(numpy数组)为 纵坐标
# 'max_TER_spwm'等 对应的值为最高结温的数值
return {'t':t,
'T14':{'spwm_Pcon':P_T1_spwm_curve_values, # SPWM模式的损耗曲线纵坐标
'svpwm_Pcon':P_T1_svpwm_curve_values, # SVPWM模式的损耗曲线纵坐标
'spwm_TER':TER_T1_spwm_curve_values, # SPWM模式的结温曲线纵坐标
'svpwm_TER':TER_T1_svpwm_curve_values, # SVPWM模式的结温曲线纵坐标
'max_TER_spwm':max_T1_spwm, # 最高结温 SPWM模式
'max_TER_svpwm':max_T1_svpwm, # 最高结温 SVPWM模式
},
'T23':{'spwm_Pcon':P_T2_spwm_curve_values,
'svpwm_Pcon':P_T2_svpwm_curve_values,
'spwm_TER':TER_T2_spwm_curve_values,
'svpwm_TER':TER_T2_svpwm_curve_values,
'max_TER_spwm':max_T2_spwm,
'max_TER_svpwm':max_T2_svpwm,
},
'D78':{'spwm_Pcon':P_D7_spwm_curve_values,
'svpwm_Pcon':P_D7_svpwm_curve_values,
'spwm_TER':TER_D7_spwm_curve_values,
'svpwm_TER':TER_D7_svpwm_curve_values,
'max_TER_spwm':max_D7_spwm,
'max_TER_svpwm':max_D7_svpwm,
},
'D56':{'spwm_Pcon':P_D5_spwm_curve_values,
'svpwm_Pcon':P_D5_svpwm_curve_values,
'spwm_TER':TER_D5_spwm_curve_values,
'svpwm_TER':TER_D5_svpwm_curve_values,
'max_TER_spwm':max_D5_spwm,
'max_TER_svpwm':max_D5_svpwm,
},
}
# # 将所有的曲线图以字典格式返回,返回字典中的值为 PIL库格式的图像
# # 带 Pcon 的为动态损耗
# # 带 TER 的为动态结温
# return {'T14':{'spwm_Pcon':self.Pcon_T1_spwm_curve_img,
# 'svpwm_Pcon':self.Pcon_T1_svpwm_curve_img,
# 'spwm_TER':self.TER_T1_spwm_curve_img,
# 'svpwm_TER':self.TER_T1_svpwm_curve_img,
# 'max_TER_spwm':max_T1_spwm, # 最高结温 SPWM模式
# 'max_TER_svpwm':max_T1_svpwm, # 最高结温 SVPWM模式
# },
# 'T23':{'spwm_Pcon':self.Pcon_T2_spwm_curve_img,
# 'svpwm_Pcon':self.Pcon_T2_svpwm_curve_img,
# 'spwm_TER':self.TER_T2_spwm_curve_img,
# 'svpwm_TER':self.TER_T2_svpwm_curve_img,
# 'max_TER_spwm':max_T2_spwm,
# 'max_TER_svpwm':max_T2_svpwm,
# },
# 'D14':{'spwm_Pcon':self.Pcon_D1_spwm_curve_img,
# 'svpwm_Pcon':self.Pcon_D1_svpwm_curve_img,
# 'spwm_TER':self.TER_D7_spwm_curve_img,
# 'svpwm_TER':self.TER_D7_svpwm_curve_img,
# 'max_TER_spwm':max_D1_spwm,
# 'max_TER_svpwm':max_D1_svpwm,
# },
# 'D23':{'spwm_Pcon':self.Pcon_D2_spwm_curve_img,
# 'svpwm_Pcon':self.Pcon_D2_svpwm_curve_img,
# 'spwm_TER':self.TER_D5_spwm_curve_img,
# 'svpwm_TER':self.TER_D5_svpwm_curve_img,
# 'max_TER_spwm':max_D2_spwm,
# 'max_TER_svpwm':max_D2_svpwm,
# }}
if __name__ == '__main__':
# 使用示例
input_param = {'fout':50,
'PF':-1,
'Vout':230,
'Vdc':630,
'I_rms':163,
'Rgon_T1':4,
'Rgoff_T1':4,
'Rgon_T2':7.5,
'Rgoff_T2':7.5,
'fsw':16000.0,
'Th':90,
}
inter_param = {'Vref':400,
'Rgon_T1_test':4,
'Rgoff_T1_test':4,
'Rgon_T2_test':4,
'Rgoff_T2_test':7.5,
}
'''
R_coefs: 字典,{'T1_on':coef, 'T1_off':coef, 'T2_on':coef, 'T2_off':coef, 'D5_rec':coef, 'D7_rec':coef,}
loss_coefs: 字典,{'Vce_Ic_T1':coef, 'EonT1':coef, 'EoffT1':coef,
'Vce_Ic_T2':coef, 'EonT2':coef, 'EoffT2':coef,
'Vf_IC_D1':coef, 'Erec_D1':coef,
'Vf_IC_D2':coef, 'Erec_D2':coef,}
'''
R_coefs = {'T1_on':[1.411, 2.933, -0.08713, 0.001509],
'T1_off':[9.102, 0.9719, -0.03199, 0.0006902],
'T2_on':[1.756, 1.39, 0.02054, -0.000799],
'T2_off':[7.31, 0.2901, 0.01963, -0.0005018],
'D7_rec':[7.31, 0.2901, 0.01963, -0.0005018],
'D5_rec':[1.411, 2.933, -0.08713, 0.001509],
}
loss_coefs = {'Vce_Ic_T1':[0.4583, 0.005928, -9.677e-6, 7.012e-9],
'EonT1':[1.12e-3, 0.01228e-3, 5.664e-8, -6.09e-11],
'EoffT1':[0.1927e-3, 0.02324e-3, 1.477e-8, 3.56e-12],
'Vce_Ic_T2':[0.4583, 0.005928, -9.677e-6, 7.012e-9],
'EonT2':[1.355e-3, 0.02898e-3, 2.631e-8, -3.546e-11],
'EoffT2':[0.7448e-3, 0.02081e-3, 4.412e-8, -4.96e-11],
'Vf_IC_D5':[0.8835, 0.002691, -3.431e-6, 2.243e-9],
'Erec_D5':[0.09434e-3, 0.01323e-3, -1.63e-8, 9.348e-12],
'Vf_IC_D7':[0.8237, 0.004587, -5.135e-6, 3.239e-9],
'Erec_D7':[0.7643e-3, 0.03146e-3, -5.984e-8, 5.527e-11],
}
Rth = {'Rth_T1':0.25, 'Rth_T2':0.25, 'Rth_D7':0.24, 'Rth_D5':0.27}
# 用于动态结温公式中的 RC_T1 的8个系数
rc_coefs = {'T1':[0.024, 0.001, 0.044, 0.01, 0.02, 0.1, 0.056, 10.0],
'T2':[0.024, 0.001, 0.044, 0.01, 0.02, 0.1, 0.056, 10.0],
'D7':[0.024, 0.001, 0.044, 0.01, 0.02, 0.1, 0.056, 10.0],
'D5':[0.024, 0.001, 0.044, 0.01, 0.02, 0.1, 0.056, 10.0],
}
# 初始化类
calculator = ItypeThreeLevelSepCalculator(input_param, inter_param)
# 计算损耗
losses = calculator.cal_loss(R_coefs, loss_coefs, Rth)
# 在终端打印以字典格式打印结果
pprint.pprint(losses)
# 画曲线图
curve_img = calculator.draw_curve(rc_coefs)
# 打开一个窗口,展示某一曲线图
# curve_img['T14']['spwm_Pcon'].show()
# curve_img['T14']['spwm_TER'].show()
# print('out: ', curve_img['T14']['spwm_Pcon'])
# curve_img['T14']['spwm_TER'].save()
# curve_img['T14']['spwm_Pcon'].save('T14_spwm_Pcon.png')
# curve_img['T14']['svpwm_Pcon'].save('T14_svpwm_Pcon.png')
# curve_img['T14']['spwm_TER'].save('T14_spwm_TER.png')
# curve_img['T14']['svpwm_TER'].save('T14_svpwm_TER.png')
# curve_img['T23']['spwm_Pcon'].save('T23_spwm_Pcon.png')
# curve_img['T23']['svpwm_Pcon'].save('T23_svpwm_Pcon.png')
# curve_img['T23']['spwm_TER'].save('T23_spwm_TER.png')
# curve_img['T23']['svpwm_TER'].save('T23_svpwm_TER.png')
# curve_img['D14']['spwm_Pcon'].save('D14_spwm_Pcon.png')
# curve_img['D14']['svpwm_Pcon'].save('D14_svpwm_Pcon.png')
# curve_img['D14']['spwm_TER'].save('D14_spwm_TER.png')
# curve_img['D14']['svpwm_TER'].save('D14_svpwm_TER.png')
# curve_img['D23']['spwm_Pcon'].save('D23_spwm_Pcon.png')
# curve_img['D23']['svpwm_Pcon'].save('D23_svpwm_Pcon.png')
# curve_img['D23']['spwm_TER'].save('D23_spwm_TER.png')
# curve_img['D23']['svpwm_TER'].save('D23_svpwm_TER.png')
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/heqi123/reptile-python.git
git@gitee.com:heqi123/reptile-python.git
heqi123
reptile-python
reptile-python
master

搜索帮助