Coder Social home page Coder Social logo

tsnet's People

Contributors

glorialulu avatar linasela avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tsnet's Issues

Differences between hammer and Simulation in tsnet

  • tsnet version: 0.2.2
  • Python version: 3.7
  • Operating System: win10

Description

Hello, the pipe network system is not operated. Why is the node head getting lower and lower in the simulation?

I simulated in hammer, and the node pressure did not change. Why?

The following two figures are the pressure changes of node 46 in transient simulation

in tsnet:
image

in HAMMER:
image

What I Did


Why is this

Initial simulation time (seconds)

Could you confirm the meaning of the initial simulation time (t0) in the code snippet below:

# Initialize steady state simulation
t0 = 0. # initialize the simulation at 0s
engine = 'DD' # or PPD
tm = tsnet.simulation.Initializer(tm, t0, engine)

By looking into the code, it seems t0 must be an integer time of EPANET reporting step. For example, if the reporting time step is 30 minutes, this initial time t0 can be 0, 1800, 3600, 5400, etc.

Thanks,

Hailiang

Default valve opening when initial status is closed

Does the transient simulator default to every valve opening at t=0? I'm finding that if I omit the line that defines the valve opening:

tm.valve_opening('valve',[tc,ts,se,m])

then the valve opens at t=0, even when I explicitly define the network with the valve initial_status='Closed'. I'm expecting that if I omit the valve opening, then the valve should never open and the pressure should remain constant and flow-rate nearly zero.
I do find that if I set the valve opening to start at a time after the end of the simulation, then the valve never opens (as expected) and the solution is constant for pressure and nearly zero for flow-rate. When I do this workaround, I see a small nonzero flow-rate for a brief period of time, about 0.5 sec, at the beginning of the simulation. Perhaps this is just numerical noise?

Originally posted by @Nathan-Becker in #4 (comment)

How to increase the maximum timestep while extracting velocity information every few meters over a large network.

  • tsnet version:
  • Python version:
  • Operating System:

Description

Dear Lu, et all. Me and Amine are attempting to model one of the local villages in Swiss (Verbier) networks with the software. The problem is as some of the pipes are quite short the maximum time step for our case is really really low - 0.00001. We as well wish to extract dynamics (velocities) through the length of the pipe. Thus we did naively by discretizing each longer pipe on many smaller pipes with nodes and using the nodes to extract velocities (as we want to study how the velocities propagate through the length of the pipe). Do you know how we can solve this time-step challenge? At the end of the day, the dynamics we will observe will be in the second's margin so 0.1 timestep for what we want to study is already enough we thought. Not sure how to make it less computationally intensive and if there is a smarter way than brute force and giant datasets?

Thanks a lot for your kind help and advice!

Iordan Doytchinov, Ph.D.

Postdoctoral researcher and scientific collaborator

Ecole Polytechnique Fédérale de Lausanne (EPFL)
EPFL – TOPO
Station 18 – Bâtiment GC C2 398

CH–1015 Lausanne

Office telephone: +41216939832
Personal mobile: +33699850592

[email protected]
http://topo.epfl.ch/

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

valve setting parameter not used as expected

(I posted this earlier, but I think it was mixed up with other issues. Reposting separately.)

The setting parameter of the FCV valve doesn't seem to be used by the transient simulation. I was expecting that if I set a FCV valve to a particular setting then the flow-rate should match it.

The following test code might be revealing. There are two parameter settings at the top: valve_setting_gpm and initial_status_active. I looked at 2 cases:

If I set initial_status_active=True, then I think that is consistent with the EPANET manual's claim that the valve is allowed to operate via control messages. In that case, if I run the below script to the end, it prints out the initial flow-rate, and it is consistent with the valve_settting_gpm value. However, the final flow-rate (after the valve opens and reaches steady state) is not consistent with the valve_setting_gpm. And, there is some noisy ringing at the beginning of the transient simulation (shown in the plots that are generated). Maybe this ringing is caused by some sort of inconsistency between EPANET valve initial condition (which seems to respect the valve_setting parameter) and the transient simulator?
If I set initial_status_active=False, then the valve is forced closed at the beginning. The noisy ringing goes away, and the plots look qualitatively plausible. However, the valve_setting_gpm seems to have no effect on the steady-state flow-rate. I expected the steady-state flow-rate to match the valve_setting_gpm if the pump can support it.

