实现多进程 epanet 模拟,不保留临时文件

This commit is contained in:
2026-03-18 16:56:44 +08:00
parent c5d3075ae2
commit 7c44654195
6 changed files with 114 additions and 127 deletions
+23 -16
View File
@@ -5,7 +5,6 @@ from math import pi
import pytz
from app.algorithms.simulation.runner import run_simulation_ex
from app.infra.epanet.epanet import Output
from app.services.tjnetwork import (
close_project,
copy_project,
@@ -110,10 +109,16 @@ def scheduling_simulation(
+ " -- Database Loading OK."
)
run_simulation_ex(
new_name, "realtime", start_time, duration=0, pump_control=pump_control
simulation_result = json.loads(
run_simulation_ex(
new_name, "realtime", start_time, duration=0, pump_control=pump_control
)
)
output_data = simulation_result.get("output")
if not isinstance(output_data, dict):
raise RuntimeError("run_simulation_ex did not return JSON output content")
if not is_project_open(new_name):
open_project(new_name)
@@ -131,18 +136,14 @@ def scheduling_simulation(
else:
tank_pipe_flow_direction[pipe_id] = -1
output = Output("./temp/{}.db.out".format(new_name))
node_results = (
output.node_results()
) # [{'node': str, 'result': [{'pressure': float}]}]
node_results = output_data.get("node_results") or [] # [{'node': str, 'result': [{'pressure': float}]}]
water_plant_output_pressure = 0
for node_result in node_results:
if node_result["node"] == water_plant_output_id: # 水厂出水压力(m)
water_plant_output_pressure = node_result["result"][-1]["pressure"]
water_plant_output_pressure /= 100 # 预计水厂出水压力(Mpa)
pipe_results = output.link_results() # [{'link': str, 'result': [{'flow': float}]}]
pipe_results = output_data.get("link_results") or [] # [{'link': str, 'result': [{'flow': float}]}]
tank_inflow = 0
for pipe_result in pipe_results:
for pipe_id in tank_pipes_id: # 遍历与水塔相连的管道
@@ -200,18 +201,24 @@ def daily_scheduling_simulation(
+ " -- Database Loading OK."
)
run_simulation_ex(
new_name, "realtime", start_time, duration=86400, pump_control=pump_control
simulation_result = json.loads(
run_simulation_ex(
new_name,
"realtime",
start_time,
duration=86400,
pump_control=pump_control,
)
)
output_data = simulation_result.get("output")
if not isinstance(output_data, dict):
raise RuntimeError("run_simulation_ex did not return JSON output content")
if not is_project_open(new_name):
open_project(new_name)
output = Output("./temp/{}.db.out".format(new_name))
node_results = (
output.node_results()
) # [{'node': str, 'result': [{'pressure': float, 'head': float}]}]
node_results = output_data.get("node_results") or [] # [{'node': str, 'result': [{'pressure': float, 'head': float}]}]
water_plant_output_pressure = []
reservoir_level = []
tank_level = []