mirror of https://gitlab.com/pamhyr/pamhyr2
DB: Some fixes for db update 0.1.0.
parent
bc157fcde7
commit
ce8c4ebd91
|
|
@ -161,7 +161,7 @@ class BasicHS(SQLSubModel):
|
||||||
|
|
||||||
bhs.enabled = enabled
|
bhs.enabled = enabled
|
||||||
|
|
||||||
data['bhs_id'] = bhs_id
|
data['bhs_id'] = bhs_pid
|
||||||
bhs._data = BHSValue._db_load(
|
bhs._data = BHSValue._db_load(
|
||||||
execute, data
|
execute, data
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -47,9 +47,9 @@ class DischargeWeir(BasicHS):
|
||||||
|
|
||||||
self._type = "S1"
|
self._type = "S1"
|
||||||
self._data = [
|
self._data = [
|
||||||
BHSValue("width", float, 1.0, status=status),
|
BHSValue(-1, "width", float, 1.0, status=status),
|
||||||
BHSValue("elevation", float, 1.0, status=status),
|
BHSValue(-1, "elevation", float, 1.0, status=status),
|
||||||
BHSValue("discharge_coefficient", float, 0.4, status=status),
|
BHSValue(-1, "discharge_coefficient", float, 0.4, status=status),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -63,11 +63,11 @@ class TrapezoidalWeir(BasicHS):
|
||||||
|
|
||||||
self._type = "S2"
|
self._type = "S2"
|
||||||
self._data = [
|
self._data = [
|
||||||
BHSValue("width", float, 1.0, status=status),
|
BHSValue(-1, "width", float, 1.0, status=status),
|
||||||
BHSValue("elevation", float, 1.0, status=status),
|
BHSValue(-1, "elevation", float, 1.0, status=status),
|
||||||
BHSValue("loading_elevation", float, 9999.999, status=status),
|
BHSValue(-1, "loading_elevation", float, 9999.999, status=status),
|
||||||
BHSValue("discharge_coefficient", float, 0.4, status=status),
|
BHSValue(-1, "discharge_coefficient", float, 0.4, status=status),
|
||||||
BHSValue("half-angle_tangent", float, 0.0, status=status),
|
BHSValue(-1, "half-angle_tangent", float, 0.0, status=status),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -81,10 +81,10 @@ class TriangularWeir(BasicHS):
|
||||||
|
|
||||||
self._type = "S3"
|
self._type = "S3"
|
||||||
self._data = [
|
self._data = [
|
||||||
BHSValue("elevation", float, 1.0, status=status),
|
BHSValue(-1, "elevation", float, 1.0, status=status),
|
||||||
BHSValue("loading_elevation", float, 9999.999, status=status),
|
BHSValue(-1, "loading_elevation", float, 9999.999, status=status),
|
||||||
BHSValue("discharge_coefficient", float, 0.4, status=status),
|
BHSValue(-1, "discharge_coefficient", float, 0.4, status=status),
|
||||||
BHSValue("half-angle_tangent", float, 0.0, status=status),
|
BHSValue(-1, "half-angle_tangent", float, 0.0, status=status),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -98,12 +98,12 @@ class RectangularOrifice(BasicHS):
|
||||||
|
|
||||||
self._type = "OR"
|
self._type = "OR"
|
||||||
self._data = [
|
self._data = [
|
||||||
BHSValue("width", float, 0.0, status=status),
|
BHSValue(-1, "width", float, 0.0, status=status),
|
||||||
BHSValue("elevation", float, 0.0, status=status),
|
BHSValue(-1, "elevation", float, 0.0, status=status),
|
||||||
BHSValue("loading_elevation", float, 9999.999,
|
BHSValue(-1, "loading_elevation", float, 9999.999,
|
||||||
status=status),
|
status=status),
|
||||||
BHSValue("discharge_coefficient", float, 0.4, status=status),
|
BHSValue(-1, "discharge_coefficient", float, 0.4, status=status),
|
||||||
BHSValue("maximal_loading_elevation", float, 9999.999,
|
BHSValue(-1, "maximal_loading_elevation", float, 9999.999,
|
||||||
status=status),
|
status=status),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -118,10 +118,10 @@ class CircularOrifice(BasicHS):
|
||||||
|
|
||||||
self._type = "OC"
|
self._type = "OC"
|
||||||
self._data = [
|
self._data = [
|
||||||
BHSValue("diameter", float, 0.0, status=status),
|
BHSValue(-1, "diameter", float, 0.0, status=status),
|
||||||
BHSValue("elevation", float, 0.0, status=status),
|
BHSValue(-1, "elevation", float, 0.0, status=status),
|
||||||
BHSValue("siltation_height", float, 0.0, status=status),
|
BHSValue(-1, "siltation_height", float, 0.0, status=status),
|
||||||
BHSValue("discharge_coefficient", float, 0.4, status=status),
|
BHSValue(-1, "discharge_coefficient", float, 0.4, status=status),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -135,11 +135,11 @@ class VaultedOrifice(BasicHS):
|
||||||
|
|
||||||
self._type = "OV"
|
self._type = "OV"
|
||||||
self._data = [
|
self._data = [
|
||||||
BHSValue("elevation", float, 1.0, status=status),
|
BHSValue(-1, "elevation", float, 1.0, status=status),
|
||||||
BHSValue("width", float, 1.0, status=status),
|
BHSValue(-1, "width", float, 1.0, status=status),
|
||||||
BHSValue("top_of_the_vault", float, 0.0, status=status),
|
BHSValue(-1, "top_of_the_vault", float, 0.0, status=status),
|
||||||
BHSValue("bottom_of_the_vault", float, 0.0, status=status),
|
BHSValue(-1, "bottom_of_the_vault", float, 0.0, status=status),
|
||||||
BHSValue("discharge_coefficient", float, 0.4, status=status),
|
BHSValue(-1, "discharge_coefficient", float, 0.4, status=status),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -153,11 +153,11 @@ class RectangularGate(BasicHS):
|
||||||
|
|
||||||
self._type = "V1"
|
self._type = "V1"
|
||||||
self._data = [
|
self._data = [
|
||||||
BHSValue("width", float, 1.0, status=status),
|
BHSValue(-1, "width", float, 1.0, status=status),
|
||||||
BHSValue("elevation", float, 0.0, status=status),
|
BHSValue(-1, "elevation", float, 0.0, status=status),
|
||||||
BHSValue("discharge coefficient", float, 0.4, status=status),
|
BHSValue(-1, "discharge coefficient", float, 0.4, status=status),
|
||||||
BHSValue("opening", float, 1.0, status=status),
|
BHSValue(-1, "opening", float, 1.0, status=status),
|
||||||
BHSValue("maximal_opening", float, 1.0, status=status),
|
BHSValue(-1, "maximal_opening", float, 1.0, status=status),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -171,11 +171,11 @@ class SimplifiedRectangularGate(BasicHS):
|
||||||
|
|
||||||
self._type = "V2"
|
self._type = "V2"
|
||||||
self._data = [
|
self._data = [
|
||||||
BHSValue("width", float, 1.0, status=status),
|
BHSValue(-1, "width", float, 1.0, status=status),
|
||||||
BHSValue("elevation", float, 0.0, status=status),
|
BHSValue(-1, "elevation", float, 0.0, status=status),
|
||||||
BHSValue("discharge coefficient", float, 0.4, status=status),
|
BHSValue(-1, "discharge coefficient", float, 0.4, status=status),
|
||||||
BHSValue("opening", float, 1.0, status=status),
|
BHSValue(-1, "opening", float, 1.0, status=status),
|
||||||
BHSValue("maximal_opening", float, 1.0, status=status),
|
BHSValue(-1, "maximal_opening", float, 1.0, status=status),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -189,9 +189,9 @@ class Borda(BasicHS):
|
||||||
|
|
||||||
self._type = "BO"
|
self._type = "BO"
|
||||||
self._data = [
|
self._data = [
|
||||||
BHSValue("step_space", float, 0.1, status=status),
|
BHSValue(-1, "step_space", float, 0.1, status=status),
|
||||||
BHSValue("weir", float, 0.15, status=status),
|
BHSValue(-1, "weir", float, 0.15, status=status),
|
||||||
BHSValue("coefficient", float, 0.4, status=status),
|
BHSValue(-1, "coefficient", float, 0.4, status=status),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -205,12 +205,12 @@ class CheckValve(BasicHS):
|
||||||
|
|
||||||
self._type = "CV"
|
self._type = "CV"
|
||||||
self._data = [
|
self._data = [
|
||||||
BHSValue("width", float, 0.0, status=status),
|
BHSValue(-1, "width", float, 0.0, status=status),
|
||||||
BHSValue("elevation", float, 0.0, status=status),
|
BHSValue(-1, "elevation", float, 0.0, status=status),
|
||||||
BHSValue("loading_elevation", float, 9999.999,
|
BHSValue(-1, "loading_elevation", float, 9999.999,
|
||||||
status=status),
|
status=status),
|
||||||
BHSValue("discharge_coefficient", float, 0.4, status=status),
|
BHSValue(-1, "discharge_coefficient", float, 0.4, status=status),
|
||||||
BHSValue("maximal_loading_elevation", float, 9999.999,
|
BHSValue(-1, "maximal_loading_elevation", float, 9999.999,
|
||||||
status=status),
|
status=status),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -225,11 +225,11 @@ class UserDefined(BasicHS):
|
||||||
|
|
||||||
self._type = "UD"
|
self._type = "UD"
|
||||||
self._data = [
|
self._data = [
|
||||||
BHSValue("parameter_1", float, 0.0, status=status),
|
BHSValue(-1, "parameter_1", float, 0.0, status=status),
|
||||||
BHSValue("parameter_2", float, 0.0, status=status),
|
BHSValue(-1, "parameter_2", float, 0.0, status=status),
|
||||||
BHSValue("parameter_3", float, 0.0, status=status),
|
BHSValue(-1, "parameter_3", float, 0.0, status=status),
|
||||||
BHSValue("parameter_4", float, 0.0, status=status),
|
BHSValue(-1, "parameter_4", float, 0.0, status=status),
|
||||||
BHSValue("parameter_5", float, 0.0, status=status),
|
BHSValue(-1, "parameter_5", float, 0.0, status=status),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,7 @@ class SQLSubModel(PamhyrID):
|
||||||
node_id = next(it)
|
node_id = next(it)
|
||||||
|
|
||||||
if node_id == -1:
|
if node_id == -1:
|
||||||
return
|
continue
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
f"UPDATE {table} " +
|
f"UPDATE {table} " +
|
||||||
|
|
@ -236,7 +236,7 @@ class SQLSubModel(PamhyrID):
|
||||||
reach_id = next(it)
|
reach_id = next(it)
|
||||||
|
|
||||||
if reach_id == -1:
|
if reach_id == -1:
|
||||||
return
|
continue
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
f"UPDATE {table} " +
|
f"UPDATE {table} " +
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ class PamhyrID(object):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_new_pamhyr_id(cls, id):
|
def get_new_pamhyr_id(cls, id):
|
||||||
pid = id
|
pid = int(id)
|
||||||
|
|
||||||
if pid < 0:
|
if pid < 0:
|
||||||
pid = PamhyrID._pamhyr_id_cnt
|
pid = PamhyrID._pamhyr_id_cnt
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import os
|
||||||
import logging
|
import logging
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
from itertools import chain
|
||||||
from tools import timer, trace, logger_exception
|
from tools import timer, trace, logger_exception
|
||||||
|
|
||||||
from Solver.CommandLine import CommandLineSolver
|
from Solver.CommandLine import CommandLineSolver
|
||||||
|
|
@ -109,6 +110,46 @@ class Mage(CommandLineSolver):
|
||||||
# Export #
|
# Export #
|
||||||
##########
|
##########
|
||||||
|
|
||||||
|
_alph = list(
|
||||||
|
map(
|
||||||
|
chr,
|
||||||
|
chain(
|
||||||
|
range(48,58), # 0..9
|
||||||
|
range(65, 91), # A..Z
|
||||||
|
range(97, 123) # a..z
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
_l_alph = len(_alph)
|
||||||
|
|
||||||
|
def get_reach_name(self, reach):
|
||||||
|
return f"Reach_{reach.pamhyr_id:>3}".replace(" ", "0")
|
||||||
|
|
||||||
|
def get_node_name(self, node):
|
||||||
|
"""Generate a 3 char name from node pamhyr_id
|
||||||
|
|
||||||
|
Args:
|
||||||
|
node: The node
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A 3 char name string
|
||||||
|
"""
|
||||||
|
n = node.pamhyr_id
|
||||||
|
|
||||||
|
return "".join(
|
||||||
|
list(
|
||||||
|
map(
|
||||||
|
lambda i: self._alph[i % self._l_alph],
|
||||||
|
[
|
||||||
|
int(n/1000),
|
||||||
|
int(n/10),
|
||||||
|
n
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def cmd_args(self, study):
|
def cmd_args(self, study):
|
||||||
lst = super(Mage, self).cmd_args(study)
|
lst = super(Mage, self).cmd_args(study)
|
||||||
|
|
||||||
|
|
@ -251,7 +292,7 @@ class Mage(CommandLineSolver):
|
||||||
if bound.node is None:
|
if bound.node is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
name = f"{bound.node.id:3}".replace(" ", "x")
|
name = self.get_node_name(bound.node)
|
||||||
f.write(f"* {bound.node.name} ({name}) {bound.bctype}\n")
|
f.write(f"* {bound.node.name} ({name}) {bound.bctype}\n")
|
||||||
f.write(f"${name}\n")
|
f.write(f"${name}\n")
|
||||||
header = bound.header
|
header = bound.header
|
||||||
|
|
@ -448,7 +489,7 @@ class Mage(CommandLineSolver):
|
||||||
|
|
||||||
reservoir.sort()
|
reservoir.sort()
|
||||||
node = reservoir.node
|
node = reservoir.node
|
||||||
name = f"{node.id:3}".replace(" ", "x")
|
name = self.get_node_name(node)
|
||||||
f.write(f"* {node.name} ({name}) Reservoir\n")
|
f.write(f"* {node.name} ({name}) Reservoir\n")
|
||||||
f.write(f"${name}\n")
|
f.write(f"${name}\n")
|
||||||
f.write(f"*{'Elev(m)':>9}|{'Area(ha)':>10}\n")
|
f.write(f"*{'Elev(m)':>9}|{'Area(ha)':>10}\n")
|
||||||
|
|
@ -826,14 +867,13 @@ class Mage8(Mage):
|
||||||
edges = study.river.enable_edges()
|
edges = study.river.enable_edges()
|
||||||
|
|
||||||
for e in edges:
|
for e in edges:
|
||||||
name = f"Reach_{e.pamhyr_id:>3}".replace(" ", "0")
|
name = self.get_reach_name(e)
|
||||||
id = name
|
n1 = self.get_node_name(e.node1)
|
||||||
|
n2 = self.get_node_name(e.node2)
|
||||||
|
|
||||||
n1 = f"{e.node1.id:3}".replace(" ", "x")
|
|
||||||
n2 = f"{e.node2.id:3}".replace(" ", "x")
|
|
||||||
file = os.path.join("net", name + ".ST")
|
file = os.path.join("net", name + ".ST")
|
||||||
|
|
||||||
f.write(f"{id} {n1} {n2} {file}\n")
|
f.write(f"{name} {n1} {n2} {file}\n")
|
||||||
|
|
||||||
return files
|
return files
|
||||||
|
|
||||||
|
|
@ -850,8 +890,7 @@ class Mage8(Mage):
|
||||||
files.append(f"{name}.QSO")
|
files.append(f"{name}.QSO")
|
||||||
|
|
||||||
for bound in bounds:
|
for bound in bounds:
|
||||||
# File header
|
name = self.get_node_name(bound.node)
|
||||||
name = f"{bound.node.id:3}".replace(" ", "x")
|
|
||||||
f.write(f"* {bound.node.name} ({name}) {bound.bctype}\n")
|
f.write(f"* {bound.node.name} ({name}) {bound.bctype}\n")
|
||||||
|
|
||||||
d50 = bound.d50
|
d50 = bound.d50
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue