基于梯度下降的变压器铁心柱横截面设计算法
一、应用背景
变压器铁心柱横截面通常为多级矩形,本算法旨在当给定铁心柱直径(mm)、分级数时,以截面圆内铁心填充率最高为目标,设计出最优的铁芯界面尺寸方案,并给出各级片宽(mm)与叠厚(mm)及最终的铁心填充率
二、实现思路
1.数学模型建立
易知当设计方案最优时,图形左右对称,故仅取半圆分析
取角度θ[i]为自变量,易知片宽w[i],叠厚t[i]与θ[i]及θ[i+1]的关系为
则填充率 filling rate 可表示为
2.梯度下降算法
梯度下降法的计算过程就是沿梯度下降的方向求解极小值(也可以沿梯度上升方向求解极大值)。其迭代公式为
,其中代表梯度负方向, 表示梯度方向上的搜索步长。
在本应用中,填充率对θ[i]的偏导为
取适当的步长,多次迭代后可以轻易得出最优解
三、实现代码
import numpy as np
class model:
def __init__(self, diameter_0, layer_num_0):
self.diameter = diameter_0
self.radius = diameter_0 / 2.0
self.layer_num = np.int(layer_num_0)
self.semicircle = 3.1415 * self.radius * self.radius/2
self.theta = np.linspace(0.0, 3.1415/8.0, self.layer_num+1)
self.theta[self.layer_num] = 3.1415/2.0
self.width = [0 for num in range(0, layer_num_0)]
self.thickness = [0 for num in range(0, layer_num_0)]
def update_model(self):
for num in range(0, self.layer_num):
self.width[num] = 2*self.radius*np.sin(self.theta[num])
for num in range(0, self.layer_num):
self.thickness[num] = self.radius*(np.cos(self.theta[num])-np.cos(self.theta[num+1]))
def calculate_filling_rate(self):
area = 0.00
for num in range(0, self.layer_num):
area = area + self.width[num]*self.thickness[num]
filling_rate = area/self.semicircle
return filling_rate
def optimize(self, learning_rate, steps):
self.update_model()
filling_rate = 0
l_r = 3.1415*learning_rate
for step in range(0, steps):
self.theta[0] = self.theta[0] - l_r * (
np.cos(2 * self.theta[0])
- np.cos(self.theta[0 + 1]) * np.cos(self.theta[0])) * (-2/3.1415)
for num in range(1, self.layer_num):
self.theta[num] = self.theta[num] - l_r * (
np.cos(2*self.theta[num])
- np.cos(self.theta[num+1])*np.cos(self.theta[num])
+ np.sin(self.theta[num-1])*np.sin(self.theta[num]))/(-2/3.1415)
self.update_model()
if step % 100 == 0:
filling_rate = self.calculate_filling_rate()
# print("step: " + str(step) + " filling_rate: " + str(filling_rate*100)+"%"+"\n")
return filling_rate
diameter_0 = 120.0
layer_num_0 = 12
learning_rate_0 = 0.001
step_0 = 10000
print("铁芯直径:")
print(diameter_0)
print("\n级数:6")
if layer_num_0 % 2 == 0:
mymodel = model(diameter_0, np.int(layer_num_0/2))
filling_rate_result = mymodel.optimize(learning_rate_0, step_0)
width_result = []
# print("角度为:")
# print(180 * mymodel.theta / 3.14)
width_result.extend(mymodel.width)
width_result.extend(mymodel.width[::-1])
print("\n宽度为:")
print(width_result)
thickness_result = []
thickness_result.extend(mymodel.thickness)
thickness_result.extend(mymodel.thickness[::-1])
print("\n厚度为:")
print(thickness_result)
print("\n填充率为:")
print(filling_rate_result)
print("\n有效面积为:")
print(filling_rate_result*3.1415*diameter_0*diameter_0/(4.0*100))
else:
mymodel = model(diameter_0, np.int((layer_num_0+1)/2))
filling_rate_result = mymodel.optimize(learning_rate_0, step_0)
width_result = []
# print(mymodel.width)
width_result.extend(mymodel.width[0:np.int((layer_num_0+1)/2)-1])
width_result.append(mymodel.width[np.int((layer_num_0+1)/2)-1])
width_result.extend((mymodel.width[0:np.int((layer_num_0+1)/2)-1])[::-1])
print("\n宽度为:")
print(width_result)
thickness_result = []
thickness_result.extend(mymodel.thickness[0:np.int((layer_num_0+1)/2)-1])
thickness_result.append(2*mymodel.thickness[np.int((layer_num_0+1)/2)-1])
thickness_result.extend((mymodel.thickness[0:np.int((layer_num_0+1)/2)-1])[::-1])
print("\n厚度为:")
print(thickness_result)
print("\n填充率为:")
print(filling_rate_result)
print("\n有效面积为:")
print(filling_rate_result*3.1415*diameter_0*diameter_0/(4.0*100))
运行结果:
四、一点总结
查阅资料后可知,本算法计算出的设计方案对比工程实际中常用的标准来说有一些差距,虽然填充率相对实际中的方案更高,但工件加工难度有所上升。
因此,本方案并不能直接应用在工程实际中,但对工程实际中的铁心柱界面设计还是有一定的指导意义。