完善了双回路EGM模型代码。

This commit is contained in:
2021-09-22 00:18:06 +08:00
parent dd44de030e
commit 392eeb0168
2 changed files with 229 additions and 142 deletions

47
core.py
View File

@@ -25,7 +25,7 @@ class Draw:
rg = rg_fun(i_curt, rc_y, u_ph, typ=rg_type)
msp.add_circle((rs_x, rs_y), rs, dxfattribs={"color": color})
msp.add_line((0, 0), (rs_x, rs_y)) # 地线
msp.add_circle((rc_x, rc_y), rc, dxfattribs={"color": color+2})
msp.add_circle((rc_x, rc_y), rc, dxfattribs={"color": color + 2})
msp.add_line((rc_x, 0), (rc_x, rc_y)) # 导线
msp.add_line((rs_x, rs_y), (rc_x, rc_y))
# 角度线
@@ -36,9 +36,12 @@ class Draw:
if rg_type == "g":
msp.add_line((0, rg), (2000, rg), dxfattribs={"color": color})
circle_line_section = solve_circle_line_intersection(rc, rg, rc_x, rc_y)
msp.add_line(
(rc_x, rc_y), circle_line_section, dxfattribs={"color": color}
) # 导线和圆的交点
if not circle_line_section:
pass
else:
msp.add_line(
(rc_x, rc_y), circle_line_section, dxfattribs={"color": color}
) # 导线和圆的交点
if rg_type == "c":
msp.add_circle((rg_x, rg_y), rg, dxfattribs={"color": color})
rg_rc_intersection = solve_circle_intersection(
@@ -138,7 +141,7 @@ def rg_fun(i_curt, h_cav, u_ph, typ="g"):
def intersection_angle(
rc_x, rc_y, rs_x, rs_y, rg_x, rg_y, i_curt, u_ph, rg_type
rc_x, rc_y, rs_x, rs_y, rg_x, rg_y, i_curt, u_ph, ground_surface, rg_type
): # 暴露弧的角度
rs = rs_fun(i_curt)
rc = rc_fun(i_curt, u_ph)
@@ -155,6 +158,18 @@ def intersection_angle(
circle_line_or_rg_intersection = solve_circle_intersection(
rg, rc, rg_x, rg_y, rc_x, rc_y
) # 两圆的交点
(
circle_line_or_rg_intersection_x,
circle_line_or_rg_intersection_y,
) = circle_line_or_rg_intersection
if (
ground_surface(circle_line_or_rg_intersection_x)
> circle_line_or_rg_intersection_y
): # 交点在地面线以下,就可以不积分
# 找到暴露弧和地面线的交点
circle_line_or_rg_intersection = circle_ground_surface_intersection(
rc, rc_x, rc_y, ground_surface
)
np_circle_intersection = np.array(circle_intersection)
theta2_line = np_circle_intersection - np.array([rc_x, rc_y])
theta2 = math.atan(theta2_line[1] / theta2_line[0])
@@ -224,9 +239,11 @@ def calculus_bd(theta, rc, rs, rg, rc_x, rc_y, rs_x, rs_y): # 对θ进行积分
return r
def bd_area(i_curt, u_ph, rc_x, rc_y, rs_x, rs_y, rg_x, rg_y, rg_type): # 暴露弧的投影面积
def bd_area(
i_curt, u_ph, rc_x, rc_y, rs_x, rs_y, rg_x, rg_y, ground_surface, rg_type
): # 暴露弧的投影面积
theta1, theta2 = intersection_angle(
rc_x, rc_y, rs_x, rs_y, rg_x, rg_y, i_curt, u_ph, rg_type
rc_x, rc_y, rs_x, rs_y, rg_x, rg_y, i_curt, u_ph, ground_surface, rg_type
) # θ角度
theta_fineness = 0.01
rc = rc_fun(i_curt, u_ph)
@@ -304,3 +321,19 @@ def tangent_line_k(line_x, line_y, center_x, center_y, radius, init_k=10.0):
def func_ng(td): # 地闪密度
return 0.023 * (td ** 1.3)
# 圆和地面线的交点只去正x轴上的。
def circle_ground_surface_intersection(radius, center_x, center_y, ground_surface):
# 最笨的办法,一个个去试
x_series = np.linspace(0, radius, int(radius / 0.001)) + center_x
part_to_be_squared = radius ** 2 - (x_series - center_x) ** 2 # 有可能出现-0.00001的数值,只是一个数值稳定问题。
part_to_be_squared[
(part_to_be_squared < 0) & (abs(part_to_be_squared) < 1e-3)
] = 0 # 强制为0
y_series = center_y - part_to_be_squared ** 0.5
ground_surface_y = ground_surface(x_series)
equal_location = np.abs(ground_surface_y - y_series) < 0.5
r_x = x_series[equal_location][0]
r_y = ground_surface(r_x)
return r_x, r_y