可以处理购电和上网两种情况。
This commit is contained in:
@@ -70,8 +70,8 @@ def validate_inputs(
|
||||
raise ValueError("弃风率必须在0.0-1.0之间")
|
||||
if not (0.0 <= params.max_curtailment_solar <= 1.0):
|
||||
raise ValueError("弃光率必须在0.0-1.0之间")
|
||||
if not (0.0 <= params.max_grid_ratio <= 1.0):
|
||||
raise ValueError("上网电量比例必须在0.0-1.0之间")
|
||||
if not (-1.0 <= params.max_grid_ratio <= 1.0):
|
||||
raise ValueError("上网电量比例必须在-1.0到1.0之间(负值表示购电)")
|
||||
if not (0.0 < params.storage_efficiency <= 1.0):
|
||||
raise ValueError("储能效率必须在0.0-1.0之间")
|
||||
if params.discharge_rate <= 0 or params.charge_rate <= 0:
|
||||
@@ -193,6 +193,7 @@ def calculate_energy_balance(
|
||||
else:
|
||||
# 电力不足,优先放电
|
||||
power_deficit = -power_surplus
|
||||
grid_feed_in[hour] = 0 # 初始化购电为0
|
||||
|
||||
max_discharge = min(
|
||||
storage_soc[hour], # 储能状态限制
|
||||
@@ -208,8 +209,19 @@ def calculate_energy_balance(
|
||||
if hour < hours - 1:
|
||||
storage_soc[hour + 1] = storage_soc[hour] - actual_discharge / params.storage_efficiency
|
||||
|
||||
# 剩余缺电(理论上应该为0,否则系统不平衡)
|
||||
# 在实际系统中,这部分可能需要从电网购电或削减负荷
|
||||
# 计算剩余缺电,需要从电网购电
|
||||
remaining_deficit = power_deficit - actual_discharge
|
||||
|
||||
# 如果还有缺电且允许购电,则从电网购电
|
||||
if remaining_deficit > 0:
|
||||
# 检查是否允许购电(max_grid_ratio为负值)
|
||||
if params.max_grid_ratio < 0:
|
||||
# 购电功率为负值,表示从电网输入
|
||||
grid_feed_in[hour] = -remaining_deficit
|
||||
else:
|
||||
# 不允许购电,缺电部分无法满足
|
||||
# 在实际系统中可能需要削减负荷
|
||||
grid_feed_in[hour] = 0 # 不购电
|
||||
|
||||
return {
|
||||
'storage_profile': storage_soc.tolist(),
|
||||
@@ -321,10 +333,17 @@ def optimize_storage_capacity(
|
||||
constraint_results = check_constraints(solar_output, wind_output, thermal_output, balance_result, params)
|
||||
|
||||
# 检查是否满足所有约束
|
||||
# 对于负的max_grid_ratio(购电约束),实际grid_feed_in_ratio应该大于等于约束值
|
||||
grid_constraint_satisfied = (
|
||||
constraint_results['total_grid_feed_in_ratio'] <= params.max_grid_ratio
|
||||
if params.max_grid_ratio >= 0
|
||||
else constraint_results['total_grid_feed_in_ratio'] >= params.max_grid_ratio
|
||||
)
|
||||
|
||||
constraints_satisfied = (
|
||||
constraint_results['total_curtailment_wind_ratio'] <= params.max_curtailment_wind and
|
||||
constraint_results['total_curtailment_solar_ratio'] <= params.max_curtailment_solar and
|
||||
constraint_results['total_grid_feed_in_ratio'] <= params.max_grid_ratio
|
||||
grid_constraint_satisfied
|
||||
)
|
||||
|
||||
# 检查储能日平衡(周期结束时储能状态应接近初始值)
|
||||
@@ -382,9 +401,16 @@ def optimize_storage_capacity(
|
||||
energy_to_storage = total_charge * params.storage_efficiency # 储能消耗的电网能量
|
||||
|
||||
# 能量平衡校验:应该接近0,但允许一定误差
|
||||
energy_balance_error = abs(
|
||||
total_generation + energy_from_storage - total_consumption - energy_to_storage - total_curtailed - total_grid
|
||||
)
|
||||
# 当total_grid为负时(购电),应该加到左侧(供给侧)
|
||||
# 当total_grid为正时(上网),应该加到右侧(需求侧)
|
||||
if total_grid < 0: # 购电情况
|
||||
energy_balance_error = abs(
|
||||
total_generation + energy_from_storage + abs(total_grid) - total_consumption - energy_to_storage - total_curtailed
|
||||
)
|
||||
else: # 上网情况
|
||||
energy_balance_error = abs(
|
||||
total_generation + energy_from_storage - total_consumption - energy_to_storage - total_curtailed - total_grid
|
||||
)
|
||||
# 使用更大的容差,考虑储能效率损失和数值误差
|
||||
# 允许误差为总发电量的15%或10MW,取较大者
|
||||
# 储能效率损失可能达到总能量的10%以上
|
||||
|
||||
Reference in New Issue
Block a user