glorialulu / TSNet

Transient simulation in water networks using MOC method.
MIT License
47 stars 20 forks source link

MOCSimulator: list index out of range #32

Closed schoeller closed 1 month ago

schoeller commented 1 month ago

Description

The following error is thrown

tm = tsnet.simulation.MOCSimulator(tm, results_obj)

File C:\Python312\Lib\site-packages\tsnet\simulation\main.py:291 in MOCSimulator
[H[abs(i)-1][a[np.sign(i)]] for i in links2[pn]],

IndexError: list index out of range

Please find the sample file attached.

What I Did

Programmatically generated an INP-file. Checked with EPANET GUI and tested. Runs flawlessly. Called the same file through

def crunsh_model():
    # Open an example network and create a transient model
    tm = tsnet.network.TransientModel('sample.inp')
    # Set wavespeed
    tm.set_wavespeed(1100.) # m/s
    # Set time options
    dt = 0.1  # time step [s], if not given, use the maximum allowed dt
    tf = 50   # simulation period [s]
    tm.set_time(tf)

    # Set pump shut off
    tc = 4 # pump closure period
    ts = 10 # pump closure start time
    se = 0 # end open percentage
    m = 1 # closure constant
    pump_op = [tc,ts,se,m]
    tm.pump_shut_off('pump1', pump_op)

    # Initialize steady state simulation
    t0 = 0. # initialize the simulation at 0 [s]
    engine = 'DD' # demand driven simulator
    tm = tsnet.simulation.Initializer(tm, t0, engine)

    # Transient simulation
    results_obj = inp_file + '.obj' # name of the object for saving simulation results
    tm = tsnet.simulation.MOCSimulator(tm, results_obj)

sample.zip

schoeller commented 1 month ago

Error seems to originate from a valve being connected to a pump. When inserting a valve the model runs.