# Define test-case options
valve_setting_gpm = 2.56
initial_status_active = True

# Initialize
import matplotlib
matplotlib.use('agg')
from matplotlib import pyplot as plt
import numpy
import pandas
import wntr
import tsnet


def gpm_to_m3s(gpm):
    return gpm/(60*264.172)

def m3s_to_gpm(m3s):
    return m3s*(60*264.172)

def m_to_psi(m):
    return m*1.4219702063247

def psi_to_m(psi):
    return psi/1.4219702063247

# New network
wn = wntr.network.WaterNetworkModel()

# Add water source --> reservoir at atmos, with a pump to get significant pressure
wn.add_reservoir('res', base_head=0)
wn.add_junction('in')
wn.add_pipe('source', start_node_name='res', end_node_name='in', length=40, diameter=0.03175)
wn.add_junction('pumpjunc')
pumpcurve = []
pumpcurve.append((gpm_to_m3s(0),psi_to_m(60)))
pumpcurve.append((gpm_to_m3s(5),psi_to_m(45)))
pumpcurve.append((gpm_to_m3s(10),psi_to_m(25)))
wn.add_curve('pumpcurve', 'HEAD', pumpcurve)
wn.add_pump(name='supply', start_node_name='in', end_node_name='pumpjunc', pump_type='HEAD', pump_parameter='pumpcurve')

# Add reference point junction 'ref'
wn.add_junction('ref')
wn.add_pipe('to_ref', start_node_name='pumpjunc', end_node_name='ref', length=10, diameter=0.03175)

# Add valve
wn.add_junction('before_valve1')
wn.add_pipe('to_valve1', start_node_name='ref', end_node_name='before_valve1', length=25, diameter=0.03175)
wn.add_junction('after_valve1')
wn.add_valve('valve1', start_node_name='before_valve1', end_node_name='after_valve1', valve_type='FCV', setting=gpm_to_m3s(valve_setting_gpm))
if initial_status_active:
    wn.get_link('valve1').initial_status = wntr.network.elements.LinkStatus.Active
else:
    wn.get_link('valve1').initial_status = wntr.network.elements.LinkStatus.Closed
wn.add_reservoir('atmos1', base_head=psi_to_m(0))
wn.add_pipe('out1', start_node_name='after_valve1', end_node_name='atmos1', length=15, diameter=0.03175/3)

# Prep plotting
fig = plt.figure(figsize=(8,5), dpi=80, facecolor='w', edgecolor='k')

# Build EPANET file
wn.write_inpfile('simp.inp')

# Construct transient model 
tm = tsnet.network.TransientModel('simp.inp')
tm.set_wavespeed(1200.) # m/s
tm.set_time(3) # simulation period [s]

# Set valve opening 
tc = 0.2 # valve opening period [s]
ts = 1 # valve opening start time [s]
se = 1 # end open percentage [s]
m = 1 # open constant [dimensionless]
tm.valve_opening('valve1',[tc,ts,se,m])

# Initialize and run simulation
tm = tsnet.simulation.Initializer(tm, 0, 'DD')
tm = tsnet.simulation.MOCSimulator(tm, 'simpres', 'unsteady')

# Gather results
t = tm.simulation_timestamps
ref_flow_rate = tm.get_link('to_ref').end_node_flowrate

# Prep plotting
fig = plt.figure(figsize=(8,5), dpi=80, facecolor='w', edgecolor='k')

# Plot flow-rates
plt.plot(t, m3s_to_gpm(ref_flow_rate), label='ref', linewidth=1.5)
plt.plot(t, m3s_to_gpm(tm.get_link('out1').end_node_flowrate), label='output1', linewidth=1.5)
plt.ylabel("flow-rate [gpm]")
plt.xlim([t[0],t[-1]])
plt.xlabel("Time [s]")
plt.legend(loc='best')
plt.draw()
plt.savefig('flowrate.png')

# Plot pressure
plt.clf()
plt.plot(t, m_to_psi(tm.get_node('ref').head), 'k', label='ref', linewidth=1.5)
plt.plot(t, m_to_psi(tm.get_node('after_valve1').head), label='output1', linewidth=1.5)
plt.ylabel("Pressure [PSI]")
plt.xlim([t[0],t[-1]])
plt.xlabel("Time [s]")
plt.legend(loc='best')
plt.draw()
plt.savefig('pressure.png')

