Add EPANET2 input format

This commit is contained in:
WQY\qiong
2023-02-28 23:04:46 +08:00
parent 97c409535f
commit ee829c0731
23 changed files with 163 additions and 0 deletions

View File

@@ -68,6 +68,10 @@ def set_status(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, set_status_cmd(name, cs))
#--------------------------------------------------------------
# [EPANET2]
# link value
#--------------------------------------------------------------
class InpStatus:
def __init__(self, line: str) -> None:
tokens = line.split()

View File

@@ -93,6 +93,10 @@ def delete_pattern(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, delete_pattern_cmd(name, cs))
#--------------------------------------------------------------
# [EPANET2]
# id mult1 mult2 .....
#--------------------------------------------------------------
def inp_in_pattern(section: list[str]) -> ChangeSet:
descs = {}
patterns: dict[str, list[float]] = {}

View File

@@ -121,6 +121,10 @@ def delete_curve(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, delete_curve_cmd(name, cs))
#--------------------------------------------------------------
# [EPANET2]
# id x y
#--------------------------------------------------------------
def inp_in_curve(section: list[str]) -> ChangeSet:
types = {}
descs = {}

View File

@@ -34,6 +34,13 @@ def set_control(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, set_control_cmd(name, cs))
#--------------------------------------------------------------
# [EPANET2]
# LINK linkID setting IF NODE nodeID {BELOW/ABOVE} level
# LINK linkID setting AT TIME value (units)
# LINK linkID setting AT CLOCKTIME value (units)
# (0) (1) (2) (3) (4) (5) (6) (7)
#--------------------------------------------------------------
def inp_in_control(section: list[str]) -> ChangeSet:
if len(section) > 0:
return ChangeSet(g_update_prefix | {'type': 'control', 'controls' : section})

View File

@@ -34,6 +34,10 @@ def set_rule(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, set_rule_cmd(name, cs))
#--------------------------------------------------------------
# [EPANET2]
# TODO...
#--------------------------------------------------------------
def inp_in_rule(section: list[str]) -> ChangeSet:
if len(section) > 0:
return ChangeSet(g_update_prefix | {'type': 'rule', 'rules' : section})

View File

@@ -131,6 +131,12 @@ def set_pump_energy(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, set_pump_energy_cmd(name, cs))
#--------------------------------------------------------------
# [EPANET2]
# GLOBAL {PRICE/PATTERN/EFFIC} value
# PUMP id {PRICE/PATTERN/EFFIC} value
# DEMAND CHARGE value
#--------------------------------------------------------------
def inp_in_energy(section: list[str]) -> ChangeSet:
cs = ChangeSet()

View File

@@ -59,6 +59,10 @@ def set_emitter(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, set_emitter_cmd(name, cs))
#--------------------------------------------------------------
# [EPANET2]
# node Ke
#--------------------------------------------------------------
class InpEmitter:
def __init__(self, line: str) -> None:
tokens = line.split()

View File

@@ -59,6 +59,10 @@ def set_quality(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, set_quality_cmd(name, cs))
#--------------------------------------------------------------
# [EPANET2]
# node initqual
#--------------------------------------------------------------
class InpQuality:
def __init__(self, line: str) -> None:
tokens = line.split()

View File

@@ -102,6 +102,10 @@ def delete_source(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, delete_source_cmd(name, cs))
#--------------------------------------------------------------
# [EPANET2]
# node sourcetype quality (pattern)
#--------------------------------------------------------------
class InpSource:
def __init__(self, line: str) -> None:
tokens = line.split()

View File

@@ -181,6 +181,17 @@ def set_tank_reaction(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, set_tank_reaction_cmd(name, cs))
#--------------------------------------------------------------
# [EPANET2]
# ORDER {BULK/WALL/TANK} value
# GLOBAL BULK coeff
# GLOBAL WALL coeff
# BULK link1 (link2) coeff
# WALL link1 (link2) coeff
# TANK node1 (node2) coeff
# LIMITING POTENTIAL value
# ROUGHNESS CORRELATION value
#--------------------------------------------------------------
def inp_in_reaction(section: list[str]) -> ChangeSet:
cs = ChangeSet()

View File

@@ -96,6 +96,10 @@ def delete_mixing(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, delete_mixing_cmd(name, cs))
#--------------------------------------------------------------
# [EPANET2]
# TankID MixModel FractVolume
#--------------------------------------------------------------
class InpMixing:
def __init__(self, line: str) -> None:
tokens = line.split()

View File

@@ -67,6 +67,19 @@ def set_time(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, set_time_cmd(name, cs))
#--------------------------------------------------------------
# [EPANET2]
# STATISTIC {NONE/AVERAGE/MIN/MAX/RANGE}
# DURATION value (units)
# HYDRAULIC TIMESTEP value (units)
# QUALITY TIMESTEP value (units)
# RULE TIMESTEP value (units)
# PATTERN TIMESTEP value (units)
# PATTERN START value (units)
# REPORT TIMESTEP value (units)
# REPORT START value (units)
# START CLOCKTIME value (AM PM)
#--------------------------------------------------------------
def inp_in_time(section: list[str]) -> ChangeSet:
if len(section) > 0:
cs = g_update_prefix | { 'type' : 'time' }

View File

