Files
multi_energy_complementarity/example_usage.py
2025-12-25 18:06:12 +08:00

230 lines
8.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
多能互补系统储能容量优化计算程序使用示例
该文件展示了如何使用储能优化程序处理不同的实际场景。
作者: iFlow CLI
创建日期: 2025-12-25
"""
import numpy as np
import matplotlib.pyplot as plt
from storage_optimization import optimize_storage_capacity, SystemParameters
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 '未通过'}")
return result
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 '未通过'}")
return result
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 '未通过'}")
return result
def plot_results(result, title):
"""绘制结果图表"""
hours = list(range(24))
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(15, 10))
fig.suptitle(title, fontsize=16)
# 储能状态
ax1.plot(hours, result['storage_profile'], 'b-', linewidth=2)
ax1.set_title('储能状态 (MWh)')
ax1.set_xlabel('时间 (小时)')
ax1.set_ylabel('储能容量 (MWh)')
ax1.grid(True)
# 充放电功率
ax2.plot(hours, result['charge_profile'], 'g-', label='充电', linewidth=2)
ax2.plot(hours, [-p for p in result['discharge_profile']], 'r-', label='放电', linewidth=2)
ax2.set_title('储能充放电功率 (MW)')
ax2.set_xlabel('时间 (小时)')
ax2.set_ylabel('功率 (MW)')
ax2.legend()
ax2.grid(True)
# 弃风弃光
ax3.plot(hours, result['curtailed_wind'], 'c-', label='弃风', linewidth=2)
ax3.plot(hours, result['curtailed_solar'], 'm-', label='弃光', linewidth=2)
ax3.set_title('弃风弃光量 (MW)')
ax3.set_xlabel('时间 (小时)')
ax3.set_ylabel('功率 (MW)')
ax3.legend()
ax3.grid(True)
# 上网电量
ax4.plot(hours, result['grid_feed_in'], 'orange', linewidth=2)
ax4.set_title('上网电量 (MW)')
ax4.set_xlabel('时间 (小时)')
ax4.set_ylabel('功率 (MW)')
ax4.grid(True)
plt.tight_layout()
plt.show()
def compare_scenarios():
"""比较不同场景的结果"""
print("\n=== 场景比较 ===")
# 运行三个场景
result1 = example_1_basic_scenario()
result2 = example_2_high_renewable_scenario()
result3 = example_3_winter_scenario()
# 比较结果
scenarios = ['基础场景', '高可再生能源场景', '冬季场景']
storage_capacities = [
result1['required_storage_capacity'],
result2['required_storage_capacity'],
result3['required_storage_capacity']
]
curtailment_wind = [
result1['total_curtailment_wind_ratio'],
result2['total_curtailment_wind_ratio'],
result3['total_curtailment_wind_ratio']
]
curtailment_solar = [
result1['total_curtailment_solar_ratio'],
result2['total_curtailment_solar_ratio'],
result3['total_curtailment_solar_ratio']
]
grid_feed_in = [
result1['total_grid_feed_in_ratio'],
result2['total_grid_feed_in_ratio'],
result3['total_grid_feed_in_ratio']
]
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}")
return result1, result2, result3
if __name__ == "__main__":
print("多能互补系统储能容量优化计算程序示例")
print("=" * 50)
# 运行示例
result1, result2, result3 = compare_scenarios()
# 绘制图表如果matplotlib可用
try:
plot_results(result1, "基础场景储能运行情况")
plot_results(result2, "高可再生能源场景储能运行情况")
plot_results(result3, "冬季场景储能运行情况")
except ImportError:
print("\n注意: matplotlib未安装无法绘制图表")
print("要安装matplotlib请运行: pip install matplotlib")
print("\n示例运行完成!")