print('Initial ref flow rate={}'.format(m3s_to_gpm(ref_flow_rate[0])))
print('Final ref flow rate={}'.format(m3s_to_gpm(ref_flow_rate[-1])))

Issue with the initial steady state simulation

  • tsnet version: 0.1.0
  • Python version: 3.7.3
  • Operating System: Ubuntu 19.04

Description

Trying to run a single pipe model created in EPANET2,
Reservoir - Pipe - Junction (with Demand)

What I Did

Isn't able to solve the initial conditions. From exploring things it looks like it is an issue with the WNTR solver. If I use wntr.sim.EpanetSimulator I can get steady state results.

Suggest reinstating the option of using the WNTR.EpanetSimulator as a steady state option

Code
#Open an example network and create a transient model
inp_file = 'Projects/SinglePipe/SinglePipe.inp'
tm = tsnet.network.TransientModel(inp_file)

Set wavespeed

tm.set_wavespeed(100.) # m/s

Set time options

tf = 60 # simulation period [s]
tm.set_time(tf)

Initialize steady state simulation

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

Output
Simulation time step 5.00000 s
Total Time Step in this simulation 12
/usr/local/lib/python3.7/dist-packages/tsnet-0.1.0-py3.7.egg/tsnet/simulation/initialize.py:176: RuntimeWarning:

invalid value encountered in sqrt

/usr/local/lib/python3.7/dist-packages/tsnet-0.1.0-py3.7.egg/tsnet/simulation/initialize.py:130: RuntimeWarning:

invalid value encountered in sqrt

/usr/local/lib/python3.7/dist-packages/tsnet-0.1.0-py3.7.egg/tsnet/simulation/initialize.py:131: RuntimeWarning:

invalid value encountered in sqrt

/usr/local/lib/python3.7/dist-packages/tsnet-0.1.0-py3.7.egg/tsnet/simulation/initialize.py:213: UserWarning:

1 :the friction coefficient 9582331419.0118 is too large. The D-W coeff has been set to 0.03

AttributeError: can't set attribute

  • tsnet version: 0.2.2
  • Python version: python3.9
  • Operating System: Mac OS BigSur

Description


AttributeError Traceback (most recent call last)
/var/folders/zc/l6fqnfjd14sg421vzg4ys2900000gn/T/ipykernel_9351/3006219835.py in
----> 1 tm = tsnet.network.TransientModel(inp_file)

~/opt/anaconda3/lib/python3.9/site-packages/tsnet/network/model.py in init(self, inp_file)
57 for _, node in self.nodes():
58 node.id = i
---> 59 node.leak_status = False
60 node.burst_status = False
61 node.blockage_status = False

AttributeError: can't set attribute

What I Did

I tried to run the example but unable to load the .inp file. Getting AttributeError

import tsnet
inp_file = 'Network/Tnet1.inp'
tm = tsnet.network.TransientModel(inp_file)

valve warnings and pump instability

  • tsnet version: latest master
  • Python version: 3.7.4
  • Operating System: Mac OSX

Description

I'm trying to model transients after opening a valve with flow being driven by a pump.

The code below seems to work and give plausible results. However, I have a few issues:

  1. Even though I tried to set the valve status to LinkStatus.Closed in 2 places, I still get a warning that says, "model.py:318: UserWarning: Valve valve is already open in its initial setting. The initial setting has been changed to closed to perform the opening." How do I properly initialize the valve to closed at the start? Also, can you explain what the valve 'setting' parameter does? I haven't been able to find any documentation on that.

  2. I would like to be able to adjust the maximum pressure from the pump. But I find that almost any adjustment of the pump curves gives totally crazy results. For example, if I change the first point in the curve to psi_to_m(41) instead of psi_to_m(40), the outputs from the simulation blow up. How can I stabilize this?

What I Did

Here is the code

import matplotlib
matplotlib.use('agg')
from matplotlib import pyplot as plt
import wntr
import tsnet


def gpm_to_m3s(gpm):
    return gpm/(60*264.172)

def m3s_to_gpm(m3s):
    return m3s*(60*264.172)

def m_to_psi(m):
    return m*1.4219702063247

def psi_to_m(psi):
    return psi/1.4219702063247


# New network
wn = wntr.network.WaterNetworkModel()

