Getting Started¶
To use tsnet in a project, open a Python console and import the package:
import tsnet
Simple example¶
A simple example, Tnet1_valve_closure.py is included in the examples folder. This example demonstrates how to:
- Import tsnet
- Generate a transient model
- Set wave speed
- Set time step and simulation period
- Perform initial condition calculation
- Define valve closure rule
- Run transient simulation and save results to .obj file
- Plot simulation results
# Open an example network and create a transient model
tm = tsnet.network.TransientModel('/Users/luxing/Code/TSNet/examples/networks/Tnet1.inp')
# Set wavespeed
tm.set_wavespeed(1200.) # m/s
# Set time options
tf = 20 # simulation period [s]
tm.set_time(tf)
# Set valve closure
ts = 5 # valve closure start time [s]
tc = 1 # valve closure period [s]
se = 0 # end open percentage [s]
m = 2 # closure constant [dimensionless]
tm.valve_closure('VALVE',[tc,ts,se,m])
# Initialize steady state simulation
t0=0
tm = tsnet.simulation.Initializer(tm,t0)
# Transient simulation
tm = tsnet.simulation.MOCSimulator(tm)
# report results
node = ['N2','N3']
tm.plot_node_head(node)
Three additional EPANET INP files and example files are also included in the TSNet examples repository in the examples folder. Example networks range from a simple 8-node network to a 126-node network.