Files
multi_energy_complementarity/example_usage.py

298 lines
12 KiB
Python
Raw Normal View History

2025-12-25 18:06:12 +08:00
"""
多能互补系统储能容量优化计算程序使用示例
该文件展示了如何使用储能优化程序处理不同的实际场景
作者: iFlow CLI
创建日期: 2025-12-25
"""
import numpy as np
import matplotlib.pyplot as plt
from storage_optimization import optimize_storage_capacity, SystemParameters
2025-12-25 21:05:53 +08:00
# 配置matplotlib支持中文显示
plt.rcParams['font.sans-serif'] = ['SimHei', 'Microsoft YaHei', 'DejaVu Sans']
plt.rcParams['axes.unicode_minus'] = False # 解决负号显示问题
2025-12-25 18:06:12 +08:00
def example_1_basic_scenario():
"""示例1: 基础场景"""
print("=== 示例1: 基础场景 ===")
# 基础数据 - 夏日典型日
solar_output = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 2.0, 4.0, 6.0, 8.0, 9.0,
8.0, 6.0, 4.0, 2.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
wind_output = [4.0, 4.5, 5.0, 5.5, 5.0, 4.5, 4.0, 3.5, 3.0, 2.5, 2.0, 1.5,
1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 5.0, 4.5, 4.0]
thermal_output = [8.0] * 24 # 火电基荷
load_demand = [6.0, 5.5, 5.0, 5.0, 5.5, 7.0, 9.0, 12.0, 15.0, 18.0, 20.0, 19.0,
18.0, 17.0, 16.0, 15.0, 14.0, 13.0, 12.0, 10.0, 8.0, 7.0, 6.0, 6.0]
# 系统参数
params = SystemParameters(
max_curtailment_wind=0.1, # 最大弃风率10%
max_curtailment_solar=0.05, # 最大弃光率5%
max_grid_ratio=0.15, # 最大上网电量比例15%
storage_efficiency=0.9, # 储能效率90%
discharge_rate=1.0, # 1C放电
charge_rate=1.0 # 1C充电
)
# 计算最优储能容量
result = optimize_storage_capacity(solar_output, wind_output, thermal_output, load_demand, params)
# 打印结果
print(f"所需储能容量: {result['required_storage_capacity']:.2f} MWh")
print(f"实际弃风率: {result['total_curtailment_wind_ratio']:.3f} (约束: {params.max_curtailment_wind})")
print(f"实际弃光率: {result['total_curtailment_solar_ratio']:.3f} (约束: {params.max_curtailment_solar})")
print(f"实际上网电量比例: {result['total_grid_feed_in_ratio']:.3f} (约束: {params.max_grid_ratio})")
print(f"能量平衡校验: {'通过' if result['energy_balance_check'] else '未通过'}")
2025-12-25 21:05:53 +08:00
return {
'result': result,
'solar_output': solar_output,
'wind_output': wind_output,
'thermal_output': thermal_output,
'load_demand': load_demand
}
2025-12-25 18:06:12 +08:00
def example_2_high_renewable_scenario():
"""示例2: 高可再生能源渗透场景"""
print("\n=== 示例2: 高可再生能源渗透场景 ===")
# 高可再生能源数据
solar_output = [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 3.0, 6.0, 10.0, 14.0, 18.0, 20.0,
18.0, 14.0, 10.0, 6.0, 3.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
wind_output = [8.0, 9.0, 10.0, 11.0, 10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0,
3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 10.0, 9.0, 8.0]
thermal_output = [4.0] * 24 # 较低的火电基荷
load_demand = [8.0, 7.5, 7.0, 7.0, 7.5, 9.0, 11.0, 14.0, 17.0, 20.0, 22.0, 21.0,
20.0, 19.0, 18.0, 17.0, 16.0, 15.0, 14.0, 12.0, 10.0, 9.0, 8.0, 8.0]
# 系统参数 - 较高的弃风弃光容忍度
params = SystemParameters(
max_curtailment_wind=0.2, # 最大弃风率20%
max_curtailment_solar=0.15, # 最大弃光率15%
max_grid_ratio=0.25, # 最大上网电量比例25%
storage_efficiency=0.85, # 较低的储能效率
discharge_rate=1.0,
charge_rate=1.0
)
result = optimize_storage_capacity(solar_output, wind_output, thermal_output, load_demand, params)
print(f"所需储能容量: {result['required_storage_capacity']:.2f} MWh")
print(f"实际弃风率: {result['total_curtailment_wind_ratio']:.3f}")
print(f"实际弃光率: {result['total_curtailment_solar_ratio']:.3f}")
print(f"实际上网电量比例: {result['total_grid_feed_in_ratio']:.3f}")
print(f"能量平衡校验: {'通过' if result['energy_balance_check'] else '未通过'}")
2025-12-25 21:05:53 +08:00
return {
'result': result,
'solar_output': solar_output,
'wind_output': wind_output,
'thermal_output': thermal_output,
'load_demand': load_demand
}
2025-12-25 18:06:12 +08:00
def example_3_winter_scenario():
"""示例3: 冬季场景"""
print("\n=== 示例3: 冬季场景 ===")
# 冬季数据 - 光照弱,风电强,负荷高
solar_output = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2, 0.8, 1.5, 2.0, 2.5, 2.8,
2.5, 2.0, 1.5, 0.8, 0.2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
wind_output = [12.0, 13.0, 14.0, 15.0, 14.0, 13.0, 12.0, 11.0, 10.0, 9.0, 8.0, 7.0,
7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 14.0, 13.0, 12.0]
thermal_output = [12.0] * 24 # 高火电基荷
load_demand = [12.0, 11.5, 11.0, 11.0, 11.5, 13.0, 15.0, 18.0, 21.0, 24.0, 26.0, 25.0,
24.0, 23.0, 22.0, 21.0, 20.0, 19.0, 18.0, 16.0, 14.0, 13.0, 12.0, 12.0]
# 系统参数 - 严格的弃风弃光控制
params = SystemParameters(
max_curtailment_wind=0.05, # 严格的弃风控制
max_curtailment_solar=0.02, # 严格的弃光控制
max_grid_ratio=0.1, # 低上网电量比例
storage_efficiency=0.92, # 高储能效率
discharge_rate=1.0,
charge_rate=1.0
)
result = optimize_storage_capacity(solar_output, wind_output, thermal_output, load_demand, params)
print(f"所需储能容量: {result['required_storage_capacity']:.2f} MWh")
print(f"实际弃风率: {result['total_curtailment_wind_ratio']:.3f}")
print(f"实际弃光率: {result['total_curtailment_solar_ratio']:.3f}")
print(f"实际上网电量比例: {result['total_grid_feed_in_ratio']:.3f}")
print(f"能量平衡校验: {'通过' if result['energy_balance_check'] else '未通过'}")
2025-12-25 21:05:53 +08:00
return {
'result': result,
'solar_output': solar_output,
'wind_output': wind_output,
'thermal_output': thermal_output,
'load_demand': load_demand
}
2025-12-25 18:06:12 +08:00
2025-12-25 21:05:53 +08:00
def plot_results(result, title, solar_output, wind_output, thermal_output, load_demand):
2025-12-25 18:06:12 +08:00
"""绘制结果图表"""
hours = list(range(24))
2025-12-25 21:05:53 +08:00
fig, ((ax1, ax2), (ax3, ax4), (ax5, ax6)) = plt.subplots(3, 2, figsize=(16, 12))
2025-12-25 18:06:12 +08:00
fig.suptitle(title, fontsize=16)
2025-12-25 21:05:53 +08:00
# 发电与负荷对比
ax1.plot(hours, load_demand, 'r-', linewidth=2, label='负荷需求')
ax1.plot(hours, thermal_output, 'b-', linewidth=2, label='火电出力')
ax1.plot(hours, wind_output, 'g-', linewidth=2, label='风电出力')
ax1.plot(hours, solar_output, 'orange', linewidth=2, label='光伏出力')
# 计算总发电量
total_generation = [thermal_output[i] + wind_output[i] + solar_output[i] for i in range(24)]
ax1.plot(hours, total_generation, 'k--', linewidth=1.5, alpha=0.7, label='总发电量')
ax1.set_title('发电与负荷曲线')
2025-12-25 18:06:12 +08:00
ax1.set_xlabel('时间 (小时)')
2025-12-25 21:05:53 +08:00
ax1.set_ylabel('功率 (MW)')
ax1.legend()
2025-12-25 18:06:12 +08:00
ax1.grid(True)
2025-12-25 21:05:53 +08:00
# 储能状态
ax2.plot(hours, result['storage_profile'], 'b-', linewidth=2)
ax2.set_title('储能状态 (MWh)')
2025-12-25 18:06:12 +08:00
ax2.set_xlabel('时间 (小时)')
2025-12-25 21:05:53 +08:00
ax2.set_ylabel('储能容量 (MWh)')
2025-12-25 18:06:12 +08:00
ax2.grid(True)
2025-12-25 21:05:53 +08:00
# 充放电功率
ax3.plot(hours, result['charge_profile'], 'g-', label='充电', linewidth=2)
ax3.plot(hours, [-p for p in result['discharge_profile']], 'r-', label='放电', linewidth=2)
ax3.set_title('储能充放电功率 (MW)')
2025-12-25 18:06:12 +08:00
ax3.set_xlabel('时间 (小时)')
ax3.set_ylabel('功率 (MW)')
ax3.legend()
ax3.grid(True)
2025-12-25 21:05:53 +08:00
# 弃风弃光
ax4.plot(hours, result['curtailed_wind'], 'c-', label='弃风', linewidth=2)
ax4.plot(hours, result['curtailed_solar'], 'm-', label='弃光', linewidth=2)
ax4.set_title('弃风弃光量 (MW)')
2025-12-25 18:06:12 +08:00
ax4.set_xlabel('时间 (小时)')
ax4.set_ylabel('功率 (MW)')
2025-12-25 21:05:53 +08:00
ax4.legend()
2025-12-25 18:06:12 +08:00
ax4.grid(True)
2025-12-25 21:05:53 +08:00
# 上网电量
ax5.plot(hours, result['grid_feed_in'], 'orange', linewidth=2)
ax5.set_title('上网电量 (MW)')
ax5.set_xlabel('时间 (小时)')
ax5.set_ylabel('功率 (MW)')
ax5.grid(True)
# 能量平衡分析
total_gen = sum(thermal_output) + sum(wind_output) + sum(solar_output)
total_load = sum(load_demand)
total_curtailed = sum(result['curtailed_wind']) + sum(result['curtailed_solar'])
total_grid = sum(result['grid_feed_in'])
total_charge = sum(result['charge_profile'])
total_discharge = sum(result['discharge_profile'])
# 创建能量平衡柱状图
categories = ['总发电量', '总负荷', '弃风弃光', '上网电量', '储能充电', '储能放电']
values = [total_gen, total_load, total_curtailed, total_grid, total_charge, total_discharge]
colors = ['blue', 'red', 'orange', 'green', 'cyan', 'magenta']
bars = ax6.bar(categories, values, color=colors, alpha=0.7)
ax6.set_title('能量平衡分析')
ax6.set_ylabel('能量 (MWh)')
ax6.grid(True, axis='y', alpha=0.3)
# 在柱状图上添加数值标签
for bar, value in zip(bars, values):
height = bar.get_height()
ax6.text(bar.get_x() + bar.get_width()/2., height,
f'{value:.1f}', ha='center', va='bottom', fontsize=9)
2025-12-25 18:06:12 +08:00
plt.tight_layout()
plt.show()
def compare_scenarios():
"""比较不同场景的结果"""
print("\n=== 场景比较 ===")
# 运行三个场景
2025-12-25 21:05:53 +08:00
data1 = example_1_basic_scenario()
data2 = example_2_high_renewable_scenario()
data3 = example_3_winter_scenario()
2025-12-25 18:06:12 +08:00
# 比较结果
scenarios = ['基础场景', '高可再生能源场景', '冬季场景']
storage_capacities = [
2025-12-25 21:05:53 +08:00
data1['result']['required_storage_capacity'],
data2['result']['required_storage_capacity'],
data3['result']['required_storage_capacity']
2025-12-25 18:06:12 +08:00
]
curtailment_wind = [
2025-12-25 21:05:53 +08:00
data1['result']['total_curtailment_wind_ratio'],
data2['result']['total_curtailment_wind_ratio'],
data3['result']['total_curtailment_wind_ratio']
2025-12-25 18:06:12 +08:00
]
curtailment_solar = [
2025-12-25 21:05:53 +08:00
data1['result']['total_curtailment_solar_ratio'],
data2['result']['total_curtailment_solar_ratio'],
data3['result']['total_curtailment_solar_ratio']
2025-12-25 18:06:12 +08:00
]
grid_feed_in = [
2025-12-25 21:05:53 +08:00
data1['result']['total_grid_feed_in_ratio'],
data2['result']['total_grid_feed_in_ratio'],
data3['result']['total_grid_feed_in_ratio']
2025-12-25 18:06:12 +08:00
]
print("\n场景比较结果:")
print(f"{'场景':<15} {'储能容量(MWh)':<12} {'弃风率':<8} {'弃光率':<8} {'上网比例':<8}")
print("-" * 55)
for i, scenario in enumerate(scenarios):
print(f"{scenario:<15} {storage_capacities[i]:<12.2f} {curtailment_wind[i]:<8.3f} "
f"{curtailment_solar[i]:<8.3f} {grid_feed_in[i]:<8.3f}")
2025-12-25 21:05:53 +08:00
return data1, data2, data3
2025-12-25 18:06:12 +08:00
if __name__ == "__main__":
print("多能互补系统储能容量优化计算程序示例")
print("=" * 50)
# 运行示例
2025-12-25 21:05:53 +08:00
data1, data2, data3 = compare_scenarios()
2025-12-25 18:06:12 +08:00
# 绘制图表如果matplotlib可用
try:
2025-12-25 21:05:53 +08:00
plot_results(data1['result'], "基础场景储能运行情况",
data1['solar_output'], data1['wind_output'],
data1['thermal_output'], data1['load_demand'])
plot_results(data2['result'], "高可再生能源场景储能运行情况",
data2['solar_output'], data2['wind_output'],
data2['thermal_output'], data2['load_demand'])
plot_results(data3['result'], "冬季场景储能运行情况",
data3['solar_output'], data3['wind_output'],
data3['thermal_output'], data3['load_demand'])
2025-12-25 18:06:12 +08:00
except ImportError:
print("\n注意: matplotlib未安装无法绘制图表")
print("要安装matplotlib请运行: pip install matplotlib")
print("\n示例运行完成!")