# Add components
wn.add_reservoir('res', base_head=0, coordinates=(-100,0))
wn.add_junction('in', coordinates=(-20,0))
wn.add_pipe('source', start_node_name='res', end_node_name='in', length=80, diameter=0.03175*2)
wn.add_junction('ref', coordinates=(0,0))
pumpcurve = []
pumpcurve.append((gpm_to_m3s(0),psi_to_m(40)))
pumpcurve.append((gpm_to_m3s(1),psi_to_m(30)))
pumpcurve.append((gpm_to_m3s(2),psi_to_m(20)))
wn.add_curve('pumpcurve', 'HEAD', pumpcurve)
wn.add_pump(name='supply', start_node_name='in', end_node_name='ref', pump_type='HEAD', pump_parameter='pumpcurve')
wn.add_reservoir('atmos', base_head=psi_to_m(0), coordinates=(40,0))
wn.add_junction('before_valve', coordinates=(20,0))
wn.add_pipe('to_valve', start_node_name='ref', end_node_name='before_valve', length=100, diameter=0.03175)
wn.add_junction('after_valve', base_demand=0, coordinates=(20,0))
wn.add_valve('valve', start_node_name='before_valve', end_node_name='after_valve', valve_type='FCV', setting=0)
wn.get_link('valve').status = wntr.network.elements.LinkStatus.Closed
wn.add_reservoir('atmos', base_head=0, coordinates=(40,0))
wn.add_pipe('out', start_node_name='after_valve', end_node_name='atmos', length=10, diameter=0.03175/3)

# Build EPANET file
wn.write_inpfile('simp.inp')

# Construct transient model 
tm = tsnet.network.TransientModel('simp.inp')
tm.get_link('valve').status = wntr.network.elements.LinkStatus.Closed

# Set wavespeed
tm.set_wavespeed(1200.) # m/s

# Set time options
tf = 5   # simulation period [s]
tm.set_time(tf)

# Set valve opening 
tc = 0.1 # valve opening period [s]
ts = 0.5 # valve opening start time [s]
se = 0.1 # end open percentage [s]
m = 1 # open constant [dimensionless]
tm.valve_opening('valve',[tc,ts,se,m])

# Initialize steady state simulation
t0=0
tm = tsnet.simulation.Initializer(tm,t0,'DD')

# Transient simulation
results_obj = 'simpres'
friction = 'unsteady'
tm = tsnet.simulation.MOCSimulator(tm, results_obj, friction)

# Gather results
t = tm.simulation_timestamps
ref_head = tm.get_node('ref').head
output_head = tm.get_node('after_valve').head
ref_flow_rate = tm.get_link('to_valve').start_node_flowrate
output_flow_rate = tm.get_link('out').end_node_flowrate

# Prep plotting
fig = plt.figure(figsize=(8,5), dpi=80, facecolor='w', edgecolor='k')

# Plot flow-rates
plt.plot(t, m3s_to_gpm(ref_flow_rate), 'k', label='ref', linewidth=1.5)
plt.plot(t, m3s_to_gpm(output_flow_rate), 'r--', label='output', linewidth=1.5)
plt.ylabel("flow-rate [gpm]")
plt.xlim([t[0],t[-1]])
plt.xlabel("Time [s]")
plt.legend(loc='best')
plt.draw()
plt.savefig('flowrate.png')
    
# Plot heads
plt.clf()
plt.plot(t, m_to_psi(ref_head), 'k', label='ref', linewidth=1.5)
plt.plot(t, m_to_psi(output_head), 'r--', label='output', linewidth=1.5)
plt.ylabel("Pressure [PSI]")
plt.xlim([t[0],t[-1]])
plt.xlabel("Time [s]")
plt.legend(loc='best')
plt.draw()
plt.savefig('pressure.png')

Custom pressure driven demands, leaks and no leaks setup.

  • tsnet version: 0.2.2
  • Python version: 3.9
  • Operating System: Linux

Description

Dear all, we trying to use TSnet to create (random or designer chosen) user demand pulse patterns https://tsnet.readthedocs.io/en/latest/transient.html#demand-pulse (using a function to create desired waveform) on some nodes driving the hydraulic network, no leaks and no demands on another set of nodes and constant pressure driven leaks on 3rd set of nodes in a distributed network. We are not sure how to set-up the simulation accordingly. Is it true that when we use 'demand pulse' function with some custom waveform it will be still pressure/head driven with Q= k*sqrt(Hp local)? As well how should we set our EPANET .ipn in order to make this work right? Not sure if we set everything to zero would work as I guess you use the .ipn file for initial k constant calculation? As well do we need to select PDD (pressure de) instead of DD? Thanks a lot for the help and clarification!

