fix: 修正损耗计算单位从瓦特(W)转换为千瓦(kW)

- 将evaluate_design函数中的损耗计算结果从W转换为kW
- loss_w变量存储三相损耗(W),loss_kw转换为kW后累加
- 确保total_loss返回值单位为kW,与后续经济性分析计算一致
This commit is contained in:
dmy
2026-01-07 10:01:32 +08:00
parent 45c99b41b3
commit 7aef58de1e

31
main.py
View File

@@ -858,8 +858,9 @@ def evaluate_design(
total_cost += cable["cost"] total_cost += cable["cost"]
# 计算I²R损耗 (简化版) # 计算I²R损耗 (简化版)
loss = (cable["current"] ** 2) * cable["resistance"] * 3 # 三相 loss_w = (cable["current"] ** 2) * cable["resistance"] * 3 # 三相单位W
total_loss += loss loss_kw = loss_w / 1000 # 转换为 kW
total_loss += loss_kw
return { return {
"total_cost": total_cost, "total_cost": total_cost,
@@ -1551,7 +1552,7 @@ def compare_design_methods(
if comparison_results: if comparison_results:
# 计算每个方案的总费用(净现值) # 计算每个方案的总费用(净现值)
comparison_results = total_investment(comparison_results, system_params) comparison_results = total_investment(comparison_results, system_params)
export_all_scenarios_to_excel(comparison_results, excel_out_filename) export_all_scenarios_to_excel(comparison_results, excel_out_filename)
if not interactive: if not interactive:
@@ -1680,21 +1681,23 @@ def total_investment(results, system_params):
更新后的results列表每个结果新增 'total_cost_npv' 字段(总费用净现值,元) 更新后的results列表每个结果新增 'total_cost_npv' 字段(总费用净现值,元)
""" """
# 获取系统参数,使用默认值 # 获取系统参数,使用默认值
discount_rate_percent = system_params.get('discount_rate', DISCOUNT_RATE) discount_rate_percent = system_params.get("discount_rate", DISCOUNT_RATE)
electricity_price = system_params.get('electricity_price', ELECTRICITY_PRICE) electricity_price = system_params.get("electricity_price", ELECTRICITY_PRICE)
project_lifetime = system_params.get('project_lifetime', PROJECT_LIFETIME) project_lifetime = system_params.get("project_lifetime", PROJECT_LIFETIME)
annual_loss_hours = system_params.get('annual_loss_hours', ANNUAL_LOSS_HOURS) annual_loss_hours = system_params.get("annual_loss_hours", ANNUAL_LOSS_HOURS)
# 将折现率转换为小数 # 将折现率转换为小数
r = discount_rate_percent / 100.0 r = discount_rate_percent / 100.0
for result in results: for result in results:
cable_cost = result['cost'] # 电缆总投资(元) cable_cost = result["cost"] # 电缆总投资(元)
loss_power = result['loss'] # 线损功率kW loss_power = result["loss"] # 线损功率kW
# 1. 计算电缆投资的净现值2年分期 # 1. 计算电缆投资的净现值2年分期
# 第1年支付50%第2年支付50% # 第1年支付50%第2年支付50%
npv_cable = (cable_cost * 0.5) / ((1 + r) ** 1) + (cable_cost * 0.5) / ((1 + r) ** 2) npv_cable = (cable_cost * 0.5) / ((1 + r) ** 1) + (cable_cost * 0.5) / (
(1 + r) ** 2
)
# 2. 计算电费损耗的净现值(生命周期内) # 2. 计算电费损耗的净现值(生命周期内)
# 年损耗费用 = 损耗功率(kW) * 年损耗小时数 * 电价(元/kWh) # 年损耗费用 = 损耗功率(kW) * 年损耗小时数 * 电价(元/kWh)
@@ -1713,10 +1716,10 @@ def total_investment(results, system_params):
total_cost_npv = npv_cable + npv_loss total_cost_npv = npv_cable + npv_loss
# 将结果添加到字典中 # 将结果添加到字典中
result['total_cost_npv'] = total_cost_npv result["total_cost_npv"] = total_cost_npv
result['npv_cable'] = npv_cable result["npv_cable"] = npv_cable
result['npv_loss'] = npv_loss result["npv_loss"] = npv_loss
result['annual_loss_cost'] = annual_loss_cost result["annual_loss_cost"] = annual_loss_cost
return results return results