USEPA / WNTR

An EPANET compatible python package to simulate and analyze water distribution networks under disaster scenarios.
Other
310 stars 177 forks source link

Step-wise simulation #204

Open mortvif opened 3 years ago

mortvif commented 3 years ago

Hi!

I am trying to run a Epanet simulation step by step using the same approach proposed in issue #59. However, step time execution increases linearlly with time in my tests, sugesting that simulation is completly recomputed in each step.

I haven't found any information on this step-wise approach in the documentation. After a quick code lookup I have found ENnextH and ENrunH methods in the internal epanet bindings (wntr.epanet.toolkit module) which might be useful. However, it seems to me that they are not used in the exposed high level interface (wntr.sim.epanet module).

Is it possible to perform this step-wise simulation? If so, which is the proper approach to achieve it?

Thanks!

kaklise commented 3 years ago

Right now, the step-wise simulation only works with the WNTRSimulator. We are currently working on features that will extend this to the EpanetSimulator. This includes the ability to initialize the water network model with simulation results (such as results from a previous timestep). We plan to push these updates to the dev branch in the next few weeks.

mortvif commented 3 years ago

Thanks! I'll stay tuned for the upcoming changes.

mortvif commented 2 years ago

I have looked at the repo history and couldn't find any related commits in the last few months. Did you finished this feature and I have missed it or is it still work in progress?

In any case, I would greatly appreciate if you could provide an update on the current state of this topic. Thanks!

dbhart commented 2 years ago

Hi @@.***>

We have not pushed into the main fork yet, but if you go to my (dbhart/WNTR) fork and the “realtime” branch you can find a stepwise simulator that may require a little work to make it stepwise (the example under the tests directory is set up for real time, but there is just a flag that is needed to make it run for an arbitrary time for each step). There is also a UML diagram for a flow example in the documentation.

I hope that helps, and we are looking forward to pushing into at least the dev branch of the main fork soon.

mortvif commented 2 years ago

Thank you for your quick response!

After analyzing the code I understand the flag that is required is the until parameter in the run_sim function. I have adapted your test scenario to run it stepwise as follows (using same setup):

sim = rt.EpanetSimulator_RT(wn)
prov = rt.RealtimeProvider(timelimit=wn.options.time.duration,
    outfile="temp.out",
    infile="temp.in",
    controls=controls)
for sensor in nodesens:
    sim.add_sensor_instrument(sensor[0], 'node', sensor[1], sensor[2])
for sensor in linksens:
    sim.add_sensor_instrument(sensor[0], 'link', sensor[1], sensor[2])
for controller in controllers:
    sim.add_controller_instrument(controller[0], controller[1], controller[2])

sim.initialize(transmit=prov.proc_sensors, receive=prov.proc_controllers, stop=prov.check_time, file_prefix="temp")
for i in range(1, 101):
    try:
        sim.run_sim(until= i * 3600)      
        print("Simulating until " +str(i*3600) + " in "+str((end-start).seconds) + " seconds")
    except:
        print("Error")

res = sim.close()

However, this approach prompts what I understand is an EPANET convergence warning after the first timestep.

/home/mortvif/.local/share/virtualenvs/water_rt-0SEeEPjZ/lib/python3.9/site-packages/wntr/epanet/io.py:2777: UserWarning: Simulation did not converge at time 01:02:00.
warnings.warn('Simulation did not converge at time ' + self._get_time(t) + '.')

Execution seems to continue without raising an error but no further timesteps are simulated and results obtained after invoking sim.close() are limited to those times before the convergence warning.

I don't know if I am missing something or this still requires further work on the library to make it functional.

Thank you once again for your helpful attention!

Naycat commented 2 years ago

Is the step by step simulation for the Epanet simulator now available?

kaklise commented 2 years ago

We continue to develop the stepwise and realtime EPANET simulators in WNTR, but they are not quite ready to push to the USEPA main branch. It will take some time to get these updates fully documented and tested. We can create a separate branch with this capability as soon as it's ready, perhaps this summer.

Pu-nk commented 1 year ago

So maybe the step-wise simulator is avaliable now?

kaklise commented 1 year ago

The step-wise simulator is not available yet, we are finishing up documentation and tests.