Thanks a lot for your help and advice!

Iordan Doytchinov

project status?

Hi,
Ive started using TSNet and its looking useful for my application so thanks for the efforts to date.
I note not much work on the project of late and that TSNet has been pegged to 0.30 of wntr which is also holding TSNet back to python 3.7.
I also note that python 3.7 is end of life in about 12 months and that many python packages have already dropped python 3.7 support.

Is there a plan to keep the project active and at a minimum fix the python and WNTR version compatibility issue?

Im happy to have a look at fixing it if it's a small task that you can point me to and a fix is likely to get merged.

Single Pipe Simulations

  • tsnet version: 0.1.0
  • Python version: 3.7.3
  • Operating System: Ubuntu 19.04

Description

Simulations with a single pipeline fail.
The same physical system but split into 2 pipe sections appears to work.

I don't think this is a big concern but I can't work out why the issue appears

I am Including python tester file and the two scenarios tested in .inp format in the zip file

issue.zip

Pressure-driven Demand

  • tsnet version: latest master
  • Python version: 3.7
  • Operating System: windows

Description

During the transient simulation in TSNet, the demands are treated as pressure-dependent discharge. The actual demands will vary from the demands defined in the INP file, why not use the same hydraulic equation? What are the considerations for this?

According to the formula in https://tsnet.readthedocs.io/en/latest/transient.html, if the pressure increases, the flow rate will continue to increase. However, the node requirements at the beginning have been determined. After the node pressure exceeds the required pressure, shouldn't the node flow rate remain unchanged?

Pressure dependent demand the formula in wntr

