Set valve value ENsetlinkvalue problem

Hello,

I have an issue with ENsetlinkvalue. I am trying to set the value of the PRV valve number 55 but it doesn’t change the value. Why please ?

I am working with Python.

file=‘chateau.inp’
es=EPANetSimulation(file)
presion=Node.value_type[‘EN_PRESSURE’]

for d in np.arange(70,76,0.1):
    es.ENsetlinkvalue(55,5,d)   # 5 => EN_INITSETTING'
    print("Consign : ",d)
    es.run()
    Pf=[]
    Pf=es.network.nodes['2189'].results[presion]
    Pftab=np.array(Pf)
    print(Pftab)

Hello,

Any help please. I tried to save to a temporary file but it didn’t work.

for d in np.arange(70.00,76.00,0.25):
    print("Consigne du stabilisateur : ",d)
    f=os.path.join(tempfile.gettempdir(),"temp.inp")
    es.ENsaveinpfile(f) # save the changed file
    e2=EPANetSimulation(f)
    e2.ENsetlinkvalue(55,consignas,d)
    e2.run()
    Pf=[]
    Pf=e2.network.nodes['2189'].results[presiones]
    Pftab=np.array(Pf)
    print('Pression nouvelle calculée au point mesuré : ')
    print(Pftab)
    E = [(i-j)**2 for i, j in zip(Pftab,P2189tab)]
    print("Erreur : ",E)
    Sum = sum(E)
    print(Sum)
    if sqrt(Sum/len(E))<=0.05: print('Consign to choose = ',d)
    else:
        print("Not enough precision !")

Hi @Bastien43
I’m not sure which Python wrapper you are using, so it’s hard for me to say why your script isn’t working as expected.

The following code replaces the diameter of a single link, runs a simulation, and gets the pressure value of a single node. The inp file is the Example 1 network, and the python wrapper is the epanet-python by OWA

import numpy as np
import epamodule as em

file='net1.inp'
em.ENopen('net1.inp','net1.rpt','net1.nib')

pipe_id = '111'
target_node_id = '21'

pipe_idx = em.ENgetlinkindex(pipe_id)
target_node_idx = em.ENgetnodeindex(target_node_id)

for d in np.arange(10,20,1):
    em.ENsetlinkvalue(pipe_idx, em.EN_DIAMETER,d)
    em.ENsolveH()
    em.ENsaveH()

    p = em.ENgetnodevalue(target_node_idx, em.EN_PRESSURE)
    print('Diameter:', d, ' ', 'Pressure:', p)

Hello,
Thank you for the explication and the code (sorry for being late and the late answer)
I tried the code it works.
Thanks for your help.
Regards