@@ -1,6 +1,25 @@
from .database import *
#--------------------------------------------------------------
# [EPANET2]
# PAGE linesperpage
# STATUS {NONE/YES/FULL}
# SUMMARY {YES/NO}
# MESSAGES {YES/NO}
# ENERGY {NO/YES}
# NODES {NONE/ALL}
# NODES node1 node2 ...
# LINKS {NONE/ALL}
# LINKS link1 link2 ...
# FILE filename
# variable {YES/NO}
# variable {BELOW/ABOVE/PRECISION} value
#--------------------------------------------------------------
def inp_in_report(section: list[str]) -> ChangeSet:
return ChangeSet()
def inp_out_report(name: str) -> list[str]:
lines = []
objs = read_all(name, f"select * from report")

View File

@@ -105,6 +105,40 @@ def set_option(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, set_option_cmd(name, cs))
#--------------------------------------------------------------
# [EPANET2]
# UNITS CFS/GPM/MGD/IMGD/AFD/LPS/LPM/MLD/CMH/CMD/SI
# PRESSURE PSI/KPA/M
# HEADLOSS H-W/D-W/C-M
# HYDRAULICS USE/SAVE filename
# QUALITY NONE/AGE/TRACE/CHEMICAL (TraceNode)
# MAP filename
# VERIFY filename
# UNBALANCED STOP/CONTINUE {Niter}
# PATTERN id
# DEMAND MODEL DDA/PDA
# DEMAND MULTIPLIER value
# EMITTER EXPONENT value
# VISCOSITY value
# DIFFUSIVITY value
# SPECIFIC GRAVITY value
# TRIALS value
# ACCURACY value#
# HEADERROR value
# FLOWCHANGE value
# MINIMUM PRESSURE value
# REQUIRED PRESSURE value
# PRESSURE EXPONENT value#
# TOLERANCE value
# SEGMENTS value (not used)
# ---- Undocumented Options -----
# HTOL value
# QTOL value
# RQTOL value
# CHECKFREQ value
# MAXCHECK value
# DAMPLIMIT value
#--------------------------------------------------------------
def inp_in_option(section: list[str]) -> ChangeSet:
if len(section) > 0:
cs = g_update_prefix | { 'type' : 'option' }

View File

@@ -10,6 +10,11 @@ def get_node_coord(name: str, id: str) -> dict[str, float]:
row = read(name, f"select * from coordinates where node = '{id}'")
return _to_client_point(row['coord'])
#--------------------------------------------------------------
# [EPANET2]
# id x y
#--------------------------------------------------------------
# exception ! need merge to node change set !
def inp_in_coord(section: list[str]) -> dict[str, dict[str, float]]:
coords = {}

View File

@@ -75,6 +75,10 @@ def delete_vertex(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, result)
#--------------------------------------------------------------
# [EPANET2]
# id x y
#--------------------------------------------------------------
def inp_in_vertex(section: list[str]) -> ChangeSet:
vertices: dict[str, list[dict[str, float]]] = {}

View File

@@ -120,6 +120,10 @@ def delete_junction(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, delete_junction_cmd(name, cs))
#--------------------------------------------------------------
# [EPANET2]
# id elev. (demand) (demand pattern)
#--------------------------------------------------------------
class InpJunction:
def __init__(self, line: str) -> None:
tokens = line.split()

View File

@@ -116,6 +116,10 @@ def delete_reservoir(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, delete_reservoir_cmd(name, cs))
#--------------------------------------------------------------
# [EPANET2]
# id elev (pattern)
#--------------------------------------------------------------
class InpReservoir:
def __init__(self, line: str) -> None:
tokens = line.split()

View File

@@ -144,6 +144,10 @@ def delete_tank(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, delete_tank_cmd(name, cs))
#--------------------------------------------------------------
# [EPANET2]
# id elev initlevel minlevel maxlevel diam (minvol vcurve)
#--------------------------------------------------------------
class InpTank:
def __init__(self, line: str) -> None:
tokens = line.split()

View File

@@ -123,6 +123,10 @@ def delete_pipe(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, delete_pipe_cmd(name, cs))
#--------------------------------------------------------------
# [EPANET2]
# id node1 node2 length diam rcoeff (lcoeff) (status)
#--------------------------------------------------------------
class InpPipe:
def __init__(self, line: str) -> None:
tokens = line.split()

View File

@@ -114,6 +114,11 @@ def delete_pump(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, delete_pump_cmd(name, cs))
#--------------------------------------------------------------
# [EPANET2] Version 1.x is deprecated
# id node1 node2 KEYWORD value {KEYWORD value ...}
# where KEYWORD = [POWER,HEAD,PATTERN,SPEED]
#--------------------------------------------------------------
class InpPump:
def __init__(self, line: str) -> None:
tokens = line.split()

View File

@@ -122,6 +122,12 @@ def delete_valve(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, delete_valve_cmd(name, cs))
#--------------------------------------------------------------
# [EPANET2]
# id node1 node2 diam type setting (lcoeff lcurve)
# for GPV, setting is string = head curve id
# for PCV, add loss curve if present
#--------------------------------------------------------------
class InpValve:
def __init__(self, line: str) -> None:
tokens = line.split()

View File

@@ -85,6 +85,11 @@ def set_demand(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, set_demand_cmd(name, cs))
#--------------------------------------------------------------
# [EPANET2]
# MULTIPLY factor
# node base_demand (pattern)
#--------------------------------------------------------------
class InpDemand:
def __init__(self, line: str) -> None:
tokens = line.split()