Skip to content

Commit

Permalink
Change LV reniforcement
Browse files Browse the repository at this point in the history
  • Loading branch information
birgits committed Oct 22, 2023
1 parent b7886fc commit 43552cf
Showing 1 changed file with 53 additions and 14 deletions.
67 changes: 53 additions & 14 deletions edisgo/flex_opt/reinforce_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ def enhanced_reinforce_grid(
logger.info("Run initial grid reinforcement for single LV grids.")
for lv_grid in list(edisgo_object.topology.mv_grid.lv_grids):
logger.info(f"Check initial convergence for {lv_grid=}.")
_, ts_not_converged = edisgo_object.analyze(
ts_converged, ts_not_converged = edisgo_object.analyze(
mode="lv", raise_not_converged=False, lv_grid_id=lv_grid.id
)
if len(ts_not_converged) > 0:
Expand All @@ -902,12 +902,31 @@ def enhanced_reinforce_grid(
)
try:
logger.info(f"Try initial mode 'lv' reinforcement for {lv_grid=}.")
edisgo_object.reinforce(
mode="lv",
lv_grid_id=lv_grid.id,
catch_convergence_problems=True,
**kwargs,
)
if len(ts_not_converged) > 0:
# if there are time steps that did not converge, run reinforcement
# first on converged time steps
edisgo_object.reinforce(
mode="lv",
lv_grid_id=lv_grid.id,
catch_convergence_problems=False,
timesteps_pfa=ts_converged,
**kwargs,
)
# run reinforcement again in catch-convergence mode with all time steps
edisgo_object.reinforce(
mode="lv",
lv_grid_id=lv_grid.id,
catch_convergence_problems=True,
**kwargs,
)
else:
# if all time steps converged, run normal reinforcement
edisgo_object.reinforce(
mode="lv",
lv_grid_id=lv_grid.id,
catch_convergence_problems=False,
**kwargs,
)
logger.info(f"Initial mode 'lv' reinforcement for {lv_grid} successful.")
except (ValueError, RuntimeError, exceptions.MaximumIterationError):
logger.warning(f"Initial mode 'lv' reinforcement for {lv_grid} failed.")
Expand Down Expand Up @@ -940,7 +959,7 @@ def enhanced_reinforce_grid(

for lv_grid in list(edisgo_object.topology.mv_grid.lv_grids):
logger.info(f"Check convergence for {lv_grid=}.")
_, ts_not_converged = edisgo_object.analyze(
ts_converged, ts_not_converged = edisgo_object.analyze(
mode="lv", raise_not_converged=False, lv_grid_id=lv_grid.id
)
if len(ts_not_converged) > 0:
Expand All @@ -961,12 +980,32 @@ def enhanced_reinforce_grid(
)
try:
logger.info(f"Try mode 'lv' reinforcement for {lv_grid=}.")
edisgo_object.reinforce(
mode="lv",
lv_grid_id=lv_grid.id,
catch_convergence_problems=True,
**kwargs,
)
if len(ts_not_converged) > 0:
# if there are time steps that did not converge, run reinforcement
# first on converged time steps
edisgo_object.reinforce(
mode="lv",
lv_grid_id=lv_grid.id,
catch_convergence_problems=False,
timesteps_pfa=ts_converged,
**kwargs,
)
# run reinforcement again in catch-convergence mode with all time
# steps
edisgo_object.reinforce(
mode="lv",
lv_grid_id=lv_grid.id,
catch_convergence_problems=True,
**kwargs,
)
else:
# if all time steps converged, run normal reinforcement
edisgo_object.reinforce(
mode="lv",
lv_grid_id=lv_grid.id,
catch_convergence_problems=False,
**kwargs,
)
logger.info(f"Mode 'lv' reinforcement for {lv_grid} successful.")
except (ValueError, RuntimeError, exceptions.MaximumIterationError):
logger.info(f"Mode 'lv' reinforcement for {lv_grid} failed.")
Expand Down

0 comments on commit 43552cf

Please sign in to comment.