循环向量化

This commit is contained in:
2021-09-21 01:35:42 +08:00
parent 011db48f8b
commit 77951ae54a
2 changed files with 53 additions and 45 deletions

36
main.py
View File

@@ -1,3 +1,5 @@
import numpy as np
from core import *
import timeit
@@ -104,19 +106,27 @@ def egm():
i_curt_samples, d_curt = np.linspace(
i_min, i_max, curt_segment_n + 1, retstep=True
)
for i_curt in i_curt_samples[:-1]:
cal_bd_first = bd_area(i_curt, u_ph, dgc, h_gav, h_cav)
cal_bd_second = bd_area(i_curt + d_curt, u_ph, dgc, h_gav, h_cav)
cal_thunder_density_first = thunder_density(i_curt)
cal_thunder_density_second = thunder_density(i_curt + d_curt)
calculus += (
(
cal_bd_first * cal_thunder_density_first
+ cal_bd_second * cal_thunder_density_second
)
/ 2
* d_curt
)
bd_area_vec = np.vectorize(bd_area)
cal_bd_np = bd_area_vec(
i_curt_samples, u_ph, dgc, h_gav, h_cav
) * thunder_density(i_curt_samples)
calculus = np.sum(cal_bd_np[:-1] + cal_bd_np[1:]) / 2 * d_curt
# for i_curt in i_curt_samples[:-1]:
# cal_bd_first = bd_area(i_curt, u_ph, dgc, h_gav, h_cav)
# cal_bd_second = bd_area(i_curt + d_curt, u_ph, dgc, h_gav, h_cav)
# cal_thunder_density_first = thunder_density(i_curt)
# cal_thunder_density_second = thunder_density(i_curt + d_curt)
# calculus += (
# (
# cal_bd_first * cal_thunder_density_first
# + cal_bd_second * cal_thunder_density_second
# )
# / 2
# * d_curt
# )
# if abs(calculus-0.05812740052770032)<1e-5:
# abc=123
# pass
n_sf = (
2 * ng / 10 * calculus
) # 跳闸率 利用QGDW 11452-2015 架空输电线路防雷导则的公式 Ng=0.023*Td^(1.3) 20天雷暴日地闪密度为1.13