d = { 0 p ≤ P 0 D f ( p − P 0 P f − P 0 ) 1 / e P 0 ≤ p ≤ P f D f p ≥ P f

--
Pressure dependent demand the formula in TSNet:

--

Use of the TSNet engine with other hydraulic modelling software

Great work on this project!

I'm curious to know if TSNet could be used with modelling package other then EPANET?

The first obvious option would be to convert the model into EPANET.

Alternatively, I was wondering if it would be possible to pass in the definition of the network topology and steady-state results into the transient engine without having to run an EPANET simulation in WNTR to get the initial state?

My limited look through the code base suggests this may be possible, and that you could use an interface/abstraction between WNTR and TSNET which you could inject any modelling results, but I haven't run through the entire project to see where else WNTR is required.

I have models in InfoWater, WaterGEMS and InfoWorks WS Pro that I would like to try this approach with. I also have access to InfoSurge and would also love to compare the results between the two packages and see if we could start using an open-source option in preference to a commercial product.

My questions boil down to:

  • Would it be possible to load in other models and their results directly into TSNet without EPANET?
  • Is this something you would want to be added into this project?

Thanks again for making this project!

AttributeError: can't set attribute

  • tsnet version: 0.2.2
  • Python version: 3.7.9
  • Operating System: Windows 10

Description

I am having AttributeError: can't set attribute when trying to import network transient model "Tnet1" shown in example. As i read from docs leak_status its nodes read only property and can not be changed. Any idea how to fix this?

What I Did

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\Wes Trade\PycharmProjects\pythonProject\TSNet-test\env\lib\site-packages\tsnet\network\model.py", line 59, in __init__
    node.leak_status = False
AttributeError: can't set attribute

Negative pressure warnings

Reproduce the example in the official document: Define background leak location, JUNCTION-22. When performing transient simulation, JUNCTION -29 has negative pressure, but the document can operate normally. Why?

reproduce Tnet0 example plots

  • tsnet version: latest master
  • Python version: 3.7.4
  • Operating System: Mac OS X

Description

I'm experimenting with this software, trying to understand how to setup some simple transient models, consisting of a reservoir, a few pipes, and a valve. My goal is to model the transients upon either opening or closing the valve.

What I Did

I tried to reproduce Figs. A and B of Tnet0 shown here: https://tsnet.readthedocs.io/en/latest/validation.html

I am able to reproduce Fig. B but not Fig. A. When I plot the flow-rate, I see a steady sinusoid pattern with no apparent damping, unlike the plot in the link above, which shows rapid flow-rate decay in the first 2 seconds.

Also, why does the flow-rate and pressure head ring for such a long time? I tried increasing the simulation period to 600s and there is very little damping of the pressure head.

Here is the code I used:

import matplotlib
matplotlib.use('agg')
from matplotlib import pyplot as plt
import tsnet


# Open an example network and create a transient model
inp_file = 'Tnet0.inp'
tm = tsnet.network.TransientModel(inp_file)

# Set wavespeed
tm.set_wavespeed(1200.) # m/s

# Set time options
dt = 0.01
tf = 60   # simulation period [s]
tm.set_time(tf,dt)

# Set valve closure
tc = 2 # valve closure period [s]
ts = 0 # valve closure start time [s]
se = 0 # end open percentage [s]
m = 1 # closure constant [dimensionless]
valve_op = [tc,ts,se,m]
tm.valve_closure('3',valve_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 = 'Tnet0' # name of the object for saving simulation results
friction = 'steady'
tm1 = tsnet.simulation.MOCSimulator(tm, results_obj, friction)

# Get head at junction between the pipes
node = '2'
head1 = tm1.get_node(node).head

# Get flow-rate in pipe 2
fr = tm1.get_link('2').start_node_flowrate

# Prep plotting
t1 = tm1.simulation_timestamps
fig = plt.figure(figsize=(8,5), dpi=80, facecolor='w', edgecolor='k')

# Plot flow-rate
plt.plot(t1, fr, 'k',label='steady', linewidth=2.5)
plt.ylabel("flow-rate [m^3/s]")
plt.xlim([t1[0],t1[-1]])
plt.xlabel("Time [s]")
plt.legend(loc='best')
plt.draw()
plt.savefig('a.png')

# Plot head
plt.clf()
plt.plot(t1, head1, 'k',label='steady', linewidth=2.5)
plt.ylabel("Pressure Head [m]")
plt.xlim([t1[0],t1[-1]])
plt.xlabel("Time [s]")
plt.legend(loc='best')
plt.draw()
plt.savefig('b.png')

TransientModel

Hello, how do you understand that N in set_time_N is ‘Number of segments in the critical pipe’?

stability issue from small differences in initialization

I'm having some trouble getting stable results out of the simulations. I'm attaching an example code below. It reads from two versions of the wntr_network input file. Both versions are identical except for a slightly different pump curve. For pump_curve_1 I see crazy pressure fluctuations after the valve is opened. But for pump_curve_2 I see smooth pressure oscillations that are much more physically plausible. Shown below:

pressure

If I change the valve_open_period (at the beginning of the program) from 0.5 to 0.6, then the behavior switches and pump_curve_1 produces more stable results than pump_curve_2:
pressure_b

How can I consistently achieve stable results?

Here is the test program:

valve_open_period=0.5


import matplotlib
matplotlib.use('agg')
from matplotlib import pyplot as plt
import numpy
import wntr
import tsnet


def m3s_to_gpm(m3s):
    return m3s*(60*264.172)

def m_to_psi(m):
    return m*1.4219702063247


# Restore model for each pump
wn1 = wntr.network.WaterNetworkModel('pumpcurve_1.inp')
wn2 = wntr.network.WaterNetworkModel('pumpcurve_2.inp')

# Access pump curve 1
pts_1 = wn1.get_link('supply').get_pump_curve().points
coeffs_1 = wn1.get_link('supply').get_head_curve_coefficients()
q_1 = numpy.linspace(pts_1[0][0],pts_1[-1][0])
H_1 = coeffs_1[0] - coeffs_1[1]*(q_1**coeffs_1[2])

# Access pump curve 2 
pts_2 = wn2.get_link('supply').get_pump_curve().points
coeffs_2 = wn2.get_link('supply').get_head_curve_coefficients()
q_2 = numpy.linspace(pts_2[0][0],pts_2[-1][0])
H_2 = coeffs_2[0] - coeffs_2[1]*(q_2**coeffs_2[2])

# Plot pump curves
plt.plot(m3s_to_gpm(q_1), m_to_psi(H_1), label='pumpcurve_1')
plt.plot(m3s_to_gpm(q_2), m_to_psi(H_2), label='pumpcurve_2')
plt.xlabel('gpm')
plt.ylabel('PSI')
plt.draw()
plt.legend(loc='best')
plt.savefig('pumpcurves.png')

# Define valve curve
valve_curve = [(100.0, 0.0008099981681764881), (90.0, 0.00040499908408824403), (80.0, 0.00020249954204412202), (70.0, 0.00010124977102206101), (60.0, 5.394587800055411e-05), (50.0, 2.7539937718000598e-05), (40.0, 1.6199963363529762e-05), (30.0, 9.007179630122548e-06), (20.0, 5.0705885327848155e-06), (10.0, 2.7053938817094702e-06), (0.0, 0.0)]

# Simulate using each pump curve
time_index = []
pressure = []
flowrate = []
for input_name in ['pumpcurve_1', 'pumpcurve_2']:
    # Construct transient model
    tm = tsnet.network.TransientModel(input_name+'.inp')

    # Set wavespeed
    tm.set_wavespeed(1200) # m/s

    # Set time options
    tf = 4   # simulation period [s]
    dt = tsnet.network.discretize.max_time_step(tm)
    tm.set_time(tf, dt)

    # Set valve opening
    tc = valve_open_period # valve opening period [s]
    ts = 1 # valve opening start time [s]
    se = 1 # end open fraction (ranges from 0 to 1)
    m = 1 # open constant [dimensionless]
    tm.valve_opening('valve_3',[tc,ts,se,m], curve=valve_curve)

    # Initialize steady state simulation
    tm = tsnet.simulation.Initializer(tm, 0, 'DD')

    # Transient simulation
    tm = tsnet.simulation.MOCSimulator(tm, 'temp.res', 'unsteady')

    # Save results
    time_index.append(numpy.asarray(tm.simulation_timestamps, dtype=float))
    pressure.append(m_to_psi(numpy.asarray(tm.get_node('ref').head, dtype=float)))
    flowrate.append(m3s_to_gpm(numpy.asarray(tm.get_link('to_ref').start_node_flowrate, dtype=float)))

# Prep plotting
fig = plt.figure(figsize=(8,5), dpi=80, facecolor='w', edgecolor='k')

# Plot pressure
plt.clf()
plt.plot(time_index[0], pressure[0], label='pump_curve_1', linewidth=1.5)
plt.plot(time_index[1], pressure[1], label='pump_curve_2', linewidth=1.5)
plt.ylabel("Pressure [PSI]")
plt.xlim([0,4])
plt.ylim([0,100])
plt.xlabel("Time [s]")
plt.legend(loc='best')
plt.draw()
plt.savefig('pressure.png')


# Plot flow-rates
plt.clf()
plt.plot(time_index[0], flowrate[0], label='pump_curve_1', linewidth=1.5)
plt.plot(time_index[1], flowrate[1], label='pump_curve_2', linewidth=1.5)
plt.ylabel("flow-rate [gpm]")
plt.xlim([0,4])
plt.ylim([0,3])
plt.xlabel("Time [s]")
plt.legend(loc='best')
plt.draw()
plt.savefig('flowrate.png')

Here are the wntr input files:

pumpcurve_1.txt
pumpcurve_2.txt

Water flow direction

  • tsnet version:
  • Python version:
  • Operating System:

Description

Hello, we were wondering how to know the absolute flow direction for each pipe within a pipe network system? We guess that if the flow velocity goes negative during simulation then the direction of the water flow direction has shifted? As well if we have a positive velocity how do we know the original direction of the water in a meshed system? Assuming we have a water tank and water network on the same level?

Thanks a lot for your help and advice!

Iordan D

Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

Define new elements (relief valves...)

Description

Hello,
We currently use a transient simulation software (Allievi) to model some complex networks with a lot of scenarii that can cause water hammers. With a python package like TSNET we could automate the computation of the scenarii. However, some objects present in Allievi are not yet included in TSNET:

  • Relief valves
  • Air valves
  • Flow/pressure control valves (control valves are defined in the INP file, but not how they react to brutal pressure changes)
  • Pumps with inertia (#5)

Is it possible to program in python new elements like those above, if we know their equations? If so, we will try TSNET next time we have to do transient simulations.

Thanks for your answer,
Antoine

.obj文件数据提取

  • tsnet version:
  • Python version:
  • Operating System:

Description

作者您好!您开发的TSnet非常好用。我的问题是:如何从.obj文件中提取我所需的数据,我不想重新运行模型获取结果。

What I Did

我已经根据教程获得Net3.obj文件

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.