Spills and Bypasses Example
This notebook expands upon the EOPS model to illustrate the use of spills and bypasses in the ltmapi. Spills are used to define where overflow water from a reservoir will end up, and bypasses works as a redirection mechanism around a power plant.
Bypassrepresent a conduit that redirects water around a power plant.Spillrepresent a safety mechanism to divert overflow water.
from IPython.display import HTML, display, display_markdown
import logging
import os
from pyltmapi import LtmSession, LtmDot
from pathlib import Path
from gen_plots import generate_plots
logging.basicConfig(level=logging.WARN)
ltm_core_path = os.environ.get("LTM_CORE_PATH", str(Path("~").expanduser().joinpath("ltm/release/bin/")))
license_file = os.environ.get("LTM_CORE_LICENSE_FILE", str(Path("~").expanduser().joinpath("ltm/ltm-license.dat")))
with LtmSession("ikernel", overwrite_session=True) as session:
session.load(filename="spills_and_bypasses.json")
LtmDot.display_dot_image(session.build_connection_tree())
Implementing bypass/spill in the model is done in the same way as reservoirs and plants.
"bypasses": [
{"name": "Bypass1", ...}
],
"spills": [
{"name": "Spill1", ...}
]Then, one has to define which reservoirs they are connected to.
"connections": [
{
"from": "UpperReservoir",
"to": "Bypass1"
},
{
"from": "Bypass1",
"to": "LowerReservoir1"
},
{
"from": "UpperReservoir",
"to": "Spill1"
},
{
"from": "Spill1",
"to": "LowerReservoir2"
}
]Here are some examples of illegal connections:
Combining objects in an invalid order (e.g., Reservoir → Bypass → Plant).
Connecting multiple objects of the same type (e.g., Reservoir → (2x Bypass) → Plant).
Any upwards connections.
Bellow is an example of a simple hydro system using both bypass and spill. In this example one lower reservoir is used where overflow water from spill and redirected water from bypass is colleceted. The water from the power plant is not defined, meaning it flows to the sea. If the bypass or spill was not connected to a lower reservoir, it would indicate flow to the sea.
from pyltmapi import LtmPlot
with LtmSession(
"ikernel", ltm_core_path=ltm_core_path, overwrite_session=True
) as session:
session.load(filename="spills_and_bypasses.json")
# session.set_execute_callback(usercallback, {})
session.model.global_settings.ltm_license_file_path = license_file
validation = session.validate_model()
write_model = session.write_model()
last_rc, results = session.execute_model()
if last_rc != 0:
err = results[0]["log_file_contents"]
display_markdown(err)
else:
generate_plots(session)busbar: numedal
water values shape: (53, 7, 1, 51)








